Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/physics/src/ogreode/OgreOdeMass.cpp @ 1919

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

Added OgreODE to our source repository because already we really need the newest version. And there is no hope to find any packages under linux.
The files included should compile and link with Ogre 1.4/1.6 and ODE 0.9/0.10. I was only able to test Ogre 1.4 and ODE 0.9/.10 under msvc until now.

  • Property svn:eol-style set to native
File size: 3.9 KB
Line 
1
2#include "OgreOdePrecompiledHeaders.h"
3
4#include "OgreOdePreReqs.h"
5#include "OgreOdeMass.h"
6
7using namespace OgreOde;
8using namespace Ogre;
9
10Mass::Mass()
11{
12        dMassSetZero(&_mass); 
13}
14
15Mass::Mass(Real mass,const Ogre::Vector3& center_of_gravity,const Matrix3& intertia_matrix)
16{
17        dMassSetParameters
18        (
19                &_mass,
20                (dReal)mass,
21                (dReal)center_of_gravity.x,(dReal)center_of_gravity.y,(dReal)center_of_gravity.z,
22                (dReal)intertia_matrix[0][0],(dReal)intertia_matrix[1][1],(dReal)intertia_matrix[2][2],
23                (dReal)intertia_matrix[0][1],(dReal)intertia_matrix[0][2],(dReal)intertia_matrix[1][2]
24        ); 
25}
26
27Mass::~Mass()
28{
29}
30
31void Mass::adjust(Real mass)
32{
33        dMassAdjust(&_mass,(dReal)mass); 
34}
35
36void Mass::translate(const Ogre::Vector3& offset)
37{
38        dMassTranslate(&_mass,offset.x,offset.y,offset.z); 
39}
40
41void Mass::rotate(const Ogre::Quaternion& orientation)
42{
43        Matrix3 m;
44        orientation.ToRotationMatrix(m);
45        dMatrix3 r;
46
47        r[0] = m[0][0];
48        r[1] = m[0][1];
49        r[2] = m[0][2];
50
51        r[3] = m[1][0];
52        r[4] = m[1][1];
53        r[5] = m[1][2];
54
55        r[6] = m[2][0];
56        r[7] = m[2][1];
57        r[8] = m[2][2];
58
59        r[9] = 0.0;
60        r[10] = 0.0;
61        r[11] = 0.0;
62
63        dMassRotate(&_mass,r); 
64}
65
66Ogre::Real Mass::getMassValue() const
67{
68        return _mass.mass;
69}
70
71Ogre::Vector3 Mass::getCenterOfGravity() const
72{
73        // not sure why its a dVector4 in dMass and not a dVector3
74        // and I think ode requires the center of mass to be the bodies position so this
75        // would always return Vector3::ZERO
76        return Vector3(_mass.c[0], _mass.c[1], _mass.c[2]);
77}
78
79
80
81Ogre::Matrix3 Mass::getLocalInertiaTensor() const
82{
83        return Ogre::Matrix3(   
84                _mass.I[0], _mass.I[1], _mass.I[2],
85                _mass.I[4], _mass.I[5], _mass.I[6],
86                _mass.I[8], _mass.I[9], _mass.I[10]);
87}
88void Mass::add(const Mass& other)
89{
90        dMassAdd(&_mass,&(other._mass)); 
91}
92
93const dMass* Mass::getMassPtr() const
94{
95        return &_mass;
96}
97
98SphereMass::SphereMass():Mass()
99{
100}
101
102SphereMass::SphereMass(Real mass,Real radius)
103{
104        dMassSetSphereTotal(&_mass,(dReal)mass,(dReal)radius); 
105}
106
107SphereMass::~SphereMass()
108{
109}
110
111void SphereMass::setDensity(Real density,Real radius)
112{
113        dMassSetSphere(&_mass,(dReal)density,(dReal)radius); 
114}
115
116CapsuleMass::CapsuleMass():Mass()
117{
118}
119
120CapsuleMass::CapsuleMass(Real mass,Real radius,const Ogre::Vector3& direction,Real length)
121{
122        int dir = (direction == Ogre::Vector3::UNIT_X)?1:(direction == Ogre::Vector3::UNIT_Y)?2:(direction == Ogre::Vector3::UNIT_Z)?3:0;
123        assert(dir);
124        dMassSetCappedCylinderTotal(&_mass,(dReal)mass,dir,(dReal)radius,(dReal)length); 
125}
126
127CapsuleMass::~CapsuleMass()
128{
129}
130
131void CapsuleMass::setDensity(Real density,Real radius,const Ogre::Vector3& direction,Real length)
132{
133        int dir = (direction == Ogre::Vector3::UNIT_X)?1:(direction == Ogre::Vector3::UNIT_Y)?2:(direction == Ogre::Vector3::UNIT_Z)?3:0;
134        assert(dir && "Invalid direction specified for CapsuleMass");
135        dMassSetCappedCylinder(&_mass,(dReal)density,dir,(dReal)radius,(dReal)length); 
136}
137
138CylinderMass::CylinderMass():Mass()
139{
140}
141
142CylinderMass::CylinderMass(Real mass,const Ogre::Vector3& direction,Real radius,Real length)
143{
144        int dir = (direction == Ogre::Vector3::UNIT_X)?1:(direction == Ogre::Vector3::UNIT_Y)?2:(direction == Ogre::Vector3::UNIT_Z)?3:0;
145        assert(dir);
146        dMassSetCylinderTotal(&_mass,(dReal)mass,dir,(dReal)radius,(dReal)length); 
147}
148
149CylinderMass::~CylinderMass()
150{
151}
152
153void CylinderMass::setDensity(Real density,const Ogre::Vector3& direction,Real radius,Real length)
154{
155        int dir = (direction == Ogre::Vector3::UNIT_X)?1:(direction == Ogre::Vector3::UNIT_Y)?2:(direction == Ogre::Vector3::UNIT_Z)?3:0;
156        assert(dir);
157        dMassSetCylinder(&_mass,(dReal)density,dir,(dReal)radius,(dReal)length); 
158}
159
160BoxMass::BoxMass():Mass()
161{
162}
163
164BoxMass::BoxMass(Real mass,const Ogre::Vector3& size)
165{
166        dMassSetBoxTotal(&_mass,(dReal)mass,(dReal)size.x,(dReal)size.y,(dReal)size.z);
167}
168
169BoxMass::~BoxMass()
170{
171}
172
173void BoxMass::setDensity(Real density,const Ogre::Vector3& size)
174{
175        dMassSetBox(&_mass,(dReal)density,(dReal)size.x,(dReal)size.y,(dReal)size.z); 
176}
Note: See TracBrowser for help on using the repository browser.