diff options
Diffstat (limited to 'servers/physics_server_2d.h')
-rw-r--r-- | servers/physics_server_2d.h | 233 |
1 files changed, 166 insertions, 67 deletions
diff --git a/servers/physics_server_2d.h b/servers/physics_server_2d.h index 26e1411111..2bff8f5dcb 100644 --- a/servers/physics_server_2d.h +++ b/servers/physics_server_2d.h @@ -28,8 +28,8 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef PHYSICS_2D_SERVER_H -#define PHYSICS_2D_SERVER_H +#ifndef PHYSICS_SERVER_2D_H +#define PHYSICS_SERVER_2D_H #include "core/io/resource.h" #include "core/object/class_db.h" @@ -49,6 +49,7 @@ public: virtual real_t get_total_angular_damp() const = 0; // get density of this body space/area virtual Vector2 get_center_of_mass() const = 0; + virtual Vector2 get_center_of_mass_local() const = 0; virtual real_t get_inverse_mass() const = 0; // get the mass virtual real_t get_inverse_inertia() const = 0; // get density of this body space @@ -94,60 +95,15 @@ public: PhysicsDirectBodyState2D(); }; -//used for script -class PhysicsShapeQueryParameters2D : public RefCounted { - GDCLASS(PhysicsShapeQueryParameters2D, RefCounted); - friend class PhysicsDirectSpaceState2D; - - RES shape_ref; - RID shape; - Transform2D transform; - Vector2 motion; - real_t margin = 0.0; - Set<RID> exclude; - uint32_t collision_mask = UINT32_MAX; - - bool collide_with_bodies = true; - bool collide_with_areas = false; - -protected: - static void _bind_methods(); - -public: - void set_shape(const RES &p_shape_ref); - RES get_shape() const; - void set_shape_rid(const RID &p_shape); - RID get_shape_rid() const; - - void set_transform(const Transform2D &p_transform); - Transform2D get_transform() const; - - void set_motion(const Vector2 &p_motion); - Vector2 get_motion() const; - - void set_margin(real_t p_margin); - real_t get_margin() const; - - void set_collision_mask(uint32_t p_mask); - uint32_t get_collision_mask() const; - - void set_collide_with_bodies(bool p_enable); - bool is_collide_with_bodies_enabled() const; - - void set_collide_with_areas(bool p_enable); - bool is_collide_with_areas_enabled() const; - - void set_exclude(const Vector<RID> &p_exclude); - Vector<RID> get_exclude() const; -}; +class PhysicsRayQueryParameters2D; +class PhysicsPointQueryParameters2D; +class PhysicsShapeQueryParameters2D; class PhysicsDirectSpaceState2D : public Object { GDCLASS(PhysicsDirectSpaceState2D, Object); - Dictionary _intersect_ray(const Vector2 &p_from, const Vector2 &p_to, const Vector<RID> &p_exclude = Vector<RID>(), uint32_t p_layers = 0, bool p_collide_with_bodies = true, bool p_collide_with_areas = false); - Array _intersect_point(const Vector2 &p_point, int p_max_results = 32, const Vector<RID> &p_exclude = Vector<RID>(), uint32_t p_layers = 0, bool p_collide_with_bodies = true, bool p_collide_with_areas = false); - Array _intersect_point_on_canvas(const Vector2 &p_point, ObjectID p_canvas_intance_id, int p_max_results = 32, const Vector<RID> &p_exclude = Vector<RID>(), uint32_t p_layers = 0, bool p_collide_with_bodies = true, bool p_collide_with_areas = false); - Array _intersect_point_impl(const Vector2 &p_point, int p_max_results, const Vector<RID> &p_exclud, uint32_t p_layers, bool p_collide_with_bodies, bool p_collide_with_areas, bool p_filter_by_canvas = false, ObjectID p_canvas_instance_id = ObjectID()); + Dictionary _intersect_ray(const Ref<PhysicsRayQueryParameters2D> &p_ray_query); + Array _intersect_point(const Ref<PhysicsPointQueryParameters2D> &p_point_query, int p_max_results = 32); Array _intersect_shape(const Ref<PhysicsShapeQueryParameters2D> &p_shape_query, int p_max_results = 32); Array _cast_motion(const Ref<PhysicsShapeQueryParameters2D> &p_shape_query); Array _collide_shape(const Ref<PhysicsShapeQueryParameters2D> &p_shape_query, int p_max_results = 32); @@ -157,6 +113,18 @@ protected: static void _bind_methods(); public: + struct RayParameters { + Vector2 from; + Vector2 to; + Set<RID> exclude; + uint32_t collision_mask = UINT32_MAX; + + bool collide_with_bodies = true; + bool collide_with_areas = false; + + bool hit_from_inside = false; + }; + struct RayResult { Vector2 position; Vector2 normal; @@ -166,7 +134,7 @@ public: int shape = 0; }; - virtual bool intersect_ray(const Vector2 &p_from, const Vector2 &p_to, RayResult &r_result, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_layer = UINT32_MAX, bool p_collide_with_bodies = true, bool p_collide_with_areas = false) = 0; + virtual bool intersect_ray(const RayParameters &p_parameters, RayResult &r_result) = 0; struct ShapeResult { RID rid; @@ -175,14 +143,31 @@ public: int shape = 0; }; - virtual int intersect_point(const Vector2 &p_point, ShapeResult *r_results, int p_result_max, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_layer = UINT32_MAX, bool p_collide_with_bodies = true, bool p_collide_with_areas = false, bool p_pick_point = false) = 0; - virtual int intersect_point_on_canvas(const Vector2 &p_point, ObjectID p_canvas_instance_id, ShapeResult *r_results, int p_result_max, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_layer = UINT32_MAX, bool p_collide_with_bodies = true, bool p_collide_with_areas = false, bool p_pick_point = false) = 0; + struct PointParameters { + Vector2 position; + ObjectID canvas_instance_id; + Set<RID> exclude; + uint32_t collision_mask = UINT32_MAX; + + bool collide_with_bodies = true; + bool collide_with_areas = false; - virtual int intersect_shape(const RID &p_shape, const Transform2D &p_xform, const Vector2 &p_motion, real_t p_margin, ShapeResult *r_results, int p_result_max, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_layer = UINT32_MAX, bool p_collide_with_bodies = true, bool p_collide_with_areas = false) = 0; + bool pick_point = false; + }; + + virtual int intersect_point(const PointParameters &p_parameters, ShapeResult *r_results, int p_result_max) = 0; - virtual bool cast_motion(const RID &p_shape, const Transform2D &p_xform, const Vector2 &p_motion, real_t p_margin, real_t &p_closest_safe, real_t &p_closest_unsafe, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_layer = UINT32_MAX, bool p_collide_with_bodies = true, bool p_collide_with_areas = false) = 0; + struct ShapeParameters { + RID shape_rid; + Transform2D transform; + Vector2 motion; + real_t margin = 0.0; + Set<RID> exclude; + uint32_t collision_mask = UINT32_MAX; - virtual bool collide_shape(RID p_shape, const Transform2D &p_shape_xform, const Vector2 &p_motion, real_t p_margin, Vector2 *r_results, int p_result_max, int &r_result_count, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_layer = UINT32_MAX, bool p_collide_with_bodies = true, bool p_collide_with_areas = false) = 0; + bool collide_with_bodies = true; + bool collide_with_areas = false; + }; struct ShapeRestInfo { Vector2 point; @@ -190,10 +175,13 @@ public: RID rid; ObjectID collider_id; int shape = 0; - Vector2 linear_velocity; //velocity at contact point + Vector2 linear_velocity; // Velocity at contact point. }; - virtual bool rest_info(RID p_shape, const Transform2D &p_shape_xform, const Vector2 &p_motion, real_t p_margin, ShapeRestInfo *r_info, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_layer = UINT32_MAX, bool p_collide_with_bodies = true, bool p_collide_with_areas = false) = 0; + virtual int intersect_shape(const ShapeParameters &p_parameters, ShapeResult *r_results, int p_result_max) = 0; + virtual bool cast_motion(const ShapeParameters &p_parameters, real_t &p_closest_safe, real_t &p_closest_unsafe) = 0; + virtual bool collide_shape(const ShapeParameters &p_parameters, Vector2 *r_results, int p_result_max, int &r_result_count) = 0; + virtual bool rest_info(const ShapeParameters &p_parameters, ShapeRestInfo *r_info) = 0; PhysicsDirectSpaceState2D(); }; @@ -278,12 +266,15 @@ public: //missing attenuation? missing better override? enum AreaParameter { + AREA_PARAM_GRAVITY_OVERRIDE_MODE, AREA_PARAM_GRAVITY, AREA_PARAM_GRAVITY_VECTOR, AREA_PARAM_GRAVITY_IS_POINT, AREA_PARAM_GRAVITY_DISTANCE_SCALE, AREA_PARAM_GRAVITY_POINT_ATTENUATION, + AREA_PARAM_LINEAR_DAMP_OVERRIDE_MODE, AREA_PARAM_LINEAR_DAMP, + AREA_PARAM_ANGULAR_DAMP_OVERRIDE_MODE, AREA_PARAM_ANGULAR_DAMP, AREA_PARAM_PRIORITY }; @@ -301,9 +292,6 @@ public: AREA_SPACE_OVERRIDE_REPLACE_COMBINE // Discards all previous calculations, then keeps combining }; - virtual void area_set_space_override_mode(RID p_area, AreaSpaceOverrideMode p_mode) = 0; - virtual AreaSpaceOverrideMode area_get_space_override_mode(RID p_area) const = 0; - virtual void area_add_shape(RID p_area, RID p_shape, const Transform2D &p_transform = Transform2D(), bool p_disabled = false) = 0; virtual void area_set_shape(RID p_area, int p_shape_idx, RID p_shape) = 0; virtual void area_set_shape_transform(RID p_area, int p_shape_idx, const Transform2D &p_transform) = 0; @@ -335,8 +323,8 @@ public: virtual void area_set_monitorable(RID p_area, bool p_monitorable) = 0; virtual void area_set_pickable(RID p_area, bool p_pickable) = 0; - virtual void area_set_monitor_callback(RID p_area, Object *p_receiver, const StringName &p_method) = 0; - virtual void area_set_area_monitor_callback(RID p_area, Object *p_receiver, const StringName &p_method) = 0; + virtual void area_set_monitor_callback(RID p_area, const Callable &p_callback) = 0; + virtual void area_set_area_monitor_callback(RID p_area, const Callable &p_callback) = 0; /* BODY API */ @@ -400,11 +388,18 @@ public: BODY_PARAM_INERTIA, BODY_PARAM_CENTER_OF_MASS, BODY_PARAM_GRAVITY_SCALE, + BODY_PARAM_LINEAR_DAMP_MODE, + BODY_PARAM_ANGULAR_DAMP_MODE, BODY_PARAM_LINEAR_DAMP, BODY_PARAM_ANGULAR_DAMP, BODY_PARAM_MAX, }; + enum BodyDampMode { + BODY_DAMP_MODE_COMBINE, + BODY_DAMP_MODE_REPLACE, + }; + virtual void body_set_param(RID p_body, BodyParameter p_param, const Variant &p_value) = 0; virtual Variant body_get_param(RID p_body, BodyParameter p_param) const = 0; @@ -585,6 +580,110 @@ public: ~PhysicsServer2D(); }; +class PhysicsRayQueryParameters2D : public RefCounted { + GDCLASS(PhysicsRayQueryParameters2D, RefCounted); + + PhysicsDirectSpaceState2D::RayParameters parameters; + +protected: + static void _bind_methods(); + +public: + const PhysicsDirectSpaceState2D::RayParameters &get_parameters() const { return parameters; } + + void set_from(const Vector2 &p_from) { parameters.from = p_from; } + const Vector2 &get_from() const { return parameters.from; } + + void set_to(const Vector2 &p_to) { parameters.to = p_to; } + const Vector2 &get_to() const { return parameters.to; } + + void set_collision_mask(uint32_t p_mask) { parameters.collision_mask = p_mask; } + uint32_t get_collision_mask() const { return parameters.collision_mask; } + + void set_collide_with_bodies(bool p_enable) { parameters.collide_with_bodies = p_enable; } + bool is_collide_with_bodies_enabled() const { return parameters.collide_with_bodies; } + + void set_collide_with_areas(bool p_enable) { parameters.collide_with_areas = p_enable; } + bool is_collide_with_areas_enabled() const { return parameters.collide_with_areas; } + + void set_hit_from_inside(bool p_enable) { parameters.hit_from_inside = p_enable; } + bool is_hit_from_inside_enabled() const { return parameters.hit_from_inside; } + + void set_exclude(const Vector<RID> &p_exclude); + Vector<RID> get_exclude() const; +}; + +class PhysicsPointQueryParameters2D : public RefCounted { + GDCLASS(PhysicsPointQueryParameters2D, RefCounted); + + PhysicsDirectSpaceState2D::PointParameters parameters; + +protected: + static void _bind_methods(); + +public: + const PhysicsDirectSpaceState2D::PointParameters &get_parameters() const { return parameters; } + + void set_position(const Vector2 &p_position) { parameters.position = p_position; } + const Vector2 &get_position() const { return parameters.position; } + + void set_canvas_instance_id(ObjectID p_canvas_instance_id) { parameters.canvas_instance_id = p_canvas_instance_id; } + ObjectID get_canvas_instance_id() const { return parameters.canvas_instance_id; } + + void set_collision_mask(uint32_t p_mask) { parameters.collision_mask = p_mask; } + uint32_t get_collision_mask() const { return parameters.collision_mask; } + + void set_collide_with_bodies(bool p_enable) { parameters.collide_with_bodies = p_enable; } + bool is_collide_with_bodies_enabled() const { return parameters.collide_with_bodies; } + + void set_collide_with_areas(bool p_enable) { parameters.collide_with_areas = p_enable; } + bool is_collide_with_areas_enabled() const { return parameters.collide_with_areas; } + + void set_exclude(const Vector<RID> &p_exclude); + Vector<RID> get_exclude() const; +}; + +class PhysicsShapeQueryParameters2D : public RefCounted { + GDCLASS(PhysicsShapeQueryParameters2D, RefCounted); + + PhysicsDirectSpaceState2D::ShapeParameters parameters; + + RES shape_ref; + +protected: + static void _bind_methods(); + +public: + const PhysicsDirectSpaceState2D::ShapeParameters &get_parameters() const { return parameters; } + + void set_shape(const RES &p_shape_ref); + RES get_shape() const { return shape_ref; } + + void set_shape_rid(const RID &p_shape); + RID get_shape_rid() const { return parameters.shape_rid; } + + void set_transform(const Transform2D &p_transform) { parameters.transform = p_transform; } + const Transform2D &get_transform() const { return parameters.transform; } + + void set_motion(const Vector2 &p_motion) { parameters.motion = p_motion; } + const Vector2 &get_motion() const { return parameters.motion; } + + void set_margin(real_t p_margin) { parameters.margin = p_margin; } + real_t get_margin() const { return parameters.margin; } + + void set_collision_mask(uint32_t p_mask) { parameters.collision_mask = p_mask; } + uint32_t get_collision_mask() const { return parameters.collision_mask; } + + void set_collide_with_bodies(bool p_enable) { parameters.collide_with_bodies = p_enable; } + bool is_collide_with_bodies_enabled() const { return parameters.collide_with_bodies; } + + void set_collide_with_areas(bool p_enable) { parameters.collide_with_areas = p_enable; } + bool is_collide_with_areas_enabled() const { return parameters.collide_with_areas; } + + void set_exclude(const Vector<RID> &p_exclude); + Vector<RID> get_exclude() const; +}; + class PhysicsTestMotionParameters2D : public RefCounted { GDCLASS(PhysicsTestMotionParameters2D, RefCounted); @@ -692,13 +791,13 @@ VARIANT_ENUM_CAST(PhysicsServer2D::AreaParameter); VARIANT_ENUM_CAST(PhysicsServer2D::AreaSpaceOverrideMode); VARIANT_ENUM_CAST(PhysicsServer2D::BodyMode); VARIANT_ENUM_CAST(PhysicsServer2D::BodyParameter); +VARIANT_ENUM_CAST(PhysicsServer2D::BodyDampMode); VARIANT_ENUM_CAST(PhysicsServer2D::BodyState); VARIANT_ENUM_CAST(PhysicsServer2D::CCDMode); VARIANT_ENUM_CAST(PhysicsServer2D::JointParam); VARIANT_ENUM_CAST(PhysicsServer2D::JointType); VARIANT_ENUM_CAST(PhysicsServer2D::DampedSpringParam); -//VARIANT_ENUM_CAST( PhysicsServer2D::ObjectType ); VARIANT_ENUM_CAST(PhysicsServer2D::AreaBodyStatus); VARIANT_ENUM_CAST(PhysicsServer2D::ProcessInfo); -#endif +#endif // PHYSICS_SERVER_2D_H |