Gravity + double precision fixes

ccfreak2k

23-05-2014 06:20:40

I've made two small patches for this library. The first adds a getter/setter pair for gravity on rigid bodies (though it's possible to get/set the values manually, having a wrapper is nice):

Dynamics/include/OgreBulletDynamicsRigidBody.h | 3 +++
Dynamics/src/OgreBulletDynamicsRigidBody.cpp | 10 ++++++++++
2 files changed, 13 insertions(+)

diff --git a/Dynamics/include/OgreBulletDynamicsRigidBody.h b/Dynamics/include/OgreBulletDynamicsRigidBody.h
index 0d7fd63..aa858b7 100644
--- a/Dynamics/include/OgreBulletDynamicsRigidBody.h
+++ b/Dynamics/include/OgreBulletDynamicsRigidBody.h
@@ -93,6 +93,9 @@ namespace OgreBulletDynamics
void setAngularVelocity(const Ogre::Real x, const Ogre::Real y, const Ogre::Real z);
Ogre::Vector3 getAngularVelocity() const;

+ void setGravity(const Ogre::Vector3 &acceleration);
+ Ogre::Vector3 getGravity() const;
+
void applyImpulse(const Ogre::Vector3 &impulse, const Ogre::Vector3 &position);
void applyForce(const Ogre::Vector3 &impulse, const Ogre::Vector3 &position);

diff --git a/Dynamics/src/OgreBulletDynamicsRigidBody.cpp b/Dynamics/src/OgreBulletDynamicsRigidBody.cpp
index 7442244..0869a96 100644
--- a/Dynamics/src/OgreBulletDynamicsRigidBody.cpp
+++ b/Dynamics/src/OgreBulletDynamicsRigidBody.cpp
@@ -208,6 +208,16 @@ namespace OgreBulletDynamics
return convert(getBulletRigidBody()->getAngularVelocity());
}
// -------------------------------------------------------------------------
+ void RigidBody::setGravity(const Ogre::Vector3 &acceleration)
+ {
+ getBulletRigidBody()->setGravity(convert(acceleration));
+ }
+ // -------------------------------------------------------------------------
+ Ogre::Vector3 RigidBody::getGravity() const
+ {
+ return convert (getBulletRigidBody()->getGravity());
+ }
+ // -------------------------------------------------------------------------
void RigidBody::applyImpulse(const Ogre::Vector3 &impulse, const Ogre::Vector3 &position)
{
getBulletRigidBody()->applyImpulse(convert(impulse), convert(position));


The second fixes point2pointconstraint to use Ogre::Real, which eliminates a warning when using doubles:

.../Constraints/OgreBulletDynamicsPoint2pointConstraint.h | 8 ++++----
.../OgreBulletDynamicsPoint2pointConstraint.cpp | 8 ++++----
1 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/Dynamics/include/Constraints/OgreBulletDynamicsPoint2pointConstraint.h b/Dynamics/include/Constraints/OgreBulletDynamicsPoint2pointConstraint.h
index 8e786b5..e885fd3 100644
--- a/Dynamics/include/Constraints/OgreBulletDynamicsPoint2pointConstraint.h
+++ b/Dynamics/include/Constraints/OgreBulletDynamicsPoint2pointConstraint.h
@@ -48,11 +48,11 @@ namespace OgreBulletDynamics

inline btPoint2PointConstraint *getBulletPoint2PointConstraint() const;

- void setTau(float tau);
- void setDamping(float damping);
+ void setTau(Ogre::Real tau);
+ void setDamping(Ogre::Real damping);

- float getTau() const;
- float getDamping() const;
+ Ogre::Real getTau() const;
+ Ogre::Real getDamping() const;

void setPivotA(const Ogre::Vector3 &pivotA);
void setPivotB(const Ogre::Vector3 &pivotB);
diff --git a/Dynamics/src/Constraints/OgreBulletDynamicsPoint2pointConstraint.cpp b/Dynamics/src/Constraints/OgreBulletDynamicsPoint2pointConstraint.cpp
index dff4ddd..5fcb521 100644
--- a/Dynamics/src/Constraints/OgreBulletDynamicsPoint2pointConstraint.cpp
+++ b/Dynamics/src/Constraints/OgreBulletDynamicsPoint2pointConstraint.cpp
@@ -62,22 +62,22 @@ namespace OgreBulletDynamics
OgreBulletCollisions::convert(pivotB));
}
// -------------------------------------------------------------------------
- void PointToPointConstraint::setTau(float tau)
+ void PointToPointConstraint::setTau(Ogre::Real tau)
{
getBulletPoint2PointConstraint()->m_setting.m_tau = tau;
}
// -------------------------------------------------------------------------
- void PointToPointConstraint::setDamping(float damping)
+ void PointToPointConstraint::setDamping(Ogre::Real damping)
{
getBulletPoint2PointConstraint()->m_setting.m_damping = damping;
}
// -------------------------------------------------------------------------
- float PointToPointConstraint::getTau() const
+ Ogre::Real PointToPointConstraint::getTau() const
{
return getBulletPoint2PointConstraint()->m_setting.m_tau;
}
// -------------------------------------------------------------------------
- float PointToPointConstraint::getDamping() const
+ Ogre::Real PointToPointConstraint::getDamping() const
{
return getBulletPoint2PointConstraint()->m_setting.m_damping;
}


It should be noted that I haven't tested either of these patches, however I think they're simple enough that they shouldn't cause any major problems.

AlexeyKnyshev

23-05-2014 10:57:11

Commited 6a6df81, 609cd8c.