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