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