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 NewtonDeformableMeshSegment {}
75 struct NewtonFracturedCompoundMeshPart {}
76 
77 union NewtonMaterialData
78 {
79     void* m_ptr;
80     dLong m_int;
81     dFloat m_float;
82 }
83 
84 struct NewtonCollisionMaterial
85 {
86     dLong m_userId;
87     NewtonMaterialData m_userData;
88     NewtonMaterialData[6] m_userParam;
89 }
90 
91 struct NewtonBoxParam
92 {
93     dFloat m_x;
94     dFloat m_y;
95     dFloat m_z;
96 }
97 
98 struct NewtonSphereParam
99 {
100     dFloat m_radio;
101 }
102 
103 struct NewtonCapsuleParam
104 {
105     dFloat m_radio0;
106     dFloat m_radio1;
107     dFloat m_height;
108 }
109 
110 struct NewtonCylinderParam
111 {
112     dFloat m_radio0;
113     dFloat m_radio1;
114     dFloat m_height;
115 }
116 
117 struct NewtonConeParam
118 {
119     dFloat m_radio;
120     dFloat m_height;
121 }
122 
123 struct NewtonChamferCylinderParam
124 {
125     dFloat m_radio;
126     dFloat m_height;
127 }
128 
129 struct NewtonConvexHullParam
130 {
131     int m_vertexCount;
132     int m_vertexStrideInBytes;
133     int m_faceCount;
134     dFloat* m_vertex;
135 }
136 
137 struct NewtonCompoundCollisionParam
138 {
139     int m_chidrenCount;
140 }
141 
142 struct NewtonCollisionTreeParam
143 {
144     int m_vertexCount;
145     int m_indexCount;
146 }
147 
148 struct NewtonDeformableMeshParam
149 {
150     int m_vertexCount;
151     int m_triangleCount;
152     int m_vrtexStrideInBytes;
153     ushort* m_indexList;
154     dFloat* m_vertexList;
155 }
156 
157 struct NewtonHeightFieldCollisionParam
158 {
159     int m_width;
160     int m_height;
161     int m_gridsDiagonals;
162     int m_elevationDataType; // 0 = 32 bit floats, 1 = unsigned 16 bit integers
163     dFloat m_verticalScale;
164     dFloat m_horizonalScale_x;
165     dFloat m_horizonalScale_z;
166     void* m_vertialElevation;
167     char* m_atributes;
168 }
169 
170 struct NewtonSceneCollisionParam
171 {
172     int m_childrenProxyCount;
173 }
174 
175 struct NewtonCollisionInfoRecord
176 {
177     dFloat[4][4] m_offsetMatrix;
178     NewtonCollisionMaterial m_collisionMaterial;
179     int m_collisionType; // tag id to identify the collision primitive
180 
181     union
182     {
183         NewtonBoxParam m_box;
184         NewtonConeParam m_cone;
185         NewtonSphereParam m_sphere;
186         NewtonCapsuleParam m_capsule;
187         NewtonCylinderParam m_cylinder;
188         NewtonChamferCylinderParam m_chamferCylinder;
189         NewtonConvexHullParam m_convexHull;
190         NewtonDeformableMeshParam m_deformableMesh;
191         NewtonCompoundCollisionParam m_compoundCollision;
192         NewtonCollisionTreeParam m_collisionTree;
193         NewtonHeightFieldCollisionParam m_heightField;
194         NewtonSceneCollisionParam m_sceneCollision;
195         dFloat[64] m_paramArray; // user define collision can use this to store information
196     }
197 }
198 
199 struct NewtonJointRecord
200 {
201     dFloat[4][4] m_attachmenMatrix_0;
202     dFloat[4][4] m_attachmenMatrix_1;
203     dFloat[3] m_minLinearDof;
204     dFloat[3] m_maxLinearDof;
205     dFloat[3] m_minAngularDof;
206     dFloat[3] m_maxAngularDof;
207     const(NewtonBody)* m_attachBody_0;
208     const(NewtonBody)* m_attachBody_1;
209     dFloat[64] m_extraParameters;
210     int m_bodiesCollisionOn;
211     char[128] m_descriptionType;
212 }
213 
214 struct NewtonUserMeshCollisionCollideDesc
215 {
216     dFloat[4] m_boxP0; // lower bounding box of intersection query in local space
217     dFloat[4] m_boxP1; // upper bounding box of intersection query in local space
218     dFloat[4] m_boxDistanceTravel; // max distance that box bpxP0 and boxP1 can travel on this timestep, used this for continue collision mode.
219     int m_threadNumber; // current thread executing this query
220     int m_faceCount; // the application should set here how many polygons intersect the query box
221     int m_vertexStrideInBytes; // the application should set here the size of each vertex
222     dFloat m_skinThickness; // this is the minimum skin separation specified by the material between these two colliding shapes
223     void* m_userData; // user data passed to the collision geometry at creation time
224 
225     NewtonBody* m_objBody; // pointer to the colliding body
226     NewtonBody* m_polySoupBody; // pointer to the rigid body owner of this collision tree 
227     NewtonCollision* m_objCollision; // collision shape of the colliding body, (no necessarily the collision of m_objBody)
228     NewtonCollision* m_polySoupCollision; // collision shape of the collision tree, (no necessarily the collision of m_polySoupBody)
229 
230     dFloat* m_vertex; // the application should set here the pointer to the global vertex of the mesh. 
231     int* m_faceIndexCount; // the application should set here the pointer to the vertex count of each face.
232     int* m_faceVertexIndex; // the application should set here the pointer index array for each vertex on a face.
233     // the format of a face is I0, I1, I2, I3, ..., M, N, E0, E1, E2, ..., A
234     // I0, I1, I2, .. are the indices to the vertex, relative to m_vertex pointer
235     // M is the index to the material sub shape id
236     // N in the index to the vertex normal relative to m_vertex pointer
237     // 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    
238     // 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. 
239 }
240 
241 struct NewtonWorldConvexCastReturnInfo
242 {
243     dFloat[4] m_point; // collision point in global space
244     dFloat[4] m_normal; // surface normal at collision point in global space
245     //dFloat m_normalOnHitPoint[4];           // surface normal at the surface of the hit body, 
246     // is the same as the normal calculated by a ray cast hitting the body at the hit point
247     dLong m_contactID; // collision ID at contact point
248     const(NewtonBody)* m_hitBody; // body hit at contact point
249     dFloat m_penetration; // contact penetration at collision point
250 }
251 
252 struct NewtonUserMeshCollisionRayHitDesc
253 {
254     dFloat[4] m_p0; // ray origin in collision local space
255     dFloat[4] m_p1; // ray destination in collision local space   
256     dFloat[4] m_normalOut; // copy here the normal at the ray intersection
257     dLong m_userIdOut; // copy here a user defined id for further feedback  
258     void* m_userData; // user data passed to the collision geometry at creation time
259 }
260 
261 struct NewtonHingeSliderUpdateDesc
262 {
263     dFloat m_accel;
264     dFloat m_minFriction;
265     dFloat m_maxFriction;
266     dFloat m_timestep;
267 }
268 
269 struct NewtonUserContactPoint
270 {
271     dFloat[4] m_point;
272     dFloat[4] m_normal;
273     dLong m_shapeId0;
274     dLong m_shapeId1;
275     dFloat m_penetration;
276     int[3] m_unused;
277 }
278 
279 struct NewtonImmediateModeConstraint
280 {
281     dFloat[8][6] m_jacobian01;
282     dFloat[8][6] m_jacobian10;
283     dFloat[8] m_minFriction;
284     dFloat[8] m_maxFriction;
285     dFloat[8] m_jointAccel;
286     dFloat[8] m_jointStiffness;
287 }
288 
289 // data structure for interfacing with NewtonMesh
290 struct NewtonMeshDoubleData
291 {
292     dFloat64* m_data;
293     int* m_indexList;
294     int m_strideInBytes;
295 }
296 
297 struct NewtonMeshFloatData
298 {
299     dFloat* m_data;
300     int* m_indexList;
301     int m_strideInBytes;
302 }
303 
304 struct NewtonMeshVertexFormat
305 {
306     int m_faceCount;
307     int* m_faceIndexCount;
308     int* m_faceMaterial;
309     NewtonMeshDoubleData m_vertex;
310     NewtonMeshFloatData m_normal;
311     NewtonMeshFloatData m_binormal;
312     NewtonMeshFloatData m_uv0;
313     NewtonMeshFloatData m_uv1;
314     NewtonMeshFloatData m_vertexColor;
315 }
316 
317 // Newton callback functions
318 alias NewtonAllocMemory = void* function (int sizeInBytes);
319 alias NewtonFreeMemory = void function (void* ptr, int sizeInBytes);
320 
321 alias NewtonWorldDestructorCallback = void function (const NewtonWorld* world);
322 alias NewtonPostUpdateCallback = void function (const NewtonWorld* world, dFloat timestep);
323 
324 alias NewtonCreateContactCallback = void function(const NewtonWorld*  newtonWorld, NewtonJoint* contact);
325 alias NewtonDestroyContactCallback = void function(const NewtonWorld*  newtonWorld, NewtonJoint* contact);
326 
327 alias NewtonWorldListenerDebugCallback = void function (const NewtonWorld* world, void* listener, void* debugContext);
328 alias NewtonWorldListenerBodyDestroyCallback = void function (const NewtonWorld* world, void* listenerUserData, NewtonBody* body_);
329 alias NewtonWorldUpdateListenerCallback = void function (const NewtonWorld* world, void* listenerUserData, dFloat timestep);
330 alias NewtonWorldDestroyListenerCallback = void function (const NewtonWorld* world, void* listenerUserData);
331 
332 alias NewtonGetTimeInMicrosencondsCallback = dLong function ();
333 
334 alias NewtonSerializeCallback = void function (void* serializeHandle, const void* buffer, int size);
335 alias NewtonDeserializeCallback = void function (void* serializeHandle, void* buffer, int size);
336 
337 alias NewtonOnBodySerializationCallback = void function (NewtonBody* body_, void* userData, NewtonSerializeCallback function_, void* serializeHandle);
338 alias NewtonOnBodyDeserializationCallback = void function (NewtonBody* body_, void* userData, NewtonDeserializeCallback function_, void* serializeHandle);
339 
340 alias NewtonOnJointSerializationCallback = void function (const NewtonJoint* joint, NewtonSerializeCallback function_, void* serializeHandle);
341 alias NewtonOnJointDeserializationCallback = void function (NewtonBody* body0, NewtonBody* body1, NewtonDeserializeCallback function_, void* serializeHandle);
342 
343 alias NewtonOnUserCollisionSerializationCallback = void function (void* userData, NewtonSerializeCallback function_, void* serializeHandle);
344 
345 // user collision callbacks    
346 alias NewtonUserMeshCollisionDestroyCallback = void function (void* userData);
347 alias NewtonUserMeshCollisionRayHitCallback = dFloat function (NewtonUserMeshCollisionRayHitDesc* lineDescData);
348 alias NewtonUserMeshCollisionGetCollisionInfo = void function (void* userData, NewtonCollisionInfoRecord* infoRecord);
349 alias NewtonUserMeshCollisionAABBTest = int function (void* userData, const dFloat* boxP0, const dFloat* boxP1);
350 alias NewtonUserMeshCollisionGetFacesInAABB = int function (
351     void* userData,
352     const dFloat* p0,
353     const dFloat* p1,
354     const dFloat** vertexArray,
355     int* vertexCount,
356     int* vertexStrideInBytes,
357     const int* indexList,
358     int maxIndexCount,
359     const int* userDataList);
360 alias NewtonUserMeshCollisionCollideCallback = void function (NewtonUserMeshCollisionCollideDesc* collideDescData, const void* continueCollisionHandle);
361 
362 alias NewtonTreeCollisionFaceCallback = int function (void* context, const dFloat* polygon, int strideInBytes, const int* indexArray, int indexCount);
363 
364 alias NewtonCollisionTreeRayCastCallback = dFloat function (const NewtonBody* body_, const NewtonCollision* treeCollision, dFloat intersection, dFloat* normal, int faceId, void* usedData);
365 alias NewtonHeightFieldRayCastCallback = dFloat function (const NewtonBody* body_, const NewtonCollision* heightFieldCollision, dFloat intersection, int row, int col, dFloat* normal, int faceId, void* usedData);
366 
367 alias NewtonCollisionCopyConstructionCallback = void function (const NewtonWorld* newtonWorld, NewtonCollision* collision, const NewtonCollision* sourceCollision);
368 alias NewtonCollisionDestructorCallback = void function (const NewtonWorld* newtonWorld, const NewtonCollision* collision);
369 
370 // collision tree call back (obsoleted no recommended)
371 alias NewtonTreeCollisionCallback = void function (
372     const NewtonBody* bodyWithTreeCollision,
373     const NewtonBody* body_,
374     int faceID,
375     int vertexCount,
376     const dFloat* vertex,
377     int vertexStrideInBytes);
378 
379 alias NewtonBodyDestructor = void function (const NewtonBody* body_);
380 alias NewtonApplyForceAndTorque = void function (const NewtonBody* body_, dFloat timestep, int threadIndex);
381 alias NewtonSetTransform = void function (const NewtonBody* body_, const dFloat* matrix, int threadIndex);
382 
383 alias NewtonIslandUpdate = int function (const NewtonWorld* newtonWorld, const(void)* islandHandle, int bodyCount);
384 
385 alias NewtonFractureCompoundCollisionOnEmitCompoundFractured = void function (NewtonBody* fracturedBody);
386 alias NewtonFractureCompoundCollisionOnEmitChunk = void function (NewtonBody* chunkBody, NewtonFracturedCompoundMeshPart* fracturexChunkMesh, const NewtonCollision* fracturedCompountCollision);
387 alias NewtonFractureCompoundCollisionReconstructMainMeshCallBack = void function (NewtonBody* body_, NewtonFracturedCompoundMeshPart* mainMesh, const NewtonCollision* fracturedCompountCollision);
388 
389 alias NewtonWorldRayPrefilterCallback = uint function (const NewtonBody* body_, const NewtonCollision* collision, void* userData);
390 alias NewtonWorldRayFilterCallback = dFloat function (const NewtonBody* body_, const NewtonCollision* shapeHit, const dFloat* hitContact, const dFloat* hitNormal, long collisionID, void* userData, dFloat intersectParam);
391 
392 alias NewtonOnAABBOverlap = int function (const NewtonJoint* contact, dFloat timestep, int threadIndex);
393 alias NewtonContactsProcess = void function (const NewtonJoint* contact, dFloat timestep, int threadIndex);
394 alias NewtonOnCompoundSubCollisionAABBOverlap = int function (const NewtonJoint* contact, dFloat timestep, const NewtonBody* body0, const void* collisionNode0, const NewtonBody* body1, const void* collisionNode1, int threadIndex);
395 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);
396 
397 alias NewtonBodyIterator = int function (const NewtonBody* body_, void* userData);
398 alias NewtonJointIterator = void function (const NewtonJoint* joint, void* userData);
399 alias NewtonCollisionIterator = void function (void* userData, int vertexCount, const dFloat* faceArray, int faceId);
400 
401 alias NewtonBallCallback = void function (const NewtonJoint* ball, dFloat timestep);
402 alias NewtonHingeCallback = uint function (const NewtonJoint* hinge, NewtonHingeSliderUpdateDesc* desc);
403 alias NewtonSliderCallback = uint function (const NewtonJoint* slider, NewtonHingeSliderUpdateDesc* desc);
404 alias NewtonUniversalCallback = uint function (const NewtonJoint* universal, NewtonHingeSliderUpdateDesc* desc);
405 alias NewtonCorkscrewCallback = uint function (const NewtonJoint* corkscrew, NewtonHingeSliderUpdateDesc* desc);
406 
407 alias NewtonUserBilateralCallback = void function (const NewtonJoint* userJoint, dFloat timestep, int threadIndex);
408 alias NewtonUserBilateralGetInfoCallback = void function (const NewtonJoint* userJoint, NewtonJointRecord* info);
409 
410 alias NewtonConstraintDestructor = void function (const NewtonJoint* me);
411 
412 alias NewtonJobTask = void function (NewtonWorld* world, void* userData, int threadIndex);
413 alias NewtonReportProgress = int function (dFloat normalizedProgressPercent, void* userData);