Difference between revisions of "NewtonUserMeshCollisionCollideCallback"

From Newton Wiki
Jump to: navigation, search
m (1 revision imported)
(formatting)
 
Line 39: Line 39:
 
Then you set these pointers to the corresponding members in NewtonUserMeshCollisionCollideDesc
 
Then you set these pointers to the corresponding members in NewtonUserMeshCollisionCollideDesc
  
''int m_faceCount'' - App should set this to the number of faces in the returned polygon set.
+
''int m_faceCount'' - App should set this to the number of faces in the returned polygon set.
''dFloat* m_vertex'' - App should set this to the vertex array for the intersection polygon set.
+
''dFloat* m_vertex'' - App should set this to the vertex array for the intersection polygon set.
''int m_vertexStrideInBytes'' - App should set here the size of each vertex.
+
''int m_vertexStrideInBytes'' - App should set here the size of each vertex.
''int* m_userAttribute'' - App should set here the pointer to the user data, one for each face.
+
''int* m_userAttribute'' - App should set here the pointer to the user data, one for each face.
''int* m_faceIndexCount'' - App should set here the pointer to the vertex count of each face.
+
''int* m_faceIndexCount'' - App should set here the pointer to the vertex count of each face.
''int* m_faceVertexIndex'' - App should set here the pointer index array for each vertex on a face.
+
''int* m_faceVertexIndex'' - App should set here the pointer index array for each vertex on a face.
  
 
== Remarks ==
 
== Remarks ==

Latest revision as of 08:49, 3 October 2019

NewtonUserMeshCollisionCollideCallback

typedef void (*NewtonUserMeshCollisionCollideCallback) (NewtonUserMeshCollisionCollideDesc* const collideDescData, const void* const continueCollisionHandle)

Usage

Called whenever a User Mesh collision is checked by newton when the shape potentially collides with another object (a object's AABB overlaps the usermesh's AABB).

Parameters

  • NewtonUserMeshCollisionCollideDesc* collideDescData - Collision data structure, identifies the data about current intresection check, the collision data - if any is returned into this structure.
  • continueCollisionHandle void*

Examples

It's the App's job to fill in aCollideDesc params to define the user mesh polygons intersected by the given AABB (Axis-aligned bounding box).

CollideDesc members

dFloat m_boxP0[4] - Min point of bounding box being requested (last index irrelevant). dFloat m_boxP1[4] - Max point of bounding box being requested (last index irrelevant). void* m_userData - Set when callback was registered with NewtonCreateUserMeshCollision NewtonBody* m_objBody - Pointer to the colliding body. NewtonBody* m_polySoupBody - Pointer to the rigid body owner of this collision tree.

The rest of the members are for you to fill up during the call back. To make it clear let say that your mesh is a geometry like this:

vertex array[] { v0, v1, v1, v2, …..}
face array { 4, 3, 4, …..}
attribute array {0, 0, 0, 0}
index array { 0, 1, 2, 4, 5, 5, 3, 4 …..}

This is an indexed mesh that can only be read sequentially. To read it to set in local pointer to the index array, face array [0] say how many indices from array list need to be read to make the first face. When this face is processed then the index array is advanced by the number of indices and the second face is read, this is done until all face are processed. Attribute is the user data assigned to that particular face.

Usually you will only have to generate the indices, and keep the vertex on a large array, but sometimes even the vertices will have to be generated at run time, this will be the case for height map terrains.

Essentially you will need to implement an algorithm that produces the polygon intersecting your mesh and generate this arrays at run time into some persistent variables. Then you set these pointers to the corresponding members in NewtonUserMeshCollisionCollideDesc

int m_faceCount - App should set this to the number of faces in the returned polygon set.
dFloat* m_vertex - App should set this to the vertex array for the intersection polygon set.
int m_vertexStrideInBytes - App should set here the size of each vertex.
int* m_userAttribute - App should set here the pointer to the user data, one for each face.
int* m_faceIndexCount - App should set here the pointer to the vertex count of each face.
int* m_faceVertexIndex - App should set here the pointer index array for each vertex on a face.

Remarks

  • The intersection bounding box is in local mesh space, and may not be fully inside the user mesh bounding box.
  • If a body is made from composite collision primitives, the intersection box may be totally outside the user mesh bounding box (presume it just calls for each primitive.)
  • The app manages the memory m_vertex points to, which must persist after the callback returns.
  • Ensure polygon winding convention adhered to (anticlockwise?)
  • This is not a library function, but a callback event.

See also

NewtonCreateUserMeshCollision