Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/ogreode/src/OgreOdeUtility.cpp @ 21

Last change on this file since 21 was 21, checked in by nicolasc, 17 years ago

added ogreode and Colladaplugin

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