[1919] | 1 | #include "OgreOdePrecompiledHeaders.h" |
---|
| 2 | #include "OgreOdeUtility.h" |
---|
| 3 | |
---|
| 4 | using namespace OgreOde; |
---|
| 5 | using namespace Ogre; |
---|
| 6 | |
---|
| 7 | const Ogre::Real Utility::Infinity = dInfinity; |
---|
| 8 | |
---|
| 9 | Real Utility::randomReal() |
---|
| 10 | { |
---|
| 11 | return (Real)dRandReal(); |
---|
| 12 | } |
---|
| 13 | |
---|
| 14 | /** |
---|
| 15 | According to the ODE docs; |
---|
| 16 | |
---|
| 17 | By adjusting the values of ERP and CFM, you can achieve various effects. |
---|
| 18 | For example you can simulate springy constraints, where the two bodies oscillate |
---|
| 19 | as though connected by springs. Or you can simulate more spongy constraints, without |
---|
| 20 | the oscillation. In fact, ERP and CFM can be selected to have the same effect as any |
---|
| 21 | desired spring and damper constants. If you have a spring constant kp and damping constant kd, |
---|
| 22 | then the corresponding ODE constants are: |
---|
| 23 | |
---|
| 24 | ERP = h kp / (h kp + kd) |
---|
| 25 | CFM = 1 / (h kp + kd) |
---|
| 26 | |
---|
| 27 | where h is the stepsize. These values will give the same effect as a spring-and-damper |
---|
| 28 | system simulated with implicit first order integration. |
---|
| 29 | */ |
---|
| 30 | //----------------------------------------------------------------------- |
---|
| 31 | Real Utility::getCFM(Real spring, Real dampening, Real timeStep) |
---|
| 32 | { |
---|
| 33 | return 1 / ((timeStep * spring) + dampening); |
---|
| 34 | } |
---|
| 35 | |
---|
| 36 | //----------------------------------------------------------------------- |
---|
| 37 | Real Utility::getERP(Real spring, Real dampening, Real timeStep) |
---|
| 38 | { |
---|
| 39 | return (timeStep * spring) / ((timeStep * spring) + dampening); |
---|
| 40 | } |
---|
| 41 | |
---|
| 42 | //----------------------------------------------------------------------- |
---|
| 43 | void Utility::getSpringConstants(Real CFM, Real ERP, Real timeStep, Real &spring, Real &dampening) |
---|
| 44 | { |
---|
| 45 | spring = (ERP / CFM) / timeStep; |
---|
| 46 | dampening = (1 / CFM) - timeStep * spring; |
---|
| 47 | } |
---|