Panda3D
 All Classes Functions Variables Enumerations
odeBody.I
1 // Filename: odeBody.I
2 // Created by: joswilso (27Dec06)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 ////////////////////////////////////////////////////////////////////
16 // Function: OdeBody::is_empty
17 // Access: Published
18 // Description: Returns true if the ID is 0, meaning the OdeBody
19 // does not point to a valid body. It is an error to
20 // call a method on an empty body.
21 // Note that an empty OdeBody also evaluates to False.
22 ////////////////////////////////////////////////////////////////////
23 INLINE bool OdeBody::
24 is_empty() const {
25  return (_id == 0);
26 }
27 
28 ////////////////////////////////////////////////////////////////////
29 // Function: OdeBody::get_id
30 // Access: Published
31 // Description: Returns the underlying dBodyID.
32 ////////////////////////////////////////////////////////////////////
33 INLINE dBodyID OdeBody::
34 get_id() const {
35  return _id;
36 }
37 
38 INLINE dReal OdeBody::
39 get_auto_disable_linear_threshold() const {
40  return dBodyGetAutoDisableLinearThreshold(_id);
41 }
42 
43 INLINE void OdeBody::
44 set_auto_disable_linear_threshold(dReal linear_threshold) {
45  dBodySetAutoDisableLinearThreshold(_id, linear_threshold);
46 }
47 
48 INLINE dReal OdeBody::
49 get_auto_disable_angular_threshold() const {
50  return dBodyGetAutoDisableAngularThreshold(_id);
51 }
52 
53 INLINE void OdeBody::
54 set_auto_disable_angular_threshold(dReal angular_threshold) {
55  dBodySetAutoDisableAngularThreshold(_id, angular_threshold);
56 }
57 
58 INLINE int OdeBody::
59 get_auto_disable_steps() const {
60  return dBodyGetAutoDisableSteps(_id);
61 }
62 
63 INLINE void OdeBody::
64 set_auto_disable_steps(int steps) {
65  dBodySetAutoDisableSteps(_id, steps);
66 }
67 
68 INLINE dReal OdeBody::
69 get_auto_disable_time() const {
70  return dBodyGetAutoDisableTime(_id);
71 }
72 
73 INLINE void OdeBody::
74 set_auto_disable_time(dReal time) {
75  dBodySetAutoDisableTime(_id, time);
76 }
77 
78 INLINE int OdeBody::
79 get_auto_disable_flag() const {
80  return dBodyGetAutoDisableFlag(_id);
81 }
82 
83 INLINE void OdeBody::
84 set_auto_disable_flag(int do_auto_disable) {
85  dBodySetAutoDisableFlag(_id, do_auto_disable);
86 }
87 
88 INLINE void OdeBody::
89 set_auto_disable_defaults() {
90  dBodySetAutoDisableDefaults(_id);
91 }
92 
93 INLINE void OdeBody::
94 set_data(void *data) {
95  dBodySetData(_id, data);
96 }
97 
98 #ifdef HAVE_PYTHON
99 INLINE void OdeBody::
100 set_data(PyObject *data) {
101  Py_XDECREF((PyObject*) dBodyGetData(_id));
102  Py_XINCREF(data);
103  dBodySetData(_id, data);
104 }
105 
106 INLINE PyObject* OdeBody::
107 get_data() const {
108  PyObject* data = (PyObject*) dBodyGetData(_id);
109  Py_XINCREF(data);
110  return data;
111 }
112 #else
113 
114 INLINE void* OdeBody::
115 get_data() const {
116  return dBodyGetData(_id);
117 }
118 #endif
119 
120 INLINE void OdeBody::
121 set_position(dReal x, dReal y, dReal z) {
122  dBodySetPosition(_id, x, y, z);
123 }
124 
125 INLINE void OdeBody::
126 set_position(const LVecBase3f &pos) {
127  set_position(pos[0], pos[1], pos[2]);
128 }
129 
130 INLINE void OdeBody::
131 set_rotation(const LMatrix3f &r) {
132  dMatrix3 mat3 = { r(0, 0), r(0, 1), r(0, 2), 0,
133  r(1, 0), r(1, 1), r(1, 2), 0,
134  r(2, 0), r(2, 1), r(2, 2), 0 };
135 
136  dBodySetRotation(_id, mat3);
137 }
138 
139 INLINE void OdeBody::
140 set_quaternion(const LQuaternionf &q) {
141  dQuaternion quat = { q[0], q[1], q[2], q[3] };
142  dBodySetQuaternion(_id, quat);
143 }
144 
145 INLINE void OdeBody::
146 set_linear_vel(dReal x, dReal y, dReal z) {
147  dBodySetLinearVel(_id, x, y, z);
148 }
149 
150 INLINE void OdeBody::
151 set_linear_vel(const LVecBase3f &vel) {
152  set_linear_vel(vel[0], vel[1], vel[2]);
153 }
154 
155 INLINE void OdeBody::
156 set_angular_vel(dReal x, dReal y, dReal z) {
157  dBodySetAngularVel(_id, x, y, z);
158 }
159 
160 INLINE void OdeBody::
161 set_angular_vel(const LVecBase3f &vel) {
162  set_angular_vel(vel[0], vel[1], vel[2]);
163 }
164 
165 INLINE LVecBase3f OdeBody::
166 get_position() const {
167  const dReal *res = dBodyGetPosition(_id);
168  return LVecBase3f(res[0], res[1], res[2]);
169 }
170 
171 INLINE LMatrix3f OdeBody::
172 get_rotation() const {
173  const dReal *rot = dBodyGetRotation(_id);
174  return LMatrix3f(rot[0], rot[1], rot[2],
175  rot[4], rot[5], rot[6],
176  rot[8], rot[9], rot[10]);
177 }
178 
179 INLINE LVecBase4f OdeBody::
180 get_quaternion() const {
181  const dReal *res = dBodyGetQuaternion(_id);
182  return LVecBase4f(res[0], res[1], res[2], res[3]);
183 }
184 
185 INLINE LVecBase3f OdeBody::
186 get_linear_vel() const {
187  const dReal *res = dBodyGetLinearVel(_id);
188  return LVecBase3f(res[0], res[1], res[2]);
189 }
190 
191 INLINE LVecBase3f OdeBody::
192 get_angular_vel() const {
193  const dReal *res = dBodyGetAngularVel(_id);
194  return LVecBase3f(res[0], res[1], res[2]);
195 }
196 
197 INLINE void OdeBody::
198 set_mass(OdeMass &mass) {
199  dBodySetMass(_id, mass.get_mass_ptr());
200 }
201 
202 INLINE OdeMass OdeBody::
203 get_mass() const {
204  OdeMass mass;
205  dBodyGetMass(_id, mass.get_mass_ptr());
206  return mass;
207 }
208 
209 INLINE void OdeBody::
210 add_force(dReal fx, dReal fy, dReal fz) {
211  dBodyAddForce(_id, fx, fy, fz);
212 }
213 
214 INLINE void OdeBody::
215 add_force(const LVecBase3f &f) {
216  add_force(f[0], f[1], f[2]);
217 }
218 
219 INLINE void OdeBody::
220 add_torque(dReal fx, dReal fy, dReal fz) {
221  dBodyAddTorque(_id, fx, fy, fz);
222 }
223 
224 INLINE void OdeBody::
225 add_torque(const LVecBase3f &f) {
226  add_torque(f[0], f[1], f[2]);
227 }
228 
229 INLINE void OdeBody::
230 add_rel_force(dReal fx, dReal fy, dReal fz) {
231  dBodyAddRelForce(_id, fx, fy, fz);
232 }
233 
234 INLINE void OdeBody::
235 add_rel_force(const LVecBase3f &f) {
236  add_rel_force(f[0], f[1], f[2]);
237 }
238 
239 INLINE void OdeBody::
240 add_rel_torque(dReal fx, dReal fy, dReal fz) {
241  dBodyAddRelTorque(_id, fx, fy, fz);
242 }
243 
244 INLINE void OdeBody::
245 add_rel_torque(const LVecBase3f &f) {
246  add_rel_torque(f[0], f[1], f[2]);
247 }
248 
249 INLINE void OdeBody::
250 add_force_at_pos(dReal fx, dReal fy, dReal fz, dReal px, dReal py, dReal pz) {
251  dBodyAddForceAtPos(_id, fx, fy, fz, px, py, pz);
252 }
253 
254 INLINE void OdeBody::
255 add_force_at_pos(const LVecBase3f &f, const LVecBase3f &pos) {
256  add_force_at_pos(f[0], f[1], f[2], pos[0], pos[1], pos[2]);
257 }
258 
259 INLINE void OdeBody::
260 add_force_at_rel_pos(dReal fx, dReal fy, dReal fz, dReal px, dReal py, dReal pz) {
261  dBodyAddForceAtRelPos(_id, fx, fy, fz, px, py, pz);
262 }
263 
264 INLINE void OdeBody::
265 add_force_at_rel_pos(const LVecBase3f &f, const LVecBase3f &pos) {
266  add_force_at_rel_pos(f[0], f[1], f[2], pos[0], pos[1], pos[2]);
267 }
268 
269 INLINE void OdeBody::
270 add_rel_force_at_pos(dReal fx, dReal fy, dReal fz, dReal px, dReal py, dReal pz) {
271  dBodyAddRelForceAtPos(_id, fx, fy, fz, px, py, pz);
272 }
273 
274 INLINE void OdeBody::
275 add_rel_force_at_pos(const LVecBase3f &f, const LVecBase3f &pos) {
276  add_rel_force_at_pos(f[0], f[1], f[2], pos[0], pos[1], pos[2]);
277 }
278 
279 INLINE void OdeBody::
280 add_rel_force_at_rel_pos(dReal fx, dReal fy, dReal fz, dReal px, dReal py, dReal pz) {
281  dBodyAddRelForceAtRelPos(_id, fx, fy, fz, px, py, pz);
282 }
283 
284 INLINE void OdeBody::
285 add_rel_force_at_rel_pos(const LVecBase3f &f, const LVecBase3f &pos) {
286  add_rel_force_at_rel_pos(f[0], f[1], f[2], pos[0], pos[1], pos[2]);
287 }
288 
289 INLINE void OdeBody::
290 set_force(dReal x, dReal y, dReal z) {
291  dBodySetForce(_id, x, y, z);
292 }
293 
294 INLINE void OdeBody::
295 set_force(const LVecBase3f &f) {
296  set_force(f[0], f[1], f[2]);
297 }
298 
299 INLINE void OdeBody::
300 set_torque(dReal x, dReal y, dReal z) {
301  dBodySetTorque(_id, x, y, z);
302 }
303 
304 INLINE void OdeBody::
305 set_torque(const LVecBase3f &f) {
306  set_torque(f[0], f[1], f[2]);
307 }
308 
309 INLINE LPoint3f OdeBody::
310 get_rel_point_pos(dReal px, dReal py, dReal pz) const {
311  dVector3 result;
312  dBodyGetRelPointPos(_id, px, py, pz, result);
313  return LPoint3f(result[0], result[1], result[2]);
314 }
315 
316 INLINE LPoint3f OdeBody::
317 get_rel_point_pos(const LVecBase3f &pos) const {
318  return get_rel_point_pos(pos[0], pos[1], pos[2]);
319 }
320 
321 INLINE LPoint3f OdeBody::
322 get_rel_point_vel(dReal px, dReal py, dReal pz) const {
323  dVector3 result;
324  dBodyGetRelPointVel(_id, px, py, pz, result);
325  return LPoint3f(result[0], result[1], result[2]);
326 }
327 
328 INLINE LPoint3f OdeBody::
329 get_rel_point_vel(const LVecBase3f &pos) const {
330  return get_rel_point_vel(pos[0], pos[1], pos[2]);
331 }
332 
333 INLINE LPoint3f OdeBody::
334 get_point_vel(dReal px, dReal py, dReal pz) const {
335  dVector3 result;
336  dBodyGetPointVel(_id, px, py, pz, result);
337  return LPoint3f(result[0], result[1], result[2]);
338 }
339 
340 INLINE LPoint3f OdeBody::
341 get_point_vel(const LVecBase3f &pos) const {
342  return get_point_vel(pos[0], pos[1], pos[2]);
343 }
344 
345 INLINE LPoint3f OdeBody::
346 get_pos_rel_point(dReal px, dReal py, dReal pz) const {
347  dVector3 result;
348  dBodyGetPosRelPoint(_id, px, py, pz, result);
349  return LPoint3f(result[0], result[1], result[2]);
350 }
351 
352 INLINE LPoint3f OdeBody::
353 get_pos_rel_point(const LVecBase3f &pos) const {
354  return get_pos_rel_point(pos[0], pos[1], pos[2]);
355 }
356 
357 INLINE LVecBase3f OdeBody::
358 vector_to_world(dReal px, dReal py, dReal pz) const {
359  dVector3 result;
360  dBodyVectorToWorld(_id, px, py, pz, result);
361  return LVecBase3f(result[0], result[1], result[2]);
362 }
363 
364 INLINE LVecBase3f OdeBody::
365 vector_to_world(const LVecBase3f &pos) const {
366  return vector_to_world(pos[0], pos[1], pos[2]);
367 }
368 
369 INLINE LVecBase3f OdeBody::
370 vector_from_world(dReal px, dReal py, dReal pz) const {
371  dVector3 result;
372  dBodyVectorFromWorld(_id, px, py, pz, result);
373  return LVecBase3f(result[0], result[1], result[2]);
374 }
375 
376 INLINE LVecBase3f OdeBody::
377 vector_from_world(const LVecBase3f &pos) const {
378  return vector_from_world(pos[0], pos[1], pos[2]);
379 }
380 
381 INLINE void OdeBody::
382 set_finite_rotation_mode(int mode) {
383  dBodySetFiniteRotationMode(_id, mode);
384 }
385 
386 INLINE void OdeBody::
387 set_finite_rotation_axis(dReal x, dReal y, dReal z) {
388  dBodySetFiniteRotationAxis(_id, x, y, z);
389 }
390 
391 INLINE void OdeBody::
392 set_finite_rotation_axis(const LVecBase3f &axis) {
393  set_finite_rotation_axis(axis[0], axis[1], axis[2]);
394 }
395 
396 INLINE int OdeBody::
397 get_finite_rotation_mode() const {
398  return dBodyGetFiniteRotationMode(_id);
399 }
400 
401 INLINE LVecBase3f OdeBody::
402 get_finite_rotation_axis() const {
403  dVector3 result;
404  dBodyGetFiniteRotationAxis(_id, result);
405  return LVecBase3f(result[0], result[1], result[2]);
406 }
407 
408 INLINE int OdeBody::
409 get_num_joints() const {
410  return dBodyGetNumJoints(_id);
411 }
412 
413 INLINE void OdeBody::
414 enable() {
415  dBodyEnable(_id);
416 }
417 
418 INLINE void OdeBody::
419 disable() {
420  dBodyDisable(_id);
421 }
422 
423 INLINE int OdeBody::
424 is_enabled() const {
425  return dBodyIsEnabled(_id);
426 }
427 
428 INLINE void OdeBody::
429 set_gravity_mode(int mode) {
430  dBodySetGravityMode(_id, mode);
431 }
432 
433 INLINE int OdeBody::
434 get_gravity_mode() const {
435  return dBodyGetGravityMode(_id);
436 }
437 
438 INLINE int OdeBody::
439 compare_to(const OdeBody &other) const {
440  if (_id != other._id) {
441  return _id < other._id ? -1 : 1;
442  }
443  return 0;
444 }
This is the base class for all three-component vectors and points.
Definition: lvecBase3.h:105
This is a three-component point in space (as opposed to a three-component vector, which represents a ...
Definition: lpoint3.h:99
dBodyID get_id() const
Returns the underlying dBodyID.
Definition: odeBody.I:34
This is the base class for all three-component vectors and points.
Definition: lvecBase4.h:111
This is the base quaternion class.
Definition: lquaternion.h:96
bool is_empty() const
Returns true if the ID is 0, meaning the OdeBody does not point to a valid body.
Definition: odeBody.I:24
This is a 3-by-3 transform matrix.
Definition: lmatrix.h:110