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
|
#include "StdAfx.h"
#include <ode/ode.h>
#include "Geom.h"
namespace ODEManaged
{
//Constructors
Geom::Geom(void)
{
_id = 0;
}
//Destructor
Geom::~Geom(void)
{
dGeomDestroy(this->_id);
}
//Methods
//Id
dGeomID Geom::Id(void)
{
return _id;
}
//GetBody
dBodyID Geom::GetBody(void)
{
return dGeomGetBody(this->_id);
}
//Overloaded SetBody
void Geom::SetBody(Body &body)
{
dGeomSetBody(this->_id, body.Id());
}
//void Geom::SetBody(dBodyID b)
//{
// dGeomSetBody(this->_id, b);
//}
//SetPosition
void Geom::SetPosition(double x, double y, double z)
{
dGeomSetPosition(this->_id, x, y, z);
}
//SetRotation
void Geom::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;
dGeomSetRotation(_id, temp);
}
//Destroy
void Geom::Destroy()
{
if(this->_id) dGeomDestroy(this->_id);
_id = 0;
}
//SetData
void Geom::SetData(void *data)
{
dGeomSetData(this->_id, data);
}
//GetData
void *Geom::GetData(void)
{
return dGeomGetData(this->_id);
}
//GetPosition
Vector3 Geom::GetPosition(void)
{
Vector3 retVal;
const dReal *temp;
temp = dGeomGetPosition(this->_id);
retVal.x = temp[0];
retVal.y = temp[1];
retVal.z = temp[2];
return retVal;
}
//GetRotation (left handed system=>transpose)
Matrix3 Geom::GetRotation(void)
{
Matrix3 retVal;
const dReal *temp;
temp = dGeomGetRotation(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;
}
//CreateSphere
void Geom::CreateSphere(Space &space, double radius)
{
if(this->_id) dGeomDestroy(this->_id);
_id = dCreateSphere(space.Id(), radius);
}
//CreateBox
void Geom::CreateBox(Space &space, double lx, double ly, double lz)
{
if(this->_id) dGeomDestroy(this->_id);
_id = dCreateBox(space.Id(), lx, ly, lz);
}
//CreatePlane
void Geom::CreatePlane(Space &space, double a, double b, double c, double d)
{
if(this->_id) dGeomDestroy(this->_id);
_id = dCreatePlane(space.Id(), a, b, c, d);
}
//CreateCCylinder
void Geom::CreateCCylinder(Space &space, double radius, double length)
{
if(this->_id) dGeomDestroy(this->_id);
_id = dCreateCCylinder(space.Id(), radius, length);
}
//SphereGetRadius
double Geom::SphereGetRadius(void)
{
return dGeomSphereGetRadius(this->_id);
}
//BoxGetLengths
Vector3 Geom::BoxGetLengths(void)
{
Vector3 retVal;
dVector3 temp;
dGeomBoxGetLengths(this->_id, temp);
retVal.x = temp[0];
retVal.y = temp[1];
retVal.z = temp[2];
return retVal;
}
//PlaneGetParams
Vector4 Geom::PlaneGetParams(void)
{
Vector4 retVal;
dVector4 temp;
dGeomPlaneGetParams(this->_id, temp);
retVal.W = temp[0];
retVal.x = temp[1];
retVal.y = temp[2];
retVal.z = temp[3];
return retVal;
}
//CCylinderGetParams
void Geom::CCylinderGetParams(double *radius, double *length)
{
dGeomCCylinderGetParams(this->_id, radius, length);
}
//GetClass
int Geom::GetClass(void)
{
return dGeomGetClass(this->_id);
}
}
|