summaryrefslogtreecommitdiff
path: root/servers/physics_3d
diff options
context:
space:
mode:
Diffstat (limited to 'servers/physics_3d')
-rw-r--r--servers/physics_3d/area_3d_sw.cpp10
-rw-r--r--servers/physics_3d/area_3d_sw.h31
-rw-r--r--servers/physics_3d/body_3d_sw.h6
-rw-r--r--servers/physics_3d/body_pair_3d_sw.h20
-rw-r--r--servers/physics_3d/broad_phase_3d_bvh.cpp3
-rw-r--r--servers/physics_3d/broad_phase_3d_bvh.h8
-rw-r--r--servers/physics_3d/collision_object_3d_sw.cpp6
-rw-r--r--servers/physics_3d/collision_object_3d_sw.h18
-rw-r--r--servers/physics_3d/collision_solver_3d_sat.cpp29
-rw-r--r--servers/physics_3d/collision_solver_3d_sw.cpp28
-rw-r--r--servers/physics_3d/collision_solver_3d_sw.h4
-rw-r--r--servers/physics_3d/gjk_epa.cpp4
-rw-r--r--servers/physics_3d/joints/cone_twist_joint_3d_sw.cpp12
-rw-r--r--servers/physics_3d/joints/cone_twist_joint_3d_sw.h38
-rw-r--r--servers/physics_3d/joints/generic_6dof_joint_3d_sw.cpp2
-rw-r--r--servers/physics_3d/joints/generic_6dof_joint_3d_sw.h81
-rw-r--r--servers/physics_3d/joints/hinge_joint_3d_sw.cpp32
-rw-r--r--servers/physics_3d/joints/hinge_joint_3d_sw.h38
-rw-r--r--servers/physics_3d/joints/jacobian_entry_3d_sw.h4
-rw-r--r--servers/physics_3d/joints/pin_joint_3d_sw.cpp7
-rw-r--r--servers/physics_3d/joints/pin_joint_3d_sw.h14
-rw-r--r--servers/physics_3d/joints/slider_joint_3d_sw.cpp39
-rw-r--r--servers/physics_3d/joints/slider_joint_3d_sw.h85
-rw-r--r--servers/physics_3d/physics_server_3d_sw.cpp10
-rw-r--r--servers/physics_3d/physics_server_3d_sw.h20
-rw-r--r--servers/physics_3d/physics_server_3d_wrap_mt.cpp3
-rw-r--r--servers/physics_3d/physics_server_3d_wrap_mt.h4
-rw-r--r--servers/physics_3d/shape_3d_sw.cpp51
-rw-r--r--servers/physics_3d/shape_3d_sw.h36
-rw-r--r--servers/physics_3d/soft_body_3d_sw.cpp2
-rw-r--r--servers/physics_3d/space_3d_sw.cpp17
-rw-r--r--servers/physics_3d/space_3d_sw.h24
-rw-r--r--servers/physics_3d/step_3d_sw.cpp2
-rw-r--r--servers/physics_3d/step_3d_sw.h2
34 files changed, 254 insertions, 436 deletions
diff --git a/servers/physics_3d/area_3d_sw.cpp b/servers/physics_3d/area_3d_sw.cpp
index c9e8bcb8ca..630ab7e229 100644
--- a/servers/physics_3d/area_3d_sw.cpp
+++ b/servers/physics_3d/area_3d_sw.cpp
@@ -329,17 +329,7 @@ Area3DSW::Area3DSW() :
monitor_query_list(this),
moved_list(this) {
_set_static(true); //areas are never active
- space_override_mode = PhysicsServer3D::AREA_SPACE_OVERRIDE_DISABLED;
- gravity = 9.80665;
- gravity_vector = Vector3(0, -1, 0);
- gravity_is_point = false;
- gravity_distance_scale = 0;
- point_attenuation = 1;
- angular_damp = 0.1;
- linear_damp = 0.1;
- priority = 0;
set_ray_pickable(false);
- monitorable = false;
}
Area3DSW::~Area3DSW() {
diff --git a/servers/physics_3d/area_3d_sw.h b/servers/physics_3d/area_3d_sw.h
index d5f1e60119..af5c23949c 100644
--- a/servers/physics_3d/area_3d_sw.h
+++ b/servers/physics_3d/area_3d_sw.h
@@ -41,20 +41,20 @@ class SoftBody3DSW;
class Constraint3DSW;
class Area3DSW : public CollisionObject3DSW {
- PhysicsServer3D::AreaSpaceOverrideMode space_override_mode;
- real_t gravity;
- Vector3 gravity_vector;
- bool gravity_is_point;
- real_t gravity_distance_scale;
- real_t point_attenuation;
- real_t linear_damp;
- real_t angular_damp;
+ PhysicsServer3D::AreaSpaceOverrideMode space_override_mode = PhysicsServer3D::AREA_SPACE_OVERRIDE_DISABLED;
+ real_t gravity = 9.80665;
+ Vector3 gravity_vector = Vector3(0, -1, 0);
+ bool gravity_is_point = false;
+ real_t gravity_distance_scale = 0.0;
+ real_t point_attenuation = 1.0;
+ real_t linear_damp = 0.1;
+ real_t angular_damp = 0.1;
real_t wind_force_magnitude = 0.0;
real_t wind_attenuation_factor = 0.0;
Vector3 wind_source;
Vector3 wind_direction;
- int priority;
- bool monitorable;
+ int priority = 0;
+ bool monitorable = false;
ObjectID monitor_callback_id;
StringName monitor_callback_method;
@@ -68,8 +68,8 @@ class Area3DSW : public CollisionObject3DSW {
struct BodyKey {
RID rid;
ObjectID instance_id;
- uint32_t body_shape;
- uint32_t area_shape;
+ uint32_t body_shape = 0;
+ uint32_t area_shape = 0;
_FORCE_INLINE_ bool operator<(const BodyKey &p_key) const {
if (rid == p_key.rid) {
@@ -90,10 +90,9 @@ class Area3DSW : public CollisionObject3DSW {
};
struct BodyState {
- int state;
+ int state = 0;
_FORCE_INLINE_ void inc() { state++; }
_FORCE_INLINE_ void dec() { state--; }
- _FORCE_INLINE_ BodyState() { state = 0; }
};
Map<BodyKey, BodyState> monitored_soft_bodies;
@@ -232,8 +231,8 @@ void Area3DSW::remove_area_from_query(Area3DSW *p_area, uint32_t p_area_shape, u
}
struct AreaCMP {
- Area3DSW *area;
- int refCount;
+ Area3DSW *area = nullptr;
+ int refCount = 0;
_FORCE_INLINE_ bool operator==(const AreaCMP &p_cmp) const { return area->get_self() == p_cmp.area->get_self(); }
_FORCE_INLINE_ bool operator<(const AreaCMP &p_cmp) const { return area->get_priority() < p_cmp.area->get_priority(); }
_FORCE_INLINE_ AreaCMP() {}
diff --git a/servers/physics_3d/body_3d_sw.h b/servers/physics_3d/body_3d_sw.h
index 8b74c7e5b9..fc47040389 100644
--- a/servers/physics_3d/body_3d_sw.h
+++ b/servers/physics_3d/body_3d_sw.h
@@ -108,10 +108,10 @@ class Body3DSW : public CollisionObject3DSW {
struct Contact {
Vector3 local_pos;
Vector3 local_normal;
- real_t depth;
- int local_shape;
+ real_t depth = 0.0;
+ int local_shape = 0;
Vector3 collider_pos;
- int collider_shape;
+ int collider_shape = 0;
ObjectID collider_instance_id;
RID collider;
Vector3 collider_velocity_at_pos;
diff --git a/servers/physics_3d/body_pair_3d_sw.h b/servers/physics_3d/body_pair_3d_sw.h
index 19d6a46880..01afb07e13 100644
--- a/servers/physics_3d/body_pair_3d_sw.h
+++ b/servers/physics_3d/body_pair_3d_sw.h
@@ -41,18 +41,18 @@ protected:
struct Contact {
Vector3 position;
Vector3 normal;
- int index_A, index_B;
+ int index_A = 0, index_B = 0;
Vector3 local_A, local_B;
- real_t acc_normal_impulse; // accumulated normal impulse (Pn)
+ real_t acc_normal_impulse = 0.0; // accumulated normal impulse (Pn)
Vector3 acc_tangent_impulse; // accumulated tangent impulse (Pt)
- real_t acc_bias_impulse; // accumulated normal impulse for position bias (Pnb)
- real_t acc_bias_impulse_center_of_mass; // accumulated normal impulse for position bias applied to com
- real_t mass_normal;
- real_t bias;
- real_t bounce;
-
- real_t depth;
- bool active;
+ real_t acc_bias_impulse = 0.0; // accumulated normal impulse for position bias (Pnb)
+ real_t acc_bias_impulse_center_of_mass = 0.0; // accumulated normal impulse for position bias applied to com
+ real_t mass_normal = 0.0;
+ real_t bias = 0.0;
+ real_t bounce = 0.0;
+
+ real_t depth = 0.0;
+ bool active = false;
Vector3 rA, rB; // Offset in world orientation with respect to center of mass
};
diff --git a/servers/physics_3d/broad_phase_3d_bvh.cpp b/servers/physics_3d/broad_phase_3d_bvh.cpp
index f9f64f786d..d89e0e1f6d 100644
--- a/servers/physics_3d/broad_phase_3d_bvh.cpp
+++ b/servers/physics_3d/broad_phase_3d_bvh.cpp
@@ -114,7 +114,4 @@ BroadPhase3DSW *BroadPhase3DBVH::_create() {
BroadPhase3DBVH::BroadPhase3DBVH() {
bvh.set_pair_callback(_pair_callback, this);
bvh.set_unpair_callback(_unpair_callback, this);
- pair_callback = nullptr;
- pair_userdata = nullptr;
- unpair_userdata = nullptr;
}
diff --git a/servers/physics_3d/broad_phase_3d_bvh.h b/servers/physics_3d/broad_phase_3d_bvh.h
index 30b8b7f2aa..03131c9db2 100644
--- a/servers/physics_3d/broad_phase_3d_bvh.h
+++ b/servers/physics_3d/broad_phase_3d_bvh.h
@@ -40,10 +40,10 @@ class BroadPhase3DBVH : public BroadPhase3DSW {
static void *_pair_callback(void *, uint32_t, CollisionObject3DSW *, int, uint32_t, CollisionObject3DSW *, int);
static void _unpair_callback(void *, uint32_t, CollisionObject3DSW *, int, uint32_t, CollisionObject3DSW *, int, void *);
- PairCallback pair_callback;
- void *pair_userdata;
- UnpairCallback unpair_callback;
- void *unpair_userdata;
+ PairCallback pair_callback = nullptr;
+ void *pair_userdata = nullptr;
+ UnpairCallback unpair_callback = nullptr;
+ void *unpair_userdata = nullptr;
public:
// 0 is an invalid ID
diff --git a/servers/physics_3d/collision_object_3d_sw.cpp b/servers/physics_3d/collision_object_3d_sw.cpp
index 24c7d7b85c..098f627d11 100644
--- a/servers/physics_3d/collision_object_3d_sw.cpp
+++ b/servers/physics_3d/collision_object_3d_sw.cpp
@@ -236,11 +236,5 @@ void CollisionObject3DSW::_shape_changed() {
CollisionObject3DSW::CollisionObject3DSW(Type p_type) :
pending_shape_update_list(this) {
- _static = true;
type = p_type;
- space = nullptr;
-
- collision_layer = 1;
- collision_mask = 1;
- ray_pickable = true;
}
diff --git a/servers/physics_3d/collision_object_3d_sw.h b/servers/physics_3d/collision_object_3d_sw.h
index 6ffab54645..3aa48946b7 100644
--- a/servers/physics_3d/collision_object_3d_sw.h
+++ b/servers/physics_3d/collision_object_3d_sw.h
@@ -56,26 +56,24 @@ private:
Type type;
RID self;
ObjectID instance_id;
- uint32_t collision_layer;
- uint32_t collision_mask;
+ uint32_t collision_layer = 1;
+ uint32_t collision_mask = 1;
struct Shape {
Transform3D xform;
Transform3D xform_inv;
BroadPhase3DSW::ID bpid;
AABB aabb_cache; //for rayqueries
- real_t area_cache;
- Shape3DSW *shape;
- bool disabled;
-
- Shape() { disabled = false; }
+ real_t area_cache = 0.0;
+ Shape3DSW *shape = nullptr;
+ bool disabled = false;
};
Vector<Shape> shapes;
- Space3DSW *space;
+ Space3DSW *space = nullptr;
Transform3D transform;
Transform3D inv_transform;
- bool _static;
+ bool _static = true;
SelfList<CollisionObject3DSW> pending_shape_update_list;
@@ -102,7 +100,7 @@ protected:
virtual void _shapes_changed() = 0;
void _set_space(Space3DSW *p_space);
- bool ray_pickable;
+ bool ray_pickable = true;
CollisionObject3DSW(Type p_type);
diff --git a/servers/physics_3d/collision_solver_3d_sat.cpp b/servers/physics_3d/collision_solver_3d_sat.cpp
index de81348b4e..76738bb746 100644
--- a/servers/physics_3d/collision_solver_3d_sat.cpp
+++ b/servers/physics_3d/collision_solver_3d_sat.cpp
@@ -66,11 +66,11 @@
struct _CollectorCallback {
CollisionSolver3DSW::CallbackResult callback;
- void *userdata;
- bool swap;
- bool collided;
+ void *userdata = nullptr;
+ bool swap = false;
+ bool collided = false;
Vector3 normal;
- Vector3 *prev_axis;
+ Vector3 *prev_axis = nullptr;
_FORCE_INLINE_ void call(const Vector3 &p_point_A, const Vector3 &p_point_B) {
if (swap) {
@@ -606,15 +606,15 @@ static void _generate_contacts_from_supports(const Vector3 *p_points_A, int p_po
template <class ShapeA, class ShapeB, bool withMargin = false>
class SeparatorAxisTest {
- const ShapeA *shape_A;
- const ShapeB *shape_B;
- const Transform3D *transform_A;
- const Transform3D *transform_B;
- real_t best_depth;
+ const ShapeA *shape_A = nullptr;
+ const ShapeB *shape_B = nullptr;
+ const Transform3D *transform_A = nullptr;
+ const Transform3D *transform_B = nullptr;
+ real_t best_depth = 1e15;
Vector3 best_axis;
- _CollectorCallback *callback;
- real_t margin_A;
- real_t margin_B;
+ _CollectorCallback *callback = nullptr;
+ real_t margin_A = 0.0;
+ real_t margin_B = 0.0;
Vector3 separator_axis;
public:
@@ -749,7 +749,6 @@ public:
}
_FORCE_INLINE_ SeparatorAxisTest(const ShapeA *p_shape_A, const Transform3D &p_transform_A, const ShapeB *p_shape_B, const Transform3D &p_transform_B, _CollectorCallback *p_callback, real_t p_margin_A = 0, real_t p_margin_B = 0) {
- best_depth = 1e15;
shape_A = p_shape_A;
shape_B = p_shape_B;
transform_A = &p_transform_A;
@@ -2272,13 +2271,13 @@ static void _collision_convex_polygon_face(const Shape3DSW *p_a, const Transform
bool sat_calculate_penetration(const Shape3DSW *p_shape_A, const Transform3D &p_transform_A, const Shape3DSW *p_shape_B, const Transform3D &p_transform_B, CollisionSolver3DSW::CallbackResult p_result_callback, void *p_userdata, bool p_swap, Vector3 *r_prev_axis, real_t p_margin_a, real_t p_margin_b) {
PhysicsServer3D::ShapeType type_A = p_shape_A->get_type();
- ERR_FAIL_COND_V(type_A == PhysicsServer3D::SHAPE_PLANE, false);
+ ERR_FAIL_COND_V(type_A == PhysicsServer3D::SHAPE_WORLD_BOUNDARY, false);
ERR_FAIL_COND_V(type_A == PhysicsServer3D::SHAPE_SEPARATION_RAY, false);
ERR_FAIL_COND_V(p_shape_A->is_concave(), false);
PhysicsServer3D::ShapeType type_B = p_shape_B->get_type();
- ERR_FAIL_COND_V(type_B == PhysicsServer3D::SHAPE_PLANE, false);
+ ERR_FAIL_COND_V(type_B == PhysicsServer3D::SHAPE_WORLD_BOUNDARY, false);
ERR_FAIL_COND_V(type_B == PhysicsServer3D::SHAPE_SEPARATION_RAY, false);
ERR_FAIL_COND_V(p_shape_B->is_concave(), false);
diff --git a/servers/physics_3d/collision_solver_3d_sw.cpp b/servers/physics_3d/collision_solver_3d_sw.cpp
index 4a4a8164d3..dcc363638e 100644
--- a/servers/physics_3d/collision_solver_3d_sw.cpp
+++ b/servers/physics_3d/collision_solver_3d_sw.cpp
@@ -37,12 +37,12 @@
#define collision_solver sat_calculate_penetration
//#define collision_solver gjk_epa_calculate_penetration
-bool CollisionSolver3DSW::solve_static_plane(const Shape3DSW *p_shape_A, const Transform3D &p_transform_A, const Shape3DSW *p_shape_B, const Transform3D &p_transform_B, CallbackResult p_result_callback, void *p_userdata, bool p_swap_result) {
- const PlaneShape3DSW *plane = static_cast<const PlaneShape3DSW *>(p_shape_A);
- if (p_shape_B->get_type() == PhysicsServer3D::SHAPE_PLANE) {
+bool CollisionSolver3DSW::solve_static_world_boundary(const Shape3DSW *p_shape_A, const Transform3D &p_transform_A, const Shape3DSW *p_shape_B, const Transform3D &p_transform_B, CallbackResult p_result_callback, void *p_userdata, bool p_swap_result) {
+ const WorldBoundaryShape3DSW *world_boundary = static_cast<const WorldBoundaryShape3DSW *>(p_shape_A);
+ if (p_shape_B->get_type() == PhysicsServer3D::SHAPE_WORLD_BOUNDARY) {
return false;
}
- Plane p = p_transform_A.xform(plane->get_plane());
+ Plane p = p_transform_A.xform(world_boundary->get_plane());
static const int max_supports = 16;
Vector3 supports[max_supports];
@@ -365,8 +365,8 @@ bool CollisionSolver3DSW::solve_static(const Shape3DSW *p_shape_A, const Transfo
swap = true;
}
- if (type_A == PhysicsServer3D::SHAPE_PLANE) {
- if (type_B == PhysicsServer3D::SHAPE_PLANE) {
+ if (type_A == PhysicsServer3D::SHAPE_WORLD_BOUNDARY) {
+ if (type_B == PhysicsServer3D::SHAPE_WORLD_BOUNDARY) {
return false;
}
if (type_B == PhysicsServer3D::SHAPE_SEPARATION_RAY) {
@@ -377,9 +377,9 @@ bool CollisionSolver3DSW::solve_static(const Shape3DSW *p_shape_A, const Transfo
}
if (swap) {
- return solve_static_plane(p_shape_B, p_transform_B, p_shape_A, p_transform_A, p_result_callback, p_userdata, true);
+ return solve_static_world_boundary(p_shape_B, p_transform_B, p_shape_A, p_transform_A, p_result_callback, p_userdata, true);
} else {
- return solve_static_plane(p_shape_A, p_transform_A, p_shape_B, p_transform_B, p_result_callback, p_userdata, false);
+ return solve_static_world_boundary(p_shape_A, p_transform_A, p_shape_B, p_transform_B, p_result_callback, p_userdata, false);
}
} else if (type_A == PhysicsServer3D::SHAPE_SEPARATION_RAY) {
@@ -443,12 +443,12 @@ bool CollisionSolver3DSW::concave_distance_callback(void *p_userdata, Shape3DSW
return false;
}
-bool CollisionSolver3DSW::solve_distance_plane(const Shape3DSW *p_shape_A, const Transform3D &p_transform_A, const Shape3DSW *p_shape_B, const Transform3D &p_transform_B, Vector3 &r_point_A, Vector3 &r_point_B) {
- const PlaneShape3DSW *plane = static_cast<const PlaneShape3DSW *>(p_shape_A);
- if (p_shape_B->get_type() == PhysicsServer3D::SHAPE_PLANE) {
+bool CollisionSolver3DSW::solve_distance_world_boundary(const Shape3DSW *p_shape_A, const Transform3D &p_transform_A, const Shape3DSW *p_shape_B, const Transform3D &p_transform_B, Vector3 &r_point_A, Vector3 &r_point_B) {
+ const WorldBoundaryShape3DSW *world_boundary = static_cast<const WorldBoundaryShape3DSW *>(p_shape_A);
+ if (p_shape_B->get_type() == PhysicsServer3D::SHAPE_WORLD_BOUNDARY) {
return false;
}
- Plane p = p_transform_A.xform(plane->get_plane());
+ Plane p = p_transform_A.xform(world_boundary->get_plane());
static const int max_supports = 16;
Vector3 supports[max_supports];
@@ -500,9 +500,9 @@ bool CollisionSolver3DSW::solve_distance(const Shape3DSW *p_shape_A, const Trans
return false;
}
- if (p_shape_B->get_type() == PhysicsServer3D::SHAPE_PLANE) {
+ if (p_shape_B->get_type() == PhysicsServer3D::SHAPE_WORLD_BOUNDARY) {
Vector3 a, b;
- bool col = solve_distance_plane(p_shape_B, p_transform_B, p_shape_A, p_transform_A, a, b);
+ bool col = solve_distance_world_boundary(p_shape_B, p_transform_B, p_shape_A, p_transform_A, a, b);
r_point_A = b;
r_point_B = a;
return !col;
diff --git a/servers/physics_3d/collision_solver_3d_sw.h b/servers/physics_3d/collision_solver_3d_sw.h
index c13614ab3e..0a9ea7c0eb 100644
--- a/servers/physics_3d/collision_solver_3d_sw.h
+++ b/servers/physics_3d/collision_solver_3d_sw.h
@@ -42,12 +42,12 @@ private:
static void soft_body_contact_callback(const Vector3 &p_point_A, int p_index_A, const Vector3 &p_point_B, int p_index_B, void *p_userdata);
static bool soft_body_concave_callback(void *p_userdata, Shape3DSW *p_convex);
static bool concave_callback(void *p_userdata, Shape3DSW *p_convex);
- static bool solve_static_plane(const Shape3DSW *p_shape_A, const Transform3D &p_transform_A, const Shape3DSW *p_shape_B, const Transform3D &p_transform_B, CallbackResult p_result_callback, void *p_userdata, bool p_swap_result);
+ static bool solve_static_world_boundary(const Shape3DSW *p_shape_A, const Transform3D &p_transform_A, const Shape3DSW *p_shape_B, const Transform3D &p_transform_B, CallbackResult p_result_callback, void *p_userdata, bool p_swap_result);
static bool solve_separation_ray(const Shape3DSW *p_shape_A, const Transform3D &p_transform_A, const Shape3DSW *p_shape_B, const Transform3D &p_transform_B, CallbackResult p_result_callback, void *p_userdata, bool p_swap_result, real_t p_margin = 0);
static bool solve_soft_body(const Shape3DSW *p_shape_A, const Transform3D &p_transform_A, const Shape3DSW *p_shape_B, const Transform3D &p_transform_B, CallbackResult p_result_callback, void *p_userdata, bool p_swap_result);
static bool solve_concave(const Shape3DSW *p_shape_A, const Transform3D &p_transform_A, const Shape3DSW *p_shape_B, const Transform3D &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 bool concave_distance_callback(void *p_userdata, Shape3DSW *p_convex);
- static bool solve_distance_plane(const Shape3DSW *p_shape_A, const Transform3D &p_transform_A, const Shape3DSW *p_shape_B, const Transform3D &p_transform_B, Vector3 &r_point_A, Vector3 &r_point_B);
+ static bool solve_distance_world_boundary(const Shape3DSW *p_shape_A, const Transform3D &p_transform_A, const Shape3DSW *p_shape_B, const Transform3D &p_transform_B, Vector3 &r_point_A, Vector3 &r_point_B);
public:
static bool solve_static(const Shape3DSW *p_shape_A, const Transform3D &p_transform_A, const Shape3DSW *p_shape_B, const Transform3D &p_transform_B, CallbackResult p_result_callback, void *p_userdata, Vector3 *r_sep_axis = nullptr, real_t p_margin_A = 0, real_t p_margin_B = 0);
diff --git a/servers/physics_3d/gjk_epa.cpp b/servers/physics_3d/gjk_epa.cpp
index f2f712193a..a1dbdd0a70 100644
--- a/servers/physics_3d/gjk_epa.cpp
+++ b/servers/physics_3d/gjk_epa.cpp
@@ -37,7 +37,7 @@
/*
Bullet Continuous Collision Detection and Physics Library
-Copyright (c) 2003-2008 Erwin Coumans https://bulletphysics.org
+Copyright (c) 2003-2008 Erwin Coumans http://continuousphysics.com/Bullet/
This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from the
@@ -96,7 +96,7 @@ struct sResults {
Vector3 witnesses[2];
Vector3 normal;
- real_t distance;
+ real_t distance = 0.0;
};
// Shorthands
diff --git a/servers/physics_3d/joints/cone_twist_joint_3d_sw.cpp b/servers/physics_3d/joints/cone_twist_joint_3d_sw.cpp
index 7315e9c709..bb9cc1bf67 100644
--- a/servers/physics_3d/joints/cone_twist_joint_3d_sw.cpp
+++ b/servers/physics_3d/joints/cone_twist_joint_3d_sw.cpp
@@ -92,20 +92,8 @@ ConeTwistJoint3DSW::ConeTwistJoint3DSW(Body3DSW *rbA, Body3DSW *rbB, const Trans
m_rbAFrame = rbAFrame;
m_rbBFrame = rbBFrame;
- m_swingSpan1 = Math_TAU / 8.0;
- m_swingSpan2 = Math_TAU / 8.0;
- m_twistSpan = Math_TAU;
- m_biasFactor = 0.3f;
- m_relaxationFactor = 1.0f;
-
- m_angularOnly = false;
- m_solveTwistLimit = false;
- m_solveSwingLimit = false;
-
A->add_constraint(this, 0);
B->add_constraint(this, 1);
-
- m_appliedImpulse = 0;
}
bool ConeTwistJoint3DSW::setup(real_t p_timestep) {
diff --git a/servers/physics_3d/joints/cone_twist_joint_3d_sw.h b/servers/physics_3d/joints/cone_twist_joint_3d_sw.h
index 608847352c..bf7e593820 100644
--- a/servers/physics_3d/joints/cone_twist_joint_3d_sw.h
+++ b/servers/physics_3d/joints/cone_twist_joint_3d_sw.h
@@ -67,39 +67,39 @@ public:
Body3DSW *B;
};
- Body3DSW *_arr[2];
+ Body3DSW *_arr[2] = { nullptr, nullptr };
};
- JacobianEntry3DSW m_jac[3]; //3 orthogonal linear constraints
+ JacobianEntry3DSW m_jac[3] = {}; //3 orthogonal linear constraints
- real_t m_appliedImpulse;
+ real_t m_appliedImpulse = 0.0;
Transform3D m_rbAFrame;
Transform3D m_rbBFrame;
- real_t m_limitSoftness;
- real_t m_biasFactor;
- real_t m_relaxationFactor;
+ real_t m_limitSoftness = 0.0;
+ real_t m_biasFactor = 0.3;
+ real_t m_relaxationFactor = 1.0;
- real_t m_swingSpan1;
- real_t m_swingSpan2;
- real_t m_twistSpan;
+ real_t m_swingSpan1 = Math_TAU / 8.0;
+ real_t m_swingSpan2 = 0.0;
+ real_t m_twistSpan = 0.0;
Vector3 m_swingAxis;
Vector3 m_twistAxis;
- real_t m_kSwing;
- real_t m_kTwist;
+ real_t m_kSwing = 0.0;
+ real_t m_kTwist = 0.0;
- real_t m_twistLimitSign;
- real_t m_swingCorrection;
- real_t m_twistCorrection;
+ real_t m_twistLimitSign = 0.0;
+ real_t m_swingCorrection = 0.0;
+ real_t m_twistCorrection = 0.0;
- real_t m_accSwingLimitImpulse;
- real_t m_accTwistLimitImpulse;
+ real_t m_accSwingLimitImpulse = 0.0;
+ real_t m_accTwistLimitImpulse = 0.0;
- bool m_angularOnly;
- bool m_solveTwistLimit;
- bool m_solveSwingLimit;
+ bool m_angularOnly = false;
+ bool m_solveTwistLimit = false;
+ bool m_solveSwingLimit = false;
public:
virtual PhysicsServer3D::JointType get_type() const override { return PhysicsServer3D::JOINT_TYPE_CONE_TWIST; }
diff --git a/servers/physics_3d/joints/generic_6dof_joint_3d_sw.cpp b/servers/physics_3d/joints/generic_6dof_joint_3d_sw.cpp
index d2b64ce6e3..56aba24b42 100644
--- a/servers/physics_3d/joints/generic_6dof_joint_3d_sw.cpp
+++ b/servers/physics_3d/joints/generic_6dof_joint_3d_sw.cpp
@@ -34,7 +34,7 @@ Adapted to Godot from the Bullet library.
/*
Bullet Continuous Collision Detection and Physics Library
-Copyright (c) 2003-2006 Erwin Coumans https://bulletphysics.org
+Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from the use of this software.
diff --git a/servers/physics_3d/joints/generic_6dof_joint_3d_sw.h b/servers/physics_3d/joints/generic_6dof_joint_3d_sw.h
index c2a0443aff..6492e40393 100644
--- a/servers/physics_3d/joints/generic_6dof_joint_3d_sw.h
+++ b/servers/physics_3d/joints/generic_6dof_joint_3d_sw.h
@@ -40,7 +40,7 @@ Adapted to Godot from the Bullet library.
/*
Bullet Continuous Collision Detection and Physics Library
-Copyright (c) 2003-2006 Erwin Coumans https://bulletphysics.org
+Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from the use of this software.
@@ -65,43 +65,28 @@ class G6DOFRotationalLimitMotor3DSW {
public:
//! limit_parameters
//!@{
- real_t m_loLimit; //!< joint limit
- real_t m_hiLimit; //!< joint limit
- real_t m_targetVelocity; //!< target motor velocity
- real_t m_maxMotorForce; //!< max force on motor
- real_t m_maxLimitForce; //!< max force on limit
- real_t m_damping; //!< Damping.
- real_t m_limitSoftness; //! Relaxation factor
- real_t m_ERP; //!< Error tolerance factor when joint is at limit
- real_t m_bounce; //!< restitution factor
- bool m_enableMotor;
- bool m_enableLimit;
+ real_t m_loLimit = -1e30; //!< joint limit
+ real_t m_hiLimit = 1e30; //!< joint limit
+ real_t m_targetVelocity = 0.0; //!< target motor velocity
+ real_t m_maxMotorForce = 0.1; //!< max force on motor
+ real_t m_maxLimitForce = 300.0; //!< max force on limit
+ real_t m_damping = 1.0; //!< Damping.
+ real_t m_limitSoftness = 0.5; //! Relaxation factor
+ real_t m_ERP = 0.5; //!< Error tolerance factor when joint is at limit
+ real_t m_bounce = 0.0; //!< restitution factor
+ bool m_enableMotor = false;
+ bool m_enableLimit = false;
//!@}
//! temp_variables
//!@{
- real_t m_currentLimitError; //!< How much is violated this limit
- int m_currentLimit; //!< 0=free, 1=at lo limit, 2=at hi limit
- real_t m_accumulatedImpulse;
+ real_t m_currentLimitError = 0.0; //!< How much is violated this limit
+ int m_currentLimit = 0; //!< 0=free, 1=at lo limit, 2=at hi limit
+ real_t m_accumulatedImpulse = 0.0;
//!@}
- G6DOFRotationalLimitMotor3DSW() {
- m_accumulatedImpulse = 0.f;
- m_targetVelocity = 0;
- m_maxMotorForce = 0.1f;
- m_maxLimitForce = 300.0f;
- m_loLimit = -1e30;
- m_hiLimit = 1e30;
- m_ERP = 0.5f;
- m_bounce = 0.0f;
- m_damping = 1.0f;
- m_limitSoftness = 0.5f;
- m_currentLimit = 0;
- m_currentLimitError = 0;
- m_enableMotor = false;
- m_enableLimit = false;
- }
+ G6DOFRotationalLimitMotor3DSW() {}
//! Is limited
bool isLimited() {
@@ -125,30 +110,16 @@ public:
class G6DOFTranslationalLimitMotor3DSW {
public:
- Vector3 m_lowerLimit; //!< the constraint lower limits
- Vector3 m_upperLimit; //!< the constraint upper limits
- Vector3 m_accumulatedImpulse;
+ Vector3 m_lowerLimit = Vector3(0.0, 0.0, 0.0); //!< the constraint lower limits
+ Vector3 m_upperLimit = Vector3(0.0, 0.0, 0.0); //!< the constraint upper limits
+ Vector3 m_accumulatedImpulse = Vector3(0.0, 0.0, 0.0);
//! Linear_Limit_parameters
//!@{
- Vector3 m_limitSoftness; //!< Softness for linear limit
- Vector3 m_damping; //!< Damping for linear limit
- Vector3 m_restitution; //! Bounce parameter for linear limit
+ Vector3 m_limitSoftness = Vector3(0.7, 0.7, 0.7); //!< Softness for linear limit
+ Vector3 m_damping = Vector3(1.0, 1.0, 1.0); //!< Damping for linear limit
+ Vector3 m_restitution = Vector3(0.5, 0.5, 0.5); //! Bounce parameter for linear limit
//!@}
- bool enable_limit[3];
-
- G6DOFTranslationalLimitMotor3DSW() {
- m_lowerLimit = Vector3(0.f, 0.f, 0.f);
- m_upperLimit = Vector3(0.f, 0.f, 0.f);
- m_accumulatedImpulse = Vector3(0.f, 0.f, 0.f);
-
- m_limitSoftness = Vector3(1, 1, 1) * 0.7f;
- m_damping = Vector3(1, 1, 1) * real_t(1.0f);
- m_restitution = Vector3(1, 1, 1) * real_t(0.5f);
-
- enable_limit[0] = true;
- enable_limit[1] = true;
- enable_limit[2] = true;
- }
+ bool enable_limit[3] = { true, true, true };
//! Test limit
/*!
@@ -180,7 +151,7 @@ protected:
Body3DSW *B;
};
- Body3DSW *_arr[2];
+ Body3DSW *_arr[2] = { nullptr, nullptr };
};
//! relative_frames
@@ -208,7 +179,7 @@ protected:
protected:
//! temporal variables
//!@{
- real_t m_timeStep;
+ real_t m_timeStep = 0.0;
Transform3D m_calculatedTransformA;
Transform3D m_calculatedTransformB;
Vector3 m_calculatedAxisAngleDiff;
@@ -216,7 +187,7 @@ protected:
Vector3 m_AnchorPos; // point between pivots of bodies A and B to solve linear axes
- bool m_useLinearReferenceFrameA;
+ bool m_useLinearReferenceFrameA = false;
//!@}
diff --git a/servers/physics_3d/joints/hinge_joint_3d_sw.cpp b/servers/physics_3d/joints/hinge_joint_3d_sw.cpp
index e2bf2845fe..a45fcf7eb5 100644
--- a/servers/physics_3d/joints/hinge_joint_3d_sw.cpp
+++ b/servers/physics_3d/joints/hinge_joint_3d_sw.cpp
@@ -34,7 +34,7 @@ Adapted to Godot from the Bullet library.
/*
Bullet Continuous Collision Detection and Physics Library
-Copyright (c) 2003-2006 Erwin Coumans https://bulletphysics.org
+Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from the use of this software.
@@ -79,21 +79,6 @@ HingeJoint3DSW::HingeJoint3DSW(Body3DSW *rbA, Body3DSW *rbB, const Transform3D &
m_rbBFrame.basis[1][2] *= real_t(-1.);
m_rbBFrame.basis[2][2] *= real_t(-1.);
- //start with free
- m_lowerLimit = Math_PI;
- m_upperLimit = -Math_PI;
-
- m_useLimit = false;
- m_biasFactor = 0.3f;
- m_relaxationFactor = 1.0f;
- m_limitSoftness = 0.9f;
- m_solveLimit = false;
-
- tau = 0.3;
-
- m_angularOnly = false;
- m_enableAngularMotor = false;
-
A->add_constraint(this, 0);
B->add_constraint(this, 1);
}
@@ -135,21 +120,6 @@ HingeJoint3DSW::HingeJoint3DSW(Body3DSW *rbA, Body3DSW *rbB, const Vector3 &pivo
rbAxisB1.y, rbAxisB2.y, -axisInB.y,
rbAxisB1.z, rbAxisB2.z, -axisInB.z);
- //start with free
- m_lowerLimit = Math_PI;
- m_upperLimit = -Math_PI;
-
- m_useLimit = false;
- m_biasFactor = 0.3f;
- m_relaxationFactor = 1.0f;
- m_limitSoftness = 0.9f;
- m_solveLimit = false;
-
- tau = 0.3;
-
- m_angularOnly = false;
- m_enableAngularMotor = false;
-
A->add_constraint(this, 0);
B->add_constraint(this, 1);
}
diff --git a/servers/physics_3d/joints/hinge_joint_3d_sw.h b/servers/physics_3d/joints/hinge_joint_3d_sw.h
index 572c35266f..a4ceff9ffe 100644
--- a/servers/physics_3d/joints/hinge_joint_3d_sw.h
+++ b/servers/physics_3d/joints/hinge_joint_3d_sw.h
@@ -40,7 +40,7 @@ Adapted to Godot from the Bullet library.
/*
Bullet Continuous Collision Detection and Physics Library
-Copyright (c) 2003-2006 Erwin Coumans https://bulletphysics.org
+Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from the use of this software.
@@ -60,7 +60,7 @@ class HingeJoint3DSW : public Joint3DSW {
Body3DSW *B;
};
- Body3DSW *_arr[2];
+ Body3DSW *_arr[2] = {};
};
JacobianEntry3DSW m_jac[3]; //3 orthogonal linear constraints
@@ -69,31 +69,31 @@ class HingeJoint3DSW : public Joint3DSW {
Transform3D m_rbAFrame; // constraint axii. Assumes z is hinge axis.
Transform3D m_rbBFrame;
- real_t m_motorTargetVelocity;
- real_t m_maxMotorImpulse;
+ real_t m_motorTargetVelocity = 0.0;
+ real_t m_maxMotorImpulse = 0.0;
- real_t m_limitSoftness;
- real_t m_biasFactor;
- real_t m_relaxationFactor;
+ real_t m_limitSoftness = 0.9;
+ real_t m_biasFactor = 0.3;
+ real_t m_relaxationFactor = 1.0;
- real_t m_lowerLimit;
- real_t m_upperLimit;
+ real_t m_lowerLimit = Math_PI;
+ real_t m_upperLimit = -Math_PI;
- real_t m_kHinge;
+ real_t m_kHinge = 0.0;
- real_t m_limitSign;
- real_t m_correction;
+ real_t m_limitSign = 0.0;
+ real_t m_correction = 0.0;
- real_t m_accLimitImpulse;
+ real_t m_accLimitImpulse = 0.0;
- real_t tau;
+ real_t tau = 0.3;
- bool m_useLimit;
- bool m_angularOnly;
- bool m_enableAngularMotor;
- bool m_solveLimit;
+ bool m_useLimit = false;
+ bool m_angularOnly = false;
+ bool m_enableAngularMotor = false;
+ bool m_solveLimit = false;
- real_t m_appliedImpulse;
+ real_t m_appliedImpulse = 0.0;
public:
virtual PhysicsServer3D::JointType get_type() const override { return PhysicsServer3D::JOINT_TYPE_HINGE; }
diff --git a/servers/physics_3d/joints/jacobian_entry_3d_sw.h b/servers/physics_3d/joints/jacobian_entry_3d_sw.h
index 30c80db23f..7294ff78e3 100644
--- a/servers/physics_3d/joints/jacobian_entry_3d_sw.h
+++ b/servers/physics_3d/joints/jacobian_entry_3d_sw.h
@@ -37,7 +37,7 @@ Adapted to Godot from the Bullet library.
/*
Bullet Continuous Collision Detection and Physics Library
-Copyright (c) 2003-2006 Erwin Coumans https://bulletphysics.org
+Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from the use of this software.
@@ -163,7 +163,7 @@ public:
Vector3 m_0MinvJt;
Vector3 m_1MinvJt;
//Optimization: can be stored in the w/last component of one of the vectors
- real_t m_Adiag;
+ real_t m_Adiag = 1.0;
};
#endif // JACOBIAN_ENTRY_SW_H
diff --git a/servers/physics_3d/joints/pin_joint_3d_sw.cpp b/servers/physics_3d/joints/pin_joint_3d_sw.cpp
index 7a713c1161..f41151ec0e 100644
--- a/servers/physics_3d/joints/pin_joint_3d_sw.cpp
+++ b/servers/physics_3d/joints/pin_joint_3d_sw.cpp
@@ -34,7 +34,7 @@ Adapted to Godot from the Bullet library.
/*
Bullet Continuous Collision Detection and Physics Library
-Copyright (c) 2003-2006 Erwin Coumans https://bulletphysics.org
+Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from the use of this software.
@@ -171,11 +171,6 @@ PinJoint3DSW::PinJoint3DSW(Body3DSW *p_body_a, const Vector3 &p_pos_a, Body3DSW
m_pivotInA = p_pos_a;
m_pivotInB = p_pos_b;
- m_tau = 0.3;
- m_damping = 1;
- m_impulseClamp = 0;
- m_appliedImpulse = 0;
-
A->add_constraint(this, 0);
B->add_constraint(this, 1);
}
diff --git a/servers/physics_3d/joints/pin_joint_3d_sw.h b/servers/physics_3d/joints/pin_joint_3d_sw.h
index 09deefc5c4..79af48f2a5 100644
--- a/servers/physics_3d/joints/pin_joint_3d_sw.h
+++ b/servers/physics_3d/joints/pin_joint_3d_sw.h
@@ -40,7 +40,7 @@ Adapted to Godot from the Bullet library.
/*
Bullet Continuous Collision Detection and Physics Library
-Copyright (c) 2003-2006 Erwin Coumans https://bulletphysics.org
+Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from the use of this software.
@@ -60,15 +60,15 @@ class PinJoint3DSW : public Joint3DSW {
Body3DSW *B;
};
- Body3DSW *_arr[2];
+ Body3DSW *_arr[2] = {};
};
- real_t m_tau; //bias
- real_t m_damping;
- real_t m_impulseClamp;
- real_t m_appliedImpulse;
+ real_t m_tau = 0.3; //bias
+ real_t m_damping = 1.0;
+ real_t m_impulseClamp = 0.0;
+ real_t m_appliedImpulse = 0.0;
- JacobianEntry3DSW m_jac[3]; //3 orthogonal linear constraints
+ JacobianEntry3DSW m_jac[3] = {}; //3 orthogonal linear constraints
Vector3 m_pivotInA;
Vector3 m_pivotInB;
diff --git a/servers/physics_3d/joints/slider_joint_3d_sw.cpp b/servers/physics_3d/joints/slider_joint_3d_sw.cpp
index 9f01196c30..e10ed436d5 100644
--- a/servers/physics_3d/joints/slider_joint_3d_sw.cpp
+++ b/servers/physics_3d/joints/slider_joint_3d_sw.cpp
@@ -34,7 +34,7 @@ Adapted to Godot from the Bullet library.
/*
Bullet Continuous Collision Detection and Physics Library
-Copyright (c) 2003-2006 Erwin Coumans https://bulletphysics.org
+Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from the use of this software.
@@ -72,41 +72,6 @@ static _FORCE_INLINE_ real_t atan2fast(real_t y, real_t x) {
return (y < 0.0f) ? -angle : angle;
}
-void SliderJoint3DSW::initParams() {
- m_lowerLinLimit = real_t(1.0);
- m_upperLinLimit = real_t(-1.0);
- m_lowerAngLimit = real_t(0.);
- m_upperAngLimit = real_t(0.);
- m_softnessDirLin = SLIDER_CONSTRAINT_DEF_SOFTNESS;
- m_restitutionDirLin = SLIDER_CONSTRAINT_DEF_RESTITUTION;
- m_dampingDirLin = real_t(0.);
- m_softnessDirAng = SLIDER_CONSTRAINT_DEF_SOFTNESS;
- m_restitutionDirAng = SLIDER_CONSTRAINT_DEF_RESTITUTION;
- m_dampingDirAng = real_t(0.);
- m_softnessOrthoLin = SLIDER_CONSTRAINT_DEF_SOFTNESS;
- m_restitutionOrthoLin = SLIDER_CONSTRAINT_DEF_RESTITUTION;
- m_dampingOrthoLin = SLIDER_CONSTRAINT_DEF_DAMPING;
- m_softnessOrthoAng = SLIDER_CONSTRAINT_DEF_SOFTNESS;
- m_restitutionOrthoAng = SLIDER_CONSTRAINT_DEF_RESTITUTION;
- m_dampingOrthoAng = SLIDER_CONSTRAINT_DEF_DAMPING;
- m_softnessLimLin = SLIDER_CONSTRAINT_DEF_SOFTNESS;
- m_restitutionLimLin = SLIDER_CONSTRAINT_DEF_RESTITUTION;
- m_dampingLimLin = SLIDER_CONSTRAINT_DEF_DAMPING;
- m_softnessLimAng = SLIDER_CONSTRAINT_DEF_SOFTNESS;
- m_restitutionLimAng = SLIDER_CONSTRAINT_DEF_RESTITUTION;
- m_dampingLimAng = SLIDER_CONSTRAINT_DEF_DAMPING;
-
- m_poweredLinMotor = false;
- m_targetLinMotorVelocity = real_t(0.);
- m_maxLinMotorForce = real_t(0.);
- m_accumulatedLinMotorImpulse = real_t(0.0);
-
- m_poweredAngMotor = false;
- m_targetAngMotorVelocity = real_t(0.);
- m_maxAngMotorForce = real_t(0.);
- m_accumulatedAngMotorImpulse = real_t(0.0);
-} // SliderJointSW::initParams()
-
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
@@ -120,8 +85,6 @@ SliderJoint3DSW::SliderJoint3DSW(Body3DSW *rbA, Body3DSW *rbB, const Transform3D
A->add_constraint(this, 0);
B->add_constraint(this, 1);
-
- initParams();
} // SliderJointSW::SliderJointSW()
//-----------------------------------------------------------------------------
diff --git a/servers/physics_3d/joints/slider_joint_3d_sw.h b/servers/physics_3d/joints/slider_joint_3d_sw.h
index f09476f570..d32ad9469e 100644
--- a/servers/physics_3d/joints/slider_joint_3d_sw.h
+++ b/servers/physics_3d/joints/slider_joint_3d_sw.h
@@ -40,7 +40,7 @@ Adapted to Godot from the Bullet library.
/*
Bullet Continuous Collision Detection and Physics Library
-Copyright (c) 2003-2006 Erwin Coumans https://bulletphysics.org
+Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from the use of this software.
@@ -73,53 +73,53 @@ protected:
Body3DSW *B;
};
- Body3DSW *_arr[2];
+ Body3DSW *_arr[2] = { nullptr, nullptr };
};
Transform3D m_frameInA;
Transform3D m_frameInB;
// linear limits
- real_t m_lowerLinLimit;
- real_t m_upperLinLimit;
+ real_t m_lowerLinLimit = 1.0;
+ real_t m_upperLinLimit = -1.0;
// angular limits
- real_t m_lowerAngLimit;
- real_t m_upperAngLimit;
+ real_t m_lowerAngLimit = 0.0;
+ real_t m_upperAngLimit = 0.0;
// softness, restitution and damping for different cases
// DirLin - moving inside linear limits
// LimLin - hitting linear limit
// DirAng - moving inside angular limits
// LimAng - hitting angular limit
// OrthoLin, OrthoAng - against constraint axis
- real_t m_softnessDirLin;
- real_t m_restitutionDirLin;
- real_t m_dampingDirLin;
- real_t m_softnessDirAng;
- real_t m_restitutionDirAng;
- real_t m_dampingDirAng;
- real_t m_softnessLimLin;
- real_t m_restitutionLimLin;
- real_t m_dampingLimLin;
- real_t m_softnessLimAng;
- real_t m_restitutionLimAng;
- real_t m_dampingLimAng;
- real_t m_softnessOrthoLin;
- real_t m_restitutionOrthoLin;
- real_t m_dampingOrthoLin;
- real_t m_softnessOrthoAng;
- real_t m_restitutionOrthoAng;
- real_t m_dampingOrthoAng;
+ real_t m_softnessDirLin = SLIDER_CONSTRAINT_DEF_SOFTNESS;
+ real_t m_restitutionDirLin = SLIDER_CONSTRAINT_DEF_RESTITUTION;
+ real_t m_dampingDirLin = 0.0;
+ real_t m_softnessDirAng = SLIDER_CONSTRAINT_DEF_SOFTNESS;
+ real_t m_restitutionDirAng = SLIDER_CONSTRAINT_DEF_RESTITUTION;
+ real_t m_dampingDirAng = 0.0;
+ real_t m_softnessLimLin = SLIDER_CONSTRAINT_DEF_SOFTNESS;
+ real_t m_restitutionLimLin = SLIDER_CONSTRAINT_DEF_RESTITUTION;
+ real_t m_dampingLimLin = SLIDER_CONSTRAINT_DEF_DAMPING;
+ real_t m_softnessLimAng = SLIDER_CONSTRAINT_DEF_SOFTNESS;
+ real_t m_restitutionLimAng = SLIDER_CONSTRAINT_DEF_RESTITUTION;
+ real_t m_dampingLimAng = SLIDER_CONSTRAINT_DEF_DAMPING;
+ real_t m_softnessOrthoLin = SLIDER_CONSTRAINT_DEF_SOFTNESS;
+ real_t m_restitutionOrthoLin = SLIDER_CONSTRAINT_DEF_RESTITUTION;
+ real_t m_dampingOrthoLin = SLIDER_CONSTRAINT_DEF_DAMPING;
+ real_t m_softnessOrthoAng = SLIDER_CONSTRAINT_DEF_SOFTNESS;
+ real_t m_restitutionOrthoAng = SLIDER_CONSTRAINT_DEF_RESTITUTION;
+ real_t m_dampingOrthoAng = SLIDER_CONSTRAINT_DEF_DAMPING;
// for interlal use
- bool m_solveLinLim;
- bool m_solveAngLim;
+ bool m_solveLinLim = false;
+ bool m_solveAngLim = false;
- JacobianEntry3DSW m_jacLin[3];
- real_t m_jacLinDiagABInv[3];
+ JacobianEntry3DSW m_jacLin[3] = {};
+ real_t m_jacLinDiagABInv[3] = {};
- JacobianEntry3DSW m_jacAng[3];
+ JacobianEntry3DSW m_jacAng[3] = {};
- real_t m_timeStep;
+ real_t m_timeStep = 0.0;
Transform3D m_calculatedTransformA;
Transform3D m_calculatedTransformB;
@@ -132,23 +132,20 @@ protected:
Vector3 m_relPosA;
Vector3 m_relPosB;
- real_t m_linPos;
+ real_t m_linPos = 0.0;
- real_t m_angDepth;
- real_t m_kAngle;
+ real_t m_angDepth = 0.0;
+ real_t m_kAngle = 0.0;
- bool m_poweredLinMotor;
- real_t m_targetLinMotorVelocity;
- real_t m_maxLinMotorForce;
- real_t m_accumulatedLinMotorImpulse;
+ bool m_poweredLinMotor = false;
+ real_t m_targetLinMotorVelocity = 0.0;
+ real_t m_maxLinMotorForce = 0.0;
+ real_t m_accumulatedLinMotorImpulse = 0.0;
- bool m_poweredAngMotor;
- real_t m_targetAngMotorVelocity;
- real_t m_maxAngMotorForce;
- real_t m_accumulatedAngMotorImpulse;
-
- //------------------------
- void initParams();
+ bool m_poweredAngMotor = false;
+ real_t m_targetAngMotorVelocity = 0.0;
+ real_t m_maxAngMotorForce = 0.0;
+ real_t m_accumulatedAngMotorImpulse = 0.0;
public:
// constructors
diff --git a/servers/physics_3d/physics_server_3d_sw.cpp b/servers/physics_3d/physics_server_3d_sw.cpp
index 8de54c5c48..8bfadeb356 100644
--- a/servers/physics_3d/physics_server_3d_sw.cpp
+++ b/servers/physics_3d/physics_server_3d_sw.cpp
@@ -43,8 +43,8 @@
#define FLUSH_QUERY_CHECK(m_object) \
ERR_FAIL_COND_MSG(m_object->get_space() && flushing_queries, "Can't change this state while flushing queries. Use call_deferred() or set_deferred() to change monitoring state instead.");
-RID PhysicsServer3DSW::plane_shape_create() {
- Shape3DSW *shape = memnew(PlaneShape3DSW);
+RID PhysicsServer3DSW::world_boundary_shape_create() {
+ Shape3DSW *shape = memnew(WorldBoundaryShape3DSW);
RID rid = shape_owner.make_rid(shape);
shape->set_self(rid);
return rid;
@@ -1744,11 +1744,5 @@ PhysicsServer3DSW::PhysicsServer3DSW(bool p_using_threads) {
singletonsw = this;
BroadPhase3DSW::create_func = BroadPhase3DBVH::_create;
- island_count = 0;
- active_objects = 0;
- collision_pairs = 0;
using_threads = p_using_threads;
- active = true;
- flushing_queries = false;
- doing_sync = false;
};
diff --git a/servers/physics_3d/physics_server_3d_sw.h b/servers/physics_3d/physics_server_3d_sw.h
index 071ad0a694..c34f8bff7a 100644
--- a/servers/physics_3d/physics_server_3d_sw.h
+++ b/servers/physics_3d/physics_server_3d_sw.h
@@ -42,18 +42,18 @@ class PhysicsServer3DSW : public PhysicsServer3D {
GDCLASS(PhysicsServer3DSW, PhysicsServer3D);
friend class PhysicsDirectSpaceState3DSW;
- bool active;
- int iterations;
+ bool active = true;
+ int iterations = 0;
- int island_count;
- int active_objects;
- int collision_pairs;
+ int island_count = 0;
+ int active_objects = 0;
+ int collision_pairs = 0;
- bool using_threads;
- bool doing_sync;
- bool flushing_queries;
+ bool using_threads = false;
+ bool doing_sync = false;
+ bool flushing_queries = false;
- Step3DSW *stepper;
+ Step3DSW *stepper = nullptr;
Set<const Space3DSW *> active_spaces;
mutable RID_PtrOwner<Shape3DSW, true> shape_owner;
@@ -79,7 +79,7 @@ public:
static void _shape_col_cbk(const Vector3 &p_point_A, int p_index_A, const Vector3 &p_point_B, int p_index_B, void *p_userdata);
- virtual RID plane_shape_create() override;
+ virtual RID world_boundary_shape_create() override;
virtual RID separation_ray_shape_create() override;
virtual RID sphere_shape_create() override;
virtual RID box_shape_create() override;
diff --git a/servers/physics_3d/physics_server_3d_wrap_mt.cpp b/servers/physics_3d/physics_server_3d_wrap_mt.cpp
index 0a89c1a9c9..c424100bba 100644
--- a/servers/physics_3d/physics_server_3d_wrap_mt.cpp
+++ b/servers/physics_3d/physics_server_3d_wrap_mt.cpp
@@ -119,8 +119,6 @@ PhysicsServer3DWrapMT::PhysicsServer3DWrapMT(PhysicsServer3D *p_contained, bool
command_queue(p_create_thread) {
physics_3d_server = p_contained;
create_thread = p_create_thread;
- step_pending = 0;
- step_thread_up = false;
pool_max_size = GLOBAL_GET("memory/limits/multithreaded_server/rid_pool_prealloc");
@@ -131,7 +129,6 @@ PhysicsServer3DWrapMT::PhysicsServer3DWrapMT(PhysicsServer3D *p_contained, bool
}
main_thread = Thread::get_caller_id();
- first_frame = true;
}
PhysicsServer3DWrapMT::~PhysicsServer3DWrapMT() {
diff --git a/servers/physics_3d/physics_server_3d_wrap_mt.h b/servers/physics_3d/physics_server_3d_wrap_mt.h
index 58986969d4..a5683b99c3 100644
--- a/servers/physics_3d/physics_server_3d_wrap_mt.h
+++ b/servers/physics_3d/physics_server_3d_wrap_mt.h
@@ -58,7 +58,7 @@ class PhysicsServer3DWrapMT : public PhysicsServer3D {
bool create_thread = false;
Semaphore step_sem;
- int step_pending;
+ int step_pending = 0;
void thread_step(real_t p_delta);
void thread_flush();
@@ -78,7 +78,7 @@ public:
#include "servers/server_wrap_mt_common.h"
//FUNC1RID(shape,ShapeType); todo fix
- FUNCRID(plane_shape)
+ FUNCRID(world_boundary_shape)
FUNCRID(separation_ray_shape)
FUNCRID(sphere_shape)
FUNCRID(box_shape)
diff --git a/servers/physics_3d/shape_3d_sw.cpp b/servers/physics_3d/shape_3d_sw.cpp
index 945d0120be..1533d6e592 100644
--- a/servers/physics_3d/shape_3d_sw.cpp
+++ b/servers/physics_3d/shape_3d_sw.cpp
@@ -39,7 +39,7 @@
/*
Bullet Continuous Collision Detection and Physics Library
-Copyright (c) 2003-2009 Erwin Coumans https://bulletphysics.org
+Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org
This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from the use of this software.
@@ -101,30 +101,25 @@ const Map<ShapeOwner3DSW *, int> &Shape3DSW::get_owners() const {
return owners;
}
-Shape3DSW::Shape3DSW() {
- custom_bias = 0;
- configured = false;
-}
-
Shape3DSW::~Shape3DSW() {
ERR_FAIL_COND(owners.size());
}
-Plane PlaneShape3DSW::get_plane() const {
+Plane WorldBoundaryShape3DSW::get_plane() const {
return plane;
}
-void PlaneShape3DSW::project_range(const Vector3 &p_normal, const Transform3D &p_transform, real_t &r_min, real_t &r_max) const {
+void WorldBoundaryShape3DSW::project_range(const Vector3 &p_normal, const Transform3D &p_transform, real_t &r_min, real_t &r_max) const {
// gibberish, a plane is infinity
r_min = -1e7;
r_max = 1e7;
}
-Vector3 PlaneShape3DSW::get_support(const Vector3 &p_normal) const {
+Vector3 WorldBoundaryShape3DSW::get_support(const Vector3 &p_normal) const {
return p_normal * 1e15;
}
-bool PlaneShape3DSW::intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_result, Vector3 &r_normal) const {
+bool WorldBoundaryShape3DSW::intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_result, Vector3 &r_normal) const {
bool inters = plane.intersects_segment(p_begin, p_end, &r_result);
if (inters) {
r_normal = plane.normal;
@@ -132,11 +127,11 @@ bool PlaneShape3DSW::intersect_segment(const Vector3 &p_begin, const Vector3 &p_
return inters;
}
-bool PlaneShape3DSW::intersect_point(const Vector3 &p_point) const {
+bool WorldBoundaryShape3DSW::intersect_point(const Vector3 &p_point) const {
return plane.distance_to(p_point) < 0;
}
-Vector3 PlaneShape3DSW::get_closest_point_to(const Vector3 &p_point) const {
+Vector3 WorldBoundaryShape3DSW::get_closest_point_to(const Vector3 &p_point) const {
if (plane.is_point_over(p_point)) {
return plane.project(p_point);
} else {
@@ -144,24 +139,24 @@ Vector3 PlaneShape3DSW::get_closest_point_to(const Vector3 &p_point) const {
}
}
-Vector3 PlaneShape3DSW::get_moment_of_inertia(real_t p_mass) const {
- return Vector3(); //wtf
+Vector3 WorldBoundaryShape3DSW::get_moment_of_inertia(real_t p_mass) const {
+ return Vector3(); // not applicable.
}
-void PlaneShape3DSW::_setup(const Plane &p_plane) {
+void WorldBoundaryShape3DSW::_setup(const Plane &p_plane) {
plane = p_plane;
configure(AABB(Vector3(-1e4, -1e4, -1e4), Vector3(1e4 * 2, 1e4 * 2, 1e4 * 2)));
}
-void PlaneShape3DSW::set_data(const Variant &p_data) {
+void WorldBoundaryShape3DSW::set_data(const Variant &p_data) {
_setup(p_data);
}
-Variant PlaneShape3DSW::get_data() const {
+Variant WorldBoundaryShape3DSW::get_data() const {
return plane;
}
-PlaneShape3DSW::PlaneShape3DSW() {
+WorldBoundaryShape3DSW::WorldBoundaryShape3DSW() {
}
//
@@ -244,10 +239,7 @@ Variant SeparationRayShape3DSW::get_data() const {
return d;
}
-SeparationRayShape3DSW::SeparationRayShape3DSW() {
- length = 1;
- slide_on_slope = false;
-}
+SeparationRayShape3DSW::SeparationRayShape3DSW() {}
/********** SPHERE *************/
@@ -311,9 +303,7 @@ Variant SphereShape3DSW::get_data() const {
return radius;
}
-SphereShape3DSW::SphereShape3DSW() {
- radius = 0;
-}
+SphereShape3DSW::SphereShape3DSW() {}
/********** BOX *************/
@@ -502,8 +492,7 @@ Variant BoxShape3DSW::get_data() const {
return half_extents;
}
-BoxShape3DSW::BoxShape3DSW() {
-}
+BoxShape3DSW::BoxShape3DSW() {}
/********** CAPSULE *************/
@@ -668,9 +657,7 @@ Variant CapsuleShape3DSW::get_data() const {
return d;
}
-CapsuleShape3DSW::CapsuleShape3DSW() {
- height = radius = 0;
-}
+CapsuleShape3DSW::CapsuleShape3DSW() {}
/********** CYLINDER *************/
@@ -848,9 +835,7 @@ Variant CylinderShape3DSW::get_data() const {
return d;
}
-CylinderShape3DSW::CylinderShape3DSW() {
- height = radius = 0;
-}
+CylinderShape3DSW::CylinderShape3DSW() {}
/********** CONVEX POLYGON *************/
diff --git a/servers/physics_3d/shape_3d_sw.h b/servers/physics_3d/shape_3d_sw.h
index 73eddc469c..061d66a085 100644
--- a/servers/physics_3d/shape_3d_sw.h
+++ b/servers/physics_3d/shape_3d_sw.h
@@ -48,8 +48,8 @@ public:
class Shape3DSW {
RID self;
AABB aabb;
- bool configured;
- real_t custom_bias;
+ bool configured = false;
+ real_t custom_bias = 0.0;
Map<ShapeOwner3DSW *, int> owners;
@@ -95,7 +95,7 @@ public:
bool is_owner(ShapeOwner3DSW *p_owner) const;
const Map<ShapeOwner3DSW *, int> &get_owners() const;
- Shape3DSW();
+ Shape3DSW() {}
virtual ~Shape3DSW();
};
@@ -112,7 +112,7 @@ public:
ConcaveShape3DSW() {}
};
-class PlaneShape3DSW : public Shape3DSW {
+class WorldBoundaryShape3DSW : public Shape3DSW {
Plane plane;
void _setup(const Plane &p_plane);
@@ -121,7 +121,7 @@ public:
Plane get_plane() const;
virtual real_t get_area() const override { return INFINITY; }
- virtual PhysicsServer3D::ShapeType get_type() const override { return PhysicsServer3D::SHAPE_PLANE; }
+ virtual PhysicsServer3D::ShapeType get_type() const override { return PhysicsServer3D::SHAPE_WORLD_BOUNDARY; }
virtual void project_range(const Vector3 &p_normal, const Transform3D &p_transform, real_t &r_min, real_t &r_max) const override;
virtual Vector3 get_support(const Vector3 &p_normal) const override;
virtual void get_supports(const Vector3 &p_normal, int p_max, Vector3 *r_supports, int &r_amount, FeatureType &r_type) const override { r_amount = 0; }
@@ -134,12 +134,12 @@ public:
virtual void set_data(const Variant &p_data) override;
virtual Variant get_data() const override;
- PlaneShape3DSW();
+ WorldBoundaryShape3DSW();
};
class SeparationRayShape3DSW : public Shape3DSW {
- real_t length;
- bool slide_on_slope;
+ real_t length = 1.0;
+ bool slide_on_slope = false;
void _setup(real_t p_length, bool p_slide_on_slope);
@@ -166,7 +166,7 @@ public:
};
class SphereShape3DSW : public Shape3DSW {
- real_t radius;
+ real_t radius = 0.0;
void _setup(real_t p_radius);
@@ -218,8 +218,8 @@ public:
};
class CapsuleShape3DSW : public Shape3DSW {
- real_t height;
- real_t radius;
+ real_t height = 0.0;
+ real_t radius = 0.0;
void _setup(real_t p_height, real_t p_radius);
@@ -247,8 +247,8 @@ public:
};
class CylinderShape3DSW : public Shape3DSW {
- real_t height;
- real_t radius;
+ real_t height = 0.0;
+ real_t radius = 0.0;
void _setup(real_t p_height, real_t p_radius);
@@ -308,7 +308,7 @@ struct ConcavePolygonShape3DSW : public ConcaveShape3DSW {
struct Face {
Vector3 normal;
- int indices[3];
+ int indices[3] = {};
};
Vector<Face> faces;
@@ -316,10 +316,10 @@ struct ConcavePolygonShape3DSW : public ConcaveShape3DSW {
struct BVH {
AABB aabb;
- int left;
- int right;
+ int left = 0;
+ int right = 0;
- int face_index;
+ int face_index = 0;
};
Vector<BVH> bvh;
@@ -469,7 +469,7 @@ struct FaceShape3DSW : public Shape3DSW {
};
struct MotionShape3DSW : public Shape3DSW {
- Shape3DSW *shape;
+ Shape3DSW *shape = nullptr;
Vector3 motion;
virtual PhysicsServer3D::ShapeType get_type() const override { return PhysicsServer3D::SHAPE_CONVEX_POLYGON; }
diff --git a/servers/physics_3d/soft_body_3d_sw.cpp b/servers/physics_3d/soft_body_3d_sw.cpp
index d7e13867bf..5f6e202c73 100644
--- a/servers/physics_3d/soft_body_3d_sw.cpp
+++ b/servers/physics_3d/soft_body_3d_sw.cpp
@@ -38,7 +38,7 @@
/*
Bullet Continuous Collision Detection and Physics Library
-Copyright (c) 2003-2006 Erwin Coumans https://bulletphysics.org
+Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from the use of this software.
diff --git a/servers/physics_3d/space_3d_sw.cpp b/servers/physics_3d/space_3d_sw.cpp
index 3b08184e00..bf72e90932 100644
--- a/servers/physics_3d/space_3d_sw.cpp
+++ b/servers/physics_3d/space_3d_sw.cpp
@@ -1142,18 +1142,6 @@ PhysicsDirectSpaceState3DSW *Space3DSW::get_direct_state() {
}
Space3DSW::Space3DSW() {
- collision_pairs = 0;
- active_objects = 0;
- island_count = 0;
- contact_debug_count = 0;
-
- locked = false;
- contact_recycle_radius = 0.01;
- contact_max_separation = 0.05;
- contact_max_allowed_penetration = 0.01;
- test_motion_min_contact_depth = 0.00001;
-
- constraint_bias = 0.01;
body_linear_velocity_sleep_threshold = GLOBAL_DEF("physics/3d/sleep_threshold_linear", 0.1);
body_angular_velocity_sleep_threshold = GLOBAL_DEF("physics/3d/sleep_threshold_angular", Math::deg2rad(8.0));
body_time_to_sleep = GLOBAL_DEF("physics/3d/time_before_sleep", 0.5);
@@ -1163,14 +1151,9 @@ Space3DSW::Space3DSW() {
broadphase = BroadPhase3DSW::create_func();
broadphase->set_pair_callback(_broadphase_pair, this);
broadphase->set_unpair_callback(_broadphase_unpair, this);
- area = nullptr;
direct_access = memnew(PhysicsDirectSpaceState3DSW);
direct_access->space = this;
-
- for (int i = 0; i < ELAPSED_TIME_MAX; i++) {
- elapsed_time[i] = 0;
- }
}
Space3DSW::~Space3DSW() {
diff --git a/servers/physics_3d/space_3d_sw.h b/servers/physics_3d/space_3d_sw.h
index 98c335cb80..aa4557d136 100644
--- a/servers/physics_3d/space_3d_sw.h
+++ b/servers/physics_3d/space_3d_sw.h
@@ -72,7 +72,7 @@ public:
};
private:
- uint64_t elapsed_time[ELAPSED_TIME_MAX];
+ uint64_t elapsed_time[ELAPSED_TIME_MAX] = {};
PhysicsDirectSpaceState3DSW *direct_access;
RID self;
@@ -90,13 +90,13 @@ private:
Set<CollisionObject3DSW *> objects;
- Area3DSW *area;
+ Area3DSW *area = nullptr;
- real_t contact_recycle_radius;
- real_t contact_max_separation;
- real_t contact_max_allowed_penetration;
- real_t constraint_bias;
- real_t test_motion_min_contact_depth;
+ real_t contact_recycle_radius = 0.01;
+ real_t contact_max_separation = 0.05;
+ real_t contact_max_allowed_penetration = 0.01;
+ real_t constraint_bias = 0.01;
+ real_t test_motion_min_contact_depth = 0.00001;
enum {
INTERSECTION_QUERY_MAX = 2048
@@ -110,18 +110,18 @@ private:
real_t body_time_to_sleep;
real_t body_angular_velocity_damp_ratio;
- bool locked;
+ bool locked = false;
real_t last_step = 0.001;
- int island_count;
- int active_objects;
- int collision_pairs;
+ int island_count = 0;
+ int active_objects = 0;
+ int collision_pairs = 0;
RID static_global_body;
Vector<Vector3> contact_debug;
- int contact_debug_count;
+ int contact_debug_count = 0;
friend class PhysicsDirectSpaceState3DSW;
diff --git a/servers/physics_3d/step_3d_sw.cpp b/servers/physics_3d/step_3d_sw.cpp
index d0604b0aa0..7c18944b4d 100644
--- a/servers/physics_3d/step_3d_sw.cpp
+++ b/servers/physics_3d/step_3d_sw.cpp
@@ -407,8 +407,6 @@ void Step3DSW::step(Space3DSW *p_space, real_t p_delta, int p_iterations) {
}
Step3DSW::Step3DSW() {
- _step = 1;
-
body_islands.reserve(BODY_ISLAND_COUNT_RESERVE);
constraint_islands.reserve(ISLAND_COUNT_RESERVE);
all_constraints.reserve(CONSTRAINT_COUNT_RESERVE);
diff --git a/servers/physics_3d/step_3d_sw.h b/servers/physics_3d/step_3d_sw.h
index 9c60004b24..f2f879104a 100644
--- a/servers/physics_3d/step_3d_sw.h
+++ b/servers/physics_3d/step_3d_sw.h
@@ -37,7 +37,7 @@
#include "core/templates/thread_work_pool.h"
class Step3DSW {
- uint64_t _step;
+ uint64_t _step = 1;
int iterations = 0;
real_t delta = 0.0;