Geom.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. #include "StdAfx.h"
  2. #include <ode/ode.h>
  3. #include "Geom.h"
  4. namespace ODEManaged
  5. {
  6. //Constructors
  7. Geom::Geom(void)
  8. {
  9. _id = 0;
  10. }
  11. //Destructor
  12. Geom::~Geom(void)
  13. {
  14. dGeomDestroy(this->_id);
  15. }
  16. //Methods
  17. //Id
  18. dGeomID Geom::Id(void)
  19. {
  20. return _id;
  21. }
  22. //GetBody
  23. dBodyID Geom::GetBody(void)
  24. {
  25. return dGeomGetBody(this->_id);
  26. }
  27. //Overloaded SetBody
  28. void Geom::SetBody(Body &body)
  29. {
  30. dGeomSetBody(this->_id, body.Id());
  31. }
  32. //void Geom::SetBody(dBodyID b)
  33. //{
  34. // dGeomSetBody(this->_id, b);
  35. //}
  36. //SetPosition
  37. void Geom::SetPosition(double x, double y, double z)
  38. {
  39. dGeomSetPosition(this->_id, x, y, z);
  40. }
  41. //SetRotation
  42. void Geom::SetRotation(Matrix3 rotation)
  43. {
  44. dMatrix3 temp;
  45. temp[0] = rotation.m11;
  46. temp[4] = rotation.m12;
  47. temp[8] = rotation.m13;
  48. temp[1] = rotation.m21;
  49. temp[5] = rotation.m22;
  50. temp[9] = rotation.m23;
  51. temp[2] = rotation.m31;
  52. temp[6] = rotation.m32;
  53. temp[10] = rotation.m33;
  54. dGeomSetRotation(_id, temp);
  55. }
  56. //Destroy
  57. void Geom::Destroy()
  58. {
  59. if(this->_id) dGeomDestroy(this->_id);
  60. _id = 0;
  61. }
  62. //SetData
  63. void Geom::SetData(void *data)
  64. {
  65. dGeomSetData(this->_id, data);
  66. }
  67. //GetData
  68. void *Geom::GetData(void)
  69. {
  70. return dGeomGetData(this->_id);
  71. }
  72. //GetPosition
  73. Vector3 Geom::GetPosition(void)
  74. {
  75. Vector3 retVal;
  76. const dReal *temp;
  77. temp = dGeomGetPosition(this->_id);
  78. retVal.x = temp[0];
  79. retVal.y = temp[1];
  80. retVal.z = temp[2];
  81. return retVal;
  82. }
  83. //GetRotation (left handed system=>transpose)
  84. Matrix3 Geom::GetRotation(void)
  85. {
  86. Matrix3 retVal;
  87. const dReal *temp;
  88. temp = dGeomGetRotation(this->_id);
  89. retVal.m11 = temp[0];
  90. retVal.m12 = temp[4];
  91. retVal.m13 = temp[8];
  92. retVal.m21 = temp[1];
  93. retVal.m22 = temp[5];
  94. retVal.m23 = temp[9];
  95. retVal.m31 = temp[2];
  96. retVal.m32 = temp[6];
  97. retVal.m33 = temp[10];
  98. return retVal;
  99. }
  100. //CreateSphere
  101. void Geom::CreateSphere(Space &space, double radius)
  102. {
  103. if(this->_id) dGeomDestroy(this->_id);
  104. _id = dCreateSphere(space.Id(), radius);
  105. }
  106. //CreateBox
  107. void Geom::CreateBox(Space &space, double lx, double ly, double lz)
  108. {
  109. if(this->_id) dGeomDestroy(this->_id);
  110. _id = dCreateBox(space.Id(), lx, ly, lz);
  111. }
  112. //CreatePlane
  113. void Geom::CreatePlane(Space &space, double a, double b, double c, double d)
  114. {
  115. if(this->_id) dGeomDestroy(this->_id);
  116. _id = dCreatePlane(space.Id(), a, b, c, d);
  117. }
  118. //CreateCCylinder
  119. void Geom::CreateCCylinder(Space &space, double radius, double length)
  120. {
  121. if(this->_id) dGeomDestroy(this->_id);
  122. _id = dCreateCCylinder(space.Id(), radius, length);
  123. }
  124. //SphereGetRadius
  125. double Geom::SphereGetRadius(void)
  126. {
  127. return dGeomSphereGetRadius(this->_id);
  128. }
  129. //BoxGetLengths
  130. Vector3 Geom::BoxGetLengths(void)
  131. {
  132. Vector3 retVal;
  133. dVector3 temp;
  134. dGeomBoxGetLengths(this->_id, temp);
  135. retVal.x = temp[0];
  136. retVal.y = temp[1];
  137. retVal.z = temp[2];
  138. return retVal;
  139. }
  140. //PlaneGetParams
  141. Vector4 Geom::PlaneGetParams(void)
  142. {
  143. Vector4 retVal;
  144. dVector4 temp;
  145. dGeomPlaneGetParams(this->_id, temp);
  146. retVal.W = temp[0];
  147. retVal.x = temp[1];
  148. retVal.y = temp[2];
  149. retVal.z = temp[3];
  150. return retVal;
  151. }
  152. //CCylinderGetParams
  153. void Geom::CCylinderGetParams(double *radius, double *length)
  154. {
  155. dGeomCCylinderGetParams(this->_id, radius, length);
  156. }
  157. //GetClass
  158. int Geom::GetClass(void)
  159. {
  160. return dGeomGetClass(this->_id);
  161. }
  162. }