1 /************************************************************************* 2 * D bindings for ODE * 3 * * 4 * C header port by Daniel "q66" Kolesa <quaker66@gmail.com> * 5 * * 6 * Open Dynamics Engine, Copyright (C) 2001-2003 Russell L. Smith. * 7 * All rights reserved. Email: russ@q12.org Web: www.q12.org * 8 * * 9 * This library is free software; you can redistribute it and/or * 10 * modify it under the terms of EITHER: * 11 * (1) The GNU Lesser General Public License as published by the Free * 12 * Software Foundation; either version 2.1 of the License, or (at * 13 * your option) any later version. The text of the GNU Lesser * 14 * General Public License is included with this library in the * 15 * file LICENSE.TXT. * 16 * (2) The BSD-style license that is included with this library in * 17 * the file LICENSE-BSD.TXT. * 18 * * 19 * This library is distributed in the hope that it will be useful, * 20 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files * 22 * LICENSE.TXT and LICENSE-BSD.TXT for more details. * 23 * * 24 *************************************************************************/ 25 26 module deimos.ode.common; 27 28 public import deimos.ode.odeconfig; 29 public import deimos.ode.error; 30 31 private import std.math; 32 33 extern (C): 34 nothrow: 35 36 version(dSINGLE) 37 alias float dReal; 38 else 39 alias double dReal; 40 41 alias PI M_PI; 42 alias SQRT1_2 M_SQRT1_2; 43 44 version (dTRIMESH_16BIT_INDICIES) 45 { 46 version (dTRIMESH_GIMPACT) 47 alias uint32 dTriIndex; 48 else 49 alias uint16 dTriIndex; 50 } 51 else 52 alias uint32 dTriIndex; 53 54 /* round an integer up to a multiple of 4, except that 0 and 1 are unmodified 55 * (used to compute matrix leading dimensions) 56 */ 57 int dPAD(int a) 58 { 59 return (a > 1) ? (((a - 1)|3)+1) : a; 60 } 61 62 /* these types are mainly just used in headers */ 63 alias dReal[4] dVector3; 64 alias dReal[4] dVector4; 65 alias dReal[4*3] dMatrix3; 66 alias dReal[4*4] dMatrix4; 67 alias dReal[8*6] dMatrix6; 68 alias dReal[4] dQuaternion; 69 70 dReal dRecip(dReal x) 71 { 72 return 1.0/x; 73 } 74 75 dReal dRecipSqrt(dReal x) 76 { 77 return 1.0/sqrt(x); 78 } 79 80 dReal dFMod(dReal a, dReal b) 81 { 82 real c; 83 return modf(a, c); 84 } 85 86 alias sqrt dSqrt; 87 alias sin dSin; 88 alias cos dCos; 89 alias fabs dFabs; 90 alias atan2 dAtan2; 91 alias isNaN dIsNan; 92 alias copysign dCopySign; 93 alias floor dFloor; 94 alias ceil dCeil; 95 alias nextafter dNextAfter; 96 97 /* internal object types (all prefixed with `dx') */ 98 99 struct dxWorld; /* dynamics world */ 100 struct dxSpace; /* collision space */ 101 struct dxBody; /* rigid body (dynamics object) */ 102 struct dxGeom; /* geometry (collision object) */ 103 struct dxJoint; 104 struct dxJointNode; 105 struct dxJointGroup; 106 struct dxWorldProcessThreadingManager; 107 108 alias dxWorld* dWorldID; 109 alias dxSpace* dSpaceID; 110 alias dxBody* dBodyID; 111 alias dxGeom* dGeomID; 112 alias dxJoint* dJointID; 113 alias dxJointGroup* dJointGroupID; 114 alias dxWorldProcessThreadingManager* dWorldStepThreadingManagerId; 115 116 /* error numbers */ 117 118 enum 119 { 120 d_ERR_UNKNOWN = 0, /* unknown error */ 121 d_ERR_IASSERT, /* internal assertion failed */ 122 d_ERR_UASSERT, /* user assertion failed */ 123 d_ERR_LCP /* user assertion failed */ 124 } 125 126 127 /* joint type numbers */ 128 129 alias int dJointType; 130 enum 131 { 132 dJointTypeNone = 0, /* or "unknown" */ 133 dJointTypeBall, 134 dJointTypeHinge, 135 dJointTypeSlider, 136 dJointTypeContact, 137 dJointTypeUniversal, 138 dJointTypeHinge2, 139 dJointTypeFixed, 140 dJointTypeNull, 141 dJointTypeAMotor, 142 dJointTypeLMotor, 143 dJointTypePlane2D, 144 dJointTypePR, 145 dJointTypePU, 146 dJointTypePiston, 147 } 148 149 /* an alternative way of setting joint parameters, using joint parameter 150 * structures and member constants. we don't actually do this yet. 151 */ 152 153 /* 154 typedef struct dLimot { 155 int mode; 156 dReal lostop, histop; 157 dReal vel, fmax; 158 dReal fudge_factor; 159 dReal bounce, soft; 160 dReal suspension_erp, suspension_cfm; 161 } dLimot; 162 163 enum { 164 dLimotLoStop = 0x0001, 165 dLimotHiStop = 0x0002, 166 dLimotVel = 0x0004, 167 dLimotFMax = 0x0008, 168 dLimotFudgeFactor = 0x0010, 169 dLimotBounce = 0x0020, 170 dLimotSoft = 0x0040 171 }; 172 */ 173 174 /* standard joint parameter names */ 175 176 enum 177 { 178 /* parameters for limits and motors */ 179 dParamLoStop = 0, 180 dParamHiStop, 181 dParamVel, 182 dParamFMax, 183 dParamFudgeFactor, 184 dParamBounce, 185 dParamCFM, 186 dParamStopERP, 187 dParamStopCFM, 188 /* parameters for suspension */ 189 dParamSuspensionERP, 190 dParamSuspensionCFM, 191 dParamERP, 192 dParamsInGroup, 193 /* parameters for limits and motors */ 194 dParamLoStop1 = 0x000, 195 dParamHiStop1, 196 dParamVel1, 197 dParamFMax1, 198 dParamFudgeFactor1, 199 dParamBounce1, 200 dParamCFM1, 201 dParamStopERP1, 202 dParamStopCFM1, 203 /* parameters for suspension */ 204 dParamSuspensionERP1, 205 dParamSuspensionCFM1, 206 dParamERP1, 207 /* parameters for limits and motors */ 208 dParamLoStop2 = 0x100, 209 dParamHiStop2, 210 dParamVel2, 211 dParamFMax2, 212 dParamFudgeFactor2, 213 dParamBounce2, 214 dParamCFM2, 215 dParamStopERP2, 216 dParamStopCFM2, 217 /* parameters for suspension */ 218 dParamSuspensionERP2, 219 dParamSuspensionCFM2, 220 dParamERP2, 221 /* parameters for limits and motors */ 222 dParamLoStop3 = 0x200, 223 dParamHiStop3, 224 dParamVel3, 225 dParamFMax3, 226 dParamFudgeFactor3, 227 dParamBounce3, 228 dParamCFM3, 229 dParamStopERP3, 230 dParamStopCFM3, 231 /* parameters for suspension */ 232 dParamSuspensionERP3, 233 dParamSuspensionCFM3, 234 dParamERP3, 235 dParamGroup = 0x100 236 } 237 238 /* angular motor mode numbers */ 239 240 enum 241 { 242 dAMotorUser = 0, 243 dAMotorEuler = 1, 244 } 245 246 /* joint force feedback information */ 247 248 struct dJointFeedback 249 { 250 dVector3 f1; /* force applied to body 1 */ 251 dVector3 t1; /* torque applied to body 1 */ 252 dVector3 f2; /* force applied to body 2 */ 253 dVector3 t2; /* torque applied to body 2 */ 254 } 255 256 /* private functions that must be implemented by the collision library: 257 * (1) indicate that a geom has moved, (2) get the next geom in a body list. 258 * these functions are called whenever the position of geoms connected to a 259 * body have changed, e.g. with dBodySetPosition(), dBodySetRotation(), or 260 * when the ODE step function updates the body state. 261 */ 262 263 void dGeomMoved (dGeomID); 264 dGeomID dGeomGetBodyNext (dGeomID); 265 266 /** 267 * dGetConfiguration returns the specific ODE build configuration as 268 * a string of tokens. The string can be parsed in a similar way to 269 * the OpenGL extension mechanism, the naming convention should be 270 * familiar too. The following extensions are reported: 271 * 272 * ODE 273 * ODE_single_precision 274 * ODE_double_precision 275 * ODE_EXT_no_debug 276 * ODE_EXT_trimesh 277 * ODE_EXT_opcode 278 * ODE_EXT_gimpact 279 * ODE_EXT_malloc_not_alloca 280 * ODE_EXT_gyroscopic 281 * ODE_OPC_16bit_indices 282 * ODE_OPC_new_collider 283 */ 284 const(char)* dGetConfiguration(); 285 286 /** 287 * Helper to check for a token in the ODE configuration string. 288 * Caution, this function is case sensitive. 289 * 290 * @param token A configuration token, see dGetConfiguration for details 291 * 292 * @return 1 if exact token is present, 0 if not present 293 */ 294 int dCheckConfiguration(const(char)* token);