aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/ode-0.9/contrib/DotNetManaged/Body.cpp
blob: c95ae579096c9477cf2047b7e9337e2350cc7eac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
#include "StdAfx.h"

#include <ode/ode.h>
#include "Body.h"

namespace ODEManaged
{

	//Constructors

		Body::Body(void)
		{
			_id = 0;
		}

		Body::Body(World &world)
		{
			_id = dBodyCreate(world.Id());
		}


	//Destructor

		Body::~Body(void)
		{
			dBodyDestroy(this->_id);
		}


	//Methods

		//Id
		dBodyID Body::Id()
		{
			return _id;
		}


		//SetData
		void Body::SetData(void *data)
		{
			dBodySetData(this->_id, data);
		}

		//GetData
		void *Body::GetData(void)
		{
			return dBodyGetData(this->_id);
		}


		//SetPosition
		void Body::SetPosition (double x, double y, double z)
		{
			dBodySetPosition(this->_id, x, y, z);
		}


	//Overloaded GetPosition
		Vector3 Body::GetPosition(void)
		{
			Vector3 retVal;
			const dReal *temp;
			temp = dBodyGetPosition(this->_id);
			retVal.x = temp[0];
			retVal.y = temp[1];
			retVal.z = temp[2];
			return retVal;
		};

		void Body::GetPosition(double position __gc[])
		{
			const dReal *temp;
			temp = dBodyGetPosition(this->_id);
			position[0] = temp[0];
			position[1] = temp[1];
			position[2] = temp[2];
		}


		//SetRotationIdentity
		void Body::SetRotationIdentity(void)
		{
			dMatrix3 temp;
			dRSetIdentity(temp);
			dBodySetRotation(this->_id, temp);	
		}
	

		//SetRotation (left handed system=>transpose)
		void Body::SetRotation(Matrix3 rotation)
		{
			dMatrix3 temp;
			temp[0] = rotation.m11;  
			temp[4] = rotation.m12;  
			temp[8] = rotation.m13; 
			temp[1] = rotation.m21;
			temp[5] = rotation.m22; 
			temp[9] = rotation.m23; 
			temp[2] = rotation.m31; 
			temp[6] = rotation.m32; 
			temp[10] = rotation.m33; 
			dBodySetRotation(this->_id, temp);
		}

		//GetRotation (left handed system=>transpose)
		Matrix3 Body::GetRotation(void)
		{
			Matrix3 retVal;
			//const dMatrix3 *m;
			const dReal *temp;
			temp = dBodyGetRotation(this->_id);
			retVal.m11 = temp[0];
			retVal.m12 = temp[4];
			retVal.m13 = temp[8];
			retVal.m21 = temp[1];
			retVal.m22 = temp[5];
			retVal.m23 = temp[9];
			retVal.m31 = temp[2];
			retVal.m32 = temp[6];
			retVal.m33 = temp[10];
			return retVal;	
		}


		//Overloaded SetMass
		void Body::SetMass(double mass, Vector3 centerOfGravity, Matrix3 inertia)
		{
			dMass *temp = new dMass();
			dMassSetParameters(temp, mass, 
							   centerOfGravity.x, 
							   centerOfGravity.y, 
							   centerOfGravity.z, 
							   inertia.m11, inertia.m22, 
							   inertia.m33, inertia.m12, 
							   inertia.m13, inertia.m23);

  			dBodySetMass(this->_id, temp);
		}


		//SetMassSphere
		void Body::SetMassSphere(double density, double radius)
		{
			dMass *temp = new dMass();
			dMassSetSphere(temp, density, radius);
			dBodySetMass(this->_id, temp);
		}	


		//SetMassBox
		void Body::SetMassBox(double density, double sideX, double sideY, double sideZ)
		{
			dMass *temp = new dMass();
			dMassSetBox(temp, density, sideX, sideY, sideZ);
			dBodySetMass(this->_id, temp);
		}	


		//SetMassCappedCylinder
		void Body::SetMassCappedCylinder(double density, int axis, double cylinderRadius, double cylinderLength)
		{
			dMass *temp = new dMass();
			dMassSetCappedCylinder(temp, density, axis,
								   cylinderRadius, 
								   cylinderLength);

			dBodySetMass(this->_id, temp);
		}


