Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/physics/src/ogreode/OgreOdeUtility.cpp @ 1933

Last change on this file since 1933 was 1923, checked in by rgrieder, 16 years ago

Cleaned up the heavy mess with header file includes in OgreOde. It should now compile a lot faster.

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