Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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