Use constexpr for compile time constants
This commit is contained in:
parent
16478722de
commit
cfede8f179
|
@ -32,7 +32,7 @@
|
||||||
using namespace reactphysics3d;
|
using namespace reactphysics3d;
|
||||||
|
|
||||||
// Initialization of static variables
|
// Initialization of static variables
|
||||||
const int TreeNode::NULL_TREE_NODE = -1;
|
constexpr int TreeNode::NULL_TREE_NODE = -1;
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
DynamicAABBTree::DynamicAABBTree(decimal extraAABBGap) : mExtraAABBGap(extraAABBGap) {
|
DynamicAABBTree::DynamicAABBTree(decimal extraAABBGap) : mExtraAABBGap(extraAABBGap) {
|
||||||
|
|
|
@ -43,10 +43,10 @@ namespace reactphysics3d {
|
||||||
// ---------- Constants ---------- //
|
// ---------- Constants ---------- //
|
||||||
|
|
||||||
/// Maximum number of support points of the polytope
|
/// 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
|
/// Maximum number of facets of the polytope
|
||||||
const unsigned int MAX_FACETS = 200;
|
constexpr unsigned int MAX_FACETS = 200;
|
||||||
|
|
||||||
|
|
||||||
// Class TriangleComparison
|
// Class TriangleComparison
|
||||||
|
|
|
@ -32,7 +32,6 @@
|
||||||
// We want to use the ReactPhysics3D namespace
|
// We want to use the ReactPhysics3D namespace
|
||||||
using namespace reactphysics3d;
|
using namespace reactphysics3d;
|
||||||
|
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
EdgeEPA::EdgeEPA() {
|
EdgeEPA::EdgeEPA() {
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@
|
||||||
namespace reactphysics3d {
|
namespace reactphysics3d {
|
||||||
|
|
||||||
// Constants
|
// Constants
|
||||||
const unsigned int MAX_TRIANGLES = 200; // Maximum number of triangles
|
constexpr unsigned int MAX_TRIANGLES = 200; // Maximum number of triangles
|
||||||
|
|
||||||
// Class TriangleStore
|
// Class TriangleStore
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -37,9 +37,9 @@
|
||||||
namespace reactphysics3d {
|
namespace reactphysics3d {
|
||||||
|
|
||||||
// Constants
|
// Constants
|
||||||
const decimal REL_ERROR = decimal(1.0e-3);
|
constexpr decimal REL_ERROR = decimal(1.0e-3);
|
||||||
const decimal REL_ERROR_SQUARE = REL_ERROR * REL_ERROR;
|
constexpr decimal REL_ERROR_SQUARE = REL_ERROR * REL_ERROR;
|
||||||
const int MAX_ITERATIONS_GJK_RAYCAST = 32;
|
constexpr int MAX_ITERATIONS_GJK_RAYCAST = 32;
|
||||||
|
|
||||||
// Class GJKAlgorithm
|
// Class GJKAlgorithm
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -55,7 +55,7 @@ Vector3 CylinderShape::getLocalSupportPointWithoutMargin(const Vector3& directio
|
||||||
Vector3 supportPoint(0.0, 0.0, 0.0);
|
Vector3 supportPoint(0.0, 0.0, 0.0);
|
||||||
decimal uDotv = direction.y;
|
decimal uDotv = direction.y;
|
||||||
Vector3 w(direction.x, 0.0, direction.z);
|
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 (lengthW > MACHINE_EPSILON) {
|
||||||
if (uDotv < 0.0) supportPoint.y = -mHalfHeight;
|
if (uDotv < 0.0) supportPoint.y = -mHalfHeight;
|
||||||
|
|
|
@ -83,66 +83,66 @@ const decimal DECIMAL_LARGEST = std::numeric_limits<decimal>::max();
|
||||||
const decimal MACHINE_EPSILON = std::numeric_limits<decimal>::epsilon();
|
const decimal MACHINE_EPSILON = std::numeric_limits<decimal>::epsilon();
|
||||||
|
|
||||||
/// Pi constant
|
/// Pi constant
|
||||||
const decimal PI = decimal(3.14159265);
|
constexpr decimal PI = decimal(3.14159265);
|
||||||
|
|
||||||
/// 2*Pi constant
|
/// 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
|
/// 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
|
/// Default bounciness factor for a rigid body
|
||||||
const decimal DEFAULT_BOUNCINESS = decimal(0.5);
|
constexpr decimal DEFAULT_BOUNCINESS = decimal(0.5);
|
||||||
|
|
||||||
/// Default rolling resistance
|
/// 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
|
/// 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)
|
/// 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)
|
/// 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
|
/// 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
|
/// 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
|
/// 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
|
/// 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)
|
/// A body with a linear velocity smaller than the sleep linear velocity (in m/s)
|
||||||
/// might enter sleeping mode.
|
/// 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)
|
/// A body with angular velocity smaller than the sleep angular velocity (in rad/s)
|
||||||
/// might enter sleeping mode
|
/// 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
|
/// 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
|
/// 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
|
/// 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
|
/// 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
|
/// 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.
|
/// 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
|
/// Maximum number of contact manifolds in an overlapping pair that involves two
|
||||||
/// convex collision shapes.
|
/// 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
|
/// Maximum number of contact manifolds in an overlapping pair that involves at
|
||||||
/// least one concave collision shape.
|
/// least one concave collision shape.
|
||||||
const int NB_MAX_CONTACT_MANIFOLDS_CONCAVE_SHAPE = 3;
|
constexpr int NB_MAX_CONTACT_MANIFOLDS_CONCAVE_SHAPE = 3;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@
|
||||||
using namespace reactphysics3d;
|
using namespace reactphysics3d;
|
||||||
|
|
||||||
// Static variables definition
|
// Static variables definition
|
||||||
const decimal BallAndSocketJoint::BETA = decimal(0.2);
|
constexpr decimal BallAndSocketJoint::BETA = decimal(0.2);
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
BallAndSocketJoint::BallAndSocketJoint(const BallAndSocketJointInfo& jointInfo)
|
BallAndSocketJoint::BallAndSocketJoint(const BallAndSocketJointInfo& jointInfo)
|
||||||
|
|
|
@ -30,7 +30,7 @@
|
||||||
using namespace reactphysics3d;
|
using namespace reactphysics3d;
|
||||||
|
|
||||||
// Static variables definition
|
// Static variables definition
|
||||||
const decimal FixedJoint::BETA = decimal(0.2);
|
constexpr decimal FixedJoint::BETA = decimal(0.2);
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
FixedJoint::FixedJoint(const FixedJointInfo& jointInfo)
|
FixedJoint::FixedJoint(const FixedJointInfo& jointInfo)
|
||||||
|
|
|
@ -31,7 +31,7 @@
|
||||||
using namespace reactphysics3d;
|
using namespace reactphysics3d;
|
||||||
|
|
||||||
// Static variables definition
|
// Static variables definition
|
||||||
const decimal HingeJoint::BETA = decimal(0.2);
|
constexpr decimal HingeJoint::BETA = decimal(0.2);
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
HingeJoint::HingeJoint(const HingeJointInfo& jointInfo)
|
HingeJoint::HingeJoint(const HingeJointInfo& jointInfo)
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
using namespace reactphysics3d;
|
using namespace reactphysics3d;
|
||||||
|
|
||||||
// Static variables definition
|
// Static variables definition
|
||||||
const decimal SliderJoint::BETA = decimal(0.2);
|
constexpr decimal SliderJoint::BETA = decimal(0.2);
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
SliderJoint::SliderJoint(const SliderJointInfo& jointInfo)
|
SliderJoint::SliderJoint(const SliderJointInfo& jointInfo)
|
||||||
|
|
|
@ -34,9 +34,9 @@ using namespace reactphysics3d;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
// Constants initialization
|
// Constants initialization
|
||||||
const decimal ContactSolver::BETA = decimal(0.2);
|
constexpr decimal ContactSolver::BETA = decimal(0.2);
|
||||||
const decimal ContactSolver::BETA_SPLIT_IMPULSE = decimal(0.2);
|
constexpr decimal ContactSolver::BETA_SPLIT_IMPULSE = decimal(0.2);
|
||||||
const decimal ContactSolver::SLOP= decimal(0.01);
|
constexpr decimal ContactSolver::SLOP= decimal(0.01);
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
ContactSolver::ContactSolver(const std::map<RigidBody*, uint>& mapBodyToVelocityIndex)
|
ContactSolver::ContactSolver(const std::map<RigidBody*, uint>& mapBodyToVelocityIndex)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user