1 | |
---|
2 | #include "OgreOdePrecompiledHeaders.h" |
---|
3 | |
---|
4 | #include "OgreOdePreReqs.h" |
---|
5 | #include "OgreOdeMass.h" |
---|
6 | |
---|
7 | using namespace OgreOde; |
---|
8 | using namespace Ogre; |
---|
9 | |
---|
10 | Mass::Mass() |
---|
11 | { |
---|
12 | dMassSetZero(&_mass); |
---|
13 | } |
---|
14 | |
---|
15 | Mass::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 | |
---|
27 | Mass::~Mass() |
---|
28 | { |
---|
29 | } |
---|
30 | |
---|
31 | void Mass::adjust(Real mass) |
---|
32 | { |
---|
33 | dMassAdjust(&_mass,(dReal)mass); |
---|
34 | } |
---|
35 | |
---|
36 | void Mass::translate(const Ogre::Vector3& offset) |
---|
37 | { |
---|
38 | dMassTranslate(&_mass,offset.x,offset.y,offset.z); |
---|
39 | } |
---|
40 | |
---|
41 | void 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 | |
---|
66 | Ogre::Real Mass::getMassValue() const |
---|
67 | { |
---|
68 | return _mass.mass; |
---|
69 | } |
---|
70 | |
---|
71 | Ogre::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 | |
---|
81 | Ogre::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 | } |
---|
88 | void Mass::add(const Mass& other) |
---|
89 | { |
---|
90 | dMassAdd(&_mass,&(other._mass)); |
---|
91 | } |
---|
92 | |
---|
93 | const dMass* Mass::getMassPtr() const |
---|
94 | { |
---|
95 | return &_mass; |
---|
96 | } |
---|
97 | |
---|
98 | SphereMass::SphereMass():Mass() |
---|
99 | { |
---|
100 | } |
---|
101 | |
---|
102 | SphereMass::SphereMass(Real mass,Real radius) |
---|
103 | { |
---|
104 | dMassSetSphereTotal(&_mass,(dReal)mass,(dReal)radius); |
---|
105 | } |
---|
106 | |
---|
107 | SphereMass::~SphereMass() |
---|
108 | { |
---|
109 | } |
---|
110 | |
---|
111 | void SphereMass::setDensity(Real density,Real radius) |
---|
112 | { |
---|
113 | dMassSetSphere(&_mass,(dReal)density,(dReal)radius); |
---|
114 | } |
---|
115 | |
---|
116 | CapsuleMass::CapsuleMass():Mass() |
---|
117 | { |
---|
118 | } |
---|
119 | |
---|
120 | CapsuleMass::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 | |
---|
127 | CapsuleMass::~CapsuleMass() |
---|
128 | { |
---|
129 | } |
---|
130 | |
---|
131 | void 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 | |
---|
138 | CylinderMass::CylinderMass():Mass() |
---|
139 | { |
---|
140 | } |
---|
141 | |
---|
142 | CylinderMass::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 | |
---|
149 | CylinderMass::~CylinderMass() |
---|
150 | { |
---|
151 | } |
---|
152 | |
---|
153 | void 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 | |
---|
160 | BoxMass::BoxMass():Mass() |
---|
161 | { |
---|
162 | } |
---|
163 | |
---|
164 | BoxMass::BoxMass(Real mass,const Ogre::Vector3& size) |
---|
165 | { |
---|
166 | dMassSetBoxTotal(&_mass,(dReal)mass,(dReal)size.x,(dReal)size.y,(dReal)size.z); |
---|
167 | } |
---|
168 | |
---|
169 | BoxMass::~BoxMass() |
---|
170 | { |
---|
171 | } |
---|
172 | |
---|
173 | void BoxMass::setDensity(Real density,const Ogre::Vector3& size) |
---|
174 | { |
---|
175 | dMassSetBox(&_mass,(dReal)density,(dReal)size.x,(dReal)size.y,(dReal)size.z); |
---|
176 | } |
---|