diff --git a/src/collision/broadphase/DynamicAABBTree.cpp b/src/collision/broadphase/DynamicAABBTree.cpp index 7efd86ac..de494f69 100644 --- a/src/collision/broadphase/DynamicAABBTree.cpp +++ b/src/collision/broadphase/DynamicAABBTree.cpp @@ -32,7 +32,7 @@ using namespace reactphysics3d; // Initialization of static variables -const int TreeNode::NULL_TREE_NODE = -1; +constexpr int TreeNode::NULL_TREE_NODE = -1; // Constructor DynamicAABBTree::DynamicAABBTree(decimal extraAABBGap) : mExtraAABBGap(extraAABBGap) { diff --git a/src/collision/narrowphase/EPA/EPAAlgorithm.h b/src/collision/narrowphase/EPA/EPAAlgorithm.h index 3461f466..81e35bf5 100644 --- a/src/collision/narrowphase/EPA/EPAAlgorithm.h +++ b/src/collision/narrowphase/EPA/EPAAlgorithm.h @@ -43,10 +43,10 @@ namespace reactphysics3d { // ---------- Constants ---------- // /// Maximum number of support points of the polytope -const unsigned int MAX_SUPPORT_POINTS = 100; +constexpr unsigned int MAX_SUPPORT_POINTS = 100; /// Maximum number of facets of the polytope -const unsigned int MAX_FACETS = 200; +constexpr unsigned int MAX_FACETS = 200; // Class TriangleComparison diff --git a/src/collision/narrowphase/EPA/EdgeEPA.cpp b/src/collision/narrowphase/EPA/EdgeEPA.cpp index 098602da..842f445d 100644 --- a/src/collision/narrowphase/EPA/EdgeEPA.cpp +++ b/src/collision/narrowphase/EPA/EdgeEPA.cpp @@ -32,7 +32,6 @@ // We want to use the ReactPhysics3D namespace using namespace reactphysics3d; - // Constructor EdgeEPA::EdgeEPA() { diff --git a/src/collision/narrowphase/EPA/TrianglesStore.h b/src/collision/narrowphase/EPA/TrianglesStore.h index 840fdcbc..5cd7edee 100644 --- a/src/collision/narrowphase/EPA/TrianglesStore.h +++ b/src/collision/narrowphase/EPA/TrianglesStore.h @@ -36,7 +36,7 @@ namespace reactphysics3d { // Constants -const unsigned int MAX_TRIANGLES = 200; // Maximum number of triangles +constexpr unsigned int MAX_TRIANGLES = 200; // Maximum number of triangles // Class TriangleStore /** diff --git a/src/collision/narrowphase/GJK/GJKAlgorithm.h b/src/collision/narrowphase/GJK/GJKAlgorithm.h index 209000ab..c89178bc 100644 --- a/src/collision/narrowphase/GJK/GJKAlgorithm.h +++ b/src/collision/narrowphase/GJK/GJKAlgorithm.h @@ -37,9 +37,9 @@ namespace reactphysics3d { // Constants -const decimal REL_ERROR = decimal(1.0e-3); -const decimal REL_ERROR_SQUARE = REL_ERROR * REL_ERROR; -const int MAX_ITERATIONS_GJK_RAYCAST = 32; +constexpr decimal REL_ERROR = decimal(1.0e-3); +constexpr decimal REL_ERROR_SQUARE = REL_ERROR * REL_ERROR; +constexpr int MAX_ITERATIONS_GJK_RAYCAST = 32; // Class GJKAlgorithm /** diff --git a/src/collision/shapes/CylinderShape.cpp b/src/collision/shapes/CylinderShape.cpp index c65047e8..5485bb37 100644 --- a/src/collision/shapes/CylinderShape.cpp +++ b/src/collision/shapes/CylinderShape.cpp @@ -55,7 +55,7 @@ Vector3 CylinderShape::getLocalSupportPointWithoutMargin(const Vector3& directio Vector3 supportPoint(0.0, 0.0, 0.0); decimal uDotv = direction.y; Vector3 w(direction.x, 0.0, direction.z); - decimal lengthW = sqrt(direction.x * direction.x + direction.z * direction.z); + decimal lengthW = std::sqrt(direction.x * direction.x + direction.z * direction.z); if (lengthW > MACHINE_EPSILON) { if (uDotv < 0.0) supportPoint.y = -mHalfHeight; diff --git a/src/configuration.h b/src/configuration.h index 731071fd..4364c548 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -83,66 +83,66 @@ const decimal DECIMAL_LARGEST = std::numeric_limits::max(); const decimal MACHINE_EPSILON = std::numeric_limits::epsilon(); /// Pi constant -const decimal PI = decimal(3.14159265); +constexpr decimal PI = decimal(3.14159265); /// 2*Pi constant -const decimal PI_TIMES_2 = decimal(6.28318530); +constexpr decimal PI_TIMES_2 = decimal(6.28318530); /// Default friction coefficient for a rigid body -const decimal DEFAULT_FRICTION_COEFFICIENT = decimal(0.3); +constexpr decimal DEFAULT_FRICTION_COEFFICIENT = decimal(0.3); /// Default bounciness factor for a rigid body -const decimal DEFAULT_BOUNCINESS = decimal(0.5); +constexpr decimal DEFAULT_BOUNCINESS = decimal(0.5); /// Default rolling resistance -const decimal DEFAULT_ROLLING_RESISTANCE = decimal(0.0); +constexpr decimal DEFAULT_ROLLING_RESISTANCE = decimal(0.0); /// True if the spleeping technique is enabled -const bool SPLEEPING_ENABLED = true; +constexpr bool SPLEEPING_ENABLED = true; /// Object margin for collision detection in meters (for the GJK-EPA Algorithm) -const decimal OBJECT_MARGIN = decimal(0.04); +constexpr decimal OBJECT_MARGIN = decimal(0.04); /// Distance threshold for two contact points for a valid persistent contact (in meters) -const decimal PERSISTENT_CONTACT_DIST_THRESHOLD = decimal(0.03); +constexpr decimal PERSISTENT_CONTACT_DIST_THRESHOLD = decimal(0.03); /// Velocity threshold for contact velocity restitution -const decimal RESTITUTION_VELOCITY_THRESHOLD = decimal(1.0); +constexpr decimal RESTITUTION_VELOCITY_THRESHOLD = decimal(1.0); /// Number of iterations when solving the velocity constraints of the Sequential Impulse technique -const uint DEFAULT_VELOCITY_SOLVER_NB_ITERATIONS = 10; +constexpr uint DEFAULT_VELOCITY_SOLVER_NB_ITERATIONS = 10; /// Number of iterations when solving the position constraints of the Sequential Impulse technique -const uint DEFAULT_POSITION_SOLVER_NB_ITERATIONS = 5; +constexpr uint DEFAULT_POSITION_SOLVER_NB_ITERATIONS = 5; /// Time (in seconds) that a body must stay still to be considered sleeping -const float DEFAULT_TIME_BEFORE_SLEEP = 1.0f; +constexpr float DEFAULT_TIME_BEFORE_SLEEP = 1.0f; /// A body with a linear velocity smaller than the sleep linear velocity (in m/s) /// might enter sleeping mode. -const decimal DEFAULT_SLEEP_LINEAR_VELOCITY = decimal(0.02); +constexpr decimal DEFAULT_SLEEP_LINEAR_VELOCITY = decimal(0.02); /// A body with angular velocity smaller than the sleep angular velocity (in rad/s) /// might enter sleeping mode -const decimal DEFAULT_SLEEP_ANGULAR_VELOCITY = decimal(3.0 * (PI / 180.0)); +constexpr decimal DEFAULT_SLEEP_ANGULAR_VELOCITY = decimal(3.0 * (PI / 180.0)); /// In the broad-phase collision detection (dynamic AABB tree), the AABBs are /// inflated with a constant gap to allow the collision shape to move a little bit /// without triggering a large modification of the tree which can be costly -const decimal DYNAMIC_TREE_AABB_GAP = decimal(0.1); +constexpr decimal DYNAMIC_TREE_AABB_GAP = decimal(0.1); /// In the broad-phase collision detection (dynamic AABB tree), the AABBs are /// also inflated in direction of the linear motion of the body by mutliplying the /// followin constant with the linear velocity and the elapsed time between two frames. -const decimal DYNAMIC_TREE_AABB_LIN_GAP_MULTIPLIER = decimal(1.7); +constexpr decimal DYNAMIC_TREE_AABB_LIN_GAP_MULTIPLIER = decimal(1.7); /// Maximum number of contact manifolds in an overlapping pair that involves two /// convex collision shapes. -const int NB_MAX_CONTACT_MANIFOLDS_CONVEX_SHAPE = 1; +constexpr int NB_MAX_CONTACT_MANIFOLDS_CONVEX_SHAPE = 1; /// Maximum number of contact manifolds in an overlapping pair that involves at /// least one concave collision shape. -const int NB_MAX_CONTACT_MANIFOLDS_CONCAVE_SHAPE = 3; +constexpr int NB_MAX_CONTACT_MANIFOLDS_CONCAVE_SHAPE = 3; } diff --git a/src/constraint/BallAndSocketJoint.cpp b/src/constraint/BallAndSocketJoint.cpp index 8883d3e7..448499de 100644 --- a/src/constraint/BallAndSocketJoint.cpp +++ b/src/constraint/BallAndSocketJoint.cpp @@ -30,7 +30,7 @@ using namespace reactphysics3d; // Static variables definition -const decimal BallAndSocketJoint::BETA = decimal(0.2); +constexpr decimal BallAndSocketJoint::BETA = decimal(0.2); // Constructor BallAndSocketJoint::BallAndSocketJoint(const BallAndSocketJointInfo& jointInfo) diff --git a/src/constraint/FixedJoint.cpp b/src/constraint/FixedJoint.cpp index f17d0b9e..687043e8 100644 --- a/src/constraint/FixedJoint.cpp +++ b/src/constraint/FixedJoint.cpp @@ -30,7 +30,7 @@ using namespace reactphysics3d; // Static variables definition -const decimal FixedJoint::BETA = decimal(0.2); +constexpr decimal FixedJoint::BETA = decimal(0.2); // Constructor FixedJoint::FixedJoint(const FixedJointInfo& jointInfo) diff --git a/src/constraint/HingeJoint.cpp b/src/constraint/HingeJoint.cpp index 01563de4..021ee495 100644 --- a/src/constraint/HingeJoint.cpp +++ b/src/constraint/HingeJoint.cpp @@ -31,7 +31,7 @@ using namespace reactphysics3d; // Static variables definition -const decimal HingeJoint::BETA = decimal(0.2); +constexpr decimal HingeJoint::BETA = decimal(0.2); // Constructor HingeJoint::HingeJoint(const HingeJointInfo& jointInfo) diff --git a/src/constraint/SliderJoint.cpp b/src/constraint/SliderJoint.cpp index a1904174..365a9ad4 100644 --- a/src/constraint/SliderJoint.cpp +++ b/src/constraint/SliderJoint.cpp @@ -29,7 +29,7 @@ using namespace reactphysics3d; // Static variables definition -const decimal SliderJoint::BETA = decimal(0.2); +constexpr decimal SliderJoint::BETA = decimal(0.2); // Constructor SliderJoint::SliderJoint(const SliderJointInfo& jointInfo) diff --git a/src/engine/ContactSolver.cpp b/src/engine/ContactSolver.cpp index c3a0d0ef..faf58825 100644 --- a/src/engine/ContactSolver.cpp +++ b/src/engine/ContactSolver.cpp @@ -34,9 +34,9 @@ using namespace reactphysics3d; using namespace std; // Constants initialization -const decimal ContactSolver::BETA = decimal(0.2); -const decimal ContactSolver::BETA_SPLIT_IMPULSE = decimal(0.2); -const decimal ContactSolver::SLOP= decimal(0.01); +constexpr decimal ContactSolver::BETA = decimal(0.2); +constexpr decimal ContactSolver::BETA_SPLIT_IMPULSE = decimal(0.2); +constexpr decimal ContactSolver::SLOP= decimal(0.01); // Constructor ContactSolver::ContactSolver(const std::map& mapBodyToVelocityIndex)