1 /* Copyright (c) <2003-2016> <Julio Jerez, Newton Game Dynamics> 2 * 3 * This software is provided 'as-is', without any express or implied 4 * warranty. In no event will the authors be held liable for any damages 5 * arising from the use of this software. 6 * 7 * Permission is granted to anyone to use this software for any purpose, 8 * including commercial applications, and to alter it and redistribute it 9 * freely, subject to the following restrictions: 10 * 11 * 1. The origin of this software must not be misrepresented; you must not 12 * claim that you wrote the original software. If you use this software 13 * in a product, an acknowledgment in the product documentation would be 14 * appreciated but is not required. 15 * 16 * 2. Altered source versions must be plainly marked as such, and must not be 17 * misrepresented as being the original software. 18 * 19 * 3. This notice may not be removed or altered from any source distribution. 20 */ 21 module newton.types; 22 23 extern(C): 24 25 alias dLong = long; 26 alias dFloat32 = float; 27 alias dFloat64 = double; 28 version(_NEWTON_USE_DOUBLE)alias dFloat = double; 29 else alias dFloat = float; 30 31 enum NEWTON_MAJOR_VERSION = 3; 32 enum NEWTON_MINOR_VERSION = 14; 33 34 enum NEWTON_BROADPHASE_DEFAULT = 0; 35 enum NEWTON_BROADPHASE_PERSINTENT = 1; 36 37 enum NEWTON_DYNAMIC_BODY = 0; 38 enum NEWTON_KINEMATIC_BODY = 1; 39 enum NEWTON_DYNAMIC_ASYMETRIC_BODY = 2; 40 // #define NEWTON_DEFORMABLE_BODY 2 41 42 enum SERIALIZE_ID_SPHERE = 0; 43 enum SERIALIZE_ID_CAPSULE = 1; 44 enum SERIALIZE_ID_CYLINDER = 2; 45 enum SERIALIZE_ID_CHAMFERCYLINDER = 3; 46 enum SERIALIZE_ID_BOX = 4; 47 enum SERIALIZE_ID_CONE = 5; 48 enum SERIALIZE_ID_CONVEXHULL = 6; 49 enum SERIALIZE_ID_NULL = 7; 50 enum SERIALIZE_ID_COMPOUND = 8; 51 enum SERIALIZE_ID_TREE = 9; 52 enum SERIALIZE_ID_HEIGHTFIELD = 10; 53 enum SERIALIZE_ID_CLOTH_PATCH = 11; 54 enum SERIALIZE_ID_DEFORMABLE_SOLID = 12; 55 enum SERIALIZE_ID_USERMESH = 13; 56 enum SERIALIZE_ID_SCENE = 14; 57 enum SERIALIZE_ID_FRACTURED_COMPOUND = 15; 58 59 struct NewtonMesh{} 60 struct NewtonBody{} 61 struct NewtonWorld{} 62 struct NewtonJoint{} 63 struct NewtonMaterial{} 64 struct NewtonCollision{} 65 struct NewtonInverseDynamics{} 66 struct NewtonDeformableMeshSegment{} 67 struct NewtonInverseDynamicsEffector{} 68 struct NewtonFracturedCompoundMeshPart{} 69 70 struct NewtonCollisionMaterial 71 { 72 void* m_userData; 73 int m_userId; 74 int m_userFlags; 75 dFloat[8] m_userParam; 76 } 77 78 struct NewtonBoxParam 79 { 80 dFloat m_x; 81 dFloat m_y; 82 dFloat m_z; 83 } 84 85 struct NewtonSphereParam 86 { 87 dFloat m_radio; 88 } 89 90 struct NewtonCapsuleParam 91 { 92 dFloat m_radio0; 93 dFloat m_radio1; 94 dFloat m_height; 95 } 96 97 struct NewtonCylinderParam 98 { 99 dFloat m_radio0; 100 dFloat m_radio1; 101 dFloat m_height; 102 } 103 104 struct NewtonConeParam 105 { 106 dFloat m_radio; 107 dFloat m_height; 108 } 109 110 struct NewtonChamferCylinderParam 111 { 112 dFloat m_radio; 113 dFloat m_height; 114 } 115 116 struct NewtonConvexHullParam 117 { 118 int m_vertexCount; 119 int m_vertexStrideInBytes; 120 int m_faceCount; 121 dFloat* m_vertex; 122 } 123 124 struct NewtonCompoundCollisionParam 125 { 126 int m_chidrenCount; 127 } 128 129 struct NewtonCollisionTreeParam 130 { 131 int m_vertexCount; 132 int m_indexCount; 133 } 134 135 struct NewtonDeformableMeshParam 136 { 137 int m_vertexCount; 138 int m_triangleCount; 139 int m_vrtexStrideInBytes; 140 ushort* m_indexList; 141 dFloat* m_vertexList; 142 } 143 144 struct NewtonHeightFieldCollisionParam 145 { 146 int m_width; 147 int m_height; 148 int m_gridsDiagonals; 149 int m_elevationDataType; // 0 = 32 bit floats, 1 = unsigned 16 bit integers 150 dFloat m_verticalScale; 151 dFloat m_horizonalScale_x; 152 dFloat m_horizonalScale_z; 153 dFloat m_horizonalDisplacementScale_x; 154 dFloat m_horizonalDisplacementScale_z; 155 void* m_vertialElevation; 156 short* m_horizotalDisplacement; 157 char* m_atributes; 158 } 159 160 struct NewtonSceneCollisionParam 161 { 162 int m_childrenProxyCount; 163 } 164 165 struct NewtonCollisionInfoRecord 166 { 167 dFloat[4][4] m_offsetMatrix; 168 NewtonCollisionMaterial m_collisionMaterial; 169 int m_collisionType; // tag id to identify the collision primitive 170 171 union 172 { 173 NewtonBoxParam m_box; 174 NewtonConeParam m_cone; 175 NewtonSphereParam m_sphere; 176 NewtonCapsuleParam m_capsule; 177 NewtonCylinderParam m_cylinder; 178 NewtonChamferCylinderParam m_chamferCylinder; 179 NewtonConvexHullParam m_convexHull; 180 NewtonDeformableMeshParam m_deformableMesh; 181 NewtonCompoundCollisionParam m_compoundCollision; 182 NewtonCollisionTreeParam m_collisionTree; 183 NewtonHeightFieldCollisionParam m_heightField; 184 NewtonSceneCollisionParam m_sceneCollision; 185 dFloat[64] m_paramArray; // user define collision can use this to store information 186 } 187 } 188 189 struct NewtonJointRecord 190 { 191 dFloat[4][4] m_attachmenMatrix_0; 192 dFloat[4][4] m_attachmenMatrix_1; 193 dFloat[3] m_minLinearDof; 194 dFloat[3] m_maxLinearDof; 195 dFloat[3] m_minAngularDof; 196 dFloat[3] m_maxAngularDof; 197 const(NewtonBody)* m_attachBody_0; 198 const(NewtonBody)* m_attachBody_1; 199 dFloat[64] m_extraParameters; 200 int m_bodiesCollisionOn; 201 char[128] m_descriptionType; 202 } 203 204 struct NewtonUserMeshCollisionCollideDesc 205 { 206 dFloat[4] m_boxP0; // lower bounding box of intersection query in local space 207 dFloat[4] m_boxP1; // upper bounding box of intersection query in local space 208 dFloat[4] m_boxDistanceTravel; // max distance that box bpxP0 and boxP1 can travel on this timestep, used this for continue collision mode. 209 int m_threadNumber; // current thread executing this query 210 int m_faceCount; // the application should set here how many polygons intersect the query box 211 int m_vertexStrideInBytes; // the application should set here the size of each vertex 212 dFloat m_skinThickness; // this is the minimum skin separation specified by the material between these two colliding shapes 213 void* m_userData; // user data passed to the collision geometry at creation time 214 215 NewtonBody* m_objBody; // pointer to the colliding body 216 NewtonBody* m_polySoupBody; // pointer to the rigid body owner of this collision tree 217 NewtonCollision* m_objCollision; // collision shape of the colliding body, (no necessarily the collision of m_objBody) 218 NewtonCollision* m_polySoupCollision; // collision shape of the collision tree, (no necessarily the collision of m_polySoupBody) 219 220 dFloat* m_vertex; // the application should set here the pointer to the global vertex of the mesh. 221 int* m_faceIndexCount; // the application should set here the pointer to the vertex count of each face. 222 int* m_faceVertexIndex; // the application should set here the pointer index array for each vertex on a face. 223 // the format of a face is I0, I1, I2, I3, ..., M, N, E0, E1, E2, ..., A 224 // I0, I1, I2, .. are the indices to the vertex, relative to m_vertex pointer 225 // M is the index to the material sub shape id 226 // N in the index to the vertex normal relative to m_vertex pointer 227 // E0, E1, E2, ... are the indices of the the face normal that is shared to that face edge, when the edge does not share a face normal then the edge index is set to index N, which the index to the face normal 228 // A is and estimate of the largest diagonal of the face, this used internally as a hint to improve floating point accuracy and algorithm performance. 229 } 230 231 struct NewtonWorldConvexCastReturnInfo 232 { 233 dFloat[4] m_point; // collision point in global space 234 dFloat[4] m_normal; // surface normal at collision point in global space 235 //dFloat m_normalOnHitPoint[4]; // surface normal at the surface of the hit body, 236 // is the same as the normal calculated by a ray cast hitting the body at the hit point 237 dLong m_contactID; // collision ID at contact point 238 const(NewtonBody)* m_hitBody; // body hit at contact point 239 dFloat m_penetration; // contact penetration at collision point 240 } 241 242 struct NewtonUserMeshCollisionRayHitDesc 243 { 244 dFloat[4] m_p0; // ray origin in collision local space 245 dFloat[4] m_p1; // ray destination in collision local space 246 dFloat[4] m_normalOut; // copy here the normal at the ray intersection 247 dLong m_userIdOut; // copy here a user defined id for further feedback 248 void* m_userData; // user data passed to the collision geometry at creation time 249 } 250 251 struct NewtonHingeSliderUpdateDesc 252 { 253 dFloat m_accel; 254 dFloat m_minFriction; 255 dFloat m_maxFriction; 256 dFloat m_timestep; 257 } 258 259 struct NewtonUserContactPoint 260 { 261 dFloat[4] m_point; 262 dFloat[4] m_normal; 263 long m_shapeId0; 264 long m_shapeId1; 265 dFloat m_penetration; 266 int[3] m_unused; 267 } 268 269 struct NewtonImmediateModeConstraint 270 { 271 dFloat[8][6] m_jacobian01; 272 dFloat[8][6] m_jacobian10; 273 dFloat[8] m_minFriction; 274 dFloat[8] m_maxFriction; 275 dFloat[8] m_jointAccel; 276 dFloat[8] m_jointStiffness; 277 } 278 279 // data structure for interfacing with NewtonMesh 280 struct NewtonMeshDoubleData 281 { 282 dFloat64* m_data; 283 int* m_indexList; 284 int m_strideInBytes; 285 } 286 287 struct NewtonMeshFloatData 288 { 289 dFloat* m_data; 290 int* m_indexList; 291 int m_strideInBytes; 292 } 293 294 struct NewtonMeshVertexFormat 295 { 296 int m_faceCount; 297 int* m_faceIndexCount; 298 int* m_faceMaterial; 299 NewtonMeshDoubleData m_vertex; 300 NewtonMeshFloatData m_normal; 301 NewtonMeshFloatData m_binormal; 302 NewtonMeshFloatData m_uv0; 303 NewtonMeshFloatData m_uv1; 304 NewtonMeshFloatData m_vertexColor; 305 } 306 307 // Newton callback functions 308 alias NewtonAllocMemory = void* function (int sizeInBytes); 309 alias NewtonFreeMemory = void function (void* ptr, int sizeInBytes); 310 311 alias NewtonWorldDestructorCallback = void function (const NewtonWorld* world); 312 alias NewtonPostUpdateCallback = void function (const NewtonWorld* world, dFloat timestep); 313 314 alias NewtonCreateContactCallback = void function (const NewtonWorld* newtonWorld, NewtonJoint* contact); 315 alias NewtonDestroyContactCallback = void function (const NewtonWorld* newtonWorld, NewtonJoint* contact); 316 317 alias NewtonWorldListenerDebugCallback = void function (const NewtonWorld* world, void* listener, void* debugContext); 318 alias NewtonWorldListenerBodyDestroyCallback = void function (const NewtonWorld* world, void* listenerUserData, NewtonBody* body_); 319 alias NewtonWorldUpdateListenerCallback = void function (const NewtonWorld* world, void* listenerUserData, dFloat timestep); 320 alias NewtonWorldDestroyListenerCallback = void function (const NewtonWorld* world, void* listenerUserData); 321 322 alias NewtonGetTimeInMicrosencondsCallback = dLong function (); 323 324 alias NewtonSerializeCallback = void function (void* serializeHandle, const void* buffer, int size); 325 alias NewtonDeserializeCallback = void function (void* serializeHandle, void* buffer, int size); 326 327 alias NewtonOnBodySerializationCallback = void function (NewtonBody* body_, void* userData, NewtonSerializeCallback function_, void* serializeHandle); 328 alias NewtonOnBodyDeserializationCallback = void function (NewtonBody* body_, void* userData, NewtonDeserializeCallback function_, void* serializeHandle); 329 330 alias NewtonOnJointSerializationCallback = void function (const NewtonJoint* joint, NewtonSerializeCallback function_, void* serializeHandle); 331 alias NewtonOnJointDeserializationCallback = void function (NewtonBody* body0, NewtonBody* body1, NewtonDeserializeCallback function_, void* serializeHandle); 332 333 alias NewtonOnUserCollisionSerializationCallback = void function (void* userData, NewtonSerializeCallback function_, void* serializeHandle); 334 335 // user collision callbacks 336 alias NewtonUserMeshCollisionDestroyCallback = void function (void* userData); 337 alias NewtonUserMeshCollisionRayHitCallback = dFloat function (NewtonUserMeshCollisionRayHitDesc* lineDescData); 338 alias NewtonUserMeshCollisionGetCollisionInfo = void function (void* userData, NewtonCollisionInfoRecord* infoRecord); 339 alias NewtonUserMeshCollisionAABBTest = int function (void* userData, const dFloat* boxP0, const dFloat* boxP1); 340 alias NewtonUserMeshCollisionGetFacesInAABB = int function ( 341 void* userData, 342 const dFloat* p0, 343 const dFloat* p1, 344 const dFloat** vertexArray, 345 int* vertexCount, 346 int* vertexStrideInBytes, 347 const int* indexList, 348 int maxIndexCount, 349 const int* userDataList); 350 alias NewtonUserMeshCollisionCollideCallback = void function (NewtonUserMeshCollisionCollideDesc* collideDescData, const void* continueCollisionHandle); 351 352 alias NewtonTreeCollisionFaceCallback = int function (void* context, const dFloat* polygon, int strideInBytes, const int* indexArray, int indexCount); 353 354 alias NewtonCollisionTreeRayCastCallback = dFloat function (const NewtonBody* body_, const NewtonCollision* treeCollision, dFloat intersection, dFloat* normal, int faceId, void* usedData); 355 alias NewtonHeightFieldRayCastCallback = dFloat function (const NewtonBody* body_, const NewtonCollision* heightFieldCollision, dFloat intersection, int row, int col, dFloat* normal, int faceId, void* usedData); 356 357 alias NewtonCollisionCopyConstructionCallback = void function (const NewtonWorld* newtonWorld, NewtonCollision* collision, const NewtonCollision* sourceCollision); 358 alias NewtonCollisionDestructorCallback = void function (const NewtonWorld* newtonWorld, const NewtonCollision* collision); 359 360 // collision tree call back (obsoleted no recommended) 361 alias NewtonTreeCollisionCallback = void function ( 362 const NewtonBody* bodyWithTreeCollision, 363 const NewtonBody* body_, 364 int faceID, 365 int vertexCount, 366 const dFloat* vertex, 367 int vertexStrideInBytes); 368 369 alias NewtonBodyDestructor = void function (const NewtonBody* body_); 370 alias NewtonApplyForceAndTorque = void function (const NewtonBody* body_, dFloat timestep, int threadIndex); 371 alias NewtonSetTransform = void function (const NewtonBody* body_, const dFloat* matrix, int threadIndex); 372 373 alias NewtonIslandUpdate = int function (const NewtonWorld* newtonWorld, const(void)* islandHandle, int bodyCount); 374 375 alias NewtonFractureCompoundCollisionOnEmitCompoundFractured = void function (NewtonBody* fracturedBody); 376 alias NewtonFractureCompoundCollisionOnEmitChunk = void function (NewtonBody* chunkBody, NewtonFracturedCompoundMeshPart* fracturexChunkMesh, const NewtonCollision* fracturedCompountCollision); 377 alias NewtonFractureCompoundCollisionReconstructMainMeshCallBack = void function (NewtonBody* body_, NewtonFracturedCompoundMeshPart* mainMesh, const NewtonCollision* fracturedCompountCollision); 378 379 alias NewtonWorldRayPrefilterCallback = uint function (const NewtonBody* body_, const NewtonCollision* collision, void* userData); 380 alias NewtonWorldRayFilterCallback = dFloat function (const NewtonBody* body_, const NewtonCollision* shapeHit, const dFloat* hitContact, const dFloat* hitNormal, long collisionID, void* userData, dFloat intersectParam); 381 382 alias NewtonOnAABBOverlap = int function (const NewtonJoint* contact, dFloat timestep, int threadIndex); 383 alias NewtonContactsProcess = void function (const NewtonJoint* contact, dFloat timestep, int threadIndex); 384 // typedef int (*NewtonOnAABBOverlap) (const NewtonMaterial* const material, const NewtonBody* const body0, const NewtonBody* const body1, int threadIndex); 385 // typedef int (*NewtonOnCompoundSubCollisionAABBOverlap) (const NewtonMaterial* const material, const NewtonBody* const body0, const void* const collisionNode0, const NewtonBody* const body1, const void* const collisionNode1, int threadIndex); 386 alias NewtonOnCompoundSubCollisionAABBOverlap = int function (const NewtonJoint* contact, dFloat timestep, const NewtonBody* body0, const void* collisionNode0, const NewtonBody* body1, const void* collisionNode1, int threadIndex); 387 alias NewtonOnContactGeneration = int function (const NewtonMaterial* material, const NewtonBody* body0, const NewtonCollision* collision0, const NewtonBody* body1, const NewtonCollision* collision1, NewtonUserContactPoint* contactBuffer, int maxCount, int threadIndex); 388 389 alias NewtonBodyIterator = int function (const NewtonBody* body_, void* userData); 390 alias NewtonJointIterator = void function (const NewtonJoint* joint, void* userData); 391 alias NewtonCollisionIterator = void function (void* userData, int vertexCount, const dFloat* faceArray, int faceId); 392 393 alias NewtonBallCallback = void function (const NewtonJoint* ball, dFloat timestep); 394 alias NewtonHingeCallback = uint function (const NewtonJoint* hinge, NewtonHingeSliderUpdateDesc* desc); 395 alias NewtonSliderCallback = uint function (const NewtonJoint* slider, NewtonHingeSliderUpdateDesc* desc); 396 alias NewtonUniversalCallback = uint function (const NewtonJoint* universal, NewtonHingeSliderUpdateDesc* desc); 397 alias NewtonCorkscrewCallback = uint function (const NewtonJoint* corkscrew, NewtonHingeSliderUpdateDesc* desc); 398 399 alias NewtonUserBilateralCallback = void function (const NewtonJoint* userJoint, dFloat timestep, int threadIndex); 400 alias NewtonUserBilateralGetInfoCallback = void function (const NewtonJoint* userJoint, NewtonJointRecord* info); 401 402 alias NewtonConstraintDestructor = void function (const NewtonJoint* me); 403 404 alias NewtonJobTask = void function (NewtonWorld* world, void* userData, int threadIndex); 405 alias NewtonReportProgress = int function (dFloat normalizedProgressPercent, void* userData); 406