Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/ogreode/src/OgreOdeMass.cpp @ 69

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

added ogreode and Colladaplugin

File size: 3.5 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::Matrix3 Mass::getLocalInertiaTensor() const
67{
68        return Ogre::Matrix3(   _mass.I[0], _mass.I[1], _mass.I[2],
69                _mass.I[4], _mass.I[5], _mass.I[6],
70                _mass.I[8], _mass.I[9], _mass.I[10]);
71}
72void Mass::add(const Mass& other)
73{
74        dMassAdd(&_mass,&(other._mass)); 
75}
76
77const dMass* Mass::getMassPtr() const
78{
79        return &_mass;
80}
81
82SphereMass::SphereMass():Mass()
83{
84}
85
86SphereMass::SphereMass(Real mass,Real radius)
87{
88        dMassSetSphereTotal(&_mass,(dReal)mass,(dReal)radius); 
89}
90
91SphereMass::~SphereMass()
92{
93}
94
95void SphereMass::setDensity(Real density,Real radius)
96{
97        dMassSetSphere(&_mass,(dReal)density,(dReal)radius); 
98}
99
100CapsuleMass::CapsuleMass():Mass()
101{
102}
103
104CapsuleMass::CapsuleMass(Real mass,Real radius,const Ogre::Vector3& direction,Real length)
105{
106        int dir = (direction == Ogre::Vector3::UNIT_X)?1:(direction == Ogre::Vector3::UNIT_Y)?2:(direction == Ogre::Vector3::UNIT_Z)?3:0;
107        assert(dir);
108        dMassSetCappedCylinderTotal(&_mass,(dReal)mass,dir,(dReal)radius,(dReal)length); 
109}
110
111CapsuleMass::~CapsuleMass()
112{
113}
114
115void CapsuleMass::setDensity(Real density,Real radius,const Ogre::Vector3& direction,Real length)
116{
117        int dir = (direction == Ogre::Vector3::UNIT_X)?1:(direction == Ogre::Vector3::UNIT_Y)?2:(direction == Ogre::Vector3::UNIT_Z)?3:0;
118        assert(dir && "Invalid direction specified for CapsuleMass");
119        dMassSetCappedCylinder(&_mass,(dReal)density,dir,(dReal)radius,(dReal)length); 
120}
121
122CylinderMass::CylinderMass():Mass()
123{
124}
125
126CylinderMass::CylinderMass(Real mass,const Ogre::Vector3& direction,Real radius,Real length)
127{
128        int dir = (direction == Ogre::Vector3::UNIT_X)?1:(direction == Ogre::Vector3::UNIT_Y)?2:(direction == Ogre::Vector3::UNIT_Z)?3:0;
129        assert(dir);
130        dMassSetCylinderTotal(&_mass,(dReal)mass,dir,(dReal)radius,(dReal)length); 
131}
132
133CylinderMass::~CylinderMass()
134{
135}
136
137void CylinderMass::setDensity(Real density,const Ogre::Vector3& direction,Real radius,Real length)
138{
139        int dir = (direction == Ogre::Vector3::UNIT_X)?1:(direction == Ogre::Vector3::UNIT_Y)?2:(direction == Ogre::Vector3::UNIT_Z)?3:0;
140        assert(dir);
141        dMassSetCylinder(&_mass,(dReal)density,dir,(dReal)radius,(dReal)length); 
142}
143
144BoxMass::BoxMass():Mass()
145{
146}
147
148BoxMass::BoxMass(Real mass,const Ogre::Vector3& size)
149{
150        dMassSetBoxTotal(&_mass,(dReal)mass,(dReal)size.x,(dReal)size.y,(dReal)size.z);
151}
152
153BoxMass::~BoxMass()
154{
155}
156
157void BoxMass::setDensity(Real density,const Ogre::Vector3& size)
158{
159        dMassSetBox(&_mass,(dReal)density,(dReal)size.x,(dReal)size.y,(dReal)size.z); 
160}
Note: See TracBrowser for help on using the repository browser.