		//AddForce
		void Body::AddForce(double fX, double fY, double fZ)
		{
			dBodyAddForce(this->_id, fX, fY, fZ);
		}


		//AddRelForce
		void Body::AddRelForce(double fX, double fY, double fZ)
		{
			dBodyAddRelForce(this->_id, fX,fY,fZ);
		}


		//AddForceAtPos
		void Body::AddForceAtPos(double fX, double fY, double fZ, double pX, double pY, double pZ)
		{
			dBodyAddForceAtPos(this->_id, fX, fY, fZ, pX, pY, pZ);
		}


		//AddRelForceAtPos
		void Body::AddRelForceAtPos(double fX, double fY, double fZ, double pX, double pY, double pZ)
		{
			dBodyAddRelForceAtPos(this->_id, fX, fY, fZ, pX, pY, pZ);
		}


		//AddRelForceAtRelPos
		void Body::AddRelForceAtRelPos(double fX, double fY, double fZ, double pX, double pY, double pZ)
		{
			dBodyAddRelForceAtRelPos(this->_id, fX, fY, fZ, pX, pY, pZ);
		}	


		//ApplyLinearVelocityDrag
		void Body::ApplyLinearVelocityDrag(double dragCoef)
		{
			const dReal *temp;
			double fX;
			double fY;
			double fZ;		
			temp = dBodyGetLinearVel(this->_id);			
			fX = temp[0]*dragCoef*-1;
			fY = temp[1]*dragCoef*-1;
			fZ = temp[2]*dragCoef*-1;
			dBodyAddForce(this->_id, fX, fY, fZ);
		}


		//ApplyAngularVelocityDrag
		void Body::ApplyAngularVelocityDrag(double dragCoef)
		{
			const dReal *temp;
			double fX;
			double fY;
			double fZ;
			temp = dBodyGetAngularVel(this->_id);
			fX = temp[0]*dragCoef*-1;
			fY = temp[1]*dragCoef*-1;
			fZ = temp[2]*dragCoef*-1;
			dBodyAddTorque(this->_id, fX, fY, fZ);
		}


		//AddTorque
		void Body::AddTorque(double fX, double fY, double fZ)
		{
			dBodyAddTorque(this->_id, fX, fY, fZ);
		}


		//AddRelTorque
		void Body::AddRelTorque(double fX, double fY, double fZ)
		{
			dBodyAddRelTorque(this->_id, fX,fY,fZ);
		}


		//SetLinearVelocity
		void Body::SetLinearVelocity(double x, double y, double z)
		{
			dBodySetLinearVel(this->_id, x, y, z);
		}


		//GetLinearVelocity
		Vector3 Body::GetLinearVelocity(void)
		{
			Vector3 retVal;
			const dReal *temp;
			temp = dBodyGetLinearVel(this->_id);
			retVal.x = temp[0];
			retVal.y = temp[1];
			retVal.z = temp[2];
			return retVal;
		}


		//SetAngularVelocity
		void Body::SetAngularVelocity(double x, double y, double z)
		{
			dBodySetAngularVel(this->_id, x, y, z);
		}

		//GetAngularVelocity
		Vector3 Body::GetAngularVelocity(void)
		{
			Vector3 retVal;
			const dReal *temp;
			temp = dBodyGetAngularVel(this->_id);
			retVal.x = temp[0];
			retVal.y = temp[1];
			retVal.z = temp[2];
			return retVal;
		}

		
		//GetRelPointPos
		Vector3 Body::GetRelPointPos(double pX, double pY, double pZ)
		{
			Vector3 retVal;
			dVector3 temp;
			dBodyGetRelPointPos(this->_id, pX, pY, pZ, temp);
			retVal.x = temp[0];
			retVal.y = temp[1];
			retVal.z = temp[2];
			return retVal;
		}


		//GetRelPointVel
		Vector3 Body::GetRelPointVel(double pX, double pY, double pZ)
		{
			Vector3 retVal;
			dVector3 temp;
			dBodyGetRelPointVel(this->_id, pX, pY, pZ, temp);
			retVal.x = temp[0];
			retVal.y = temp[1];
			retVal.z = temp[2];
			return retVal;
		}


		//ConnectedTo
		int Body::ConnectedTo(const Body &b)
		{ 
			return dAreConnected(this->_id, b._id);
		}

}