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