diff options
Diffstat (limited to 'servers/physics_server_3d.h')
-rw-r--r-- | servers/physics_server_3d.h | 297 |
1 files changed, 219 insertions, 78 deletions
diff --git a/servers/physics_server_3d.h b/servers/physics_server_3d.h index c2fdb0a19b..8883443e34 100644 --- a/servers/physics_server_3d.h +++ b/servers/physics_server_3d.h @@ -28,8 +28,8 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef PHYSICS_SERVER_H -#define PHYSICS_SERVER_H +#ifndef PHYSICS_SERVER_3D_H +#define PHYSICS_SERVER_3D_H #include "core/io/resource.h" #include "core/object/class_db.h" @@ -96,55 +96,18 @@ public: PhysicsDirectBodyState3D(); }; -class PhysicsShapeQueryParameters3D : public RefCounted { - GDCLASS(PhysicsShapeQueryParameters3D, RefCounted); - friend class PhysicsDirectSpaceState3D; - - RES shape_ref; - RID shape; - Transform3D transform; - 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 Transform3D &p_transform); - Transform3D get_transform() const; - - void set_margin(real_t p_margin); - real_t get_margin() const; - - void set_collision_mask(uint32_t p_collision_mask); - uint32_t get_collision_mask() const; - - void set_exclude(const Vector<RID> &p_exclude); - Vector<RID> get_exclude() 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; -}; +class PhysicsRayQueryParameters3D; +class PhysicsPointQueryParameters3D; +class PhysicsShapeQueryParameters3D; class PhysicsDirectSpaceState3D : public Object { GDCLASS(PhysicsDirectSpaceState3D, Object); private: - Dictionary _intersect_ray(const Vector3 &p_from, const Vector3 &p_to, const Vector<RID> &p_exclude = Vector<RID>(), uint32_t p_collision_mask = UINT32_MAX, bool p_collide_with_bodies = true, bool p_collide_with_areas = false); + Dictionary _intersect_ray(const Ref<PhysicsRayQueryParameters3D> &p_ray_query); + Array _intersect_point(const Ref<PhysicsPointQueryParameters3D> &p_point_query, int p_max_results = 32); Array _intersect_shape(const Ref<PhysicsShapeQueryParameters3D> &p_shape_query, int p_max_results = 32); - Array _cast_motion(const Ref<PhysicsShapeQueryParameters3D> &p_shape_query, const Vector3 &p_motion); + Array _cast_motion(const Ref<PhysicsShapeQueryParameters3D> &p_shape_query); Array _collide_shape(const Ref<PhysicsShapeQueryParameters3D> &p_shape_query, int p_max_results = 32); Dictionary _get_rest_info(const Ref<PhysicsShapeQueryParameters3D> &p_shape_query); @@ -152,27 +115,58 @@ protected: static void _bind_methods(); public: - struct ShapeResult { + struct RayParameters { + Vector3 from; + Vector3 to; + Set<RID> exclude; + uint32_t collision_mask = UINT32_MAX; + + bool collide_with_bodies = true; + bool collide_with_areas = false; + + bool pick_ray = false; + }; + + struct RayResult { + Vector3 position; + Vector3 normal; RID rid; ObjectID collider_id; Object *collider = nullptr; int shape = 0; }; - virtual int intersect_point(const Vector3 &p_point, ShapeResult *r_results, int p_result_max, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = 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 RayResult { - Vector3 position; - Vector3 normal; + struct ShapeResult { RID rid; ObjectID collider_id; Object *collider = nullptr; int shape = 0; }; - virtual bool intersect_ray(const Vector3 &p_from, const Vector3 &p_to, RayResult &r_result, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = UINT32_MAX, bool p_collide_with_bodies = true, bool p_collide_with_areas = false, bool p_pick_ray = false) = 0; + struct PointParameters { + Vector3 position; + Set<RID> exclude; + uint32_t collision_mask = UINT32_MAX; + + bool collide_with_bodies = true; + bool collide_with_areas = false; + }; + + virtual int intersect_point(const PointParameters &p_parameters, ShapeResult *r_results, int p_result_max) = 0; - virtual int intersect_shape(const RID &p_shape, const Transform3D &p_xform, real_t p_margin, ShapeResult *r_results, int p_result_max, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = UINT32_MAX, bool p_collide_with_bodies = true, bool p_collide_with_areas = false) = 0; + struct ShapeParameters { + RID shape_rid; + Transform3D transform; + Vector3 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; + }; struct ShapeRestInfo { Vector3 point; @@ -180,14 +174,13 @@ public: RID rid; ObjectID collider_id; int shape = 0; - Vector3 linear_velocity; //velocity at contact point + Vector3 linear_velocity; // Velocity at contact point. }; - virtual bool cast_motion(const RID &p_shape, const Transform3D &p_xform, const Vector3 &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_mask = UINT32_MAX, bool p_collide_with_bodies = true, bool p_collide_with_areas = false, ShapeRestInfo *r_info = nullptr) = 0; - - virtual bool collide_shape(RID p_shape, const Transform3D &p_shape_xform, real_t p_margin, Vector3 *r_results, int p_result_max, int &r_result_count, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = UINT32_MAX, bool p_collide_with_bodies = true, bool p_collide_with_areas = false) = 0; - - virtual bool rest_info(RID p_shape, const Transform3D &p_shape_xform, real_t p_margin, ShapeRestInfo *r_info, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = 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, ShapeRestInfo *r_info = nullptr) = 0; + virtual bool collide_shape(const ShapeParameters &p_parameters, Vector3 *r_results, int p_result_max, int &r_result_count) = 0; + virtual bool rest_info(const ShapeParameters &p_parameters, ShapeRestInfo *r_info) = 0; virtual Vector3 get_closest_point_to_object_volume(RID p_object, const Vector3 p_point) const = 0; @@ -203,6 +196,7 @@ public: virtual ~RenderingServerHandler() {} }; +class PhysicsTestMotionParameters3D; class PhysicsTestMotionResult3D; class PhysicsServer3D : public Object { @@ -210,7 +204,7 @@ class PhysicsServer3D : public Object { static PhysicsServer3D *singleton; - virtual bool _body_test_motion(RID p_body, const Transform3D &p_from, const Vector3 &p_motion, real_t p_margin = 0.001, const Ref<PhysicsTestMotionResult3D> &p_result = Ref<PhysicsTestMotionResult3D>(), bool p_collide_separation_ray = false, const Vector<RID> &p_exclude = Vector<RID>(), int p_max_collisions = 1); + virtual bool _body_test_motion(RID p_body, const Ref<PhysicsTestMotionParameters3D> &p_parameters, const Ref<PhysicsTestMotionResult3D> &p_result = Ref<PhysicsTestMotionResult3D>()); protected: static void _bind_methods(); @@ -347,8 +341,8 @@ public: virtual void area_set_monitorable(RID p_area, bool p_monitorable) = 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; virtual void area_set_ray_pickable(RID p_area, bool p_enable) = 0; @@ -363,6 +357,11 @@ public: BODY_MODE_DYNAMIC_LINEAR, }; + enum BodyDampMode { + BODY_DAMP_MODE_COMBINE, + BODY_DAMP_MODE_REPLACE, + }; + virtual RID body_create() = 0; virtual void body_set_space(RID p_body, RID p_space) = 0; @@ -407,6 +406,8 @@ 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, @@ -483,6 +484,23 @@ public: // this function only works on physics process, errors and returns null otherwise virtual PhysicsDirectBodyState3D *body_get_direct_state(RID p_body) = 0; + struct MotionParameters { + Transform3D from; + Vector3 motion; + real_t margin = 0.001; + int max_collisions = 1; + bool collide_separation_ray = false; + Set<RID> exclude_bodies; + Set<ObjectID> exclude_objects; + + MotionParameters() {} + + MotionParameters(const Transform3D &p_from, const Vector3 &p_motion, real_t p_margin = 0.001) : + from(p_from), + motion(p_motion), + margin(p_margin) {} + }; + struct MotionCollision { Vector3 position; Vector3 normal; @@ -501,15 +519,15 @@ public: struct MotionResult { Vector3 travel; Vector3 remainder; - real_t safe_fraction = 0.0; - real_t unsafe_fraction = 0.0; + real_t collision_safe_fraction = 0.0; + real_t collision_unsafe_fraction = 0.0; static const int MAX_COLLISIONS = 32; MotionCollision collisions[MAX_COLLISIONS]; int collision_count = 0; }; - virtual bool body_test_motion(RID p_body, const Transform3D &p_from, const Vector3 &p_motion, real_t p_margin = 0.001, MotionResult *r_result = nullptr, int p_max_collisions = 1, bool p_collide_separation_ray = false, const Set<RID> &p_exclude = Set<RID>()) = 0; + virtual bool body_test_motion(RID p_body, const MotionParameters &p_parameters, MotionResult *r_result = nullptr) = 0; /* SOFT BODY */ @@ -520,7 +538,7 @@ public: virtual void soft_body_set_space(RID p_body, RID p_space) = 0; virtual RID soft_body_get_space(RID p_body) const = 0; - virtual void soft_body_set_mesh(RID p_body, const REF &p_mesh) = 0; + virtual void soft_body_set_mesh(RID p_body, RID p_mesh) = 0; virtual AABB soft_body_get_bounds(RID p_body) const = 0; @@ -760,11 +778,141 @@ public: ~PhysicsServer3D(); }; +class PhysicsRayQueryParameters3D : public RefCounted { + GDCLASS(PhysicsRayQueryParameters3D, RefCounted); + + PhysicsDirectSpaceState3D::RayParameters parameters; + +protected: + static void _bind_methods(); + +public: + const PhysicsDirectSpaceState3D::RayParameters &get_parameters() const { return parameters; } + + void set_from(const Vector3 &p_from) { parameters.from = p_from; } + const Vector3 &get_from() const { return parameters.from; } + + void set_to(const Vector3 &p_to) { parameters.to = p_to; } + const Vector3 &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_exclude(const Vector<RID> &p_exclude); + Vector<RID> get_exclude() const; +}; + +class PhysicsPointQueryParameters3D : public RefCounted { + GDCLASS(PhysicsPointQueryParameters3D, RefCounted); + + PhysicsDirectSpaceState3D::PointParameters parameters; + +protected: + static void _bind_methods(); + +public: + const PhysicsDirectSpaceState3D::PointParameters &get_parameters() const { return parameters; } + + void set_position(const Vector3 &p_position) { parameters.position = p_position; } + const Vector3 &get_position() const { return parameters.position; } + + 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 PhysicsShapeQueryParameters3D : public RefCounted { + GDCLASS(PhysicsShapeQueryParameters3D, RefCounted); + + PhysicsDirectSpaceState3D::ShapeParameters parameters; + + RES shape_ref; + +protected: + static void _bind_methods(); + +public: + const PhysicsDirectSpaceState3D::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 Transform3D &p_transform) { parameters.transform = p_transform; } + const Transform3D &get_transform() const { return parameters.transform; } + + void set_motion(const Vector3 &p_motion) { parameters.motion = p_motion; } + const Vector3 &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 PhysicsTestMotionParameters3D : public RefCounted { + GDCLASS(PhysicsTestMotionParameters3D, RefCounted); + + PhysicsServer3D::MotionParameters parameters; + +protected: + static void _bind_methods(); + +public: + const PhysicsServer3D::MotionParameters &get_parameters() const { return parameters; } + + const Transform3D &get_from() const { return parameters.from; } + void set_from(const Transform3D &p_from) { parameters.from = p_from; } + + const Vector3 &get_motion() const { return parameters.motion; } + void set_motion(const Vector3 &p_motion) { parameters.motion = p_motion; } + + real_t get_margin() const { return parameters.margin; } + void set_margin(real_t p_margin) { parameters.margin = p_margin; } + + int get_max_collisions() const { return parameters.max_collisions; } + void set_max_collisions(int p_max_collisions) { parameters.max_collisions = p_max_collisions; } + + bool is_collide_separation_ray_enabled() const { return parameters.collide_separation_ray; } + void set_collide_separation_ray_enabled(bool p_enabled) { parameters.collide_separation_ray = p_enabled; } + + Vector<RID> get_exclude_bodies() const; + void set_exclude_bodies(const Vector<RID> &p_exclude); + + Array get_exclude_objects() const; + void set_exclude_objects(const Array &p_exclude); +}; + class PhysicsTestMotionResult3D : public RefCounted { GDCLASS(PhysicsTestMotionResult3D, RefCounted); PhysicsServer3D::MotionResult result; - friend class PhysicsServer3D; protected: static void _bind_methods(); @@ -774,8 +922,8 @@ public: Vector3 get_travel() const; Vector3 get_remainder() const; - real_t get_safe_fraction() const; - real_t get_unsafe_fraction() const; + real_t get_collision_safe_fraction() const; + real_t get_collision_unsafe_fraction() const; int get_collision_count() const; @@ -786,16 +934,8 @@ public: RID get_collider_rid(int p_collision_index = 0) const; Object *get_collider(int p_collision_index = 0) const; int get_collider_shape(int p_collision_index = 0) const; + int get_collision_local_shape(int p_collision_index = 0) const; real_t get_collision_depth(int p_collision_index = 0) const; - - Vector3 get_best_collision_point() const; - Vector3 get_best_collision_normal() const; - Vector3 get_best_collider_velocity() const; - ObjectID get_best_collider_id() const; - RID get_best_collider_rid() const; - Object *get_best_collider() const; - int get_best_collider_shape() const; - real_t get_best_collision_depth() const; }; typedef PhysicsServer3D *(*CreatePhysicsServer3DCallback)(); @@ -848,6 +988,7 @@ VARIANT_ENUM_CAST(PhysicsServer3D::AreaParameter); VARIANT_ENUM_CAST(PhysicsServer3D::AreaSpaceOverrideMode); VARIANT_ENUM_CAST(PhysicsServer3D::BodyMode); VARIANT_ENUM_CAST(PhysicsServer3D::BodyParameter); +VARIANT_ENUM_CAST(PhysicsServer3D::BodyDampMode); VARIANT_ENUM_CAST(PhysicsServer3D::BodyState); VARIANT_ENUM_CAST(PhysicsServer3D::BodyAxis); VARIANT_ENUM_CAST(PhysicsServer3D::PinJointParam); @@ -861,4 +1002,4 @@ VARIANT_ENUM_CAST(PhysicsServer3D::G6DOFJointAxisFlag); VARIANT_ENUM_CAST(PhysicsServer3D::AreaBodyStatus); VARIANT_ENUM_CAST(PhysicsServer3D::ProcessInfo); -#endif +#endif // PHYSICS_SERVER_3D_H |