Apply old method for linear & angular damping in Bullet, in order to
make it easier to tweak and consistent with Godot Physics. Include patch applied to Bullet master to enable dampings greater than 1.
This commit is contained in:
parent
8f0f2bf4ef
commit
5d8b0649be
|
@ -208,6 +208,8 @@ if env['builtin_bullet']:
|
|||
# if env['target'] == "debug" or env['target'] == "release_debug":
|
||||
# env_bullet.Append(CPPDEFINES=['BT_DEBUG'])
|
||||
|
||||
env_bullet.Append(CPPDEFINES=["BT_USE_OLD_DAMPING_METHOD"])
|
||||
|
||||
env_thirdparty = env_bullet.Clone()
|
||||
env_thirdparty.disable_warnings()
|
||||
env_thirdparty.add_source_files(env.modules_sources, thirdparty_sources)
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
diff --git a/thirdparty/bullet/BulletDynamics/Dynamics/btRigidBody.cpp b/thirdparty/bullet/BulletDynamics/Dynamics/btRigidBody.cpp
|
||||
index 9e8705b001..f1b50b39c8 100644
|
||||
--- a/thirdparty/bullet/BulletDynamics/Dynamics/btRigidBody.cpp
|
||||
+++ b/thirdparty/bullet/BulletDynamics/Dynamics/btRigidBody.cpp
|
||||
@@ -136,8 +136,13 @@ void btRigidBody::setGravity(const btVector3& acceleration)
|
||||
|
||||
void btRigidBody::setDamping(btScalar lin_damping, btScalar ang_damping)
|
||||
{
|
||||
- m_linearDamping = btClamped(lin_damping, (btScalar)btScalar(0.0), (btScalar)btScalar(1.0));
|
||||
- m_angularDamping = btClamped(ang_damping, (btScalar)btScalar(0.0), (btScalar)btScalar(1.0));
|
||||
+#ifdef BT_USE_OLD_DAMPING_METHOD
|
||||
+ m_linearDamping = btMax(lin_damping, btScalar(0.0));
|
||||
+ m_angularDamping = btMax(ang_damping, btScalar(0.0));
|
||||
+#else
|
||||
+ m_linearDamping = btClamped(lin_damping, btScalar(0.0), btScalar(1.0));
|
||||
+ m_angularDamping = btClamped(ang_damping, btScalar(0.0), btScalar(1.0));
|
||||
+#endif
|
||||
}
|
||||
|
||||
///applyDamping damps the velocity, using the given m_linearDamping and m_angularDamping
|
||||
@@ -146,10 +151,9 @@ void btRigidBody::applyDamping(btScalar timeStep)
|
||||
//On new damping: see discussion/issue report here: http://code.google.com/p/bullet/issues/detail?id=74
|
||||
//todo: do some performance comparisons (but other parts of the engine are probably bottleneck anyway
|
||||
|
||||
-//#define USE_OLD_DAMPING_METHOD 1
|
||||
-#ifdef USE_OLD_DAMPING_METHOD
|
||||
- m_linearVelocity *= GEN_clamped((btScalar(1.) - timeStep * m_linearDamping), (btScalar)btScalar(0.0), (btScalar)btScalar(1.0));
|
||||
- m_angularVelocity *= GEN_clamped((btScalar(1.) - timeStep * m_angularDamping), (btScalar)btScalar(0.0), (btScalar)btScalar(1.0));
|
||||
+#ifdef BT_USE_OLD_DAMPING_METHOD
|
||||
+ m_linearVelocity *= btMax((btScalar(1.0) - timeStep * m_linearDamping), btScalar(0.0));
|
||||
+ m_angularVelocity *= btMax((btScalar(1.0) - timeStep * m_angularDamping), btScalar(0.0));
|
||||
#else
|
||||
m_linearVelocity *= btPow(btScalar(1) - m_linearDamping, timeStep);
|
||||
m_angularVelocity *= btPow(btScalar(1) - m_angularDamping, timeStep);
|
|
@ -136,8 +136,13 @@ void btRigidBody::setGravity(const btVector3& acceleration)
|
|||
|
||||
void btRigidBody::setDamping(btScalar lin_damping, btScalar ang_damping)
|
||||
{
|
||||
m_linearDamping = btClamped(lin_damping, (btScalar)btScalar(0.0), (btScalar)btScalar(1.0));
|
||||
m_angularDamping = btClamped(ang_damping, (btScalar)btScalar(0.0), (btScalar)btScalar(1.0));
|
||||
#ifdef BT_USE_OLD_DAMPING_METHOD
|
||||
m_linearDamping = btMax(lin_damping, btScalar(0.0));
|
||||
m_angularDamping = btMax(ang_damping, btScalar(0.0));
|
||||
#else
|
||||
m_linearDamping = btClamped(lin_damping, btScalar(0.0), btScalar(1.0));
|
||||
m_angularDamping = btClamped(ang_damping, btScalar(0.0), btScalar(1.0));
|
||||
#endif
|
||||
}
|
||||
|
||||
///applyDamping damps the velocity, using the given m_linearDamping and m_angularDamping
|
||||
|
@ -146,10 +151,9 @@ void btRigidBody::applyDamping(btScalar timeStep)
|
|||
//On new damping: see discussion/issue report here: http://code.google.com/p/bullet/issues/detail?id=74
|
||||
//todo: do some performance comparisons (but other parts of the engine are probably bottleneck anyway
|
||||
|
||||
//#define USE_OLD_DAMPING_METHOD 1
|
||||
#ifdef USE_OLD_DAMPING_METHOD
|
||||
m_linearVelocity *= GEN_clamped((btScalar(1.) - timeStep * m_linearDamping), (btScalar)btScalar(0.0), (btScalar)btScalar(1.0));
|
||||
m_angularVelocity *= GEN_clamped((btScalar(1.) - timeStep * m_angularDamping), (btScalar)btScalar(0.0), (btScalar)btScalar(1.0));
|
||||
#ifdef BT_USE_OLD_DAMPING_METHOD
|
||||
m_linearVelocity *= btMax((btScalar(1.0) - timeStep * m_linearDamping), btScalar(0.0));
|
||||
m_angularVelocity *= btMax((btScalar(1.0) - timeStep * m_angularDamping), btScalar(0.0));
|
||||
#else
|
||||
m_linearVelocity *= btPow(btScalar(1) - m_linearDamping, timeStep);
|
||||
m_angularVelocity *= btPow(btScalar(1) - m_angularDamping, timeStep);
|
||||
|
|
Loading…
Reference in New Issue