diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2017-02-26 20:10:54 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-02-26 20:10:54 +0100 |
commit | f13e87e25799aafa4462779650c7d6222c782b31 (patch) | |
tree | b28e5eed3cba37a72eabcf6eb849852275624a48 | |
parent | a23e062c281292b75083c71a0a1deb03cb57c788 (diff) | |
parent | eae94ba1c87718c95768f90cda95cf665c77a362 (diff) |
Merge pull request #7802 from tagcup/physics_64bit
Use real_t as floating point type in physics code.
54 files changed, 472 insertions, 520 deletions
diff --git a/servers/physics/area_pair_sw.cpp b/servers/physics/area_pair_sw.cpp index e95c85d751..3aa0816b06 100644 --- a/servers/physics/area_pair_sw.cpp +++ b/servers/physics/area_pair_sw.cpp @@ -30,7 +30,7 @@ #include "collision_solver_sw.h" -bool AreaPairSW::setup(float p_step) { +bool AreaPairSW::setup(real_t p_step) { if (!area->test_collision_mask(body)) { colliding = false; @@ -64,7 +64,7 @@ bool AreaPairSW::setup(float p_step) { return false; //never do any post solving } -void AreaPairSW::solve(float p_step) { +void AreaPairSW::solve(real_t p_step) { } @@ -103,7 +103,7 @@ AreaPairSW::~AreaPairSW() { -bool Area2PairSW::setup(float p_step) { +bool Area2PairSW::setup(real_t p_step) { if (!area_a->test_collision_mask(area_b)) { colliding = false; @@ -139,7 +139,7 @@ bool Area2PairSW::setup(float p_step) { return false; //never do any post solving } -void Area2PairSW::solve(float p_step) { +void Area2PairSW::solve(real_t p_step) { } diff --git a/servers/physics/area_pair_sw.h b/servers/physics/area_pair_sw.h index 17477dcbd2..637976a095 100644 --- a/servers/physics/area_pair_sw.h +++ b/servers/physics/area_pair_sw.h @@ -42,8 +42,8 @@ class AreaPairSW : public ConstraintSW { bool colliding; public: - bool setup(float p_step); - void solve(float p_step); + bool setup(real_t p_step); + void solve(real_t p_step); AreaPairSW(BodySW *p_body,int p_body_shape, AreaSW *p_area,int p_area_shape); ~AreaPairSW(); @@ -59,8 +59,8 @@ class Area2PairSW : public ConstraintSW { bool colliding; public: - bool setup(float p_step); - void solve(float p_step); + bool setup(real_t p_step); + void solve(real_t p_step); Area2PairSW(AreaSW *p_area_a,int p_shape_a, AreaSW *p_area_b,int p_shape_b); ~Area2PairSW(); diff --git a/servers/physics/area_sw.h b/servers/physics/area_sw.h index 5ac6985409..4e6f1c5a51 100644 --- a/servers/physics/area_sw.h +++ b/servers/physics/area_sw.h @@ -42,13 +42,13 @@ class AreaSW : public CollisionObjectSW{ PhysicsServer::AreaSpaceOverrideMode space_override_mode; - float gravity; + real_t gravity; Vector3 gravity_vector; bool gravity_is_point; - float gravity_distance_scale; - float point_attenuation; - float linear_damp; - float angular_damp; + real_t gravity_distance_scale; + real_t point_attenuation; + real_t linear_damp; + real_t angular_damp; int priority; bool monitorable; @@ -131,8 +131,8 @@ public: void set_space_override_mode(PhysicsServer::AreaSpaceOverrideMode p_mode); PhysicsServer::AreaSpaceOverrideMode get_space_override_mode() const { return space_override_mode; } - _FORCE_INLINE_ void set_gravity(float p_gravity) { gravity=p_gravity; } - _FORCE_INLINE_ float get_gravity() const { return gravity; } + _FORCE_INLINE_ void set_gravity(real_t p_gravity) { gravity=p_gravity; } + _FORCE_INLINE_ real_t get_gravity() const { return gravity; } _FORCE_INLINE_ void set_gravity_vector(const Vector3& p_gravity) { gravity_vector=p_gravity; } _FORCE_INLINE_ Vector3 get_gravity_vector() const { return gravity_vector; } @@ -140,17 +140,17 @@ public: _FORCE_INLINE_ void set_gravity_as_point(bool p_enable) { gravity_is_point=p_enable; } _FORCE_INLINE_ bool is_gravity_point() const { return gravity_is_point; } - _FORCE_INLINE_ void set_gravity_distance_scale(float scale) { gravity_distance_scale=scale; } - _FORCE_INLINE_ float get_gravity_distance_scale() const { return gravity_distance_scale; } + _FORCE_INLINE_ void set_gravity_distance_scale(real_t scale) { gravity_distance_scale=scale; } + _FORCE_INLINE_ real_t get_gravity_distance_scale() const { return gravity_distance_scale; } - _FORCE_INLINE_ void set_point_attenuation(float p_point_attenuation) { point_attenuation=p_point_attenuation; } - _FORCE_INLINE_ float get_point_attenuation() const { return point_attenuation; } + _FORCE_INLINE_ void set_point_attenuation(real_t p_point_attenuation) { point_attenuation=p_point_attenuation; } + _FORCE_INLINE_ real_t get_point_attenuation() const { return point_attenuation; } - _FORCE_INLINE_ void set_linear_damp(float p_linear_damp) { linear_damp=p_linear_damp; } - _FORCE_INLINE_ float get_linear_damp() const { return linear_damp; } + _FORCE_INLINE_ void set_linear_damp(real_t p_linear_damp) { linear_damp=p_linear_damp; } + _FORCE_INLINE_ real_t get_linear_damp() const { return linear_damp; } - _FORCE_INLINE_ void set_angular_damp(float p_angular_damp) { angular_damp=p_angular_damp; } - _FORCE_INLINE_ float get_angular_damp() const { return angular_damp; } + _FORCE_INLINE_ void set_angular_damp(real_t p_angular_damp) { angular_damp=p_angular_damp; } + _FORCE_INLINE_ real_t get_angular_damp() const { return angular_damp; } _FORCE_INLINE_ void set_priority(int p_priority) { priority=p_priority; } _FORCE_INLINE_ int get_priority() const { return priority; } diff --git a/servers/physics/body_pair_sw.cpp b/servers/physics/body_pair_sw.cpp index 7defa87bb1..7fb3def387 100644 --- a/servers/physics/body_pair_sw.cpp +++ b/servers/physics/body_pair_sw.cpp @@ -105,7 +105,7 @@ void BodyPairSW::contact_added_callback(const Vector3& p_point_A,const Vector3& // remove the contact with the minimum depth int least_deep=-1; - float min_depth=1e10; + real_t min_depth=1e10; for (int i=0;i<=contact_count;i++) { @@ -114,7 +114,7 @@ void BodyPairSW::contact_added_callback(const Vector3& p_point_A,const Vector3& Vector3 global_B = B->get_transform().basis.xform(c.local_B)+offset_B; Vector3 axis = global_A - global_B; - float depth = axis.dot( c.normal ); + real_t depth = axis.dot( c.normal ); if (depth<min_depth) { @@ -154,7 +154,7 @@ void BodyPairSW::validate_contacts() { Vector3 global_A = A->get_transform().basis.xform(c.local_A); Vector3 global_B = B->get_transform().basis.xform(c.local_B)+offset_B; Vector3 axis = global_A - global_B; - float depth = axis.dot( c.normal ); + real_t depth = axis.dot( c.normal ); if (depth < -contact_max_separation || (global_B + c.normal * depth - global_A).length() > contact_max_separation) { // contact no longer needed, remove @@ -173,7 +173,7 @@ void BodyPairSW::validate_contacts() { } -bool BodyPairSW::_test_ccd(float p_step,BodySW *p_A, int p_shape_A,const Transform& p_xform_A,BodySW *p_B, int p_shape_B,const Transform& p_xform_B) { +bool BodyPairSW::_test_ccd(real_t p_step,BodySW *p_A, int p_shape_A,const Transform& p_xform_A,BodySW *p_B, int p_shape_B,const Transform& p_xform_B) { @@ -211,14 +211,14 @@ bool BodyPairSW::_test_ccd(float p_step,BodySW *p_A, int p_shape_A,const Transfo //shorten the linear velocity so it does not hit, but gets close enough, next frame will hit softly or soft enough Vector3 hitpos = p_xform_B.xform(rpos); - float newlen = hitpos.distance_to(from)-(max-min)*0.01; + real_t newlen = hitpos.distance_to(from)-(max-min)*0.01; p_A->set_linear_velocity((mnormal*newlen)/p_step); return true; } -bool BodyPairSW::setup(float p_step) { +bool BodyPairSW::setup(real_t p_step) { //cannot collide if (!A->test_collision_mask(B) || A->has_exception(B->get_self()) || B->has_exception(A->get_self()) || (A->get_mode()<=PhysicsServer::BODY_MODE_KINEMATIC && B->get_mode()<=PhysicsServer::BODY_MODE_KINEMATIC && A->get_max_contacts_reported()==0 && B->get_max_contacts_reported()==0)) { @@ -264,7 +264,7 @@ bool BodyPairSW::setup(float p_step) { real_t max_penetration = space->get_contact_max_allowed_penetration(); - float bias = 0.3f; + real_t bias = (real_t)0.3; if (shape_A_ptr->get_custom_bias() || shape_B_ptr->get_custom_bias()) { @@ -356,7 +356,7 @@ bool BodyPairSW::setup(float p_step) { if (depth > max_penetration) { c.bias = (depth - max_penetration) * (1.0/(p_step*(1.0/RELAXATION_TIMESTEPS))); } else { - float approach = -0.1f * (depth - max_penetration) / (CMP_EPSILON + max_penetration); + real_t approach = -0.1 * (depth - max_penetration) / (CMP_EPSILON + max_penetration); approach = CLAMP( approach, CMP_EPSILON, 1.0 ); c.bias = approach * (depth - max_penetration) * (1.0/p_step); } @@ -387,7 +387,7 @@ bool BodyPairSW::setup(float p_step) { return true; } -void BodyPairSW::solve(float p_step) { +void BodyPairSW::solve(real_t p_step) { if (!collided) return; diff --git a/servers/physics/body_pair_sw.h b/servers/physics/body_pair_sw.h index a37f75d13c..f282a56b9e 100644 --- a/servers/physics/body_pair_sw.h +++ b/servers/physics/body_pair_sw.h @@ -82,14 +82,14 @@ class BodyPairSW : public ConstraintSW { void contact_added_callback(const Vector3& p_point_A,const Vector3& p_point_B); void validate_contacts(); - bool _test_ccd(float p_step,BodySW *p_A, int p_shape_A,const Transform& p_xform_A,BodySW *p_B, int p_shape_B,const Transform& p_xform_B); + bool _test_ccd(real_t p_step,BodySW *p_A, int p_shape_A,const Transform& p_xform_A,BodySW *p_B, int p_shape_B,const Transform& p_xform_B); SpaceSW *space; public: - bool setup(float p_step); - void solve(float p_step); + bool setup(real_t p_step); + void solve(real_t p_step); BodyPairSW(BodySW *p_A, int p_shape_A,BodySW *p_B, int p_shape_B); ~BodyPairSW(); diff --git a/servers/physics/body_sw.cpp b/servers/physics/body_sw.cpp index a67dda3a01..7fcd767268 100644 --- a/servers/physics/body_sw.cpp +++ b/servers/physics/body_sw.cpp @@ -59,7 +59,7 @@ void BodySW::update_inertias() { case PhysicsServer::BODY_MODE_RIGID: { //update tensor for all shapes, not the best way but should be somehow OK. (inspired from bullet) - float total_area=0; + real_t total_area=0; for (int i=0;i<get_shape_count();i++) { @@ -70,9 +70,9 @@ void BodySW::update_inertias() { center_of_mass_local.zero(); for (int i=0; i<get_shape_count(); i++) { - float area=get_shape_area(i); + real_t area=get_shape_area(i); - float mass = area * this->mass / total_area; + real_t mass = area * this->mass / total_area; // NOTE: we assume that the shape origin is also its center of mass center_of_mass_local += mass * get_shape_transform(i).origin; @@ -88,9 +88,9 @@ void BodySW::update_inertias() { const ShapeSW* shape=get_shape(i); - float area=get_shape_area(i); + real_t area=get_shape_area(i); - float mass = area * this->mass / total_area; + real_t mass = area * this->mass / total_area; Basis shape_inertia_tensor=shape->get_moment_of_inertia(mass).to_diagonal_matrix(); Transform shape_transform=get_shape_transform(i); @@ -170,7 +170,7 @@ void BodySW::set_active(bool p_active) { -void BodySW::set_param(PhysicsServer::BodyParameter p_param, float p_value) { +void BodySW::set_param(PhysicsServer::BodyParameter p_param, real_t p_value) { switch(p_param) { case PhysicsServer::BODY_PARAM_BOUNCE: { @@ -202,7 +202,7 @@ void BodySW::set_param(PhysicsServer::BodyParameter p_param, float p_value) { } } -float BodySW::get_param(PhysicsServer::BodyParameter p_param) const { +real_t BodySW::get_param(PhysicsServer::BodyParameter p_param) const { switch(p_param) { case PhysicsServer::BODY_PARAM_BOUNCE: { @@ -511,7 +511,7 @@ void BodySW::integrate_forces(real_t p_step) { //compute a FAKE angular velocity, not so easy Basis rot=new_transform.basis.orthonormalized().transposed() * get_transform().basis.orthonormalized(); Vector3 axis; - float angle; + real_t angle; rot.get_axis_and_angle(axis,angle); axis.normalize(); @@ -615,7 +615,7 @@ void BodySW::integrate_velocities(real_t p_step) { - float ang_vel = total_angular_velocity.length(); + real_t ang_vel = total_angular_velocity.length(); Transform transform = get_transform(); @@ -666,7 +666,7 @@ void BodySW::simulate_motion(const Transform& p_xform,real_t p_step) { //compute a FAKE angular velocity, not so easy Matrix3 rot=get_transform().basis.orthonormalized().transposed() * p_xform.basis.orthonormalized(); Vector3 axis; - float angle; + real_t angle; rot.get_axis_and_angle(axis,angle); axis.normalize(); diff --git a/servers/physics/body_sw.h b/servers/physics/body_sw.h index e6ed3e75e5..2383d2d688 100644 --- a/servers/physics/body_sw.h +++ b/servers/physics/body_sw.h @@ -75,8 +75,8 @@ class BodySW : public CollisionObjectSW { Vector3 applied_force; Vector3 applied_torque; - float area_angular_damp; - float area_linear_damp; + real_t area_angular_damp; + real_t area_linear_damp; SelfList<BodySW> active_list; @@ -115,7 +115,7 @@ class BodySW : public CollisionObjectSW { Vector3 local_pos; Vector3 local_normal; - float depth; + real_t depth; int local_shape; Vector3 collider_pos; int collider_shape; @@ -174,7 +174,7 @@ public: _FORCE_INLINE_ int get_max_contacts_reported() const { return contacts.size(); } _FORCE_INLINE_ bool can_report_contacts() const { return !contacts.empty(); } - _FORCE_INLINE_ void add_contact(const Vector3& p_local_pos,const Vector3& p_local_normal, float p_depth, int p_local_shape, const Vector3& p_collider_pos, int p_collider_shape, ObjectID p_collider_instance_id, const RID& p_collider,const Vector3& p_collider_velocity_at_pos); + _FORCE_INLINE_ void add_contact(const Vector3& p_local_pos,const Vector3& p_local_normal, real_t p_depth, int p_local_shape, const Vector3& p_collider_pos, int p_collider_shape, ObjectID p_collider_instance_id, const RID& p_collider,const Vector3& p_collider_velocity_at_pos); _FORCE_INLINE_ void add_exception(const RID& p_exception) { exceptions.insert(p_exception);} @@ -248,8 +248,8 @@ public: set_active(true); } - void set_param(PhysicsServer::BodyParameter p_param, float); - float get_param(PhysicsServer::BodyParameter p_param) const; + void set_param(PhysicsServer::BodyParameter p_param, real_t); + real_t get_param(PhysicsServer::BodyParameter p_param) const; void set_mode(PhysicsServer::BodyMode p_mode); PhysicsServer::BodyMode get_mode() const; @@ -319,7 +319,7 @@ public: //add contact inline -void BodySW::add_contact(const Vector3& p_local_pos,const Vector3& p_local_normal, float p_depth, int p_local_shape, const Vector3& p_collider_pos, int p_collider_shape, ObjectID p_collider_instance_id, const RID& p_collider,const Vector3& p_collider_velocity_at_pos) { +void BodySW::add_contact(const Vector3& p_local_pos,const Vector3& p_local_normal, real_t p_depth, int p_local_shape, const Vector3& p_collider_pos, int p_collider_shape, ObjectID p_collider_instance_id, const RID& p_collider,const Vector3& p_collider_velocity_at_pos) { int c_max=contacts.size(); @@ -335,7 +335,7 @@ void BodySW::add_contact(const Vector3& p_local_pos,const Vector3& p_local_norma idx=contact_count++; } else { - float least_depth=1e20; + real_t least_depth=1e20; int least_deep=-1; for(int i=0;i<c_max;i++) { @@ -377,13 +377,13 @@ public: real_t step; virtual Vector3 get_total_gravity() const { return body->gravity; } // get gravity vector working on this body space/area - virtual float get_total_angular_damp() const { return body->area_angular_damp; } // get density of this body space/area - virtual float get_total_linear_damp() const { return body->area_linear_damp; } // get density of this body space/area + virtual real_t get_total_angular_damp() const { return body->area_angular_damp; } // get density of this body space/area + virtual real_t get_total_linear_damp() const { return body->area_linear_damp; } // get density of this body space/area virtual Vector3 get_center_of_mass() const { return body->get_center_of_mass(); } virtual Basis get_principal_inertia_axes() const { return body->get_principal_inertia_axes(); } - virtual float get_inverse_mass() const { return body->get_inv_mass(); } // get the mass + virtual real_t get_inverse_mass() const { return body->get_inv_mass(); } // get the mass virtual Vector3 get_inverse_inertia() const { return body->get_inv_inertia(); } // get density of this body space virtual Basis get_inverse_inertia_tensor() const { return body->get_inv_inertia_tensor(); } // get density of this body space diff --git a/servers/physics/collision_solver_sat.cpp b/servers/physics/collision_solver_sat.cpp index d41012caa4..9d3e1db47b 100644 --- a/servers/physics/collision_solver_sat.cpp +++ b/servers/physics/collision_solver_sat.cpp @@ -122,9 +122,9 @@ static void _generate_contacts_edge_edge(const Vector3 * p_points_A,int p_point_ Vector3 base_B = p_points_B[0] - axis * axis.dot(p_points_B[0]); //sort all 4 points in axis - float dvec[4]={ axis.dot(p_points_A[0]), axis.dot(p_points_A[1]), axis.dot(p_points_B[0]), axis.dot(p_points_B[1]) }; + real_t dvec[4]={ axis.dot(p_points_A[0]), axis.dot(p_points_A[1]), axis.dot(p_points_B[0]), axis.dot(p_points_B[1]) }; - SortArray<float> sa; + SortArray<real_t> sa; sa.sort(dvec,4); //use the middle ones as contacts @@ -234,7 +234,7 @@ static void _generate_contacts_face_face(const Vector3 * p_points_A,int p_point_ for (int i=0;i<clipbuf_len;i++) { - float d = plane_B.distance_to(clipbuf_src[i]); + real_t d = plane_B.distance_to(clipbuf_src[i]); /* if (d>CMP_EPSILON) continue; @@ -476,11 +476,11 @@ public: /****** SAT TESTS *******/ -typedef void (*CollisionFunc)(const ShapeSW*,const Transform&,const ShapeSW*,const Transform&,_CollectorCallback *p_callback,float,float); +typedef void (*CollisionFunc)(const ShapeSW*,const Transform&,const ShapeSW*,const Transform&,_CollectorCallback *p_callback,real_t,real_t); template<bool withMargin> -static void _collision_sphere_sphere(const ShapeSW *p_a,const Transform &p_transform_a,const ShapeSW *p_b,const Transform &p_transform_b,_CollectorCallback *p_collector,float p_margin_a,float p_margin_b) { +static void _collision_sphere_sphere(const ShapeSW *p_a,const Transform &p_transform_a,const ShapeSW *p_b,const Transform &p_transform_b,_CollectorCallback *p_collector,real_t p_margin_a,real_t p_margin_b) { const SphereShapeSW *sphere_A = static_cast<const SphereShapeSW*>(p_a); @@ -500,7 +500,7 @@ static void _collision_sphere_sphere(const ShapeSW *p_a,const Transform &p_trans } template<bool withMargin> -static void _collision_sphere_box(const ShapeSW *p_a,const Transform &p_transform_a,const ShapeSW *p_b,const Transform &p_transform_b,_CollectorCallback *p_collector,float p_margin_a,float p_margin_b) { +static void _collision_sphere_box(const ShapeSW *p_a,const Transform &p_transform_a,const ShapeSW *p_b,const Transform &p_transform_b,_CollectorCallback *p_collector,real_t p_margin_a,real_t p_margin_b) { const SphereShapeSW *sphere_A = static_cast<const SphereShapeSW*>(p_a); @@ -555,7 +555,7 @@ static void _collision_sphere_box(const ShapeSW *p_a,const Transform &p_transfor } template<bool withMargin> -static void _collision_sphere_capsule(const ShapeSW *p_a,const Transform &p_transform_a,const ShapeSW *p_b,const Transform &p_transform_b,_CollectorCallback *p_collector,float p_margin_a,float p_margin_b) { +static void _collision_sphere_capsule(const ShapeSW *p_a,const Transform &p_transform_a,const ShapeSW *p_b,const Transform &p_transform_b,_CollectorCallback *p_collector,real_t p_margin_a,real_t p_margin_b) { const SphereShapeSW *sphere_A = static_cast<const SphereShapeSW*>(p_a); const CapsuleShapeSW *capsule_B = static_cast<const CapsuleShapeSW*>(p_b); @@ -595,7 +595,7 @@ static void _collision_sphere_capsule(const ShapeSW *p_a,const Transform &p_tran } template<bool withMargin> -static void _collision_sphere_convex_polygon(const ShapeSW *p_a,const Transform &p_transform_a,const ShapeSW *p_b,const Transform &p_transform_b,_CollectorCallback *p_collector,float p_margin_a,float p_margin_b) { +static void _collision_sphere_convex_polygon(const ShapeSW *p_a,const Transform &p_transform_a,const ShapeSW *p_b,const Transform &p_transform_b,_CollectorCallback *p_collector,real_t p_margin_a,real_t p_margin_b) { const SphereShapeSW *sphere_A = static_cast<const SphereShapeSW*>(p_a); @@ -666,7 +666,7 @@ static void _collision_sphere_convex_polygon(const ShapeSW *p_a,const Transform } template<bool withMargin> -static void _collision_sphere_face(const ShapeSW *p_a,const Transform &p_transform_a, const ShapeSW *p_b,const Transform& p_transform_b,_CollectorCallback *p_collector,float p_margin_a,float p_margin_b) { +static void _collision_sphere_face(const ShapeSW *p_a,const Transform &p_transform_a, const ShapeSW *p_b,const Transform& p_transform_b,_CollectorCallback *p_collector,real_t p_margin_a,real_t p_margin_b) { const SphereShapeSW *sphere_A = static_cast<const SphereShapeSW*>(p_a); const FaceShapeSW *face_B = static_cast<const FaceShapeSW*>(p_b); @@ -710,7 +710,7 @@ static void _collision_sphere_face(const ShapeSW *p_a,const Transform &p_transfo template<bool withMargin> -static void _collision_box_box(const ShapeSW *p_a,const Transform &p_transform_a,const ShapeSW *p_b,const Transform &p_transform_b,_CollectorCallback *p_collector,float p_margin_a,float p_margin_b) { +static void _collision_box_box(const ShapeSW *p_a,const Transform &p_transform_a,const ShapeSW *p_b,const Transform &p_transform_b,_CollectorCallback *p_collector,real_t p_margin_a,real_t p_margin_b) { const BoxShapeSW *box_A = static_cast<const BoxShapeSW*>(p_a); @@ -818,7 +818,7 @@ static void _collision_box_box(const ShapeSW *p_a,const Transform &p_transform_a } template<bool withMargin> -static void _collision_box_capsule(const ShapeSW *p_a,const Transform &p_transform_a,const ShapeSW *p_b,const Transform &p_transform_b,_CollectorCallback *p_collector,float p_margin_a,float p_margin_b) { +static void _collision_box_capsule(const ShapeSW *p_a,const Transform &p_transform_a,const ShapeSW *p_b,const Transform &p_transform_b,_CollectorCallback *p_collector,real_t p_margin_a,real_t p_margin_b) { const BoxShapeSW *box_A = static_cast<const BoxShapeSW*>(p_a); const CapsuleShapeSW *capsule_B = static_cast<const CapsuleShapeSW*>(p_b); @@ -918,7 +918,7 @@ static void _collision_box_capsule(const ShapeSW *p_a,const Transform &p_transfo } template<bool withMargin> -static void _collision_box_convex_polygon(const ShapeSW *p_a,const Transform &p_transform_a,const ShapeSW *p_b,const Transform &p_transform_b,_CollectorCallback *p_collector,float p_margin_a,float p_margin_b) { +static void _collision_box_convex_polygon(const ShapeSW *p_a,const Transform &p_transform_a,const ShapeSW *p_b,const Transform &p_transform_b,_CollectorCallback *p_collector,real_t p_margin_a,real_t p_margin_b) { @@ -1046,7 +1046,7 @@ static void _collision_box_convex_polygon(const ShapeSW *p_a,const Transform &p_ template<bool withMargin> -static void _collision_box_face(const ShapeSW *p_a,const Transform &p_transform_a, const ShapeSW *p_b,const Transform& p_transform_b,_CollectorCallback *p_collector,float p_margin_a,float p_margin_b) { +static void _collision_box_face(const ShapeSW *p_a,const Transform &p_transform_a, const ShapeSW *p_b,const Transform& p_transform_b,_CollectorCallback *p_collector,real_t p_margin_a,real_t p_margin_b) { const BoxShapeSW *box_A = static_cast<const BoxShapeSW*>(p_a); @@ -1158,7 +1158,7 @@ static void _collision_box_face(const ShapeSW *p_a,const Transform &p_transform_ template<bool withMargin> -static void _collision_capsule_capsule(const ShapeSW *p_a,const Transform &p_transform_a,const ShapeSW *p_b,const Transform &p_transform_b,_CollectorCallback *p_collector,float p_margin_a,float p_margin_b) { +static void _collision_capsule_capsule(const ShapeSW *p_a,const Transform &p_transform_a,const ShapeSW *p_b,const Transform &p_transform_b,_CollectorCallback *p_collector,real_t p_margin_a,real_t p_margin_b) { const CapsuleShapeSW *capsule_A = static_cast<const CapsuleShapeSW*>(p_a); const CapsuleShapeSW *capsule_B = static_cast<const CapsuleShapeSW*>(p_b); @@ -1216,7 +1216,7 @@ static void _collision_capsule_capsule(const ShapeSW *p_a,const Transform &p_tra } template<bool withMargin> -static void _collision_capsule_convex_polygon(const ShapeSW *p_a,const Transform &p_transform_a,const ShapeSW *p_b,const Transform &p_transform_b,_CollectorCallback *p_collector,float p_margin_a,float p_margin_b) { +static void _collision_capsule_convex_polygon(const ShapeSW *p_a,const Transform &p_transform_a,const ShapeSW *p_b,const Transform &p_transform_b,_CollectorCallback *p_collector,real_t p_margin_a,real_t p_margin_b) { const CapsuleShapeSW *capsule_A = static_cast<const CapsuleShapeSW*>(p_a); @@ -1287,7 +1287,7 @@ static void _collision_capsule_convex_polygon(const ShapeSW *p_a,const Transform template<bool withMargin> -static void _collision_capsule_face(const ShapeSW *p_a,const Transform &p_transform_a, const ShapeSW *p_b,const Transform& p_transform_b,_CollectorCallback *p_collector,float p_margin_a,float p_margin_b) { +static void _collision_capsule_face(const ShapeSW *p_a,const Transform &p_transform_a, const ShapeSW *p_b,const Transform& p_transform_b,_CollectorCallback *p_collector,real_t p_margin_a,real_t p_margin_b) { const CapsuleShapeSW *capsule_A = static_cast<const CapsuleShapeSW*>(p_a); const FaceShapeSW *face_B = static_cast<const FaceShapeSW*>(p_b); @@ -1350,7 +1350,7 @@ static void _collision_capsule_face(const ShapeSW *p_a,const Transform &p_transf template<bool withMargin> -static void _collision_convex_polygon_convex_polygon(const ShapeSW *p_a,const Transform &p_transform_a,const ShapeSW *p_b,const Transform &p_transform_b,_CollectorCallback *p_collector,float p_margin_a,float p_margin_b) { +static void _collision_convex_polygon_convex_polygon(const ShapeSW *p_a,const Transform &p_transform_a,const ShapeSW *p_b,const Transform &p_transform_b,_CollectorCallback *p_collector,real_t p_margin_a,real_t p_margin_b) { const ConvexPolygonShapeSW *convex_polygon_A = static_cast<const ConvexPolygonShapeSW*>(p_a); @@ -1474,7 +1474,7 @@ static void _collision_convex_polygon_convex_polygon(const ShapeSW *p_a,const Tr template<bool withMargin> -static void _collision_convex_polygon_face(const ShapeSW *p_a,const Transform &p_transform_a, const ShapeSW *p_b,const Transform& p_transform_b,_CollectorCallback *p_collector,float p_margin_a,float p_margin_b) { +static void _collision_convex_polygon_face(const ShapeSW *p_a,const Transform &p_transform_a, const ShapeSW *p_b,const Transform& p_transform_b,_CollectorCallback *p_collector,real_t p_margin_a,real_t p_margin_b) { const ConvexPolygonShapeSW *convex_polygon_A = static_cast<const ConvexPolygonShapeSW*>(p_a); @@ -1585,7 +1585,7 @@ static void _collision_convex_polygon_face(const ShapeSW *p_a,const Transform &p } -bool sat_calculate_penetration(const ShapeSW *p_shape_A, const Transform& p_transform_A, const ShapeSW *p_shape_B, const Transform& p_transform_B, CollisionSolverSW::CallbackResult p_result_callback,void *p_userdata,bool p_swap,Vector3* r_prev_axis,float p_margin_a,float p_margin_b) { +bool sat_calculate_penetration(const ShapeSW *p_shape_A, const Transform& p_transform_A, const ShapeSW *p_shape_B, const Transform& p_transform_B, CollisionSolverSW::CallbackResult p_result_callback,void *p_userdata,bool p_swap,Vector3* r_prev_axis,real_t p_margin_a,real_t p_margin_b) { PhysicsServer::ShapeType type_A=p_shape_A->get_type(); @@ -1667,8 +1667,8 @@ bool sat_calculate_penetration(const ShapeSW *p_shape_A, const Transform& p_tran const ShapeSW *B=p_shape_B; const Transform *transform_A=&p_transform_A; const Transform *transform_B=&p_transform_B; - float margin_A=p_margin_a; - float margin_B=p_margin_b; + real_t margin_A=p_margin_a; + real_t margin_B=p_margin_b; if (type_A > type_B) { SWAP(A,B); diff --git a/servers/physics/collision_solver_sat.h b/servers/physics/collision_solver_sat.h index 60387a978d..15fe7dc34a 100644 --- a/servers/physics/collision_solver_sat.h +++ b/servers/physics/collision_solver_sat.h @@ -32,6 +32,6 @@ #include "collision_solver_sw.h" -bool sat_calculate_penetration(const ShapeSW *p_shape_A, const Transform& p_transform_A, const ShapeSW *p_shape_B, const Transform& p_transform_B, CollisionSolverSW::CallbackResult p_result_callback,void *p_userdata, bool p_swap=false,Vector3* r_prev_axis=NULL,float p_margin_a=0,float p_margin_b=0); +bool sat_calculate_penetration(const ShapeSW *p_shape_A, const Transform& p_transform_A, const ShapeSW *p_shape_B, const Transform& p_transform_B, CollisionSolverSW::CallbackResult p_result_callback,void *p_userdata, bool p_swap=false,Vector3* r_prev_axis=NULL,real_t p_margin_a=0,real_t p_margin_b=0); #endif // COLLISION_SOLVER_SAT_H diff --git a/servers/physics/collision_solver_sw.cpp b/servers/physics/collision_solver_sw.cpp index 3399849ab7..f0ddde3a76 100644 --- a/servers/physics/collision_solver_sw.cpp +++ b/servers/physics/collision_solver_sw.cpp @@ -115,8 +115,8 @@ struct _ConcaveCollisionInfo { int aabb_tests; int collisions; bool tested; - float margin_A; - float margin_B; + real_t margin_A; + real_t margin_B; Vector3 close_A,close_B; }; @@ -136,7 +136,7 @@ void CollisionSolverSW::concave_callback(void *p_userdata, ShapeSW *p_convex) { } -bool CollisionSolverSW::solve_concave(const ShapeSW *p_shape_A,const Transform& p_transform_A,const ShapeSW *p_shape_B,const Transform& p_transform_B,CallbackResult p_result_callback,void *p_userdata,bool p_swap_result,float p_margin_A,float p_margin_B) { +bool CollisionSolverSW::solve_concave(const ShapeSW *p_shape_A,const Transform& p_transform_A,const ShapeSW *p_shape_B,const Transform& p_transform_B,CallbackResult p_result_callback,void *p_userdata,bool p_swap_result,real_t p_margin_A,real_t p_margin_B) { const ConcaveShapeSW *concave_B=static_cast<const ConcaveShapeSW*>(p_shape_B); @@ -164,10 +164,10 @@ bool CollisionSolverSW::solve_concave(const ShapeSW *p_shape_A,const Transform& for(int i=0;i<3;i++) { Vector3 axis( p_transform_B.basis.get_axis(i) ); - float axis_scale = 1.0/axis.length(); + real_t axis_scale = 1.0/axis.length(); axis*=axis_scale; - float smin,smax; + real_t smin,smax; p_shape_A->project_range(axis,rel_transform,smin,smax); smin-=p_margin_A; smax+=p_margin_A; @@ -186,7 +186,7 @@ bool CollisionSolverSW::solve_concave(const ShapeSW *p_shape_A,const Transform& } -bool CollisionSolverSW::solve_static(const ShapeSW *p_shape_A,const Transform& p_transform_A,const ShapeSW *p_shape_B,const Transform& p_transform_B,CallbackResult p_result_callback,void *p_userdata,Vector3 *r_sep_axis,float p_margin_A,float p_margin_B) { +bool CollisionSolverSW::solve_static(const ShapeSW *p_shape_A,const Transform& p_transform_A,const ShapeSW *p_shape_B,const Transform& p_transform_B,CallbackResult p_result_callback,void *p_userdata,Vector3 *r_sep_axis,real_t p_margin_A,real_t p_margin_B) { PhysicsServer::ShapeType type_A=p_shape_A->get_type(); @@ -291,7 +291,7 @@ bool CollisionSolverSW::solve_distance_plane(const ShapeSW *p_shape_A,const Tran bool collided=false; Vector3 closest; - float closest_d; + real_t closest_d; for(int i=0;i<support_count;i++) { @@ -362,10 +362,10 @@ bool CollisionSolverSW::solve_distance(const ShapeSW *p_shape_A,const Transform& for(int i=0;i<3;i++) { Vector3 axis( p_transform_B.basis.get_axis(i) ); - float axis_scale = 1.0/axis.length(); + real_t axis_scale = ((real_t)1.0)/axis.length(); axis*=axis_scale; - float smin,smax; + real_t smin,smax; if (use_cc_hint) { cc_hint_aabb.project_range_in_plane(Plane(axis,0),smin,smax); diff --git a/servers/physics/collision_solver_sw.h b/servers/physics/collision_solver_sw.h index 16d2b92d70..b8d37a8a96 100644 --- a/servers/physics/collision_solver_sw.h +++ b/servers/physics/collision_solver_sw.h @@ -40,14 +40,14 @@ private: static void concave_callback(void *p_userdata, ShapeSW *p_convex); static bool solve_static_plane(const ShapeSW *p_shape_A,const Transform& p_transform_A,const ShapeSW *p_shape_B,const Transform& p_transform_B,CallbackResult p_result_callback,void *p_userdata,bool p_swap_result); static bool solve_ray(const ShapeSW *p_shape_A,const Transform& p_transform_A,const ShapeSW *p_shape_B,const Transform& p_transform_B,CallbackResult p_result_callback,void *p_userdata,bool p_swap_result); - static bool solve_concave(const ShapeSW *p_shape_A,const Transform& p_transform_A,const ShapeSW *p_shape_B,const Transform& p_transform_B,CallbackResult p_result_callback,void *p_userdata,bool p_swap_result,float p_margin_A=0,float p_margin_B=0); + static bool solve_concave(const ShapeSW *p_shape_A,const Transform& p_transform_A,const ShapeSW *p_shape_B,const Transform& p_transform_B,CallbackResult p_result_callback,void *p_userdata,bool p_swap_result,real_t p_margin_A=0,real_t p_margin_B=0); static void concave_distance_callback(void *p_userdata, ShapeSW *p_convex); static bool solve_distance_plane(const ShapeSW *p_shape_A,const Transform& p_transform_A,const ShapeSW *p_shape_B,const Transform& p_transform_B,Vector3& r_point_A,Vector3& r_point_B); public: - static bool solve_static(const ShapeSW *p_shape_A,const Transform& p_transform_A,const ShapeSW *p_shape_B,const Transform& p_transform_B,CallbackResult p_result_callback,void *p_userdata,Vector3 *r_sep_axis=NULL,float p_margin_A=0,float p_margin_B=0); + static bool solve_static(const ShapeSW *p_shape_A,const Transform& p_transform_A,const ShapeSW *p_shape_B,const Transform& p_transform_B,CallbackResult p_result_callback,void *p_userdata,Vector3 *r_sep_axis=NULL,real_t p_margin_A=0,real_t p_margin_B=0); static bool solve_distance(const ShapeSW *p_shape_A,const Transform& p_transform_A,const ShapeSW *p_shape_B,const Transform& p_transform_B,Vector3& r_point_A,Vector3& r_point_B,const Rect3& p_concave_hint,Vector3 *r_sep_axis=NULL); }; diff --git a/servers/physics/constraint_sw.h b/servers/physics/constraint_sw.h index adc17cb753..f5bbe4bbd0 100644 --- a/servers/physics/constraint_sw.h +++ b/servers/physics/constraint_sw.h @@ -67,8 +67,8 @@ public: _FORCE_INLINE_ int get_priority() const { return priority; } - virtual bool setup(float p_step)=0; - virtual void solve(float p_step)=0; + virtual bool setup(real_t p_step)=0; + virtual void solve(real_t p_step)=0; virtual ~ConstraintSW() {} }; diff --git a/servers/physics/joints/cone_twist_joint_sw.cpp b/servers/physics/joints/cone_twist_joint_sw.cpp index cbf444f1e8..d78bcbd16d 100644 --- a/servers/physics/joints/cone_twist_joint_sw.cpp +++ b/servers/physics/joints/cone_twist_joint_sw.cpp @@ -96,7 +96,7 @@ ConeTwistJointSW::ConeTwistJointSW(BodySW* rbA,BodySW* rbB,const Transform& rbAF } -bool ConeTwistJointSW::setup(float p_step) { +bool ConeTwistJointSW::setup(real_t p_step) { m_appliedImpulse = real_t(0.); //set bias, sign, clear accumulator @@ -318,7 +318,7 @@ void ConeTwistJointSW::solve(real_t timeStep) } -void ConeTwistJointSW::set_param(PhysicsServer::ConeTwistJointParam p_param, float p_value) { +void ConeTwistJointSW::set_param(PhysicsServer::ConeTwistJointParam p_param, real_t p_value) { switch(p_param) { case PhysicsServer::CONE_TWIST_JOINT_SWING_SPAN: { @@ -345,7 +345,7 @@ void ConeTwistJointSW::set_param(PhysicsServer::ConeTwistJointParam p_param, flo } } -float ConeTwistJointSW::get_param(PhysicsServer::ConeTwistJointParam p_param) const{ +real_t ConeTwistJointSW::get_param(PhysicsServer::ConeTwistJointParam p_param) const{ switch(p_param) { case PhysicsServer::CONE_TWIST_JOINT_SWING_SPAN: { diff --git a/servers/physics/joints/cone_twist_joint_sw.h b/servers/physics/joints/cone_twist_joint_sw.h index 0d64d67443..eb7a5cd1b1 100644 --- a/servers/physics/joints/cone_twist_joint_sw.h +++ b/servers/physics/joints/cone_twist_joint_sw.h @@ -109,8 +109,8 @@ public: virtual PhysicsServer::JointType get_type() const { return PhysicsServer::JOINT_CONE_TWIST; } - virtual bool setup(float p_step); - virtual void solve(float p_step); + virtual bool setup(real_t p_step); + virtual void solve(real_t p_step); ConeTwistJointSW(BodySW* rbA,BodySW* rbB,const Transform& rbAFrame, const Transform& rbBFrame); @@ -146,8 +146,8 @@ public: return m_twistLimitSign; } - void set_param(PhysicsServer::ConeTwistJointParam p_param, float p_value); - float get_param(PhysicsServer::ConeTwistJointParam p_param) const; + void set_param(PhysicsServer::ConeTwistJointParam p_param, real_t p_value); + real_t get_param(PhysicsServer::ConeTwistJointParam p_param) const; }; diff --git a/servers/physics/joints/generic_6dof_joint_sw.cpp b/servers/physics/joints/generic_6dof_joint_sw.cpp index 8d3fc4721a..bd07f3122a 100644 --- a/servers/physics/joints/generic_6dof_joint_sw.cpp +++ b/servers/physics/joints/generic_6dof_joint_sw.cpp @@ -38,54 +38,6 @@ See corresponding header file for licensing info. #define GENERIC_D6_DISABLE_WARMSTARTING 1 -real_t btGetMatrixElem(const Basis& mat, int index); -real_t btGetMatrixElem(const Basis& mat, int index) -{ - int i = index%3; - int j = index/3; - return mat[i][j]; -} - -///MatrixToEulerXYZ from http://www.geometrictools.com/LibFoundation/Mathematics/Wm4Matrix3.inl.html -bool matrixToEulerXYZ(const Basis& mat,Vector3& xyz); -bool matrixToEulerXYZ(const Basis& mat,Vector3& xyz) -{ - // rot = cy*cz -cy*sz sy - // cz*sx*sy+cx*sz cx*cz-sx*sy*sz -cy*sx - // -cx*cz*sy+sx*sz cz*sx+cx*sy*sz cx*cy - - if (btGetMatrixElem(mat,2) < real_t(1.0)) - { - if (btGetMatrixElem(mat,2) > real_t(-1.0)) - { - xyz[0] = Math::atan2(-btGetMatrixElem(mat,5),btGetMatrixElem(mat,8)); - xyz[1] = Math::asin(btGetMatrixElem(mat,2)); - xyz[2] = Math::atan2(-btGetMatrixElem(mat,1),btGetMatrixElem(mat,0)); - return true; - } - else - { - // WARNING. Not unique. XA - ZA = -atan2(r10,r11) - xyz[0] = -Math::atan2(btGetMatrixElem(mat,3),btGetMatrixElem(mat,4)); - xyz[1] = -Math_PI*0.5; - xyz[2] = real_t(0.0); - return false; - } - } - else - { - // WARNING. Not unique. XAngle + ZAngle = atan2(r10,r11) - xyz[0] = Math::atan2(btGetMatrixElem(mat,3),btGetMatrixElem(mat,4)); - xyz[1] = Math_PI*0.5; - xyz[2] = 0.0; - - } - - - return false; -} - - //////////////////////////// G6DOFRotationalLimitMotorSW //////////////////////////////////// @@ -297,7 +249,7 @@ void Generic6DOFJointSW::calculateAngleInfo() { Basis relative_frame = m_calculatedTransformA.basis.inverse()*m_calculatedTransformB.basis; - matrixToEulerXYZ(relative_frame,m_calculatedAxisAngleDiff); + m_calculatedAxisAngleDiff = relative_frame.get_euler(); @@ -385,7 +337,7 @@ bool Generic6DOFJointSW::testAngularLimitMotor(int axis_index) return m_angularLimits[axis_index].needApplyTorques(); } -bool Generic6DOFJointSW::setup(float p_step) { +bool Generic6DOFJointSW::setup(real_t p_step) { // Clear accumulated impulses for the next simulation step m_linearLimits.m_accumulatedImpulse=Vector3(real_t(0.), real_t(0.), real_t(0.)); @@ -531,7 +483,7 @@ void Generic6DOFJointSW::calcAnchorPos(void) } // Generic6DOFJointSW::calcAnchorPos() -void Generic6DOFJointSW::set_param(Vector3::Axis p_axis,PhysicsServer::G6DOFJointAxisParam p_param, float p_value) { +void Generic6DOFJointSW::set_param(Vector3::Axis p_axis,PhysicsServer::G6DOFJointAxisParam p_param, real_t p_value) { ERR_FAIL_INDEX(p_axis,3); switch(p_param) { @@ -607,7 +559,7 @@ void Generic6DOFJointSW::set_param(Vector3::Axis p_axis,PhysicsServer::G6DOFJoin } } -float Generic6DOFJointSW::get_param(Vector3::Axis p_axis,PhysicsServer::G6DOFJointAxisParam p_param) const{ +real_t Generic6DOFJointSW::get_param(Vector3::Axis p_axis,PhysicsServer::G6DOFJointAxisParam p_param) const{ ERR_FAIL_INDEX_V(p_axis,3,0); switch(p_param) { case PhysicsServer::G6DOF_JOINT_LINEAR_LOWER_LIMIT: { diff --git a/servers/physics/joints/generic_6dof_joint_sw.h b/servers/physics/joints/generic_6dof_joint_sw.h index 4ac727c124..207ae85a45 100644 --- a/servers/physics/joints/generic_6dof_joint_sw.h +++ b/servers/physics/joints/generic_6dof_joint_sw.h @@ -295,8 +295,8 @@ public: virtual PhysicsServer::JointType get_type() const { return PhysicsServer::JOINT_6DOF; } - virtual bool setup(float p_step); - virtual void solve(float p_step); + virtual bool setup(real_t p_step); + virtual void solve(real_t p_step); //! Calcs global transform of the offsets @@ -449,8 +449,8 @@ public: virtual void calcAnchorPos(void); // overridable - void set_param(Vector3::Axis p_axis,PhysicsServer::G6DOFJointAxisParam p_param, float p_value); - float get_param(Vector3::Axis p_axis,PhysicsServer::G6DOFJointAxisParam p_param) const; + void set_param(Vector3::Axis p_axis,PhysicsServer::G6DOFJointAxisParam p_param, real_t p_value); + real_t get_param(Vector3::Axis p_axis,PhysicsServer::G6DOFJointAxisParam p_param) const; void set_flag(Vector3::Axis p_axis,PhysicsServer::G6DOFJointAxisFlag p_flag, bool p_value); bool get_flag(Vector3::Axis p_axis,PhysicsServer::G6DOFJointAxisFlag p_flag) const; diff --git a/servers/physics/joints/hinge_joint_sw.cpp b/servers/physics/joints/hinge_joint_sw.cpp index d50d5a1a73..9617eb8794 100644 --- a/servers/physics/joints/hinge_joint_sw.cpp +++ b/servers/physics/joints/hinge_joint_sw.cpp @@ -148,7 +148,7 @@ HingeJointSW::HingeJointSW(BodySW* rbA,BodySW* rbB, const Vector3& pivotInA,cons -bool HingeJointSW::setup(float p_step) { +bool HingeJointSW::setup(real_t p_step) { m_appliedImpulse = real_t(0.); @@ -262,7 +262,7 @@ bool HingeJointSW::setup(float p_step) { return true; } -void HingeJointSW::solve(float p_step) { +void HingeJointSW::solve(real_t p_step) { Vector3 pivotAInW = A->get_transform().xform(m_rbAFrame.origin); Vector3 pivotBInW = B->get_transform().xform(m_rbBFrame.origin); @@ -418,7 +418,7 @@ real_t HingeJointSW::get_hinge_angle() { } -void HingeJointSW::set_param(PhysicsServer::HingeJointParam p_param, float p_value) { +void HingeJointSW::set_param(PhysicsServer::HingeJointParam p_param, real_t p_value) { switch (p_param) { @@ -434,7 +434,7 @@ void HingeJointSW::set_param(PhysicsServer::HingeJointParam p_param, float p_val } } -float HingeJointSW::get_param(PhysicsServer::HingeJointParam p_param) const{ +real_t HingeJointSW::get_param(PhysicsServer::HingeJointParam p_param) const{ switch (p_param) { diff --git a/servers/physics/joints/hinge_joint_sw.h b/servers/physics/joints/hinge_joint_sw.h index 60203e3cc4..8469fd1ca0 100644 --- a/servers/physics/joints/hinge_joint_sw.h +++ b/servers/physics/joints/hinge_joint_sw.h @@ -103,13 +103,13 @@ public: virtual PhysicsServer::JointType get_type() const { return PhysicsServer::JOINT_HINGE; } - virtual bool setup(float p_step); - virtual void solve(float p_step); + virtual bool setup(real_t p_step); + virtual void solve(real_t p_step); real_t get_hinge_angle(); - void set_param(PhysicsServer::HingeJointParam p_param, float p_value); - float get_param(PhysicsServer::HingeJointParam p_param) const; + void set_param(PhysicsServer::HingeJointParam p_param, real_t p_value); + real_t get_param(PhysicsServer::HingeJointParam p_param) const; void set_flag(PhysicsServer::HingeJointFlag p_flag, bool p_value); bool get_flag(PhysicsServer::HingeJointFlag p_flag) const; diff --git a/servers/physics/joints/pin_joint_sw.cpp b/servers/physics/joints/pin_joint_sw.cpp index 9c7fe65684..b545ae630b 100644 --- a/servers/physics/joints/pin_joint_sw.cpp +++ b/servers/physics/joints/pin_joint_sw.cpp @@ -34,7 +34,7 @@ See corresponding header file for licensing info. #include "pin_joint_sw.h" -bool PinJointSW::setup(float p_step) { +bool PinJointSW::setup(real_t p_step) { m_appliedImpulse = real_t(0.); @@ -59,7 +59,7 @@ bool PinJointSW::setup(float p_step) { return true; } -void PinJointSW::solve(float p_step){ +void PinJointSW::solve(real_t p_step){ Vector3 pivotAInW = A->get_transform().xform(m_pivotInA); Vector3 pivotBInW = B->get_transform().xform(m_pivotInB); @@ -116,7 +116,7 @@ void PinJointSW::solve(float p_step){ } } -void PinJointSW::set_param(PhysicsServer::PinJointParam p_param,float p_value) { +void PinJointSW::set_param(PhysicsServer::PinJointParam p_param,real_t p_value) { switch(p_param) { case PhysicsServer::PIN_JOINT_BIAS: m_tau=p_value; break; @@ -125,7 +125,7 @@ void PinJointSW::set_param(PhysicsServer::PinJointParam p_param,float p_value) { } } -float PinJointSW::get_param(PhysicsServer::PinJointParam p_param) const{ +real_t PinJointSW::get_param(PhysicsServer::PinJointParam p_param) const{ switch(p_param) { case PhysicsServer::PIN_JOINT_BIAS: return m_tau; diff --git a/servers/physics/joints/pin_joint_sw.h b/servers/physics/joints/pin_joint_sw.h index 6797972496..b72b21219d 100644 --- a/servers/physics/joints/pin_joint_sw.h +++ b/servers/physics/joints/pin_joint_sw.h @@ -79,11 +79,11 @@ public: virtual PhysicsServer::JointType get_type() const { return PhysicsServer::JOINT_PIN; } - virtual bool setup(float p_step); - virtual void solve(float p_step); + virtual bool setup(real_t p_step); + virtual void solve(real_t p_step); - void set_param(PhysicsServer::PinJointParam p_param,float p_value); - float get_param(PhysicsServer::PinJointParam p_param) const; + void set_param(PhysicsServer::PinJointParam p_param,real_t p_value); + real_t get_param(PhysicsServer::PinJointParam p_param) const; void set_pos_A(const Vector3& p_pos) { m_pivotInA=p_pos; } void set_pos_B(const Vector3& p_pos) { m_pivotInB=p_pos; } diff --git a/servers/physics/joints/slider_joint_sw.cpp b/servers/physics/joints/slider_joint_sw.cpp index bdcae08ca4..fc728ed0ba 100644 --- a/servers/physics/joints/slider_joint_sw.cpp +++ b/servers/physics/joints/slider_joint_sw.cpp @@ -112,7 +112,7 @@ SliderJointSW::SliderJointSW(BodySW* rbA, BodySW* rbB, const Transform& frameInA //----------------------------------------------------------------------------- -bool SliderJointSW::setup(float p_step) +bool SliderJointSW::setup(real_t p_step) { //calculate transforms @@ -406,7 +406,7 @@ Vector3 SliderJointSW::getAncorInB(void) return ancorInB; } // SliderJointSW::getAncorInB(); -void SliderJointSW::set_param(PhysicsServer::SliderJointParam p_param, float p_value) { +void SliderJointSW::set_param(PhysicsServer::SliderJointParam p_param, real_t p_value) { switch(p_param) { case PhysicsServer::SLIDER_JOINT_LINEAR_LIMIT_UPPER: m_upperLinLimit=p_value; break; @@ -437,7 +437,7 @@ void SliderJointSW::set_param(PhysicsServer::SliderJointParam p_param, float p_v } -float SliderJointSW::get_param(PhysicsServer::SliderJointParam p_param) const { +real_t SliderJointSW::get_param(PhysicsServer::SliderJointParam p_param) const { switch(p_param) { case PhysicsServer::SLIDER_JOINT_LINEAR_LIMIT_UPPER: return m_upperLinLimit; diff --git a/servers/physics/joints/slider_joint_sw.h b/servers/physics/joints/slider_joint_sw.h index 4e697e6f64..d01038df59 100644 --- a/servers/physics/joints/slider_joint_sw.h +++ b/servers/physics/joints/slider_joint_sw.h @@ -237,11 +237,11 @@ public: Vector3 getAncorInA(void); Vector3 getAncorInB(void); - void set_param(PhysicsServer::SliderJointParam p_param, float p_value); - float get_param(PhysicsServer::SliderJointParam p_param) const; + void set_param(PhysicsServer::SliderJointParam p_param, real_t p_value); + real_t get_param(PhysicsServer::SliderJointParam p_param) const; - bool setup(float p_step); - void solve(float p_step); + bool setup(real_t p_step); + void solve(real_t p_step); virtual PhysicsServer::JointType get_type() const { return PhysicsServer::JOINT_SLIDER; } diff --git a/servers/physics/physics_server_sw.cpp b/servers/physics/physics_server_sw.cpp index b71eae54b0..67e3b27852 100644 --- a/servers/physics/physics_server_sw.cpp +++ b/servers/physics/physics_server_sw.cpp @@ -727,7 +727,7 @@ uint32_t PhysicsServerSW::body_get_user_flags(RID p_body, uint32_t p_flags) cons return 0; }; -void PhysicsServerSW::body_set_param(RID p_body, BodyParameter p_param, float p_value) { +void PhysicsServerSW::body_set_param(RID p_body, BodyParameter p_param, real_t p_value) { BodySW *body = body_owner.get(p_body); ERR_FAIL_COND(!body); @@ -735,7 +735,7 @@ void PhysicsServerSW::body_set_param(RID p_body, BodyParameter p_param, float p_ body->set_param(p_param,p_value); }; -float PhysicsServerSW::body_get_param(RID p_body, BodyParameter p_param) const { +real_t PhysicsServerSW::body_get_param(RID p_body, BodyParameter p_param) const { BodySW *body = body_owner.get(p_body); ERR_FAIL_COND_V(!body,0); @@ -879,14 +879,14 @@ void PhysicsServerSW::body_get_collision_exceptions(RID p_body, List<RID> *p_exc }; -void PhysicsServerSW::body_set_contacts_reported_depth_treshold(RID p_body, float p_treshold) { +void PhysicsServerSW::body_set_contacts_reported_depth_treshold(RID p_body, real_t p_treshold) { BodySW *body = body_owner.get(p_body); ERR_FAIL_COND(!body); }; -float PhysicsServerSW::body_get_contacts_reported_depth_treshold(RID p_body) const { +real_t PhysicsServerSW::body_get_contacts_reported_depth_treshold(RID p_body) const { BodySW *body = body_owner.get(p_body); ERR_FAIL_COND_V(!body,0); @@ -971,7 +971,7 @@ RID PhysicsServerSW::joint_create_pin(RID p_body_A,const Vector3& p_local_A,RID return rid; } -void PhysicsServerSW::pin_joint_set_param(RID p_joint,PinJointParam p_param, float p_value){ +void PhysicsServerSW::pin_joint_set_param(RID p_joint,PinJointParam p_param, real_t p_value){ JointSW *joint = joint_owner.get(p_joint); ERR_FAIL_COND(!joint); @@ -980,7 +980,7 @@ void PhysicsServerSW::pin_joint_set_param(RID p_joint,PinJointParam p_param, flo pin_joint->set_param(p_param,p_value); } -float PhysicsServerSW::pin_joint_get_param(RID p_joint,PinJointParam p_param) const{ +real_t PhysicsServerSW::pin_joint_get_param(RID p_joint,PinJointParam p_param) const{ JointSW *joint = joint_owner.get(p_joint); ERR_FAIL_COND_V(!joint,0); @@ -1074,7 +1074,7 @@ RID PhysicsServerSW::joint_create_hinge_simple(RID p_body_A,const Vector3& p_piv } -void PhysicsServerSW::hinge_joint_set_param(RID p_joint,HingeJointParam p_param, float p_value){ +void PhysicsServerSW::hinge_joint_set_param(RID p_joint,HingeJointParam p_param, real_t p_value){ JointSW *joint = joint_owner.get(p_joint); ERR_FAIL_COND(!joint); @@ -1083,7 +1083,7 @@ void PhysicsServerSW::hinge_joint_set_param(RID p_joint,HingeJointParam p_param, hinge_joint->set_param(p_param,p_value); } -float PhysicsServerSW::hinge_joint_get_param(RID p_joint,HingeJointParam p_param) const{ +real_t PhysicsServerSW::hinge_joint_get_param(RID p_joint,HingeJointParam p_param) const{ JointSW *joint = joint_owner.get(p_joint); ERR_FAIL_COND_V(!joint,0); @@ -1154,7 +1154,7 @@ RID PhysicsServerSW::joint_create_slider(RID p_body_A,const Transform& p_local_f return rid; } -void PhysicsServerSW::slider_joint_set_param(RID p_joint,SliderJointParam p_param, float p_value){ +void PhysicsServerSW::slider_joint_set_param(RID p_joint,SliderJointParam p_param, real_t p_value){ JointSW *joint = joint_owner.get(p_joint); ERR_FAIL_COND(!joint); @@ -1162,7 +1162,7 @@ void PhysicsServerSW::slider_joint_set_param(RID p_joint,SliderJointParam p_para SliderJointSW *slider_joint = static_cast<SliderJointSW*>(joint); slider_joint->set_param(p_param,p_value); } -float PhysicsServerSW::slider_joint_get_param(RID p_joint,SliderJointParam p_param) const{ +real_t PhysicsServerSW::slider_joint_get_param(RID p_joint,SliderJointParam p_param) const{ JointSW *joint = joint_owner.get(p_joint); ERR_FAIL_COND_V(!joint,0); @@ -1193,7 +1193,7 @@ RID PhysicsServerSW::joint_create_cone_twist(RID p_body_A,const Transform& p_loc return rid; } -void PhysicsServerSW::cone_twist_joint_set_param(RID p_joint,ConeTwistJointParam p_param, float p_value) { +void PhysicsServerSW::cone_twist_joint_set_param(RID p_joint,ConeTwistJointParam p_param, real_t p_value) { JointSW *joint = joint_owner.get(p_joint); ERR_FAIL_COND(!joint); @@ -1201,7 +1201,7 @@ void PhysicsServerSW::cone_twist_joint_set_param(RID p_joint,ConeTwistJointParam ConeTwistJointSW *cone_twist_joint = static_cast<ConeTwistJointSW*>(joint); cone_twist_joint->set_param(p_param,p_value); } -float PhysicsServerSW::cone_twist_joint_get_param(RID p_joint,ConeTwistJointParam p_param) const { +real_t PhysicsServerSW::cone_twist_joint_get_param(RID p_joint,ConeTwistJointParam p_param) const { JointSW *joint = joint_owner.get(p_joint); ERR_FAIL_COND_V(!joint,0); @@ -1232,7 +1232,7 @@ RID PhysicsServerSW::joint_create_generic_6dof(RID p_body_A,const Transform& p_l return rid; } -void PhysicsServerSW::generic_6dof_joint_set_param(RID p_joint,Vector3::Axis p_axis,G6DOFJointAxisParam p_param, float p_value){ +void PhysicsServerSW::generic_6dof_joint_set_param(RID p_joint,Vector3::Axis p_axis,G6DOFJointAxisParam p_param, real_t p_value){ JointSW *joint = joint_owner.get(p_joint); ERR_FAIL_COND(!joint); @@ -1240,7 +1240,7 @@ void PhysicsServerSW::generic_6dof_joint_set_param(RID p_joint,Vector3::Axis p_a Generic6DOFJointSW *generic_6dof_joint = static_cast<Generic6DOFJointSW*>(joint); generic_6dof_joint->set_param(p_axis,p_param,p_value); } -float PhysicsServerSW::generic_6dof_joint_get_param(RID p_joint,Vector3::Axis p_axis,G6DOFJointAxisParam p_param){ +real_t PhysicsServerSW::generic_6dof_joint_get_param(RID p_joint,Vector3::Axis p_axis,G6DOFJointAxisParam p_param){ JointSW *joint = joint_owner.get(p_joint); ERR_FAIL_COND_V(!joint,0); @@ -1488,7 +1488,7 @@ void PhysicsServerSW::init() { }; -void PhysicsServerSW::step(float p_step) { +void PhysicsServerSW::step(real_t p_step) { if (!active) @@ -1611,11 +1611,11 @@ void PhysicsServerSW::_shape_col_cbk(const Vector3& p_point_A,const Vector3& p_p if (cbk->amount == cbk->max) { //find least deep - float min_depth=1e20; + real_t min_depth=1e20; int min_depth_idx=0; for(int i=0;i<cbk->amount;i++) { - float d = cbk->ptr[i*2+0].distance_squared_to(cbk->ptr[i*2+1]); + real_t d = cbk->ptr[i*2+0].distance_squared_to(cbk->ptr[i*2+1]); if (d<min_depth) { min_depth=d; min_depth_idx=i; @@ -1623,7 +1623,7 @@ void PhysicsServerSW::_shape_col_cbk(const Vector3& p_point_A,const Vector3& p_p } - float d = p_point_A.distance_squared_to(p_point_B); + real_t d = p_point_A.distance_squared_to(p_point_B); if (d<min_depth) return; cbk->ptr[min_depth_idx*2+0]=p_point_A; diff --git a/servers/physics/physics_server_sw.h b/servers/physics/physics_server_sw.h index 72b133c4b9..6e20474350 100644 --- a/servers/physics/physics_server_sw.h +++ b/servers/physics/physics_server_sw.h @@ -180,8 +180,8 @@ public: virtual void body_set_user_flags(RID p_body, uint32_t p_flags); virtual uint32_t body_get_user_flags(RID p_body, uint32_t p_flags) const; - virtual void body_set_param(RID p_body, BodyParameter p_param, float p_value); - virtual float body_get_param(RID p_body, BodyParameter p_param) const; + virtual void body_set_param(RID p_body, BodyParameter p_param, real_t p_value); + virtual real_t body_get_param(RID p_body, BodyParameter p_param) const; virtual void body_set_state(RID p_body, BodyState p_state, const Variant& p_variant); virtual Variant body_get_state(RID p_body, BodyState p_state) const; @@ -203,8 +203,8 @@ public: virtual void body_remove_collision_exception(RID p_body, RID p_body_b); virtual void body_get_collision_exceptions(RID p_body, List<RID> *p_exceptions); - virtual void body_set_contacts_reported_depth_treshold(RID p_body, float p_treshold); - virtual float body_get_contacts_reported_depth_treshold(RID p_body) const; + virtual void body_set_contacts_reported_depth_treshold(RID p_body, real_t p_treshold); + virtual real_t body_get_contacts_reported_depth_treshold(RID p_body) const; virtual void body_set_omit_force_integration(RID p_body,bool p_omit); virtual bool body_is_omitting_force_integration(RID p_body) const; @@ -221,8 +221,8 @@ public: virtual RID joint_create_pin(RID p_body_A,const Vector3& p_local_A,RID p_body_B,const Vector3& p_local_B); - virtual void pin_joint_set_param(RID p_joint,PinJointParam p_param, float p_value); - virtual float pin_joint_get_param(RID p_joint,PinJointParam p_param) const; + virtual void pin_joint_set_param(RID p_joint,PinJointParam p_param, real_t p_value); + virtual real_t pin_joint_get_param(RID p_joint,PinJointParam p_param) const; virtual void pin_joint_set_local_A(RID p_joint, const Vector3& p_A); virtual Vector3 pin_joint_get_local_A(RID p_joint) const; @@ -233,8 +233,8 @@ public: virtual RID joint_create_hinge(RID p_body_A,const Transform& p_frame_A,RID p_body_B,const Transform& p_frame_B); virtual RID joint_create_hinge_simple(RID p_body_A,const Vector3& p_pivot_A,const Vector3& p_axis_A,RID p_body_B,const Vector3& p_pivot_B,const Vector3& p_axis_B); - virtual void hinge_joint_set_param(RID p_joint,HingeJointParam p_param, float p_value); - virtual float hinge_joint_get_param(RID p_joint,HingeJointParam p_param) const; + virtual void hinge_joint_set_param(RID p_joint,HingeJointParam p_param, real_t p_value); + virtual real_t hinge_joint_get_param(RID p_joint,HingeJointParam p_param) const; virtual void hinge_joint_set_flag(RID p_joint,HingeJointFlag p_flag, bool p_value); virtual bool hinge_joint_get_flag(RID p_joint,HingeJointFlag p_flag) const; @@ -242,18 +242,18 @@ public: virtual RID joint_create_slider(RID p_body_A,const Transform& p_local_frame_A,RID p_body_B,const Transform& p_local_frame_B); //reference frame is A - virtual void slider_joint_set_param(RID p_joint,SliderJointParam p_param, float p_value); - virtual float slider_joint_get_param(RID p_joint,SliderJointParam p_param) const; + virtual void slider_joint_set_param(RID p_joint,SliderJointParam p_param, real_t p_value); + virtual real_t slider_joint_get_param(RID p_joint,SliderJointParam p_param) const; virtual RID joint_create_cone_twist(RID p_body_A,const Transform& p_local_frame_A,RID p_body_B,const Transform& p_local_frame_B); //reference frame is A - virtual void cone_twist_joint_set_param(RID p_joint,ConeTwistJointParam p_param, float p_value); - virtual float cone_twist_joint_get_param(RID p_joint,ConeTwistJointParam p_param) const; + virtual void cone_twist_joint_set_param(RID p_joint,ConeTwistJointParam p_param, real_t p_value); + virtual real_t cone_twist_joint_get_param(RID p_joint,ConeTwistJointParam p_param) const; virtual RID joint_create_generic_6dof(RID p_body_A,const Transform& p_local_frame_A,RID p_body_B,const Transform& p_local_frame_B); //reference frame is A - virtual void generic_6dof_joint_set_param(RID p_joint,Vector3::Axis,G6DOFJointAxisParam p_param, float p_value); - virtual float generic_6dof_joint_get_param(RID p_joint,Vector3::Axis,G6DOFJointAxisParam p_param); + virtual void generic_6dof_joint_set_param(RID p_joint,Vector3::Axis,G6DOFJointAxisParam p_param, real_t p_value); + virtual real_t generic_6dof_joint_get_param(RID p_joint,Vector3::Axis,G6DOFJointAxisParam p_param); virtual void generic_6dof_joint_set_flag(RID p_joint,Vector3::Axis,G6DOFJointAxisFlag p_flag, bool p_enable); virtual bool generic_6dof_joint_get_flag(RID p_joint,Vector3::Axis,G6DOFJointAxisFlag p_flag); @@ -281,7 +281,7 @@ public: virtual void set_active(bool p_active); virtual void init(); - virtual void step(float p_step); + virtual void step(real_t p_step); virtual void sync(); virtual void flush_queries(); virtual void finish(); diff --git a/servers/physics/shape_sw.cpp b/servers/physics/shape_sw.cpp index 4114980b82..10500a306f 100644 --- a/servers/physics/shape_sw.cpp +++ b/servers/physics/shape_sw.cpp @@ -125,7 +125,7 @@ bool PlaneShapeSW::intersect_segment(const Vector3& p_begin,const Vector3& p_end return inters; } -Vector3 PlaneShapeSW::get_moment_of_inertia(float p_mass) const { +Vector3 PlaneShapeSW::get_moment_of_inertia(real_t p_mass) const { return Vector3(); //wtf } @@ -154,7 +154,7 @@ PlaneShapeSW::PlaneShapeSW() { // -float RayShapeSW::get_length() const { +real_t RayShapeSW::get_length() const { return length; } @@ -196,12 +196,12 @@ bool RayShapeSW::intersect_segment(const Vector3& p_begin,const Vector3& p_end,V return false; //simply not possible } -Vector3 RayShapeSW::get_moment_of_inertia(float p_mass) const { +Vector3 RayShapeSW::get_moment_of_inertia(real_t p_mass) const { return Vector3(); } -void RayShapeSW::_setup(float p_length) { +void RayShapeSW::_setup(real_t p_length) { length=p_length; configure(Rect3(Vector3(0,0,0),Vector3(0.1,0.1,length))); @@ -234,11 +234,11 @@ real_t SphereShapeSW::get_radius() const { void SphereShapeSW::project_range(const Vector3& p_normal, const Transform& p_transform, real_t &r_min, real_t &r_max) const { - float d = p_normal.dot( p_transform.origin ); + real_t d = p_normal.dot( p_transform.origin ); // figure out scale at point Vector3 local_normal = p_transform.basis.xform_inv(p_normal); - float scale = local_normal.length(); + real_t scale = local_normal.length(); r_min = d - (radius) * scale; r_max = d + (radius) * scale; @@ -261,9 +261,9 @@ bool SphereShapeSW::intersect_segment(const Vector3& p_begin,const Vector3& p_en return Geometry::segment_intersects_sphere(p_begin,p_end,Vector3(),radius,&r_result,&r_normal); } -Vector3 SphereShapeSW::get_moment_of_inertia(float p_mass) const { +Vector3 SphereShapeSW::get_moment_of_inertia(real_t p_mass) const { - float s = 0.4 * p_mass * radius * radius; + real_t s = 0.4 * p_mass * radius * radius; return Vector3(s,s,s); } @@ -299,8 +299,8 @@ void BoxShapeSW::project_range(const Vector3& p_normal, const Transform& p_trans // no matter the angle, the box is mirrored anyway Vector3 local_normal=p_transform.basis.xform_inv(p_normal); - float length = local_normal.abs().dot(half_extents); - float distance = p_normal.dot( p_transform.origin ); + real_t length = local_normal.abs().dot(half_extents); + real_t distance = p_normal.dot( p_transform.origin ); r_min = distance - length; r_max = distance + length; @@ -329,7 +329,7 @@ void BoxShapeSW::get_supports(const Vector3& p_normal,int p_max,Vector3 *r_suppo Vector3 axis; axis[i]=1.0; - float dot = p_normal.dot( axis ); + real_t dot = p_normal.dot( axis ); if ( Math::abs( dot ) > _FACE_IS_VALID_SUPPORT_TRESHOLD ) { //Vector3 axis_b; @@ -343,7 +343,7 @@ void BoxShapeSW::get_supports(const Vector3& p_normal,int p_max,Vector3 *r_suppo int i_n=next[i]; int i_n2=next2[i]; - static const float sign[4][2]={ + static const real_t sign[4][2]={ {-1.0, 1.0}, { 1.0, 1.0}, @@ -418,11 +418,11 @@ bool BoxShapeSW::intersect_segment(const Vector3& p_begin,const Vector3& p_end,V } -Vector3 BoxShapeSW::get_moment_of_inertia(float p_mass) const { +Vector3 BoxShapeSW::get_moment_of_inertia(real_t p_mass) const { - float lx=half_extents.x; - float ly=half_extents.y; - float lz=half_extents.z; + real_t lx=half_extents.x; + real_t ly=half_extents.y; + real_t lz=half_extents.z; return Vector3( (p_mass/3.0) * (ly*ly + lz*lz), (p_mass/3.0) * (lx*lx + lz*lz), (p_mass/3.0) * (lx*lx + ly*ly) ); @@ -460,7 +460,7 @@ BoxShapeSW::BoxShapeSW() { void CapsuleShapeSW::project_range(const Vector3& p_normal, const Transform& p_transform, real_t &r_min, real_t &r_max) const { Vector3 n=p_transform.basis.xform_inv(p_normal).normalized(); - float h = (n.z > 0) ? height : -height; + real_t h = (n.z > 0) ? height : -height; n *= radius; n.z += h * 0.5; @@ -471,8 +471,8 @@ void CapsuleShapeSW::project_range(const Vector3& p_normal, const Transform& p_t n = p_transform.basis.xform(n); - float distance = p_normal.dot( p_transform.origin ); - float length = Math::abs(p_normal.dot(n)); + real_t distance = p_normal.dot( p_transform.origin ); + real_t length = Math::abs(p_normal.dot(n)); r_min = distance - length; r_max = distance + length; @@ -484,7 +484,7 @@ Vector3 CapsuleShapeSW::get_support(const Vector3& p_normal) const { Vector3 n=p_normal; - float h = (n.z > 0) ? height : -height; + real_t h = (n.z > 0) ? height : -height; n*=radius; n.z += h*0.5; @@ -496,7 +496,7 @@ void CapsuleShapeSW::get_supports(const Vector3& p_normal,int p_max,Vector3 *r_s Vector3 n=p_normal; - float d = n.z; + real_t d = n.z; if (Math::abs( d )<_EDGE_IS_VALID_SUPPORT_TRESHOLD ) { @@ -513,7 +513,7 @@ void CapsuleShapeSW::get_supports(const Vector3& p_normal,int p_max,Vector3 *r_s } else { - float h = (d > 0) ? height : -height; + real_t h = (d > 0) ? height : -height; n*=radius; n.z += h*0.5; @@ -528,7 +528,7 @@ void CapsuleShapeSW::get_supports(const Vector3& p_normal,int p_max,Vector3 *r_s bool CapsuleShapeSW::intersect_segment(const Vector3& p_begin,const Vector3& p_end,Vector3 &r_result, Vector3 &r_normal) const { Vector3 norm=(p_end-p_begin).normalized(); - float min_d=1e20; + real_t min_d=1e20; Vector3 res,n; @@ -542,7 +542,7 @@ bool CapsuleShapeSW::intersect_segment(const Vector3& p_begin,const Vector3& p_e collided = Geometry::segment_intersects_cylinder(p_begin,p_end,height,radius,&auxres,&auxn); if (collided) { - float d=norm.dot(auxres); + real_t d=norm.dot(auxres); if (d<min_d) { min_d=d; res=auxres; @@ -554,7 +554,7 @@ bool CapsuleShapeSW::intersect_segment(const Vector3& p_begin,const Vector3& p_e collided = Geometry::segment_intersects_sphere(p_begin,p_end,Vector3(0,0,height*0.5),radius,&auxres,&auxn); if (collided) { - float d=norm.dot(auxres); + real_t d=norm.dot(auxres); if (d<min_d) { min_d=d; res=auxres; @@ -566,7 +566,7 @@ bool CapsuleShapeSW::intersect_segment(const Vector3& p_begin,const Vector3& p_e collided = Geometry::segment_intersects_sphere(p_begin,p_end,Vector3(0,0,height*-0.5),radius,&auxres,&auxn); if (collided) { - float d=norm.dot(auxres); + real_t d=norm.dot(auxres); if (d<min_d) { min_d=d; @@ -584,7 +584,7 @@ bool CapsuleShapeSW::intersect_segment(const Vector3& p_begin,const Vector3& p_e return collision; } -Vector3 CapsuleShapeSW::get_moment_of_inertia(float p_mass) const { +Vector3 CapsuleShapeSW::get_moment_of_inertia(real_t p_mass) const { // use crappy AABB approximation Vector3 extents=get_aabb().size*0.5; @@ -647,7 +647,7 @@ void ConvexPolygonShapeSW::project_range(const Vector3& p_normal, const Transfor for (int i=0;i<vertex_count;i++) { - float d=p_normal.dot( p_transform.xform( vrts[i] ) ); + real_t d=p_normal.dot( p_transform.xform( vrts[i] ) ); if (i==0 || d > r_max) r_max=d; @@ -661,7 +661,7 @@ Vector3 ConvexPolygonShapeSW::get_support(const Vector3& p_normal) const { Vector3 n=p_normal; int vert_support_idx=-1; - float support_max; + real_t support_max; int vertex_count=mesh.vertices.size(); if (vertex_count==0) @@ -671,7 +671,7 @@ Vector3 ConvexPolygonShapeSW::get_support(const Vector3& p_normal) const { for (int i=0;i<vertex_count;i++) { - float d=n.dot(vrts[i]); + real_t d=n.dot(vrts[i]); if (i==0 || d > support_max) { support_max=d; @@ -702,7 +702,7 @@ void ConvexPolygonShapeSW::get_supports(const Vector3& p_normal,int p_max,Vector for (int i=0;i<vc;i++) { - float d=p_normal.dot(vertices[i]); + real_t d=p_normal.dot(vertices[i]); if (i==0 || d > max) { max=d; @@ -742,7 +742,7 @@ void ConvexPolygonShapeSW::get_supports(const Vector3& p_normal,int p_max,Vector for(int i=0;i<ec;i++) { - float dot=(vertices[edges[i].a]-vertices[edges[i].b]).normalized().dot(p_normal); + real_t dot=(vertices[edges[i].a]-vertices[edges[i].b]).normalized().dot(p_normal); dot=ABS(dot); if (dot < _EDGE_IS_VALID_SUPPORT_TRESHOLD && (edges[i].a==vtx || edges[i].b==vtx)) { @@ -768,7 +768,7 @@ bool ConvexPolygonShapeSW::intersect_segment(const Vector3& p_begin,const Vector const Vector3 *vertices = mesh.vertices.ptr(); Vector3 n = p_end-p_begin; - float min = 1e20; + real_t min = 1e20; bool col=false; for(int i=0;i<fc;i++) { @@ -784,7 +784,7 @@ bool ConvexPolygonShapeSW::intersect_segment(const Vector3& p_begin,const Vector Face3 f(vertices[ind[0]],vertices[ind[j]],vertices[ind[j+1]]); Vector3 result; if (f.intersects_segment(p_begin,p_end,&result)) { - float d = n.dot(result); + real_t d = n.dot(result); if (d<min) { min=d; r_result=result; @@ -802,7 +802,7 @@ bool ConvexPolygonShapeSW::intersect_segment(const Vector3& p_begin,const Vector } -Vector3 ConvexPolygonShapeSW::get_moment_of_inertia(float p_mass) const { +Vector3 ConvexPolygonShapeSW::get_moment_of_inertia(real_t p_mass) const { // use crappy AABB approximation Vector3 extents=get_aabb().size*0.5; @@ -859,7 +859,7 @@ void FaceShapeSW::project_range(const Vector3& p_normal, const Transform& p_tran for (int i=0;i<3;i++) { Vector3 v=p_transform.xform(vertex[i]); - float d=p_normal.dot(v); + real_t d=p_normal.dot(v); if (i==0 || d > r_max) r_max=d; @@ -873,11 +873,11 @@ Vector3 FaceShapeSW::get_support(const Vector3& p_normal) const { int vert_support_idx=-1; - float support_max; + real_t support_max; for (int i=0;i<3;i++) { - float d=p_normal.dot(vertex[i]); + real_t d=p_normal.dot(vertex[i]); if (i==0 || d > support_max) { support_max=d; @@ -907,11 +907,11 @@ void FaceShapeSW::get_supports(const Vector3& p_normal,int p_max,Vector3 *r_supp /** FIND SUPPORT VERTEX **/ int vert_support_idx=-1; - float support_max; + real_t support_max; for (int i=0;i<3;i++) { - float d=n.dot(vertex[i]); + real_t d=n.dot(vertex[i]); if (i==0 || d > support_max) { support_max=d; @@ -928,7 +928,7 @@ void FaceShapeSW::get_supports(const Vector3& p_normal,int p_max,Vector3 *r_supp continue; // check if edge is valid as a support - float dot=(vertex[i]-vertex[nx]).normalized().dot(n); + real_t dot=(vertex[i]-vertex[nx]).normalized().dot(n); dot=ABS(dot); if (dot < _EDGE_IS_VALID_SUPPORT_TRESHOLD) { @@ -957,7 +957,7 @@ bool FaceShapeSW::intersect_segment(const Vector3& p_begin,const Vector3& p_end, return c; } -Vector3 FaceShapeSW::get_moment_of_inertia(float p_mass) const { +Vector3 FaceShapeSW::get_moment_of_inertia(real_t p_mass) const { return Vector3(); // Sorry, but i don't think anyone cares, FaceShape! @@ -1003,7 +1003,7 @@ void ConcavePolygonShapeSW::project_range(const Vector3& p_normal, const Transfo for (int i=0;i<count;i++) { - float d=p_normal.dot( p_transform.xform( vptr[i] ) ); + real_t d=p_normal.dot( p_transform.xform( vptr[i] ) ); if (i==0 || d > r_max) r_max=d; @@ -1026,11 +1026,11 @@ Vector3 ConcavePolygonShapeSW::get_support(const Vector3& p_normal) const { Vector3 n=p_normal; int vert_support_idx=-1; - float support_max; + real_t support_max; for (int i=0;i<count;i++) { - float d=n.dot(vptr[i]); + real_t d=n.dot(vptr[i]); if (i==0 || d > support_max) { support_max=d; @@ -1080,7 +1080,7 @@ void ConcavePolygonShapeSW::_cull_segment(int p_idx,_SegmentCullParams *p_params &res)) { - float d=p_params->dir.dot(res) - p_params->dir.dot(p_params->from); + real_t d=p_params->dir.dot(res) - p_params->dir.dot(p_params->from); //TODO, seems segmen/triangle intersection is broken :( if (d>0 && d<p_params->min_d) { @@ -1206,7 +1206,7 @@ void ConcavePolygonShapeSW::cull(const Rect3& p_local_aabb,Callback p_callback,v } -Vector3 ConcavePolygonShapeSW::get_moment_of_inertia(float p_mass) const { +Vector3 ConcavePolygonShapeSW::get_moment_of_inertia(real_t p_mass) const { // use crappy AABB approximation Vector3 extents=get_aabb().size*0.5; @@ -1555,7 +1555,7 @@ ConcavePolygonShapeSW::ConcavePolygonShapeSW() { /* HEIGHT MAP SHAPE */ -PoolVector<float> HeightMapShapeSW::get_heights() const { +PoolVector<real_t> HeightMapShapeSW::get_heights() const { return heights; } @@ -1567,7 +1567,7 @@ int HeightMapShapeSW::get_depth() const { return depth; } -float HeightMapShapeSW::get_cell_size() const { +real_t HeightMapShapeSW::get_cell_size() const { return cell_size; } @@ -1602,7 +1602,7 @@ void HeightMapShapeSW::cull(const Rect3& p_local_aabb,Callback p_callback,void* } -Vector3 HeightMapShapeSW::get_moment_of_inertia(float p_mass) const { +Vector3 HeightMapShapeSW::get_moment_of_inertia(real_t p_mass) const { // use crappy AABB approximation @@ -1631,7 +1631,7 @@ void HeightMapShapeSW::_setup(PoolVector<real_t> p_heights,int p_width,int p_dep for(int j=0;j<width;j++) { - float h = r[i*width+j]; + real_t h = r[i*width+j]; Vector3 pos( j*cell_size, h, i*cell_size ); if (i==0 || j==0) @@ -1657,8 +1657,8 @@ void HeightMapShapeSW::set_data(const Variant& p_data) { int width=d["width"]; int depth=d["depth"]; - float cell_size=d["cell_size"]; - PoolVector<float> heights=d["heights"]; + real_t cell_size=d["cell_size"]; + PoolVector<real_t> heights=d["heights"]; ERR_FAIL_COND( width<= 0); ERR_FAIL_COND( depth<= 0); diff --git a/servers/physics/shape_sw.h b/servers/physics/shape_sw.h index 919c681105..c8194ad755 100644 --- a/servers/physics/shape_sw.h +++ b/servers/physics/shape_sw.h @@ -35,8 +35,8 @@ /* SHAPE_LINE, ///< plane:"plane" -SHAPE_SEGMENT, ///< float:"length" -SHAPE_CIRCLE, ///< float:"radius" +SHAPE_SEGMENT, ///< real_t:"length" +SHAPE_CIRCLE, ///< real_t:"radius" SHAPE_RECTANGLE, ///< vec3:"extents" SHAPE_CONVEX_POLYGON, ///< array of planes:"planes" SHAPE_CONCAVE_POLYGON, ///< Vector3 array:"triangles" , or Dictionary with "indices" (int array) and "triangles" (Vector3 array) @@ -90,7 +90,7 @@ public: virtual void get_supports(const Vector3& p_normal,int p_max,Vector3 *r_supports,int & r_amount) const=0; virtual bool intersect_segment(const Vector3& p_begin,const Vector3& p_end,Vector3 &r_point, Vector3 &r_normal) const=0; - virtual Vector3 get_moment_of_inertia(float p_mass) const=0; + virtual Vector3 get_moment_of_inertia(real_t p_mass) const=0; virtual void set_data(const Variant& p_data)=0; virtual Variant get_data() const=0; @@ -138,7 +138,7 @@ public: virtual bool intersect_segment(const Vector3& p_begin,const Vector3& p_end,Vector3 &r_result, Vector3 &r_normal) const; - virtual Vector3 get_moment_of_inertia(float p_mass) const; + virtual Vector3 get_moment_of_inertia(real_t p_mass) const; virtual void set_data(const Variant& p_data); virtual Variant get_data() const; @@ -148,12 +148,12 @@ public: class RayShapeSW : public ShapeSW { - float length; + real_t length; - void _setup(float p_length); + void _setup(real_t p_length); public: - float get_length() const; + real_t get_length() const; virtual real_t get_area() const { return 0.0; } virtual PhysicsServer::ShapeType get_type() const { return PhysicsServer::SHAPE_RAY; } @@ -163,7 +163,7 @@ public: virtual bool intersect_segment(const Vector3& p_begin,const Vector3& p_end,Vector3 &r_result, Vector3 &r_normal) const; - virtual Vector3 get_moment_of_inertia(float p_mass) const; + virtual Vector3 get_moment_of_inertia(real_t p_mass) const; virtual void set_data(const Variant& p_data); virtual Variant get_data() const; @@ -189,7 +189,7 @@ public: virtual void get_supports(const Vector3& p_normal,int p_max,Vector3 *r_supports,int & r_amount) const; virtual bool intersect_segment(const Vector3& p_begin,const Vector3& p_end,Vector3 &r_result, Vector3 &r_normal) const; - virtual Vector3 get_moment_of_inertia(float p_mass) const; + virtual Vector3 get_moment_of_inertia(real_t p_mass) const; virtual void set_data(const Variant& p_data); virtual Variant get_data() const; @@ -213,7 +213,7 @@ public: virtual void get_supports(const Vector3& p_normal,int p_max,Vector3 *r_supports,int & r_amount) const; virtual bool intersect_segment(const Vector3& p_begin,const Vector3& p_end,Vector3 &r_result, Vector3 &r_normal) const; - virtual Vector3 get_moment_of_inertia(float p_mass) const; + virtual Vector3 get_moment_of_inertia(real_t p_mass) const; virtual void set_data(const Variant& p_data); virtual Variant get_data() const; @@ -242,7 +242,7 @@ public: virtual void get_supports(const Vector3& p_normal,int p_max,Vector3 *r_supports,int & r_amount) const; virtual bool intersect_segment(const Vector3& p_begin,const Vector3& p_end,Vector3 &r_result, Vector3 &r_normal) const; - virtual Vector3 get_moment_of_inertia(float p_mass) const; + virtual Vector3 get_moment_of_inertia(real_t p_mass) const; virtual void set_data(const Variant& p_data); virtual Variant get_data() const; @@ -266,7 +266,7 @@ public: virtual void get_supports(const Vector3& p_normal,int p_max,Vector3 *r_supports,int & r_amount) const; virtual bool intersect_segment(const Vector3& p_begin,const Vector3& p_end,Vector3 &r_result, Vector3 &r_normal) const; - virtual Vector3 get_moment_of_inertia(float p_mass) const; + virtual Vector3 get_moment_of_inertia(real_t p_mass) const; virtual void set_data(const Variant& p_data); virtual Variant get_data() const; @@ -349,7 +349,7 @@ public: virtual void cull(const Rect3& p_local_aabb,Callback p_callback,void* p_userdata) const; - virtual Vector3 get_moment_of_inertia(float p_mass) const; + virtual Vector3 get_moment_of_inertia(real_t p_mass) const; virtual void set_data(const Variant& p_data); virtual Variant get_data() const; @@ -364,18 +364,18 @@ struct HeightMapShapeSW : public ConcaveShapeSW { PoolVector<real_t> heights; int width; int depth; - float cell_size; + real_t cell_size; //void _cull_segment(int p_idx,_SegmentCullParams *p_params) const; //void _cull(int p_idx,_CullParams *p_params) const; - void _setup(PoolVector<float> p_heights,int p_width,int p_depth,float p_cell_size); + void _setup(PoolVector<real_t> p_heights,int p_width,int p_depth,real_t p_cell_size); public: PoolVector<real_t> get_heights() const; int get_width() const; int get_depth() const; - float get_cell_size() const; + real_t get_cell_size() const; virtual PhysicsServer::ShapeType get_type() const { return PhysicsServer::SHAPE_HEIGHTMAP; } @@ -385,7 +385,7 @@ public: virtual void cull(const Rect3& p_local_aabb,Callback p_callback,void* p_userdata) const; - virtual Vector3 get_moment_of_inertia(float p_mass) const; + virtual Vector3 get_moment_of_inertia(real_t p_mass) const; virtual void set_data(const Variant& p_data); virtual Variant get_data() const; @@ -409,7 +409,7 @@ struct FaceShapeSW : public ShapeSW { virtual void get_supports(const Vector3& p_normal,int p_max,Vector3 *r_supports,int & r_amount) const; bool intersect_segment(const Vector3& p_begin,const Vector3& p_end,Vector3 &r_result, Vector3 &r_normal) const; - Vector3 get_moment_of_inertia(float p_mass) const; + Vector3 get_moment_of_inertia(real_t p_mass) const; virtual void set_data(const Variant& p_data) {} virtual Variant get_data() const { return Variant(); } @@ -450,7 +450,7 @@ struct MotionShapeSW : public ShapeSW { virtual void get_supports(const Vector3& p_normal,int p_max,Vector3 *r_supports,int & r_amount) const { r_amount=0; } bool intersect_segment(const Vector3& p_begin,const Vector3& p_end,Vector3 &r_result, Vector3 &r_normal) const { return false; } - Vector3 get_moment_of_inertia(float p_mass) const { return Vector3(); } + Vector3 get_moment_of_inertia(real_t p_mass) const { return Vector3(); } virtual void set_data(const Variant& p_data) {} virtual Variant get_data() const { return Variant(); } diff --git a/servers/physics/space_sw.cpp b/servers/physics/space_sw.cpp index 04b8f5b68d..0bc11041de 100644 --- a/servers/physics/space_sw.cpp +++ b/servers/physics/space_sw.cpp @@ -138,7 +138,7 @@ bool PhysicsDirectSpaceStateSW::intersect_ray(const Vector3& p_from, const Vecto } -int PhysicsDirectSpaceStateSW::intersect_shape(const RID& p_shape, const Transform& p_xform,float p_margin,ShapeResult *r_results,int p_result_max,const Set<RID>& p_exclude,uint32_t p_layer_mask,uint32_t p_object_type_mask) { +int PhysicsDirectSpaceStateSW::intersect_shape(const RID& p_shape, const Transform& p_xform,real_t p_margin,ShapeResult *r_results,int p_result_max,const Set<RID>& p_exclude,uint32_t p_layer_mask,uint32_t p_object_type_mask) { if (p_result_max<=0) return 0; @@ -193,7 +193,7 @@ int PhysicsDirectSpaceStateSW::intersect_shape(const RID& p_shape, const Transfo } -bool PhysicsDirectSpaceStateSW::cast_motion(const RID& p_shape, const Transform& p_xform,const Vector3& p_motion,float p_margin,float &p_closest_safe,float &p_closest_unsafe, const Set<RID>& p_exclude,uint32_t p_layer_mask,uint32_t p_object_type_mask,ShapeRestInfo *r_info) { +bool PhysicsDirectSpaceStateSW::cast_motion(const RID& p_shape, const Transform& 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,uint32_t p_layer_mask,uint32_t p_object_type_mask,ShapeRestInfo *r_info) { @@ -211,8 +211,8 @@ bool PhysicsDirectSpaceStateSW::cast_motion(const RID& p_shape, const Transform& int amount = space->broadphase->cull_aabb(aabb,space->intersection_query_results,SpaceSW::INTERSECTION_QUERY_MAX,space->intersection_query_subindex_results); - float best_safe=1; - float best_unsafe=1; + real_t best_safe=1; + real_t best_unsafe=1; Transform xform_inv = p_xform.affine_inverse(); MotionShapeSW mshape; @@ -264,13 +264,13 @@ bool PhysicsDirectSpaceStateSW::cast_motion(const RID& p_shape, const Transform& //just do kinematic solving - float low=0; - float hi=1; + real_t low=0; + real_t hi=1; Vector3 mnormal=p_motion.normalized(); for(int i=0;i<8;i++) { //steps should be customizable.. - float ofs = (low+hi)*0.5; + real_t ofs = (low+hi)*0.5; Vector3 sep=mnormal; //important optimization for this to work fast enough @@ -323,7 +323,7 @@ bool PhysicsDirectSpaceStateSW::cast_motion(const RID& p_shape, const Transform& return true; } -bool PhysicsDirectSpaceStateSW::collide_shape(RID p_shape, const Transform& p_shape_xform,float p_margin,Vector3 *r_results,int p_result_max,int &r_result_count, const Set<RID>& p_exclude,uint32_t p_layer_mask,uint32_t p_object_type_mask){ +bool PhysicsDirectSpaceStateSW::collide_shape(RID p_shape, const Transform& p_shape_xform,real_t p_margin,Vector3 *r_results,int p_result_max,int &r_result_count, const Set<RID>& p_exclude,uint32_t p_layer_mask,uint32_t p_object_type_mask){ if (p_result_max<=0) return 0; @@ -388,7 +388,7 @@ struct _RestCallbackData { int best_shape; Vector3 best_contact; Vector3 best_normal; - float best_len; + real_t best_len; }; static void _rest_cbk_result(const Vector3& p_point_A,const Vector3& p_point_B,void *p_userdata) { @@ -397,7 +397,7 @@ static void _rest_cbk_result(const Vector3& p_point_A,const Vector3& p_point_B,v _RestCallbackData *rd=(_RestCallbackData*)p_userdata; Vector3 contact_rel = p_point_B - p_point_A; - float len = contact_rel.length(); + real_t len = contact_rel.length(); if (len <= rd->best_len) return; @@ -408,7 +408,7 @@ static void _rest_cbk_result(const Vector3& p_point_A,const Vector3& p_point_B,v rd->best_shape=rd->shape; } -bool PhysicsDirectSpaceStateSW::rest_info(RID p_shape, const Transform& p_shape_xform,float p_margin,ShapeRestInfo *r_info, const Set<RID>& p_exclude,uint32_t p_layer_mask,uint32_t p_object_type_mask) { +bool PhysicsDirectSpaceStateSW::rest_info(RID p_shape, const Transform& p_shape_xform,real_t p_margin,ShapeRestInfo *r_info, const Set<RID>& p_exclude,uint32_t p_layer_mask,uint32_t p_object_type_mask) { ShapeSW *shape = static_cast<PhysicsServerSW*>(PhysicsServer::get_singleton())->shape_owner.get(p_shape); diff --git a/servers/physics/space_sw.h b/servers/physics/space_sw.h index 3ec01c9205..208831914f 100644 --- a/servers/physics/space_sw.h +++ b/servers/physics/space_sw.h @@ -48,10 +48,10 @@ public: SpaceSW *space; 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_layer_mask=0xFFFFFFFF,uint32_t p_object_type_mask=TYPE_MASK_COLLISION,bool p_pick_ray=false); - virtual int intersect_shape(const RID& p_shape, const Transform& p_xform,float p_margin,ShapeResult *r_results,int p_result_max,const Set<RID>& p_exclude=Set<RID>(),uint32_t p_layer_mask=0xFFFFFFFF,uint32_t p_object_type_mask=TYPE_MASK_COLLISION); - virtual bool cast_motion(const RID& p_shape, const Transform& p_xform,const Vector3& p_motion,float p_margin,float &p_closest_safe,float &p_closest_unsafe, const Set<RID>& p_exclude=Set<RID>(),uint32_t p_layer_mask=0xFFFFFFFF,uint32_t p_object_type_mask=TYPE_MASK_COLLISION,ShapeRestInfo *r_info=NULL); - virtual bool collide_shape(RID p_shape, const Transform& p_shape_xform,float p_margin,Vector3 *r_results,int p_result_max,int &r_result_count, const Set<RID>& p_exclude=Set<RID>(),uint32_t p_layer_mask=0xFFFFFFFF,uint32_t p_object_type_mask=TYPE_MASK_COLLISION); - virtual bool rest_info(RID p_shape, const Transform& p_shape_xform,float p_margin,ShapeRestInfo *r_info, const Set<RID>& p_exclude=Set<RID>(),uint32_t p_layer_mask=0xFFFFFFFF,uint32_t p_object_type_mask=TYPE_MASK_COLLISION); + virtual int intersect_shape(const RID& p_shape, const Transform& p_xform,real_t p_margin,ShapeResult *r_results,int p_result_max,const Set<RID>& p_exclude=Set<RID>(),uint32_t p_layer_mask=0xFFFFFFFF,uint32_t p_object_type_mask=TYPE_MASK_COLLISION); + virtual bool cast_motion(const RID& p_shape, const Transform& 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_layer_mask=0xFFFFFFFF,uint32_t p_object_type_mask=TYPE_MASK_COLLISION,ShapeRestInfo *r_info=NULL); + virtual bool collide_shape(RID p_shape, const Transform& 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_layer_mask=0xFFFFFFFF,uint32_t p_object_type_mask=TYPE_MASK_COLLISION); + virtual bool rest_info(RID p_shape, const Transform& p_shape_xform,real_t p_margin,ShapeRestInfo *r_info, const Set<RID>& p_exclude=Set<RID>(),uint32_t p_layer_mask=0xFFFFFFFF,uint32_t p_object_type_mask=TYPE_MASK_COLLISION); PhysicsDirectSpaceStateSW(); }; @@ -105,10 +105,10 @@ private: CollisionObjectSW *intersection_query_results[INTERSECTION_QUERY_MAX]; int intersection_query_subindex_results[INTERSECTION_QUERY_MAX]; - float body_linear_velocity_sleep_threshold; - float body_angular_velocity_sleep_threshold; - float body_time_to_sleep; - float body_angular_velocity_damp_ratio; + real_t body_linear_velocity_sleep_threshold; + real_t body_angular_velocity_sleep_threshold; + real_t body_time_to_sleep; + real_t body_angular_velocity_damp_ratio; bool locked; diff --git a/servers/physics/step_sw.cpp b/servers/physics/step_sw.cpp index 30ee33a7de..0bd5a874ea 100644 --- a/servers/physics/step_sw.cpp +++ b/servers/physics/step_sw.cpp @@ -58,7 +58,7 @@ void StepSW::_populate_island(BodySW* p_body,BodySW** p_island,ConstraintSW **p_ } } -void StepSW::_setup_island(ConstraintSW *p_island,float p_delta) { +void StepSW::_setup_island(ConstraintSW *p_island,real_t p_delta) { ConstraintSW *ci=p_island; while(ci) { @@ -68,7 +68,7 @@ void StepSW::_setup_island(ConstraintSW *p_island,float p_delta) { } } -void StepSW::_solve_island(ConstraintSW *p_island,int p_iterations,float p_delta){ +void StepSW::_solve_island(ConstraintSW *p_island,int p_iterations,real_t p_delta){ int at_priority=1; @@ -107,7 +107,7 @@ void StepSW::_solve_island(ConstraintSW *p_island,int p_iterations,float p_delta } -void StepSW::_check_suspend(BodySW *p_island,float p_delta) { +void StepSW::_check_suspend(BodySW *p_island,real_t p_delta) { bool can_sleep=true; @@ -145,7 +145,7 @@ void StepSW::_check_suspend(BodySW *p_island,float p_delta) { } } -void StepSW::step(SpaceSW* p_space,float p_delta,int p_iterations) { +void StepSW::step(SpaceSW* p_space,real_t p_delta,int p_iterations) { p_space->lock(); // can't access space during this diff --git a/servers/physics/step_sw.h b/servers/physics/step_sw.h index 2f67b3c8df..7048a76937 100644 --- a/servers/physics/step_sw.h +++ b/servers/physics/step_sw.h @@ -36,12 +36,12 @@ class StepSW { uint64_t _step; void _populate_island(BodySW* p_body,BodySW** p_island,ConstraintSW **p_constraint_island); - void _setup_island(ConstraintSW *p_island,float p_delta); - void _solve_island(ConstraintSW *p_island,int p_iterations,float p_delta); - void _check_suspend(BodySW *p_island,float p_delta); + void _setup_island(ConstraintSW *p_island,real_t p_delta); + void _solve_island(ConstraintSW *p_island,int p_iterations,real_t p_delta); + void _check_suspend(BodySW *p_island,real_t p_delta); public: - void step(SpaceSW* p_space,float p_delta,int p_iterations); + void step(SpaceSW* p_space,real_t p_delta,int p_iterations); StepSW(); }; diff --git a/servers/physics_2d/area_2d_sw.h b/servers/physics_2d/area_2d_sw.h index 6e79b28afc..02a65962e5 100644 --- a/servers/physics_2d/area_2d_sw.h +++ b/servers/physics_2d/area_2d_sw.h @@ -43,13 +43,13 @@ class Area2DSW : public CollisionObject2DSW{ Physics2DServer::AreaSpaceOverrideMode space_override_mode; - float gravity; + real_t gravity; Vector2 gravity_vector; bool gravity_is_point; - float gravity_distance_scale; - float point_attenuation; - float linear_damp; - float angular_damp; + real_t gravity_distance_scale; + real_t point_attenuation; + real_t linear_damp; + real_t angular_damp; int priority; bool monitorable; @@ -131,8 +131,8 @@ public: void set_space_override_mode(Physics2DServer::AreaSpaceOverrideMode p_mode); Physics2DServer::AreaSpaceOverrideMode get_space_override_mode() const { return space_override_mode; } - _FORCE_INLINE_ void set_gravity(float p_gravity) { gravity=p_gravity; } - _FORCE_INLINE_ float get_gravity() const { return gravity; } + _FORCE_INLINE_ void set_gravity(real_t p_gravity) { gravity=p_gravity; } + _FORCE_INLINE_ real_t get_gravity() const { return gravity; } _FORCE_INLINE_ void set_gravity_vector(const Vector2& p_gravity) { gravity_vector=p_gravity; } _FORCE_INLINE_ Vector2 get_gravity_vector() const { return gravity_vector; } @@ -140,17 +140,17 @@ public: _FORCE_INLINE_ void set_gravity_as_point(bool p_enable) { gravity_is_point=p_enable; } _FORCE_INLINE_ bool is_gravity_point() const { return gravity_is_point; } - _FORCE_INLINE_ void set_gravity_distance_scale(float scale) { gravity_distance_scale=scale; } - _FORCE_INLINE_ float get_gravity_distance_scale() const { return gravity_distance_scale; } + _FORCE_INLINE_ void set_gravity_distance_scale(real_t scale) { gravity_distance_scale=scale; } + _FORCE_INLINE_ real_t get_gravity_distance_scale() const { return gravity_distance_scale; } - _FORCE_INLINE_ void set_point_attenuation(float p_point_attenuation) { point_attenuation=p_point_attenuation; } - _FORCE_INLINE_ float get_point_attenuation() const { return point_attenuation; } + _FORCE_INLINE_ void set_point_attenuation(real_t p_point_attenuation) { point_attenuation=p_point_attenuation; } + _FORCE_INLINE_ real_t get_point_attenuation() const { return point_attenuation; } - _FORCE_INLINE_ void set_linear_damp(float p_linear_damp) { linear_damp=p_linear_damp; } - _FORCE_INLINE_ float get_linear_damp() const { return linear_damp; } + _FORCE_INLINE_ void set_linear_damp(real_t p_linear_damp) { linear_damp=p_linear_damp; } + _FORCE_INLINE_ real_t get_linear_damp() const { return linear_damp; } - _FORCE_INLINE_ void set_angular_damp(float p_angular_damp) { angular_damp=p_angular_damp; } - _FORCE_INLINE_ float get_angular_damp() const { return angular_damp; } + _FORCE_INLINE_ void set_angular_damp(real_t p_angular_damp) { angular_damp=p_angular_damp; } + _FORCE_INLINE_ real_t get_angular_damp() const { return angular_damp; } _FORCE_INLINE_ void set_priority(int p_priority) { priority=p_priority; } _FORCE_INLINE_ int get_priority() const { return priority; } diff --git a/servers/physics_2d/area_pair_2d_sw.cpp b/servers/physics_2d/area_pair_2d_sw.cpp index c26f6c45fd..cb91caf626 100644 --- a/servers/physics_2d/area_pair_2d_sw.cpp +++ b/servers/physics_2d/area_pair_2d_sw.cpp @@ -30,7 +30,7 @@ #include "collision_solver_2d_sw.h" -bool AreaPair2DSW::setup(float p_step) { +bool AreaPair2DSW::setup(real_t p_step) { bool result = area->test_collision_mask(body) && CollisionSolver2DSW::solve(body->get_shape(body_shape),body->get_transform() * body->get_shape_transform(body_shape),Vector2(),area->get_shape(area_shape),area->get_transform() * area->get_shape_transform(area_shape),Vector2(),NULL,this); @@ -59,7 +59,7 @@ bool AreaPair2DSW::setup(float p_step) { return false; //never do any post solving } -void AreaPair2DSW::solve(float p_step) { +void AreaPair2DSW::solve(real_t p_step) { } @@ -100,7 +100,7 @@ AreaPair2DSW::~AreaPair2DSW() { -bool Area2Pair2DSW::setup(float p_step) { +bool Area2Pair2DSW::setup(real_t p_step) { bool result = area_a->test_collision_mask(area_b) && CollisionSolver2DSW::solve(area_a->get_shape(shape_a),area_a->get_transform() * area_a->get_shape_transform(shape_a),Vector2(),area_b->get_shape(shape_b),area_b->get_transform() * area_b->get_shape_transform(shape_b),Vector2(),NULL,this); @@ -130,7 +130,7 @@ bool Area2Pair2DSW::setup(float p_step) { return false; //never do any post solving } -void Area2Pair2DSW::solve(float p_step) { +void Area2Pair2DSW::solve(real_t p_step) { } diff --git a/servers/physics_2d/area_pair_2d_sw.h b/servers/physics_2d/area_pair_2d_sw.h index db77bff5d4..219ca30c4b 100644 --- a/servers/physics_2d/area_pair_2d_sw.h +++ b/servers/physics_2d/area_pair_2d_sw.h @@ -42,8 +42,8 @@ class AreaPair2DSW : public Constraint2DSW { bool colliding; public: - bool setup(float p_step); - void solve(float p_step); + bool setup(real_t p_step); + void solve(real_t p_step); AreaPair2DSW(Body2DSW *p_body,int p_body_shape, Area2DSW *p_area,int p_area_shape); ~AreaPair2DSW(); @@ -59,8 +59,8 @@ class Area2Pair2DSW : public Constraint2DSW { bool colliding; public: - bool setup(float p_step); - void solve(float p_step); + bool setup(real_t p_step); + void solve(real_t p_step); Area2Pair2DSW(Area2DSW *p_area_a,int p_shape_a, Area2DSW *p_area_b,int p_shape_b); ~Area2Pair2DSW(); diff --git a/servers/physics_2d/body_2d_sw.cpp b/servers/physics_2d/body_2d_sw.cpp index 093f69a169..0dab534ef9 100644 --- a/servers/physics_2d/body_2d_sw.cpp +++ b/servers/physics_2d/body_2d_sw.cpp @@ -51,7 +51,7 @@ void Body2DSW::update_inertias() { if(user_inertia) break; //update tensor for allshapes, not the best way but should be somehow OK. (inspired from bullet) - float total_area=0; + real_t total_area=0; for (int i=0;i<get_shape_count();i++) { @@ -64,9 +64,9 @@ void Body2DSW::update_inertias() { const Shape2DSW* shape=get_shape(i); - float area=get_shape_aabb(i).get_area(); + real_t area=get_shape_aabb(i).get_area(); - float mass = area * this->mass / total_area; + real_t mass = area * this->mass / total_area; Transform2D mtx = get_shape_transform(i); Vector2 scale = mtx.get_scale(); @@ -142,7 +142,7 @@ void Body2DSW::set_active(bool p_active) { -void Body2DSW::set_param(Physics2DServer::BodyParameter p_param, float p_value) { +void Body2DSW::set_param(Physics2DServer::BodyParameter p_param, real_t p_value) { switch(p_param) { case Physics2DServer::BODY_PARAM_BOUNCE: { @@ -183,7 +183,7 @@ void Body2DSW::set_param(Physics2DServer::BodyParameter p_param, float p_value) } } -float Body2DSW::get_param(Physics2DServer::BodyParameter p_param) const { +real_t Body2DSW::get_param(Physics2DServer::BodyParameter p_param) const { switch(p_param) { case Physics2DServer::BODY_PARAM_BOUNCE: { diff --git a/servers/physics_2d/body_2d_sw.h b/servers/physics_2d/body_2d_sw.h index bf9dcaa9b0..3fb01959a9 100644 --- a/servers/physics_2d/body_2d_sw.h +++ b/servers/physics_2d/body_2d_sw.h @@ -69,7 +69,7 @@ class Body2DSW : public CollisionObject2DSW { real_t applied_torque; Vector2 one_way_collision_direction; - float one_way_collision_max_depth; + real_t one_way_collision_max_depth; SelfList<Body2DSW> active_list; @@ -109,7 +109,7 @@ class Body2DSW : public CollisionObject2DSW { Vector2 local_pos; Vector2 local_normal; - float depth; + real_t depth; int local_shape; Vector2 collider_pos; int collider_shape; @@ -168,7 +168,7 @@ public: _FORCE_INLINE_ int get_max_contacts_reported() const { return contacts.size(); } _FORCE_INLINE_ bool can_report_contacts() const { return !contacts.empty(); } - _FORCE_INLINE_ void add_contact(const Vector2& p_local_pos,const Vector2& p_local_normal, float p_depth, int p_local_shape, const Vector2& p_collider_pos, int p_collider_shape, ObjectID p_collider_instance_id, const RID& p_collider,const Vector2& p_collider_velocity_at_pos); + _FORCE_INLINE_ void add_contact(const Vector2& p_local_pos,const Vector2& p_local_normal, real_t p_depth, int p_local_shape, const Vector2& p_collider_pos, int p_collider_shape, ObjectID p_collider_instance_id, const RID& p_collider,const Vector2& p_collider_velocity_at_pos); _FORCE_INLINE_ void add_exception(const RID& p_exception) { exceptions.insert(p_exception);} @@ -229,8 +229,8 @@ public: - void set_param(Physics2DServer::BodyParameter p_param, float); - float get_param(Physics2DServer::BodyParameter p_param) const; + void set_param(Physics2DServer::BodyParameter p_param, real_t); + real_t get_param(Physics2DServer::BodyParameter p_param) const; void set_mode(Physics2DServer::BodyMode p_mode); Physics2DServer::BodyMode get_mode() const; @@ -259,8 +259,8 @@ public: } Vector2 get_one_way_collision_direction() const { return one_way_collision_direction; } - void set_one_way_collision_max_depth(float p_depth) { one_way_collision_max_depth=p_depth; } - float get_one_way_collision_max_depth() const { return one_way_collision_max_depth; } + void set_one_way_collision_max_depth(real_t p_depth) { one_way_collision_max_depth=p_depth; } + real_t get_one_way_collision_max_depth() const { return one_way_collision_max_depth; } _FORCE_INLINE_ bool is_using_one_way_collision() const { return using_one_way_cache; } @@ -303,7 +303,7 @@ public: //add contact inline -void Body2DSW::add_contact(const Vector2& p_local_pos,const Vector2& p_local_normal, float p_depth, int p_local_shape, const Vector2& p_collider_pos, int p_collider_shape, ObjectID p_collider_instance_id, const RID& p_collider,const Vector2& p_collider_velocity_at_pos) { +void Body2DSW::add_contact(const Vector2& p_local_pos,const Vector2& p_local_normal, real_t p_depth, int p_local_shape, const Vector2& p_collider_pos, int p_collider_shape, ObjectID p_collider_instance_id, const RID& p_collider,const Vector2& p_collider_velocity_at_pos) { int c_max=contacts.size(); @@ -319,7 +319,7 @@ void Body2DSW::add_contact(const Vector2& p_local_pos,const Vector2& p_local_nor idx=contact_count++; } else { - float least_depth=1e20; + real_t least_depth=1e20; int least_deep=-1; for(int i=0;i<c_max;i++) { @@ -361,10 +361,10 @@ public: real_t step; virtual Vector2 get_total_gravity() const { return body->gravity; } // get gravity vector working on this body space/area - virtual float get_total_angular_damp() const { return body->area_angular_damp; } // get density of this body space/area - virtual float get_total_linear_damp() const { return body->area_linear_damp; } // get density of this body space/area + virtual real_t get_total_angular_damp() const { return body->area_angular_damp; } // get density of this body space/area + virtual real_t get_total_linear_damp() const { return body->area_linear_damp; } // get density of this body space/area - virtual float get_inverse_mass() const { return body->get_inv_mass(); } // get the mass + virtual real_t get_inverse_mass() const { return body->get_inv_mass(); } // get the mass virtual real_t get_inverse_inertia() const { return body->get_inv_inertia(); } // get density of this body space virtual void set_linear_velocity(const Vector2& p_velocity) { body->set_linear_velocity(p_velocity); } diff --git a/servers/physics_2d/body_pair_2d_sw.cpp b/servers/physics_2d/body_pair_2d_sw.cpp index e6b62ffa66..c05d61b658 100644 --- a/servers/physics_2d/body_pair_2d_sw.cpp +++ b/servers/physics_2d/body_pair_2d_sw.cpp @@ -99,7 +99,7 @@ void BodyPair2DSW::_contact_added_callback(const Vector2& p_point_A,const Vector Vector2 global_B = B->get_transform().basis_xform(c.local_B)+offset_B; Vector2 axis = global_A - global_B; - float depth = axis.dot( c.normal ); + real_t depth = axis.dot( c.normal ); if (depth<min_depth) { @@ -149,7 +149,7 @@ void BodyPair2DSW::_validate_contacts() { Vector2 global_A = A->get_transform().basis_xform(c.local_A); Vector2 global_B = B->get_transform().basis_xform(c.local_B)+offset_B; Vector2 axis = global_A - global_B; - float depth = axis.dot( c.normal ); + real_t depth = axis.dot( c.normal ); @@ -175,7 +175,7 @@ void BodyPair2DSW::_validate_contacts() { } -bool BodyPair2DSW::_test_ccd(float p_step,Body2DSW *p_A, int p_shape_A,const Transform2D& p_xform_A,Body2DSW *p_B, int p_shape_B,const Transform2D& p_xform_B,bool p_swap_result) { +bool BodyPair2DSW::_test_ccd(real_t p_step,Body2DSW *p_A, int p_shape_A,const Transform2D& p_xform_A,Body2DSW *p_B, int p_shape_B,const Transform2D& p_xform_B,bool p_swap_result) { @@ -230,7 +230,7 @@ bool BodyPair2DSW::_test_ccd(float p_step,Body2DSW *p_A, int p_shape_A,const Tra return true; } -bool BodyPair2DSW::setup(float p_step) { +bool BodyPair2DSW::setup(real_t p_step) { //cannot collide @@ -343,7 +343,7 @@ bool BodyPair2DSW::setup(float p_step) { real_t max_penetration = space->get_contact_max_allowed_penetration(); - float bias = 0.3f; + real_t bias = 0.3; if (shape_A_ptr->get_custom_bias() || shape_B_ptr->get_custom_bias()) { if (shape_A_ptr->get_custom_bias()==0) @@ -464,7 +464,7 @@ bool BodyPair2DSW::setup(float p_step) { return do_process; } -void BodyPair2DSW::solve(float p_step) { +void BodyPair2DSW::solve(real_t p_step) { if (!collided) return; diff --git a/servers/physics_2d/body_pair_2d_sw.h b/servers/physics_2d/body_pair_2d_sw.h index b9ff1bd758..7a4771782a 100644 --- a/servers/physics_2d/body_pair_2d_sw.h +++ b/servers/physics_2d/body_pair_2d_sw.h @@ -66,7 +66,7 @@ class BodyPair2DSW : public Constraint2DSW { bool active; Vector2 rA,rB; bool reused; - float bounce; + real_t bounce; }; @@ -80,15 +80,15 @@ class BodyPair2DSW : public Constraint2DSW { int cc; - bool _test_ccd(float p_step,Body2DSW *p_A, int p_shape_A,const Transform2D& p_xform_A,Body2DSW *p_B, int p_shape_B,const Transform2D& p_xform_B,bool p_swap_result=false); + bool _test_ccd(real_t p_step,Body2DSW *p_A, int p_shape_A,const Transform2D& p_xform_A,Body2DSW *p_B, int p_shape_B,const Transform2D& p_xform_B,bool p_swap_result=false); void _validate_contacts(); static void _add_contact(const Vector2& p_point_A,const Vector2& p_point_B,void *p_self); _FORCE_INLINE_ void _contact_added_callback(const Vector2& p_point_A,const Vector2& p_point_B); public: - bool setup(float p_step); - void solve(float p_step); + bool setup(real_t p_step); + void solve(real_t p_step); BodyPair2DSW(Body2DSW *p_A, int p_shape_A,Body2DSW *p_B, int p_shape_B); ~BodyPair2DSW(); diff --git a/servers/physics_2d/collision_solver_2d_sat.cpp b/servers/physics_2d/collision_solver_2d_sat.cpp index a09574a94c..4c116cee3f 100644 --- a/servers/physics_2d/collision_solver_2d_sat.cpp +++ b/servers/physics_2d/collision_solver_2d_sat.cpp @@ -81,7 +81,7 @@ _FORCE_INLINE_ static void _generate_contacts_point_edge(const Vector2 * p_point struct _generate_contacts_Pair { bool a; int idx; - float d; + real_t d; _FORCE_INLINE_ bool operator <(const _generate_contacts_Pair& l) const { return d< l.d; } }; @@ -108,7 +108,7 @@ _FORCE_INLINE_ static void _generate_contacts_edge_edge(const Vector2 * p_points SWAP(pA[0],pA[1]); } - float dB[2]={t.dot(p_points_B[0]),t.dot(p_points_B[1])}; + real_t dB[2]={t.dot(p_points_B[0]),t.dot(p_points_B[1])}; Vector2 pB[2]={p_points_B[0],p_points_B[1]}; if (dB[0]>dB[1]) { SWAP(dB[0],dB[1]); @@ -265,10 +265,10 @@ _FORCE_INLINE_ static void _generate_contacts_edge_edge(const Vector2 * p_points Vector2 base_B = p_points_B[0] - axis * axis.dot(p_points_B[0]); //sort all 4 points in axis - float dvec[4]={ axis.dot(p_points_A[0]), axis.dot(p_points_A[1]), axis.dot(p_points_B[0]), axis.dot(p_points_B[1]) }; + real_t dvec[4]={ axis.dot(p_points_A[0]), axis.dot(p_points_A[1]), axis.dot(p_points_B[0]), axis.dot(p_points_B[1]) }; //todo , find max/min and then use 2 central points - SortArray<float> sa; + SortArray<real_t> sa; sa.sort(dvec,4); //use the middle ones as contacts @@ -596,11 +596,11 @@ public: (castA && castB && !separator.test_axis(((m_a)+p_motion_a-((m_b)+p_motion_b)).normalized())) ) -typedef void (*CollisionFunc)(const Shape2DSW*,const Transform2D&,const Shape2DSW*,const Transform2D&,_CollectorCallback2D *p_collector,const Vector2&,const Vector2&,float,float); +typedef void (*CollisionFunc)(const Shape2DSW*,const Transform2D&,const Shape2DSW*,const Transform2D&,_CollectorCallback2D *p_collector,const Vector2&,const Vector2&,real_t,real_t); template<bool castA, bool castB,bool withMargin> -static void _collision_segment_segment(const Shape2DSW* p_a,const Transform2D& p_transform_a,const Shape2DSW* p_b,const Transform2D& p_transform_b,_CollectorCallback2D *p_collector,const Vector2& p_motion_a,const Vector2& p_motion_b,float p_margin_A,float p_margin_B) { +static void _collision_segment_segment(const Shape2DSW* p_a,const Transform2D& p_transform_a,const Shape2DSW* p_b,const Transform2D& p_transform_b,_CollectorCallback2D *p_collector,const Vector2& p_motion_a,const Vector2& p_motion_b,real_t p_margin_A,real_t p_margin_B) { const SegmentShape2DSW *segment_A = static_cast<const SegmentShape2DSW*>(p_a); const SegmentShape2DSW *segment_B = static_cast<const SegmentShape2DSW*>(p_b); @@ -645,7 +645,7 @@ static void _collision_segment_segment(const Shape2DSW* p_a,const Transform2D& p } template<bool castA, bool castB,bool withMargin> -static void _collision_segment_circle(const Shape2DSW* p_a,const Transform2D& p_transform_a,const Shape2DSW* p_b,const Transform2D& p_transform_b,_CollectorCallback2D *p_collector,const Vector2& p_motion_a,const Vector2& p_motion_b,float p_margin_A,float p_margin_B) { +static void _collision_segment_circle(const Shape2DSW* p_a,const Transform2D& p_transform_a,const Shape2DSW* p_b,const Transform2D& p_transform_b,_CollectorCallback2D *p_collector,const Vector2& p_motion_a,const Vector2& p_motion_b,real_t p_margin_A,real_t p_margin_B) { const SegmentShape2DSW *segment_A = static_cast<const SegmentShape2DSW*>(p_a); @@ -678,7 +678,7 @@ static void _collision_segment_circle(const Shape2DSW* p_a,const Transform2D& p_ } template<bool castA, bool castB,bool withMargin> -static void _collision_segment_rectangle(const Shape2DSW* p_a,const Transform2D& p_transform_a,const Shape2DSW* p_b,const Transform2D& p_transform_b,_CollectorCallback2D *p_collector,const Vector2& p_motion_a,const Vector2& p_motion_b,float p_margin_A,float p_margin_B) { +static void _collision_segment_rectangle(const Shape2DSW* p_a,const Transform2D& p_transform_a,const Shape2DSW* p_b,const Transform2D& p_transform_b,_CollectorCallback2D *p_collector,const Vector2& p_motion_a,const Vector2& p_motion_b,real_t p_margin_A,real_t p_margin_B) { const SegmentShape2DSW *segment_A = static_cast<const SegmentShape2DSW*>(p_a); const RectangleShape2DSW *rectangle_B = static_cast<const RectangleShape2DSW*>(p_b); @@ -743,7 +743,7 @@ static void _collision_segment_rectangle(const Shape2DSW* p_a,const Transform2D& } template<bool castA, bool castB,bool withMargin> -static void _collision_segment_capsule(const Shape2DSW* p_a,const Transform2D& p_transform_a,const Shape2DSW* p_b,const Transform2D& p_transform_b,_CollectorCallback2D *p_collector,const Vector2& p_motion_a,const Vector2& p_motion_b,float p_margin_A,float p_margin_B) { +static void _collision_segment_capsule(const Shape2DSW* p_a,const Transform2D& p_transform_a,const Shape2DSW* p_b,const Transform2D& p_transform_b,_CollectorCallback2D *p_collector,const Vector2& p_motion_a,const Vector2& p_motion_b,real_t p_margin_A,real_t p_margin_B) { const SegmentShape2DSW *segment_A = static_cast<const SegmentShape2DSW*>(p_a); const CapsuleShape2DSW *capsule_B = static_cast<const CapsuleShape2DSW*>(p_b); @@ -775,7 +775,7 @@ static void _collision_segment_capsule(const Shape2DSW* p_a,const Transform2D& p } template<bool castA, bool castB,bool withMargin> -static void _collision_segment_convex_polygon(const Shape2DSW* p_a,const Transform2D& p_transform_a,const Shape2DSW* p_b,const Transform2D& p_transform_b,_CollectorCallback2D *p_collector,const Vector2& p_motion_a,const Vector2& p_motion_b,float p_margin_A,float p_margin_B) { +static void _collision_segment_convex_polygon(const Shape2DSW* p_a,const Transform2D& p_transform_a,const Shape2DSW* p_b,const Transform2D& p_transform_b,_CollectorCallback2D *p_collector,const Vector2& p_motion_a,const Vector2& p_motion_b,real_t p_margin_A,real_t p_margin_B) { const SegmentShape2DSW *segment_A = static_cast<const SegmentShape2DSW*>(p_a); const ConvexPolygonShape2DSW *convex_B = static_cast<const ConvexPolygonShape2DSW*>(p_b); @@ -815,7 +815,7 @@ static void _collision_segment_convex_polygon(const Shape2DSW* p_a,const Transfo ///////// template<bool castA, bool castB,bool withMargin> -static void _collision_circle_circle(const Shape2DSW* p_a,const Transform2D& p_transform_a,const Shape2DSW* p_b,const Transform2D& p_transform_b,_CollectorCallback2D *p_collector,const Vector2& p_motion_a,const Vector2& p_motion_b,float p_margin_A,float p_margin_B) { +static void _collision_circle_circle(const Shape2DSW* p_a,const Transform2D& p_transform_a,const Shape2DSW* p_b,const Transform2D& p_transform_b,_CollectorCallback2D *p_collector,const Vector2& p_motion_a,const Vector2& p_motion_b,real_t p_margin_A,real_t p_margin_B) { const CircleShape2DSW *circle_A = static_cast<const CircleShape2DSW*>(p_a); const CircleShape2DSW *circle_B = static_cast<const CircleShape2DSW*>(p_b); @@ -838,7 +838,7 @@ static void _collision_circle_circle(const Shape2DSW* p_a,const Transform2D& p_t } template<bool castA, bool castB,bool withMargin> -static void _collision_circle_rectangle(const Shape2DSW* p_a,const Transform2D& p_transform_a,const Shape2DSW* p_b,const Transform2D& p_transform_b,_CollectorCallback2D *p_collector,const Vector2& p_motion_a,const Vector2& p_motion_b,float p_margin_A,float p_margin_B) { +static void _collision_circle_rectangle(const Shape2DSW* p_a,const Transform2D& p_transform_a,const Shape2DSW* p_b,const Transform2D& p_transform_b,_CollectorCallback2D *p_collector,const Vector2& p_motion_a,const Vector2& p_motion_b,real_t p_margin_A,real_t p_margin_B) { const CircleShape2DSW *circle_A = static_cast<const CircleShape2DSW*>(p_a); const RectangleShape2DSW *rectangle_B = static_cast<const RectangleShape2DSW*>(p_b); @@ -894,7 +894,7 @@ static void _collision_circle_rectangle(const Shape2DSW* p_a,const Transform2D& } template<bool castA, bool castB,bool withMargin> -static void _collision_circle_capsule(const Shape2DSW* p_a,const Transform2D& p_transform_a,const Shape2DSW* p_b,const Transform2D& p_transform_b,_CollectorCallback2D *p_collector,const Vector2& p_motion_a,const Vector2& p_motion_b,float p_margin_A,float p_margin_B) { +static void _collision_circle_capsule(const Shape2DSW* p_a,const Transform2D& p_transform_a,const Shape2DSW* p_b,const Transform2D& p_transform_b,_CollectorCallback2D *p_collector,const Vector2& p_motion_a,const Vector2& p_motion_b,real_t p_margin_A,real_t p_margin_B) { const CircleShape2DSW *circle_A = static_cast<const CircleShape2DSW*>(p_a); const CapsuleShape2DSW *capsule_B = static_cast<const CapsuleShape2DSW*>(p_b); @@ -924,7 +924,7 @@ static void _collision_circle_capsule(const Shape2DSW* p_a,const Transform2D& p_ } template<bool castA, bool castB,bool withMargin> -static void _collision_circle_convex_polygon(const Shape2DSW* p_a,const Transform2D& p_transform_a,const Shape2DSW* p_b,const Transform2D& p_transform_b,_CollectorCallback2D *p_collector,const Vector2& p_motion_a,const Vector2& p_motion_b,float p_margin_A,float p_margin_B) { +static void _collision_circle_convex_polygon(const Shape2DSW* p_a,const Transform2D& p_transform_a,const Shape2DSW* p_b,const Transform2D& p_transform_b,_CollectorCallback2D *p_collector,const Vector2& p_motion_a,const Vector2& p_motion_b,real_t p_margin_A,real_t p_margin_B) { const CircleShape2DSW *circle_A = static_cast<const CircleShape2DSW*>(p_a); const ConvexPolygonShape2DSW *convex_B = static_cast<const ConvexPolygonShape2DSW*>(p_b); @@ -956,7 +956,7 @@ static void _collision_circle_convex_polygon(const Shape2DSW* p_a,const Transfor ///////// template<bool castA, bool castB,bool withMargin> -static void _collision_rectangle_rectangle(const Shape2DSW* p_a,const Transform2D& p_transform_a,const Shape2DSW* p_b,const Transform2D& p_transform_b,_CollectorCallback2D *p_collector,const Vector2& p_motion_a,const Vector2& p_motion_b,float p_margin_A,float p_margin_B) { +static void _collision_rectangle_rectangle(const Shape2DSW* p_a,const Transform2D& p_transform_a,const Shape2DSW* p_b,const Transform2D& p_transform_b,_CollectorCallback2D *p_collector,const Vector2& p_motion_a,const Vector2& p_motion_b,real_t p_margin_A,real_t p_margin_B) { const RectangleShape2DSW *rectangle_A = static_cast<const RectangleShape2DSW*>(p_a); const RectangleShape2DSW *rectangle_B = static_cast<const RectangleShape2DSW*>(p_b); @@ -1027,7 +1027,7 @@ static void _collision_rectangle_rectangle(const Shape2DSW* p_a,const Transform2 } template<bool castA, bool castB,bool withMargin> -static void _collision_rectangle_capsule(const Shape2DSW* p_a,const Transform2D& p_transform_a,const Shape2DSW* p_b,const Transform2D& p_transform_b,_CollectorCallback2D *p_collector,const Vector2& p_motion_a,const Vector2& p_motion_b,float p_margin_A,float p_margin_B) { +static void _collision_rectangle_capsule(const Shape2DSW* p_a,const Transform2D& p_transform_a,const Shape2DSW* p_b,const Transform2D& p_transform_b,_CollectorCallback2D *p_collector,const Vector2& p_motion_a,const Vector2& p_motion_b,real_t p_margin_A,real_t p_margin_B) { const RectangleShape2DSW *rectangle_A = static_cast<const RectangleShape2DSW*>(p_a); const CapsuleShape2DSW *capsule_B = static_cast<const CapsuleShape2DSW*>(p_b); @@ -1100,7 +1100,7 @@ static void _collision_rectangle_capsule(const Shape2DSW* p_a,const Transform2D& } template<bool castA, bool castB,bool withMargin> -static void _collision_rectangle_convex_polygon(const Shape2DSW* p_a,const Transform2D& p_transform_a,const Shape2DSW* p_b,const Transform2D& p_transform_b,_CollectorCallback2D *p_collector,const Vector2& p_motion_a,const Vector2& p_motion_b,float p_margin_A,float p_margin_B) { +static void _collision_rectangle_convex_polygon(const Shape2DSW* p_a,const Transform2D& p_transform_a,const Shape2DSW* p_b,const Transform2D& p_transform_b,_CollectorCallback2D *p_collector,const Vector2& p_motion_a,const Vector2& p_motion_b,real_t p_margin_A,real_t p_margin_B) { const RectangleShape2DSW *rectangle_A = static_cast<const RectangleShape2DSW*>(p_a); const ConvexPolygonShape2DSW *convex_B = static_cast<const ConvexPolygonShape2DSW*>(p_b); @@ -1162,7 +1162,7 @@ static void _collision_rectangle_convex_polygon(const Shape2DSW* p_a,const Trans ///////// template<bool castA, bool castB,bool withMargin> -static void _collision_capsule_capsule(const Shape2DSW* p_a,const Transform2D& p_transform_a,const Shape2DSW* p_b,const Transform2D& p_transform_b,_CollectorCallback2D *p_collector,const Vector2& p_motion_a,const Vector2& p_motion_b,float p_margin_A,float p_margin_B) { +static void _collision_capsule_capsule(const Shape2DSW* p_a,const Transform2D& p_transform_a,const Shape2DSW* p_b,const Transform2D& p_transform_b,_CollectorCallback2D *p_collector,const Vector2& p_motion_a,const Vector2& p_motion_b,real_t p_margin_A,real_t p_margin_B) { const CapsuleShape2DSW *capsule_A = static_cast<const CapsuleShape2DSW*>(p_a); const CapsuleShape2DSW *capsule_B = static_cast<const CapsuleShape2DSW*>(p_b); @@ -1205,7 +1205,7 @@ static void _collision_capsule_capsule(const Shape2DSW* p_a,const Transform2D& p } template<bool castA, bool castB,bool withMargin> -static void _collision_capsule_convex_polygon(const Shape2DSW* p_a,const Transform2D& p_transform_a,const Shape2DSW* p_b,const Transform2D& p_transform_b,_CollectorCallback2D *p_collector,const Vector2& p_motion_a,const Vector2& p_motion_b,float p_margin_A,float p_margin_B) { +static void _collision_capsule_convex_polygon(const Shape2DSW* p_a,const Transform2D& p_transform_a,const Shape2DSW* p_b,const Transform2D& p_transform_b,_CollectorCallback2D *p_collector,const Vector2& p_motion_a,const Vector2& p_motion_b,real_t p_margin_A,real_t p_margin_B) { const CapsuleShape2DSW *capsule_A = static_cast<const CapsuleShape2DSW*>(p_a); const ConvexPolygonShape2DSW *convex_B = static_cast<const ConvexPolygonShape2DSW*>(p_b); @@ -1251,7 +1251,7 @@ static void _collision_capsule_convex_polygon(const Shape2DSW* p_a,const Transfo template<bool castA, bool castB,bool withMargin> -static void _collision_convex_polygon_convex_polygon(const Shape2DSW* p_a,const Transform2D& p_transform_a,const Shape2DSW* p_b,const Transform2D& p_transform_b,_CollectorCallback2D *p_collector,const Vector2& p_motion_a,const Vector2& p_motion_b,float p_margin_A,float p_margin_B) { +static void _collision_convex_polygon_convex_polygon(const Shape2DSW* p_a,const Transform2D& p_transform_a,const Shape2DSW* p_b,const Transform2D& p_transform_b,_CollectorCallback2D *p_collector,const Vector2& p_motion_a,const Vector2& p_motion_b,real_t p_margin_A,real_t p_margin_B) { const ConvexPolygonShape2DSW *convex_A = static_cast<const ConvexPolygonShape2DSW*>(p_a); @@ -1298,7 +1298,7 @@ static void _collision_convex_polygon_convex_polygon(const Shape2DSW* p_a,const //////// -bool sat_2d_calculate_penetration(const Shape2DSW *p_shape_A, const Transform2D& p_transform_A, const Vector2& p_motion_A, const Shape2DSW *p_shape_B, const Transform2D& p_transform_B,const Vector2& p_motion_B, CollisionSolver2DSW::CallbackResult p_result_callback,void *p_userdata, bool p_swap,Vector2 *sep_axis,float p_margin_A,float p_margin_B) { +bool sat_2d_calculate_penetration(const Shape2DSW *p_shape_A, const Transform2D& p_transform_A, const Vector2& p_motion_A, const Shape2DSW *p_shape_B, const Transform2D& p_transform_B,const Vector2& p_motion_B, CollisionSolver2DSW::CallbackResult p_result_callback,void *p_userdata, bool p_swap,Vector2 *sep_axis,real_t p_margin_A,real_t p_margin_B) { Physics2DServer::ShapeType type_A=p_shape_A->get_type(); diff --git a/servers/physics_2d/collision_solver_2d_sat.h b/servers/physics_2d/collision_solver_2d_sat.h index 01acf319c7..6b698a09f2 100644 --- a/servers/physics_2d/collision_solver_2d_sat.h +++ b/servers/physics_2d/collision_solver_2d_sat.h @@ -32,6 +32,6 @@ #include "collision_solver_2d_sw.h" -bool sat_2d_calculate_penetration(const Shape2DSW *p_shape_A, const Transform2D& p_transform_A, const Vector2& p_motion_A,const Shape2DSW *p_shape_B, const Transform2D& p_transform_B,const Vector2& p_motion_B, CollisionSolver2DSW::CallbackResult p_result_callback,void *p_userdata, bool p_swap=false,Vector2 *sep_axis=NULL,float p_margin_A=0,float p_margin_B=0); +bool sat_2d_calculate_penetration(const Shape2DSW *p_shape_A, const Transform2D& p_transform_A, const Vector2& p_motion_A,const Shape2DSW *p_shape_B, const Transform2D& p_transform_B,const Vector2& p_motion_B, CollisionSolver2DSW::CallbackResult p_result_callback,void *p_userdata, bool p_swap=false,Vector2 *sep_axis=NULL,real_t p_margin_A=0,real_t p_margin_B=0); #endif // COLLISION_SOLVER_2D_SAT_H diff --git a/servers/physics_2d/collision_solver_2d_sw.cpp b/servers/physics_2d/collision_solver_2d_sw.cpp index 20a5934eb8..3fdecdf413 100644 --- a/servers/physics_2d/collision_solver_2d_sw.cpp +++ b/servers/physics_2d/collision_solver_2d_sw.cpp @@ -181,7 +181,7 @@ void CollisionSolver2DSW::concave_callback(void *p_userdata, Shape2DSW *p_convex } -bool CollisionSolver2DSW::solve_concave(const Shape2DSW *p_shape_A,const Transform2D& p_transform_A,const Vector2& p_motion_A,const Shape2DSW *p_shape_B,const Transform2D& p_transform_B,const Vector2& p_motion_B,CallbackResult p_result_callback,void *p_userdata,bool p_swap_result,Vector2 *sep_axis,float p_margin_A,float p_margin_B) { +bool CollisionSolver2DSW::solve_concave(const Shape2DSW *p_shape_A,const Transform2D& p_transform_A,const Vector2& p_motion_A,const Shape2DSW *p_shape_B,const Transform2D& p_transform_B,const Vector2& p_motion_B,CallbackResult p_result_callback,void *p_userdata,bool p_swap_result,Vector2 *sep_axis,real_t p_margin_A,real_t p_margin_B) { const ConcaveShape2DSW *concave_B=static_cast<const ConcaveShape2DSW*>(p_shape_B); @@ -211,10 +211,10 @@ bool CollisionSolver2DSW::solve_concave(const Shape2DSW *p_shape_A,const Transfo for(int i=0;i<2;i++) { Vector2 axis( p_transform_B.elements[i] ); - float axis_scale = 1.0/axis.length(); + real_t axis_scale = 1.0/axis.length(); axis*=axis_scale; - float smin,smax; + real_t smin,smax; p_shape_A->project_rangev(axis,rel_transform,smin,smax); smin*=axis_scale; smax*=axis_scale; @@ -231,7 +231,7 @@ bool CollisionSolver2DSW::solve_concave(const Shape2DSW *p_shape_A,const Transfo } -bool CollisionSolver2DSW::solve(const Shape2DSW *p_shape_A,const Transform2D& p_transform_A,const Vector2& p_motion_A,const Shape2DSW *p_shape_B,const Transform2D& p_transform_B,const Vector2& p_motion_B,CallbackResult p_result_callback,void *p_userdata,Vector2 *sep_axis,float p_margin_A,float p_margin_B) { +bool CollisionSolver2DSW::solve(const Shape2DSW *p_shape_A,const Transform2D& p_transform_A,const Vector2& p_motion_A,const Shape2DSW *p_shape_B,const Transform2D& p_transform_B,const Vector2& p_motion_B,CallbackResult p_result_callback,void *p_userdata,Vector2 *sep_axis,real_t p_margin_A,real_t p_margin_B) { diff --git a/servers/physics_2d/collision_solver_2d_sw.h b/servers/physics_2d/collision_solver_2d_sw.h index 085d3a49fb..2a5fc9fe1d 100644 --- a/servers/physics_2d/collision_solver_2d_sw.h +++ b/servers/physics_2d/collision_solver_2d_sw.h @@ -37,14 +37,14 @@ public: private: static bool solve_static_line(const Shape2DSW *p_shape_A,const Transform2D& p_transform_A,const Shape2DSW *p_shape_B,const Transform2D& p_transform_B,CallbackResult p_result_callback,void *p_userdata,bool p_swap_result); static void concave_callback(void *p_userdata, Shape2DSW *p_convex); - static bool solve_concave(const Shape2DSW *p_shape_A,const Transform2D& p_transform_A,const Vector2& p_motion_A,const Shape2DSW *p_shape_B,const Transform2D& p_transform_B,const Vector2& p_motion_B,CallbackResult p_result_callback,void *p_userdata,bool p_swap_result,Vector2 *sep_axis=NULL,float p_margin_A=0,float p_margin_B=0); + static bool solve_concave(const Shape2DSW *p_shape_A,const Transform2D& p_transform_A,const Vector2& p_motion_A,const Shape2DSW *p_shape_B,const Transform2D& p_transform_B,const Vector2& p_motion_B,CallbackResult p_result_callback,void *p_userdata,bool p_swap_result,Vector2 *sep_axis=NULL,real_t p_margin_A=0,real_t p_margin_B=0); static bool solve_raycast(const Shape2DSW *p_shape_A,const Transform2D& p_transform_A,const Shape2DSW *p_shape_B,const Transform2D& p_transform_B,CallbackResult p_result_callback,void *p_userdata,bool p_swap_result,Vector2 *sep_axis=NULL); public: - static bool solve(const Shape2DSW *p_shape_A,const Transform2D& p_transform_A,const Vector2& p_motion_A,const Shape2DSW *p_shape_B,const Transform2D& p_transform_B,const Vector2& p_motion_B,CallbackResult p_result_callback,void *p_userdata,Vector2 *sep_axis=NULL,float p_margin_A=0,float p_margin_B=0); + static bool solve(const Shape2DSW *p_shape_A,const Transform2D& p_transform_A,const Vector2& p_motion_A,const Shape2DSW *p_shape_B,const Transform2D& p_transform_B,const Vector2& p_motion_B,CallbackResult p_result_callback,void *p_userdata,Vector2 *sep_axis=NULL,real_t p_margin_A=0,real_t p_margin_B=0); }; diff --git a/servers/physics_2d/constraint_2d_sw.h b/servers/physics_2d/constraint_2d_sw.h index 4436f1f689..cce668405c 100644 --- a/servers/physics_2d/constraint_2d_sw.h +++ b/servers/physics_2d/constraint_2d_sw.h @@ -63,8 +63,8 @@ public: _FORCE_INLINE_ int get_body_count() const { return _body_count; } - virtual bool setup(float p_step)=0; - virtual void solve(float p_step)=0; + virtual bool setup(real_t p_step)=0; + virtual void solve(real_t p_step)=0; virtual ~Constraint2DSW() {} }; diff --git a/servers/physics_2d/joints_2d_sw.cpp b/servers/physics_2d/joints_2d_sw.cpp index f0703a0894..76adf06429 100644 --- a/servers/physics_2d/joints_2d_sw.cpp +++ b/servers/physics_2d/joints_2d_sw.cpp @@ -91,7 +91,7 @@ normal_relative_velocity(Body2DSW *a, Body2DSW *b, Vector2 rA, Vector2 rB, Vecto #if 0 -bool PinJoint2DSW::setup(float p_step) { +bool PinJoint2DSW::setup(real_t p_step) { Space2DSW *space = A->get_space(); ERR_FAIL_COND_V(!space,false;) @@ -136,7 +136,7 @@ bool PinJoint2DSW::setup(float p_step) { -void PinJoint2DSW::solve(float p_step){ +void PinJoint2DSW::solve(real_t p_step){ if (!correct) return; @@ -189,7 +189,7 @@ PinJoint2DSW::~PinJoint2DSW() { #else -bool PinJoint2DSW::setup(float p_step) { +bool PinJoint2DSW::setup(real_t p_step) { Space2DSW *space = A->get_space(); ERR_FAIL_COND_V(!space,false;) @@ -257,7 +257,7 @@ bool PinJoint2DSW::setup(float p_step) { return true; } -void PinJoint2DSW::solve(float p_step){ +void PinJoint2DSW::solve(real_t p_step){ // compute relative velocity @@ -370,7 +370,7 @@ mult_k(const Vector2& vr, const Vector2 &k1, const Vector2 &k2) return Vector2(vr.dot(k1), vr.dot(k2)); } -bool GrooveJoint2DSW::setup(float p_step) { +bool GrooveJoint2DSW::setup(real_t p_step) { // calculate endpoints in worldspace @@ -412,7 +412,7 @@ bool GrooveJoint2DSW::setup(float p_step) { Vector2 delta = (B->get_transform().get_origin() +rB) - (A->get_transform().get_origin() + rA); - float _b = get_bias(); + real_t _b = get_bias(); _b=0.001; gbias=(delta*-(_b==0?space->get_constraint_bias():_b)*(1.0/p_step)).clamped(get_max_bias()); @@ -424,7 +424,7 @@ bool GrooveJoint2DSW::setup(float p_step) { return true; } -void GrooveJoint2DSW::solve(float p_step){ +void GrooveJoint2DSW::solve(real_t p_step){ // compute impulse @@ -470,7 +470,7 @@ GrooveJoint2DSW::~GrooveJoint2DSW() { ////////////////////////////////////////////// -bool DampedSpringJoint2DSW::setup(float p_step) { +bool DampedSpringJoint2DSW::setup(real_t p_step) { rA = A->get_transform().basis_xform(anchor_A); rB = B->get_transform().basis_xform(anchor_B); @@ -500,7 +500,7 @@ bool DampedSpringJoint2DSW::setup(float p_step) { return true; } -void DampedSpringJoint2DSW::solve(float p_step) { +void DampedSpringJoint2DSW::solve(real_t p_step) { // compute relative velocity real_t vrn = normal_relative_velocity(A, B, rA, rB, n) - target_vrn; diff --git a/servers/physics_2d/joints_2d_sw.h b/servers/physics_2d/joints_2d_sw.h index 91113fa26d..1be15e4edc 100644 --- a/servers/physics_2d/joints_2d_sw.h +++ b/servers/physics_2d/joints_2d_sw.h @@ -85,8 +85,8 @@ public: virtual Physics2DServer::JointType get_type() const { return Physics2DServer::JOINT_PIN; } - virtual bool setup(float p_step); - virtual void solve(float p_step); + virtual bool setup(real_t p_step); + virtual void solve(real_t p_step); PinJoint2DSW(const Vector2& p_pos,Body2DSW* p_body_a,Body2DSW* p_body_b=NULL); @@ -118,8 +118,8 @@ public: virtual Physics2DServer::JointType get_type() const { return Physics2DServer::JOINT_PIN; } - virtual bool setup(float p_step); - virtual void solve(float p_step); + virtual bool setup(real_t p_step); + virtual void solve(real_t p_step); void set_param(Physics2DServer::PinJointParam p_param, real_t p_value); real_t get_param(Physics2DServer::PinJointParam p_param) const; @@ -160,8 +160,8 @@ public: virtual Physics2DServer::JointType get_type() const { return Physics2DServer::JOINT_GROOVE; } - virtual bool setup(float p_step); - virtual void solve(float p_step); + virtual bool setup(real_t p_step); + virtual void solve(real_t p_step); GrooveJoint2DSW(const Vector2& p_a_groove1,const Vector2& p_a_groove2, const Vector2& p_b_anchor, Body2DSW* p_body_a,Body2DSW* p_body_b); @@ -198,8 +198,8 @@ public: virtual Physics2DServer::JointType get_type() const { return Physics2DServer::JOINT_DAMPED_SPRING; } - virtual bool setup(float p_step); - virtual void solve(float p_step); + virtual bool setup(real_t p_step); + virtual void solve(real_t p_step); void set_param(Physics2DServer::DampedStringParam p_param, real_t p_value); real_t get_param(Physics2DServer::DampedStringParam p_param) const; diff --git a/servers/physics_2d/physics_2d_server_sw.cpp b/servers/physics_2d/physics_2d_server_sw.cpp index 15cf82c122..920742ea0b 100644 --- a/servers/physics_2d/physics_2d_server_sw.cpp +++ b/servers/physics_2d/physics_2d_server_sw.cpp @@ -158,11 +158,11 @@ void Physics2DServerSW::_shape_col_cbk(const Vector2& p_point_A,const Vector2& p if (cbk->amount == cbk->max) { //find least deep - float min_depth=1e20; + real_t min_depth=1e20; int min_depth_idx=0; for(int i=0;i<cbk->amount;i++) { - float d = cbk->ptr[i*2+0].distance_squared_to(cbk->ptr[i*2+1]); + real_t d = cbk->ptr[i*2+0].distance_squared_to(cbk->ptr[i*2+1]); if (d<min_depth) { min_depth=d; min_depth_idx=i; @@ -170,7 +170,7 @@ void Physics2DServerSW::_shape_col_cbk(const Vector2& p_point_A,const Vector2& p } - float d = p_point_A.distance_squared_to(p_point_B); + real_t d = p_point_A.distance_squared_to(p_point_B); if (d<min_depth) return; cbk->ptr[min_depth_idx*2+0]=p_point_A; @@ -785,7 +785,7 @@ uint32_t Physics2DServerSW::body_get_collision_mask(RID p_body) const { return body->get_collision_mask(); }; -void Physics2DServerSW::body_set_param(RID p_body, BodyParameter p_param, float p_value) { +void Physics2DServerSW::body_set_param(RID p_body, BodyParameter p_param, real_t p_value) { Body2DSW *body = body_owner.get(p_body); ERR_FAIL_COND(!body); @@ -793,7 +793,7 @@ void Physics2DServerSW::body_set_param(RID p_body, BodyParameter p_param, float body->set_param(p_param,p_value); }; -float Physics2DServerSW::body_get_param(RID p_body, BodyParameter p_param) const { +real_t Physics2DServerSW::body_get_param(RID p_body, BodyParameter p_param) const { Body2DSW *body = body_owner.get(p_body); ERR_FAIL_COND_V(!body,0); @@ -837,7 +837,7 @@ Vector2 Physics2DServerSW::body_get_applied_force(RID p_body) const { return body->get_applied_force(); }; -void Physics2DServerSW::body_set_applied_torque(RID p_body, float p_torque) { +void Physics2DServerSW::body_set_applied_torque(RID p_body, real_t p_torque) { Body2DSW *body = body_owner.get(p_body); ERR_FAIL_COND(!body); @@ -846,7 +846,7 @@ void Physics2DServerSW::body_set_applied_torque(RID p_body, float p_torque) { body->wakeup(); }; -float Physics2DServerSW::body_get_applied_torque(RID p_body) const { +real_t Physics2DServerSW::body_get_applied_torque(RID p_body) const { Body2DSW *body = body_owner.get(p_body); ERR_FAIL_COND_V(!body,0); @@ -915,14 +915,14 @@ void Physics2DServerSW::body_get_collision_exceptions(RID p_body, List<RID> *p_e }; -void Physics2DServerSW::body_set_contacts_reported_depth_treshold(RID p_body, float p_treshold) { +void Physics2DServerSW::body_set_contacts_reported_depth_treshold(RID p_body, real_t p_treshold) { Body2DSW *body = body_owner.get(p_body); ERR_FAIL_COND(!body); }; -float Physics2DServerSW::body_get_contacts_reported_depth_treshold(RID p_body) const { +real_t Physics2DServerSW::body_get_contacts_reported_depth_treshold(RID p_body) const { Body2DSW *body = body_owner.get(p_body); ERR_FAIL_COND_V(!body,0); @@ -973,7 +973,7 @@ Vector2 Physics2DServerSW::body_get_one_way_collision_direction(RID p_body) cons } -void Physics2DServerSW::body_set_one_way_collision_max_depth(RID p_body,float p_max_depth) { +void Physics2DServerSW::body_set_one_way_collision_max_depth(RID p_body,real_t p_max_depth) { Body2DSW *body = body_owner.get(p_body); ERR_FAIL_COND(!body); @@ -981,7 +981,7 @@ void Physics2DServerSW::body_set_one_way_collision_max_depth(RID p_body,float p_ } -float Physics2DServerSW::body_get_one_way_collision_max_depth(RID p_body) const { +real_t Physics2DServerSW::body_get_one_way_collision_max_depth(RID p_body) const { Body2DSW *body = body_owner.get(p_body); ERR_FAIL_COND_V(!body,0); @@ -1016,7 +1016,7 @@ void Physics2DServerSW::body_set_pickable(RID p_body,bool p_pickable) { } -bool Physics2DServerSW::body_test_motion(RID p_body, const Transform2D &p_from, const Vector2& p_motion, float p_margin, MotionResult *r_result) { +bool Physics2DServerSW::body_test_motion(RID p_body, const Transform2D &p_from, const Vector2& p_motion, real_t p_margin, MotionResult *r_result) { Body2DSW *body = body_owner.get(p_body); ERR_FAIL_COND_V(!body,false); @@ -1263,7 +1263,7 @@ void Physics2DServerSW::init() { }; -void Physics2DServerSW::step(float p_step) { +void Physics2DServerSW::step(real_t p_step) { if (!active) diff --git a/servers/physics_2d/physics_2d_server_sw.h b/servers/physics_2d/physics_2d_server_sw.h index 1da7d65dc8..e33e2d78c7 100644 --- a/servers/physics_2d/physics_2d_server_sw.h +++ b/servers/physics_2d/physics_2d_server_sw.h @@ -76,7 +76,7 @@ public: struct CollCbkData { Vector2 valid_dir; - float valid_depth; + real_t valid_depth; int max; int amount; Vector2 *ptr; @@ -193,8 +193,8 @@ public: virtual void body_set_collision_mask(RID p_body, uint32_t p_mask); virtual uint32_t body_get_collision_mask(RID p_) const; - virtual void body_set_param(RID p_body, BodyParameter p_param, float p_value); - virtual float body_get_param(RID p_body, BodyParameter p_param) const; + virtual void body_set_param(RID p_body, BodyParameter p_param, real_t p_value); + virtual real_t body_get_param(RID p_body, BodyParameter p_param) const; virtual void body_set_state(RID p_body, BodyState p_state, const Variant& p_variant); @@ -203,8 +203,8 @@ public: virtual void body_set_applied_force(RID p_body, const Vector2& p_force); virtual Vector2 body_get_applied_force(RID p_body) const; - virtual void body_set_applied_torque(RID p_body, float p_torque); - virtual float body_get_applied_torque(RID p_body) const; + virtual void body_set_applied_torque(RID p_body, real_t p_torque); + virtual real_t body_get_applied_torque(RID p_body) const; virtual void body_add_force(RID p_body, const Vector2& p_offset, const Vector2& p_force); @@ -215,8 +215,8 @@ public: virtual void body_remove_collision_exception(RID p_body, RID p_body_b); virtual void body_get_collision_exceptions(RID p_body, List<RID> *p_exceptions); - virtual void body_set_contacts_reported_depth_treshold(RID p_body, float p_treshold); - virtual float body_get_contacts_reported_depth_treshold(RID p_body) const; + virtual void body_set_contacts_reported_depth_treshold(RID p_body, real_t p_treshold); + virtual real_t body_get_contacts_reported_depth_treshold(RID p_body) const; virtual void body_set_omit_force_integration(RID p_body,bool p_omit); virtual bool body_is_omitting_force_integration(RID p_body) const; @@ -227,8 +227,8 @@ public: virtual void body_set_one_way_collision_direction(RID p_body,const Vector2& p_direction); virtual Vector2 body_get_one_way_collision_direction(RID p_body) const; - virtual void body_set_one_way_collision_max_depth(RID p_body,float p_max_depth); - virtual float body_get_one_way_collision_max_depth(RID p_body) const; + virtual void body_set_one_way_collision_max_depth(RID p_body,real_t p_max_depth); + virtual real_t body_get_one_way_collision_max_depth(RID p_body) const; virtual void body_set_force_integration_callback(RID p_body,Object *p_receiver,const StringName& p_method,const Variant& p_udata=Variant()); @@ -236,7 +236,7 @@ public: virtual void body_set_pickable(RID p_body,bool p_pickable); - virtual bool body_test_motion(RID p_body,const Transform2D& p_from,const Vector2& p_motion,float p_margin=0.001,MotionResult *r_result=NULL); + virtual bool body_test_motion(RID p_body,const Transform2D& p_from,const Vector2& p_motion,real_t p_margin=0.001,MotionResult *r_result=NULL); /* JOINT API */ @@ -260,7 +260,7 @@ public: virtual void set_active(bool p_active); virtual void init(); - virtual void step(float p_step); + virtual void step(real_t p_step); virtual void sync(); virtual void flush_queries(); virtual void end_sync(); diff --git a/servers/physics_2d/physics_2d_server_wrap_mt.cpp b/servers/physics_2d/physics_2d_server_wrap_mt.cpp index 027f318d2d..34ba149d23 100644 --- a/servers/physics_2d/physics_2d_server_wrap_mt.cpp +++ b/servers/physics_2d/physics_2d_server_wrap_mt.cpp @@ -35,7 +35,7 @@ void Physics2DServerWrapMT::thread_exit() { exit=true; } -void Physics2DServerWrapMT::thread_step(float p_delta) { +void Physics2DServerWrapMT::thread_step(real_t p_delta) { physics_2d_server->step(p_delta); step_sem->post(); @@ -75,7 +75,7 @@ void Physics2DServerWrapMT::thread_loop() { /* EVENT QUEUING */ -void Physics2DServerWrapMT::step(float p_step) { +void Physics2DServerWrapMT::step(real_t p_step) { if (create_thread) { diff --git a/servers/physics_2d/physics_2d_server_wrap_mt.h b/servers/physics_2d/physics_2d_server_wrap_mt.h index 7360c0637b..f8b533080e 100644 --- a/servers/physics_2d/physics_2d_server_wrap_mt.h +++ b/servers/physics_2d/physics_2d_server_wrap_mt.h @@ -60,7 +60,7 @@ class Physics2DServerWrapMT : public Physics2DServer { Semaphore *step_sem; int step_pending; - void thread_step(float p_delta); + void thread_step(real_t p_delta); void thread_flush(); void thread_exit(); @@ -220,8 +220,8 @@ public: FUNC1RC(uint32_t,body_get_collision_mask,RID); - FUNC3(body_set_param,RID,BodyParameter,float); - FUNC2RC(float,body_get_param,RID,BodyParameter); + FUNC3(body_set_param,RID,BodyParameter,real_t); + FUNC2RC(real_t,body_get_param,RID,BodyParameter); FUNC3(body_set_state,RID,BodyState,const Variant&); @@ -230,8 +230,8 @@ public: FUNC2(body_set_applied_force,RID,const Vector2&); FUNC1RC(Vector2,body_get_applied_force,RID); - FUNC2(body_set_applied_torque,RID,float); - FUNC1RC(float,body_get_applied_torque,RID); + FUNC2(body_set_applied_torque,RID,real_t); + FUNC1RC(real_t,body_get_applied_torque,RID); FUNC3(body_add_force,RID,const Vector2&,const Vector2&); FUNC3(body_apply_impulse,RID,const Vector2&,const Vector2&); @@ -247,12 +247,12 @@ public: FUNC2(body_set_one_way_collision_direction,RID,const Vector2&); FUNC1RC(Vector2,body_get_one_way_collision_direction,RID); - FUNC2(body_set_one_way_collision_max_depth,RID,float); - FUNC1RC(float,body_get_one_way_collision_max_depth,RID); + FUNC2(body_set_one_way_collision_max_depth,RID,real_t); + FUNC1RC(real_t,body_get_one_way_collision_max_depth,RID); - FUNC2(body_set_contacts_reported_depth_treshold,RID,float); - FUNC1RC(float,body_get_contacts_reported_depth_treshold,RID); + FUNC2(body_set_contacts_reported_depth_treshold,RID,real_t); + FUNC1RC(real_t,body_get_contacts_reported_depth_treshold,RID); FUNC2(body_set_omit_force_integration,RID,bool); FUNC1RC(bool,body_is_omitting_force_integration,RID); @@ -266,7 +266,7 @@ public: FUNC2(body_set_pickable,RID,bool); - bool body_test_motion(RID p_body,const Transform2D& p_from,const Vector2& p_motion,float p_margin=0.001,MotionResult *r_result=NULL) { + bool body_test_motion(RID p_body,const Transform2D& p_from,const Vector2& p_motion,real_t p_margin=0.001,MotionResult *r_result=NULL) { ERR_FAIL_COND_V(main_thread!=Thread::get_caller_ID(),false); return physics_2d_server->body_test_motion(p_body,p_from,p_motion,p_margin,r_result); @@ -303,7 +303,7 @@ public: FUNC1(set_active,bool); virtual void init(); - virtual void step(float p_step); + virtual void step(real_t p_step); virtual void sync(); virtual void end_sync(); virtual void flush_queries(); diff --git a/servers/physics_2d/shape_2d_sw.cpp b/servers/physics_2d/shape_2d_sw.cpp index 886ae7730b..b6eb427131 100644 --- a/servers/physics_2d/shape_2d_sw.cpp +++ b/servers/physics_2d/shape_2d_sw.cpp @@ -136,7 +136,7 @@ bool LineShape2DSW::intersect_segment(const Vector2& p_begin,const Vector2& p_en return true; } -real_t LineShape2DSW::get_moment_of_inertia(float p_mass, const Size2 &p_scale) const { +real_t LineShape2DSW::get_moment_of_inertia(real_t p_mass, const Size2 &p_scale) const { return 0; } @@ -191,7 +191,7 @@ bool RayShape2DSW::intersect_segment(const Vector2& p_begin,const Vector2& p_end } -real_t RayShape2DSW::get_moment_of_inertia(float p_mass, const Size2 &p_scale) const { +real_t RayShape2DSW::get_moment_of_inertia(real_t p_mass, const Size2 &p_scale) const { return 0; //rays are mass-less } @@ -224,7 +224,7 @@ void SegmentShape2DSW::get_supports(const Vector2& p_normal,Vector2 *r_supports, } - float dp=p_normal.dot(b-a); + real_t dp=p_normal.dot(b-a); if (dp>0) *r_supports=b; else @@ -252,14 +252,14 @@ bool SegmentShape2DSW::intersect_segment(const Vector2& p_begin,const Vector2& p return true; } -real_t SegmentShape2DSW::get_moment_of_inertia(float p_mass, const Size2 &p_scale) const { +real_t SegmentShape2DSW::get_moment_of_inertia(real_t p_mass, const Size2 &p_scale) const { Vector2 s[2]={a*p_scale,b*p_scale}; real_t l = s[1].distance_to(s[0]); Vector2 ofs = (s[0]+s[1])*0.5; - return p_mass*(l*l/12.0f + ofs.length_squared()); + return p_mass*(l*l/12.0 + ofs.length_squared()); } void SegmentShape2DSW::set_data(const Variant& p_data) { @@ -336,7 +336,7 @@ bool CircleShape2DSW::intersect_segment(const Vector2& p_begin,const Vector2& p_ return true; } -real_t CircleShape2DSW::get_moment_of_inertia(float p_mass, const Size2 &p_scale) const { +real_t CircleShape2DSW::get_moment_of_inertia(real_t p_mass, const Size2 &p_scale) const { return (radius*radius)*(p_scale.x*0.5+p_scale.y*0.5); @@ -367,11 +367,11 @@ void RectangleShape2DSW::get_supports(const Vector2& p_normal,Vector2 *r_support Vector2 ag; ag[i]=1.0; - float dp = ag.dot(p_normal); + real_t dp = ag.dot(p_normal); if (Math::abs(dp)<_SEGMENT_IS_VALID_SUPPORT_TRESHOLD) continue; - float sgn = dp>0 ? 1.0 : -1.0; + real_t sgn = dp>0 ? 1.0 : -1.0; r_amount=2; @@ -407,10 +407,10 @@ bool RectangleShape2DSW::intersect_segment(const Vector2& p_begin,const Vector2& return get_aabb().intersects_segment(p_begin,p_end,&r_point,&r_normal); } -real_t RectangleShape2DSW::get_moment_of_inertia(float p_mass,const Size2& p_scale) const { +real_t RectangleShape2DSW::get_moment_of_inertia(real_t p_mass,const Size2& p_scale) const { Vector2 he2=half_extents*2*p_scale; - return p_mass*he2.dot(he2)/12.0f; + return p_mass*he2.dot(he2)/12.0; } void RectangleShape2DSW::set_data(const Variant& p_data) { @@ -438,7 +438,7 @@ void CapsuleShape2DSW::get_supports(const Vector2& p_normal,Vector2 *r_supports, Vector2 n=p_normal; - float d = n.y; + real_t d = n.y; if (Math::abs( d )<(1.0-_SEGMENT_IS_VALID_SUPPORT_TRESHOLD) ) { @@ -455,7 +455,7 @@ void CapsuleShape2DSW::get_supports(const Vector2& p_normal,Vector2 *r_supports, } else { - float h = (d > 0) ? height : -height; + real_t h = (d > 0) ? height : -height; n*=radius; n.y += h*0.5; @@ -479,7 +479,7 @@ bool CapsuleShape2DSW::contains_point(const Vector2& p_point) const { bool CapsuleShape2DSW::intersect_segment(const Vector2& p_begin,const Vector2& p_end,Vector2 &r_point, Vector2 &r_normal) const { - float d = 1e10; + real_t d = 1e10; Vector2 n = (p_end-p_begin).normalized(); bool collided=false; @@ -488,7 +488,7 @@ bool CapsuleShape2DSW::intersect_segment(const Vector2& p_begin,const Vector2& p Vector2 begin = p_begin; Vector2 end = p_end; - float ofs = (i==0)?-height*0.5:height*0.5; + real_t ofs = (i==0)?-height*0.5:height*0.5; begin.y+=ofs; end.y+=ofs; @@ -540,10 +540,10 @@ bool CapsuleShape2DSW::intersect_segment(const Vector2& p_begin,const Vector2& p return collided; //todo } -real_t CapsuleShape2DSW::get_moment_of_inertia(float p_mass, const Size2 &p_scale) const { +real_t CapsuleShape2DSW::get_moment_of_inertia(real_t p_mass, const Size2 &p_scale) const { Vector2 he2=Vector2(radius*2,height+radius*2)*p_scale; - return p_mass*he2.dot(he2)/12.0f; + return p_mass*he2.dot(he2)/12.0; } void CapsuleShape2DSW::set_data(const Variant& p_data) { @@ -619,7 +619,7 @@ bool ConvexPolygonShape2DSW::contains_point(const Vector2& p_point) const { for(int i=0;i<point_count;i++) { - float d = points[i].normal.dot(p_point) - points[i].normal.dot(points[i].pos); + real_t d = points[i].normal.dot(p_point) - points[i].normal.dot(points[i].pos); if (d>0) out=true; else @@ -650,7 +650,7 @@ bool ConvexPolygonShape2DSW::intersect_segment(const Vector2& p_begin,const Vect if (!Geometry::segment_intersects_segment_2d(p_begin,p_end,points[i].pos,points[(i+1)%point_count].pos,&res)) continue; - float nd = n.dot(res); + real_t nd = n.dot(res); if (nd<d) { d=nd; @@ -672,7 +672,7 @@ bool ConvexPolygonShape2DSW::intersect_segment(const Vector2& p_begin,const Vect return inters; //todo } -real_t ConvexPolygonShape2DSW::get_moment_of_inertia(float p_mass,const Size2& p_scale) const { +real_t ConvexPolygonShape2DSW::get_moment_of_inertia(real_t p_mass,const Size2& p_scale) const { Rect2 aabb; aabb.pos=points[0].pos*p_scale; @@ -681,7 +681,7 @@ real_t ConvexPolygonShape2DSW::get_moment_of_inertia(float p_mass,const Size2& p aabb.expand_to(points[i].pos*p_scale); } - return p_mass*aabb.size.dot(aabb.size)/12.0f + p_mass * (aabb.pos+aabb.size*0.5).length_squared(); + return p_mass*aabb.size.dot(aabb.size)/12.0 + p_mass * (aabb.pos+aabb.size*0.5).length_squared(); } void ConvexPolygonShape2DSW::set_data(const Variant& p_data) { @@ -859,7 +859,7 @@ bool ConcavePolygonShape2DSW::intersect_segment(const Vector2& p_begin,const Vec if (Geometry::segment_intersects_segment_2d(p_begin,p_end,a,b,&res)) { - float nd = n.dot(res); + real_t nd = n.dot(res); if (nd<d) { d=nd; diff --git a/servers/physics_2d/shape_2d_sw.h b/servers/physics_2d/shape_2d_sw.h index 07a9d84ec8..c04cdfa456 100644 --- a/servers/physics_2d/shape_2d_sw.h +++ b/servers/physics_2d/shape_2d_sw.h @@ -35,8 +35,8 @@ /* SHAPE_LINE, ///< plane:"plane" -SHAPE_SEGMENT, ///< float:"length" -SHAPE_CIRCLE, ///< float:"radius" +SHAPE_SEGMENT, ///< real_t:"length" +SHAPE_CIRCLE, ///< real_t:"radius" SHAPE_RECTANGLE, ///< vec3:"extents" SHAPE_CONVEX_POLYGON, ///< array of planes:"planes" SHAPE_CONCAVE_POLYGON, ///< Vector2 array:"triangles" , or Dictionary with "indices" (int array) and "triangles" (Vector2 array) @@ -86,7 +86,7 @@ public: virtual void get_supports(const Vector2& p_normal,Vector2 *r_supports,int & r_amount) const=0; virtual bool intersect_segment(const Vector2& p_begin,const Vector2& p_end,Vector2 &r_point, Vector2 &r_normal) const=0; - virtual real_t get_moment_of_inertia(float p_mass,const Size2& p_scale) const=0; + virtual real_t get_moment_of_inertia(real_t p_mass,const Size2& p_scale) const=0; virtual void set_data(const Variant& p_data)=0; virtual Variant get_data() const=0; @@ -175,7 +175,7 @@ public: virtual bool contains_point(const Vector2& p_point) const; virtual bool intersect_segment(const Vector2& p_begin,const Vector2& p_end,Vector2 &r_point, Vector2 &r_normal) const; - virtual real_t get_moment_of_inertia(float p_mass,const Size2& p_scale) const; + virtual real_t get_moment_of_inertia(real_t p_mass,const Size2& p_scale) const; virtual void set_data(const Variant& p_data); virtual Variant get_data() const; @@ -218,7 +218,7 @@ public: virtual bool contains_point(const Vector2& p_point) const; virtual bool intersect_segment(const Vector2& p_begin,const Vector2& p_end,Vector2 &r_point, Vector2 &r_normal) const; - virtual real_t get_moment_of_inertia(float p_mass,const Size2& p_scale) const; + virtual real_t get_moment_of_inertia(real_t p_mass,const Size2& p_scale) const; virtual void set_data(const Variant& p_data); virtual Variant get_data() const; @@ -266,7 +266,7 @@ public: virtual bool contains_point(const Vector2& p_point) const; virtual bool intersect_segment(const Vector2& p_begin,const Vector2& p_end,Vector2 &r_point, Vector2 &r_normal) const; - virtual real_t get_moment_of_inertia(float p_mass,const Size2& p_scale) const; + virtual real_t get_moment_of_inertia(real_t p_mass,const Size2& p_scale) const; virtual void set_data(const Variant& p_data); virtual Variant get_data() const; @@ -304,7 +304,7 @@ public: virtual bool contains_point(const Vector2& p_point) const; virtual bool intersect_segment(const Vector2& p_begin,const Vector2& p_end,Vector2 &r_point, Vector2 &r_normal) const; - virtual real_t get_moment_of_inertia(float p_mass,const Size2& p_scale) const; + virtual real_t get_moment_of_inertia(real_t p_mass,const Size2& p_scale) const; virtual void set_data(const Variant& p_data); virtual Variant get_data() const; @@ -344,7 +344,7 @@ public: virtual bool contains_point(const Vector2& p_point) const; virtual bool intersect_segment(const Vector2& p_begin,const Vector2& p_end,Vector2 &r_point, Vector2 &r_normal) const; - virtual real_t get_moment_of_inertia(float p_mass,const Size2& p_scale) const; + virtual real_t get_moment_of_inertia(real_t p_mass,const Size2& p_scale) const; virtual void set_data(const Variant& p_data); virtual Variant get_data() const; @@ -432,7 +432,7 @@ public: virtual bool contains_point(const Vector2& p_point) const; virtual bool intersect_segment(const Vector2& p_begin,const Vector2& p_end,Vector2 &r_point, Vector2 &r_normal) const; - virtual real_t get_moment_of_inertia(float p_mass,const Size2& p_scale) const; + virtual real_t get_moment_of_inertia(real_t p_mass,const Size2& p_scale) const; virtual void set_data(const Variant& p_data); virtual Variant get_data() const; @@ -440,7 +440,7 @@ public: _FORCE_INLINE_ void project_range(const Vector2& p_normal, const Transform2D& p_transform, real_t &r_min, real_t &r_max) const { // no matter the angle, the box is mirrored anyway Vector2 n=p_transform.basis_xform_inv(p_normal).normalized(); - float h = (n.y > 0) ? height : -height; + real_t h = (n.y > 0) ? height : -height; n *= radius; n.y += h * 0.5; @@ -495,7 +495,7 @@ public: virtual bool contains_point(const Vector2& p_point) const; virtual bool intersect_segment(const Vector2& p_begin,const Vector2& p_end,Vector2 &r_point, Vector2 &r_normal) const; - virtual real_t get_moment_of_inertia(float p_mass,const Size2& p_scale) const; + virtual real_t get_moment_of_inertia(real_t p_mass,const Size2& p_scale) const; virtual void set_data(const Variant& p_data); virtual Variant get_data() const; @@ -506,7 +506,7 @@ public: r_min = r_max = p_normal.dot(p_transform.xform(points[0].pos)); for(int i=1;i<point_count;i++) { - float d = p_normal.dot(p_transform.xform(points[i].pos)); + real_t d = p_normal.dot(p_transform.xform(points[i].pos)); if (d>r_max) r_max=d; if (d<r_min) @@ -584,7 +584,7 @@ public: virtual bool contains_point(const Vector2& p_point) const; virtual bool intersect_segment(const Vector2& p_begin,const Vector2& p_end,Vector2 &r_point, Vector2 &r_normal) const; - virtual real_t get_moment_of_inertia(float p_mass,const Size2& p_scale) const { return 0; } + virtual real_t get_moment_of_inertia(real_t p_mass,const Size2& p_scale) const { return 0; } virtual void set_data(const Variant& p_data); virtual Variant get_data() const; diff --git a/servers/physics_2d/space_2d_sw.cpp b/servers/physics_2d/space_2d_sw.cpp index 275137ae5a..9bced50061 100644 --- a/servers/physics_2d/space_2d_sw.cpp +++ b/servers/physics_2d/space_2d_sw.cpp @@ -190,7 +190,7 @@ bool Physics2DDirectSpaceStateSW::intersect_ray(const Vector2& p_from, const Vec } -int Physics2DDirectSpaceStateSW::intersect_shape(const RID& p_shape, const Transform2D& p_xform,const Vector2& p_motion,float p_margin,ShapeResult *r_results,int p_result_max,const Set<RID>& p_exclude,uint32_t p_layer_mask,uint32_t p_object_type_mask) { +int Physics2DDirectSpaceStateSW::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,uint32_t p_layer_mask,uint32_t p_object_type_mask) { if (p_result_max<=0) return 0; @@ -237,7 +237,7 @@ int Physics2DDirectSpaceStateSW::intersect_shape(const RID& p_shape, const Trans -bool Physics2DDirectSpaceStateSW::cast_motion(const RID& p_shape, const Transform2D& p_xform,const Vector2& p_motion,float p_margin,float &p_closest_safe,float &p_closest_unsafe, const Set<RID>& p_exclude,uint32_t p_layer_mask,uint32_t p_object_type_mask) { +bool Physics2DDirectSpaceStateSW::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,uint32_t p_layer_mask,uint32_t p_object_type_mask) { @@ -255,8 +255,8 @@ bool Physics2DDirectSpaceStateSW::cast_motion(const RID& p_shape, const Transfor int amount = space->broadphase->cull_aabb(aabb,space->intersection_query_results,Space2DSW::INTERSECTION_QUERY_MAX,space->intersection_query_subindex_results); - float best_safe=1; - float best_unsafe=1; + real_t best_safe=1; + real_t best_unsafe=1; for(int i=0;i<amount;i++) { @@ -305,13 +305,13 @@ bool Physics2DDirectSpaceStateSW::cast_motion(const RID& p_shape, const Transfor //just do kinematic solving - float low=0; - float hi=1; + real_t low=0; + real_t hi=1; Vector2 mnormal=p_motion.normalized(); for(int i=0;i<8;i++) { //steps should be customizable.. - float ofs = (low+hi)*0.5; + real_t ofs = (low+hi)*0.5; Vector2 sep=mnormal; //important optimization for this to work fast enough bool collided = CollisionSolver2DSW::solve(shape,p_xform,p_motion*ofs,col_obj->get_shape(shape_idx),col_obj_xform,Vector2(),NULL,NULL,&sep,p_margin); @@ -364,7 +364,7 @@ bool Physics2DDirectSpaceStateSW::cast_motion(const RID& p_shape, const Transfor } -bool Physics2DDirectSpaceStateSW::collide_shape(RID p_shape, const Transform2D& p_shape_xform,const Vector2& p_motion,float p_margin,Vector2 *r_results,int p_result_max,int &r_result_count, const Set<RID>& p_exclude,uint32_t p_layer_mask,uint32_t p_object_type_mask) { +bool Physics2DDirectSpaceStateSW::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,uint32_t p_layer_mask,uint32_t p_object_type_mask) { if (p_result_max<=0) @@ -436,9 +436,9 @@ struct _RestCallbackData2D { int best_shape; Vector2 best_contact; Vector2 best_normal; - float best_len; + real_t best_len; Vector2 valid_dir; - float valid_depth; + real_t valid_depth; }; static void _rest_cbk_result(const Vector2& p_point_A,const Vector2& p_point_B,void *p_userdata) { @@ -458,7 +458,7 @@ static void _rest_cbk_result(const Vector2& p_point_A,const Vector2& p_point_B,v } Vector2 contact_rel = p_point_B - p_point_A; - float len = contact_rel.length(); + real_t len = contact_rel.length(); if (len <= rd->best_len) return; @@ -473,7 +473,7 @@ static void _rest_cbk_result(const Vector2& p_point_A,const Vector2& p_point_B,v } -bool Physics2DDirectSpaceStateSW::rest_info(RID p_shape, const Transform2D& p_shape_xform,const Vector2& p_motion,float p_margin,ShapeRestInfo *r_info, const Set<RID>& p_exclude,uint32_t p_layer_mask,uint32_t p_object_type_mask) { +bool Physics2DDirectSpaceStateSW::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,uint32_t p_layer_mask,uint32_t p_object_type_mask) { Shape2DSW *shape = Physics2DServerSW::singletonsw->shape_owner.get(p_shape); @@ -594,7 +594,7 @@ int Space2DSW::_cull_aabb_for_body(Body2DSW *p_body,const Rect2& p_aabb) { return amount; } -bool Space2DSW::test_body_motion(Body2DSW *p_body, const Transform2D &p_from, const Vector2&p_motion, float p_margin, Physics2DServer::MotionResult *r_result) { +bool Space2DSW::test_body_motion(Body2DSW *p_body, const Transform2D &p_from, const Vector2&p_motion, real_t p_margin, Physics2DServer::MotionResult *r_result) { //give me back regular physics engine logic //this is madness @@ -698,15 +698,15 @@ bool Space2DSW::test_body_motion(Body2DSW *p_body, const Transform2D &p_from, co #if 0 Vector2 rel = b-a; - float d = rel.length(); + real_t d = rel.length(); if (d==0) continue; Vector2 n = rel/d; - float traveled = n.dot(recover_motion); + real_t traveled = n.dot(recover_motion); a+=n*traveled; - float d = a.distance_to(b); + real_t d = a.distance_to(b); if (d<margin) continue; #endif @@ -728,8 +728,8 @@ bool Space2DSW::test_body_motion(Body2DSW *p_body, const Transform2D &p_from, co - float safe = 1.0; - float unsafe = 1.0; + real_t safe = 1.0; + real_t unsafe = 1.0; int best_shape=-1; { @@ -751,8 +751,8 @@ bool Space2DSW::test_body_motion(Body2DSW *p_body, const Transform2D &p_from, co bool stuck=false; - float best_safe=1; - float best_unsafe=1; + real_t best_safe=1; + real_t best_unsafe=1; for(int i=0;i<amount;i++) { @@ -784,13 +784,13 @@ bool Space2DSW::test_body_motion(Body2DSW *p_body, const Transform2D &p_from, co //just do kinematic solving - float low=0; - float hi=1; + real_t low=0; + real_t hi=1; Vector2 mnormal=p_motion.normalized(); for(int i=0;i<8;i++) { //steps should be customizable.. - float ofs = (low+hi)*0.5; + real_t ofs = (low+hi)*0.5; Vector2 sep=mnormal; //important optimization for this to work fast enough bool collided = CollisionSolver2DSW::solve(body_shape,body_shape_xform,p_motion*ofs,col_obj->get_shape(shape_idx),col_obj_xform,Vector2(),NULL,NULL,&sep,0); @@ -1004,7 +1004,7 @@ bool Space2DSW::test_body_motion(Body2DSW *p_body, const Transform2D &p_from, co Vector2 a = sr[i*2+0]; Vector2 b = sr[i*2+1]; - float d = a.distance_to(b); + real_t d = a.distance_to(b); /* if (d<margin) @@ -1028,8 +1028,8 @@ bool Space2DSW::test_body_motion(Body2DSW *p_body, const Transform2D &p_from, co //move second - float safe = 1.0; - float unsafe = 1.0; + real_t safe = 1.0; + real_t unsafe = 1.0; int best_shape=-1; for(int i=0;i<get_shape_count();i++) { @@ -1037,7 +1037,7 @@ bool Space2DSW::test_body_motion(Body2DSW *p_body, const Transform2D &p_from, co if (is_shape_set_as_trigger(i)) continue; - float lsafe,lunsafe; + real_t lsafe,lunsafe; bool valid = dss->cast_motion(get_shape(i)->get_rid(), get_global_transform() * get_shape_transform(i), p_motion, 0,lsafe,lunsafe,exclude,get_layer_mask(),mask); //print_line("shape: "+itos(i)+" travel:"+rtos(ltravel)); if (!valid) { diff --git a/servers/physics_2d/space_2d_sw.h b/servers/physics_2d/space_2d_sw.h index 72b34e8c4f..071aa7bdfb 100644 --- a/servers/physics_2d/space_2d_sw.h +++ b/servers/physics_2d/space_2d_sw.h @@ -49,10 +49,10 @@ public: 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_layer_mask=0xFFFFFFFF,uint32_t p_object_type_mask=TYPE_MASK_COLLISION, bool p_pick_point=false); 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_layer_mask=0xFFFFFFFF,uint32_t p_object_type_mask=TYPE_MASK_COLLISION); - virtual int intersect_shape(const RID& p_shape, const Transform2D& p_xform,const Vector2& p_motion,float p_margin,ShapeResult *r_results,int p_result_max,const Set<RID>& p_exclude=Set<RID>(),uint32_t p_layer_mask=0xFFFFFFFF,uint32_t p_object_type_mask=TYPE_MASK_COLLISION); - virtual bool cast_motion(const RID& p_shape, const Transform2D& p_xform,const Vector2& p_motion,float p_margin,float &p_closest_safe,float &p_closest_unsafe, const Set<RID>& p_exclude=Set<RID>(),uint32_t p_layer_mask=0xFFFFFFFF,uint32_t p_object_type_mask=TYPE_MASK_COLLISION); - virtual bool collide_shape(RID p_shape, const Transform2D& p_shape_xform,const Vector2& p_motion,float p_margin,Vector2 *r_results,int p_result_max,int &r_result_count, const Set<RID>& p_exclude=Set<RID>(),uint32_t p_layer_mask=0xFFFFFFFF,uint32_t p_object_type_mask=TYPE_MASK_COLLISION); - virtual bool rest_info(RID p_shape, const Transform2D& p_shape_xform,const Vector2& p_motion,float p_margin,ShapeRestInfo *r_info, const Set<RID>& p_exclude=Set<RID>(),uint32_t p_layer_mask=0xFFFFFFFF,uint32_t p_object_type_mask=TYPE_MASK_COLLISION); + 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_layer_mask=0xFFFFFFFF,uint32_t p_object_type_mask=TYPE_MASK_COLLISION); + 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_layer_mask=0xFFFFFFFF,uint32_t p_object_type_mask=TYPE_MASK_COLLISION); + 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_layer_mask=0xFFFFFFFF,uint32_t p_object_type_mask=TYPE_MASK_COLLISION); + 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_layer_mask=0xFFFFFFFF,uint32_t p_object_type_mask=TYPE_MASK_COLLISION); Physics2DDirectSpaceStateSW(); }; @@ -106,9 +106,9 @@ private: CollisionObject2DSW *intersection_query_results[INTERSECTION_QUERY_MAX]; int intersection_query_subindex_results[INTERSECTION_QUERY_MAX]; - float body_linear_velocity_sleep_treshold; - float body_angular_velocity_sleep_treshold; - float body_time_to_sleep; + real_t body_linear_velocity_sleep_treshold; + real_t body_angular_velocity_sleep_treshold; + real_t body_time_to_sleep; bool locked; @@ -185,7 +185,7 @@ public: int get_collision_pairs() const { return collision_pairs; } - bool test_body_motion(Body2DSW *p_body, const Transform2D &p_from, const Vector2&p_motion, float p_margin, Physics2DServer::MotionResult *r_result); + bool test_body_motion(Body2DSW *p_body, const Transform2D &p_from, const Vector2&p_motion, real_t p_margin, Physics2DServer::MotionResult *r_result); void set_debug_contacts(int p_amount) { contact_debug.resize(p_amount); } diff --git a/servers/physics_2d/step_2d_sw.cpp b/servers/physics_2d/step_2d_sw.cpp index 8be4e2b5d5..355cc25a69 100644 --- a/servers/physics_2d/step_2d_sw.cpp +++ b/servers/physics_2d/step_2d_sw.cpp @@ -56,7 +56,7 @@ void Step2DSW::_populate_island(Body2DSW* p_body,Body2DSW** p_island,Constraint2 } } -bool Step2DSW::_setup_island(Constraint2DSW *p_island,float p_delta) { +bool Step2DSW::_setup_island(Constraint2DSW *p_island,real_t p_delta) { Constraint2DSW *ci=p_island; Constraint2DSW *prev_ci=NULL; @@ -81,7 +81,7 @@ bool Step2DSW::_setup_island(Constraint2DSW *p_island,float p_delta) { return removed_root; } -void Step2DSW::_solve_island(Constraint2DSW *p_island,int p_iterations,float p_delta){ +void Step2DSW::_solve_island(Constraint2DSW *p_island,int p_iterations,real_t p_delta){ for(int i=0;i<p_iterations;i++) { @@ -94,7 +94,7 @@ void Step2DSW::_solve_island(Constraint2DSW *p_island,int p_iterations,float p_d } } -void Step2DSW::_check_suspend(Body2DSW *p_island,float p_delta) { +void Step2DSW::_check_suspend(Body2DSW *p_island,real_t p_delta) { bool can_sleep=true; @@ -132,7 +132,7 @@ void Step2DSW::_check_suspend(Body2DSW *p_island,float p_delta) { } } -void Step2DSW::step(Space2DSW* p_space,float p_delta,int p_iterations) { +void Step2DSW::step(Space2DSW* p_space,real_t p_delta,int p_iterations) { p_space->lock(); // can't access space during this diff --git a/servers/physics_2d/step_2d_sw.h b/servers/physics_2d/step_2d_sw.h index 917d69e7f1..0896e1016d 100644 --- a/servers/physics_2d/step_2d_sw.h +++ b/servers/physics_2d/step_2d_sw.h @@ -36,12 +36,12 @@ class Step2DSW { uint64_t _step; void _populate_island(Body2DSW* p_body,Body2DSW** p_island,Constraint2DSW **p_constraint_island); - bool _setup_island(Constraint2DSW *p_island,float p_delta); - void _solve_island(Constraint2DSW *p_island,int p_iterations,float p_delta); - void _check_suspend(Body2DSW *p_island,float p_delta); + bool _setup_island(Constraint2DSW *p_island,real_t p_delta); + void _solve_island(Constraint2DSW *p_island,int p_iterations,real_t p_delta); + void _check_suspend(Body2DSW *p_island,real_t p_delta); public: - void step(Space2DSW* p_space,float p_delta,int p_iterations); + void step(Space2DSW* p_space,real_t p_delta,int p_iterations); Step2DSW(); }; |