objects.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /*************************************************************************
  2. * *
  3. * Open Dynamics Engine, Copyright (C) 2001,2002 Russell L. Smith. *
  4. * All rights reserved. Email: [email protected] Web: www.q12.org *
  5. * *
  6. * This library is free software; you can redistribute it and/or *
  7. * modify it under the terms of EITHER: *
  8. * (1) The GNU Lesser General Public License as published by the Free *
  9. * Software Foundation; either version 2.1 of the License, or (at *
  10. * your option) any later version. The text of the GNU Lesser *
  11. * General Public License is included with this library in the *
  12. * file LICENSE.TXT. *
  13. * (2) The BSD-style license that is included with this library in *
  14. * the file LICENSE-BSD.TXT. *
  15. * *
  16. * This library is distributed in the hope that it will be useful, *
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files *
  19. * LICENSE.TXT and LICENSE-BSD.TXT for more details. *
  20. * *
  21. *************************************************************************/
  22. // object, body, and world structs.
  23. #ifndef _ODE_OBJECT_H_
  24. #define _ODE_OBJECT_H_
  25. #include <ode/common.h>
  26. #include <ode/memory.h>
  27. #include <ode/mass.h>
  28. #include "array.h"
  29. // some body flags
  30. enum {
  31. dxBodyFlagFiniteRotation = 1, // use finite rotations
  32. dxBodyFlagFiniteRotationAxis = 2, // use finite rotations only along axis
  33. dxBodyDisabled = 4, // body is disabled
  34. dxBodyNoGravity = 8, // body is not influenced by gravity
  35. dxBodyAutoDisable = 16, // enable auto-disable on body
  36. dxBodyLinearDamping = 32, // using linear damping
  37. dxBodyAngularDamping = 64, // using angular damping
  38. dxBodyMaxAngularSpeed = 128, // using maximum angular speed
  39. };
  40. // base class that does correct object allocation / deallocation
  41. struct dBase {
  42. void *operator new (size_t size) { return dAlloc (size); }
  43. void *operator new (size_t size, void *p) { return p; }
  44. void operator delete (void *ptr, size_t size) { dFree (ptr,size); }
  45. void *operator new[] (size_t size) { return dAlloc (size); }
  46. void operator delete[] (void *ptr, size_t size) { dFree (ptr,size); }
  47. };
  48. // base class for bodies and joints
  49. struct dObject : public dBase {
  50. dxWorld *world; // world this object is in
  51. dObject *next; // next object of this type in list
  52. dObject **tome; // pointer to previous object's next ptr
  53. int tag; // used by dynamics algorithms
  54. void *userdata; // user settable data
  55. dObject(dxWorld *w);
  56. virtual ~dObject() { }
  57. };
  58. // auto disable parameters
  59. struct dxAutoDisable {
  60. dReal idle_time; // time the body needs to be idle to auto-disable it
  61. int idle_steps; // steps the body needs to be idle to auto-disable it
  62. dReal linear_average_threshold; // linear (squared) average velocity threshold
  63. dReal angular_average_threshold; // angular (squared) average velocity threshold
  64. unsigned int average_samples; // size of the average_lvel and average_avel buffers
  65. };
  66. // damping parameters
  67. struct dxDampingParameters {
  68. dReal linear_scale; // multiply the linear velocity by (1 - scale)
  69. dReal angular_scale; // multiply the angular velocity by (1 - scale)
  70. dReal linear_threshold; // linear (squared) average speed threshold
  71. dReal angular_threshold; // angular (squared) average speed threshold
  72. };
  73. // quick-step parameters
  74. struct dxQuickStepParameters {
  75. int num_iterations; // number of SOR iterations to perform
  76. dReal w; // the SOR over-relaxation parameter
  77. };
  78. // contact generation parameters
  79. struct dxContactParameters {
  80. dReal max_vel; // maximum correcting velocity
  81. dReal min_depth; // thickness of 'surface layer'
  82. };
  83. // position vector and rotation matrix for geometry objects that are not
  84. // connected to bodies.
  85. struct dxPosR {
  86. dVector3 pos;
  87. dMatrix3 R;
  88. };
  89. struct dxBody : public dObject {
  90. dxJointNode *firstjoint; // list of attached joints
  91. int flags; // some dxBodyFlagXXX flags
  92. dGeomID geom; // first collision geom associated with body
  93. dMass mass; // mass parameters about POR
  94. dMatrix3 invI; // inverse of mass.I
  95. dReal invMass; // 1 / mass.mass
  96. dxPosR posr; // position and orientation of point of reference
  97. dQuaternion q; // orientation quaternion
  98. dVector3 lvel,avel; // linear and angular velocity of POR
  99. dVector3 facc,tacc; // force and torque accumulators
  100. dVector3 finite_rot_axis; // finite rotation axis, unit length or 0=none
  101. // auto-disable information
  102. dxAutoDisable adis; // auto-disable parameters
  103. dReal adis_timeleft; // time left to be idle
  104. int adis_stepsleft; // steps left to be idle
  105. dVector3* average_lvel_buffer; // buffer for the linear average velocity calculation
  106. dVector3* average_avel_buffer; // buffer for the angular average velocity calculation
  107. unsigned int average_counter; // counter/index to fill the average-buffers
  108. int average_ready; // indicates ( with = 1 ), if the Body's buffers are ready for average-calculations
  109. void (*moved_callback)(dxBody*); // let the user know the body moved
  110. dxDampingParameters dampingp; // damping parameters, depends on flags
  111. dReal max_angular_speed; // limit the angular velocity to this magnitude
  112. dxBody(dxWorld *w);
  113. };
  114. struct dxWorld : public dBase {
  115. dxBody *firstbody; // body linked list
  116. dxJoint *firstjoint; // joint linked list
  117. int nb,nj; // number of bodies and joints in lists
  118. dVector3 gravity; // gravity vector (m/s/s)
  119. dReal global_erp; // global error reduction parameter
  120. dReal global_cfm; // global costraint force mixing parameter
  121. dxAutoDisable adis; // auto-disable parameters
  122. int body_flags; // flags for new bodies
  123. dxQuickStepParameters qs;
  124. dxContactParameters contactp;
  125. dxDampingParameters dampingp; // damping parameters
  126. dReal max_angular_speed; // limit the angular velocity to this magnitude
  127. };
  128. #endif