aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/ode-0.9/contrib/DotNetManaged/Body.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/ode-0.9/contrib/DotNetManaged/Body.cpp')
-rw-r--r--libraries/ode-0.9/contrib/DotNetManaged/Body.cpp322
1 files changed, 322 insertions, 0 deletions
diff --git a/libraries/ode-0.9/contrib/DotNetManaged/Body.cpp b/libraries/ode-0.9/contrib/DotNetManaged/Body.cpp
new file mode 100644
index 0000000..c95ae57
--- /dev/null
+++ b/libraries/ode-0.9/contrib/DotNetManaged/Body.cpp
@@ -0,0 +1,322 @@
1#include "StdAfx.h"
2
3#include <ode/ode.h>
4#include "Body.h"
5
6namespace ODEManaged
7{
8
9 //Constructors
10
11 Body::Body(void)
12 {
13 _id = 0;
14 }
15
16 Body::Body(World &world)
17 {
18 _id = dBodyCreate(world.Id());
19 }
20
21
22 //Destructor
23
24 Body::~Body(void)
25 {
26 dBodyDestroy(this->_id);
27 }
28
29
30 //Methods
31
32 //Id
33 dBodyID Body::Id()
34 {
35 return _id;
36 }
37
38
39 //SetData
40 void Body::SetData(void *data)
41 {
42 dBodySetData(this->_id, data);
43 }
44
45 //GetData
46 void *Body::GetData(void)
47 {
48 return dBodyGetData(this->_id);
49 }
50
51
52 //SetPosition
53 void Body::SetPosition (double x, double y, double z)
54 {
55 dBodySetPosition(this->_id, x, y, z);
56 }
57
58
59 //Overloaded GetPosition
60 Vector3 Body::GetPosition(void)
61 {
62 Vector3 retVal;
63 const dReal *temp;
64 temp = dBodyGetPosition(this->_id);
65 retVal.x = temp[0];
66 retVal.y = temp[1];
67 retVal.z = temp[2];
68 return retVal;
69 };
70
71 void Body::GetPosition(double position __gc[])
72 {
73 const dReal *temp;
74 temp = dBodyGetPosition(this->_id);
75 position[0] = temp[0];
76 position[1] = temp[1];
77 position[2] = temp[2];
78 }
79
80
81 //SetRotationIdentity
82 void Body::SetRotationIdentity(void)
83 {
84 dMatrix3 temp;
85 dRSetIdentity(temp);
86 dBodySetRotation(this->_id, temp);
87 }
88
89
90 //SetRotation (left handed system=>transpose)
91 void Body::SetRotation(Matrix3 rotation)
92 {
93 dMatrix3 temp;
94 temp[0] = rotation.m11;
95 temp[4] = rotation.m12;
96 temp[8] = rotation.m13;
97 temp[1] = rotation.m21;
98 temp[5] = rotation.m22;
99 temp[9] = rotation.m23;
100 temp[2] = rotation.m31;
101 temp[6] = rotation.m32;
102 temp[10] = rotation.m33;
103 dBodySetRotation(this->_id, temp);
104 }
105
106 //GetRotation (left handed system=>transpose)
107 Matrix3 Body::GetRotation(void)
108 {
109 Matrix3 retVal;
110 //const dMatrix3 *m;
111 const dReal *temp;
112 temp = dBodyGetRotation(this->_id);
113 retVal.m11 = temp[0];
114 retVal.m12 = temp[4];
115 retVal.m13 = temp[8];
116 retVal.m21 = temp[1];
117 retVal.m22 = temp[5];
118 retVal.m23 = temp[9];
119 retVal.m31 = temp[2];
120 retVal.m32 = temp[6];
121 retVal.m33 = temp[10];
122 return retVal;
123 }
124
125
126 //Overloaded SetMass
127 void Body::SetMass(double mass, Vector3 centerOfGravity, Matrix3 inertia)
128 {
129 dMass *temp = new dMass();
130 dMassSetParameters(temp, mass,
131 centerOfGravity.x,
132 centerOfGravity.y,
133 centerOfGravity.z,
134 inertia.m11, inertia.m22,
135 inertia.m33, inertia.m12,
136 inertia.m13, inertia.m23);
137
138 dBodySetMass(this->_id, temp);
139 }
140
141
142 //SetMassSphere
143 void Body::SetMassSphere(double density, double radius)
144 {
145 dMass *temp = new dMass();
146 dMassSetSphere(temp, density, radius);
147 dBodySetMass(this->_id, temp);
148 }
149
150
151 //SetMassBox
152 void Body::SetMassBox(double density, double sideX, double sideY, double sideZ)
153 {
154 dMass *temp = new dMass();
155 dMassSetBox(temp, density, sideX, sideY, sideZ);
156 dBodySetMass(this->_id, temp);
157 }
158
159
160 //SetMassCappedCylinder
161 void Body::SetMassCappedCylinder(double density, int axis, double cylinderRadius, double cylinderLength)
162 {
163 dMass *temp = new dMass();
164 dMassSetCappedCylinder(temp, density, axis,
165 cylinderRadius,
166 cylinderLength);
167
168 dBodySetMass(this->_id, temp);
169 }
170
171
172 //AddForce
173 void Body::AddForce(double fX, double fY, double fZ)
174 {
175 dBodyAddForce(this->_id, fX, fY, fZ);
176 }
177
178
179 //AddRelForce
180 void Body::AddRelForce(double fX, double fY, double fZ)
181 {
182 dBodyAddRelForce(this->_id, fX,fY,fZ);
183 }
184
185
186 //AddForceAtPos
187 void Body::AddForceAtPos(double fX, double fY, double fZ, double pX, double pY, double pZ)
188 {
189 dBodyAddForceAtPos(this->_id, fX, fY, fZ, pX, pY, pZ);
190 }
191
192
193 //AddRelForceAtPos
194 void Body::AddRelForceAtPos(double fX, double fY, double fZ, double pX, double pY, double pZ)
195 {
196 dBodyAddRelForceAtPos(this->_id, fX, fY, fZ, pX, pY, pZ);
197 }
198
199
200 //AddRelForceAtRelPos
201 void Body::AddRelForceAtRelPos(double fX, double fY, double fZ, double pX, double pY, double pZ)
202 {
203 dBodyAddRelForceAtRelPos(this->_id, fX, fY, fZ, pX, pY, pZ);
204 }
205
206
207 //ApplyLinearVelocityDrag
208 void Body::ApplyLinearVelocityDrag(double dragCoef)
209 {
210 const dReal *temp;
211 double fX;
212 double fY;
213 double fZ;
214 temp = dBodyGetLinearVel(this->_id);
215 fX = temp[0]*dragCoef*-1;
216 fY = temp[1]*dragCoef*-1;
217 fZ = temp[2]*dragCoef*-1;
218 dBodyAddForce(this->_id, fX, fY, fZ);
219 }
220
221
222 //ApplyAngularVelocityDrag
223 void Body::ApplyAngularVelocityDrag(double dragCoef)
224 {
225 const dReal *temp;
226 double fX;
227 double fY;
228 double fZ;
229 temp = dBodyGetAngularVel(this->_id);
230 fX = temp[0]*dragCoef*-1;
231 fY = temp[1]*dragCoef*-1;
232 fZ = temp[2]*dragCoef*-1;
233 dBodyAddTorque(this->_id, fX, fY, fZ);
234 }
235
236
237 //AddTorque
238 void Body::AddTorque(double fX, double fY, double fZ)
239 {
240 dBodyAddTorque(this->_id, fX, fY, fZ);
241 }
242
243
244 //AddRelTorque
245 void Body::AddRelTorque(double fX, double fY, double fZ)
246 {
247 dBodyAddRelTorque(this->_id, fX,fY,fZ);
248 }
249
250
251 //SetLinearVelocity
252 void Body::SetLinearVelocity(double x, double y, double z)
253 {
254 dBodySetLinearVel(this->_id, x, y, z);
255 }
256
257
258 //GetLinearVelocity
259 Vector3 Body::GetLinearVelocity(void)
260 {
261 Vector3 retVal;
262 const dReal *temp;
263 temp = dBodyGetLinearVel(this->_id);
264 retVal.x = temp[0];
265 retVal.y = temp[1];
266 retVal.z = temp[2];
267 return retVal;
268 }
269
270
271 //SetAngularVelocity
272 void Body::SetAngularVelocity(double x, double y, double z)
273 {
274 dBodySetAngularVel(this->_id, x, y, z);
275 }
276
277 //GetAngularVelocity
278 Vector3 Body::GetAngularVelocity(void)
279 {
280 Vector3 retVal;
281 const dReal *temp;
282 temp = dBodyGetAngularVel(this->_id);
283 retVal.x = temp[0];
284 retVal.y = temp[1];
285 retVal.z = temp[2];
286 return retVal;
287 }
288
289
290 //GetRelPointPos
291 Vector3 Body::GetRelPointPos(double pX, double pY, double pZ)
292 {
293 Vector3 retVal;
294 dVector3 temp;
295 dBodyGetRelPointPos(this->_id, pX, pY, pZ, temp);
296 retVal.x = temp[0];
297 retVal.y = temp[1];
298 retVal.z = temp[2];
299 return retVal;
300 }
301
302
303 //GetRelPointVel
304 Vector3 Body::GetRelPointVel(double pX, double pY, double pZ)
305 {
306 Vector3 retVal;
307 dVector3 temp;
308 dBodyGetRelPointVel(this->_id, pX, pY, pZ, temp);
309 retVal.x = temp[0];
310 retVal.y = temp[1];
311 retVal.z = temp[2];
312 return retVal;
313 }
314
315
316 //ConnectedTo
317 int Body::ConnectedTo(const Body &b)
318 {
319 return dAreConnected(this->_id, b._id);
320 }
321
322}