Path: blob/master/scene/2d/physics/collision_object_2d.h
9906 views
/**************************************************************************/1/* collision_object_2d.h */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#pragma once3132#include "scene/2d/node_2d.h"33#include "scene/main/viewport.h"34#include "scene/resources/2d/shape_2d.h"35#include "servers/physics_server_2d.h"3637class CollisionObject2D : public Node2D {38GDCLASS(CollisionObject2D, Node2D);3940public:41enum DisableMode {42DISABLE_MODE_REMOVE,43DISABLE_MODE_MAKE_STATIC,44DISABLE_MODE_KEEP_ACTIVE,45};4647private:48uint32_t collision_layer = 1;49uint32_t collision_mask = 1;50real_t collision_priority = 1.0;5152bool area = false;53RID rid;54uint32_t callback_lock = 0;55bool pickable = false;5657DisableMode disable_mode = DISABLE_MODE_REMOVE;5859PhysicsServer2D::BodyMode body_mode = PhysicsServer2D::BODY_MODE_STATIC;6061struct ShapeData {62ObjectID owner_id;63Transform2D xform;64struct Shape {65Ref<Shape2D> shape;66int index = 0;67};6869Vector<Shape> shapes;7071bool disabled = false;72bool one_way_collision = false;73real_t one_way_collision_margin = 0.0;74};7576int total_subshapes = 0;7778RBMap<uint32_t, ShapeData> shapes;79bool only_update_transform_changes = false; // This is used for sync to physics.8081void _apply_disabled();82void _apply_enabled();8384protected:85_FORCE_INLINE_ void lock_callback() { callback_lock++; }86_FORCE_INLINE_ void unlock_callback() {87ERR_FAIL_COND(callback_lock == 0);88callback_lock--;89}9091CollisionObject2D(RID p_rid, bool p_area);9293void _notification(int p_what);94static void _bind_methods();9596void _update_pickable();97friend class Viewport;98void _input_event_call(Viewport *p_viewport, const Ref<InputEvent> &p_input_event, int p_shape);99void _mouse_enter();100void _mouse_exit();101102void _mouse_shape_enter(int p_shape);103void _mouse_shape_exit(int p_shape);104105void set_only_update_transform_changes(bool p_enable);106bool is_only_update_transform_changes_enabled() const;107108void set_body_mode(PhysicsServer2D::BodyMode p_mode);109110virtual void _space_changed(const RID &p_new_space);111112GDVIRTUAL3(_input_event, Viewport *, Ref<InputEvent>, int)113GDVIRTUAL0(_mouse_enter)114GDVIRTUAL0(_mouse_exit)115GDVIRTUAL1(_mouse_shape_enter, int)116GDVIRTUAL1(_mouse_shape_exit, int)117public:118void set_collision_layer(uint32_t p_layer);119uint32_t get_collision_layer() const;120121void set_collision_mask(uint32_t p_mask);122uint32_t get_collision_mask() const;123124void set_collision_layer_value(int p_layer_number, bool p_value);125bool get_collision_layer_value(int p_layer_number) const;126127void set_collision_mask_value(int p_layer_number, bool p_value);128bool get_collision_mask_value(int p_layer_number) const;129130void set_collision_priority(real_t p_priority);131real_t get_collision_priority() const;132133void set_disable_mode(DisableMode p_mode);134DisableMode get_disable_mode() const;135136uint32_t create_shape_owner(Object *p_owner);137void remove_shape_owner(uint32_t owner);138void get_shape_owners(List<uint32_t> *r_owners);139PackedInt32Array _get_shape_owners();140141void shape_owner_set_transform(uint32_t p_owner, const Transform2D &p_transform);142Transform2D shape_owner_get_transform(uint32_t p_owner) const;143Object *shape_owner_get_owner(uint32_t p_owner) const;144145void shape_owner_set_disabled(uint32_t p_owner, bool p_disabled);146bool is_shape_owner_disabled(uint32_t p_owner) const;147148void shape_owner_set_one_way_collision(uint32_t p_owner, bool p_enable);149bool is_shape_owner_one_way_collision_enabled(uint32_t p_owner) const;150151void shape_owner_set_one_way_collision_margin(uint32_t p_owner, real_t p_margin);152real_t get_shape_owner_one_way_collision_margin(uint32_t p_owner) const;153154void shape_owner_add_shape(uint32_t p_owner, const Ref<Shape2D> &p_shape);155int shape_owner_get_shape_count(uint32_t p_owner) const;156Ref<Shape2D> shape_owner_get_shape(uint32_t p_owner, int p_shape) const;157int shape_owner_get_shape_index(uint32_t p_owner, int p_shape) const;158159void shape_owner_remove_shape(uint32_t p_owner, int p_shape);160void shape_owner_clear_shapes(uint32_t p_owner);161162uint32_t shape_find_owner(int p_shape_index) const;163164void set_pickable(bool p_enabled);165bool is_pickable() const;166167PackedStringArray get_configuration_warnings() const override;168169_FORCE_INLINE_ RID get_rid() const { return rid; }170171CollisionObject2D();172~CollisionObject2D();173};174175VARIANT_ENUM_CAST(CollisionObject2D::DisableMode);176177178