- Code: Select all
// Make collision tree
NewtonCollision* pCollision = NewtonCreateTreeCollision(world, 0);
NewtonTreeCollisionBeginBuild(pCollision);
const int cNumVerts = 8;
float verts[cNumVerts][3] =
{
0.5, 0, 0,
-0.5, 0, 0,
0, 0, -2.5,
0, 0, 2.5,
0.5, 0.25, 0,
-0.5, 0.25, 0,
0, 0.25, -2.5,
0, 0.25, 2.5
};
const int cNumFaces = 12;
int indices[cNumFaces * 3] =
{
0, 1, 2,
0, 3, 1,
4, 6, 5,
4, 5, 7,
5, 6, 2,
5, 2, 1,
7, 5, 1,
7, 1, 3,
4, 2, 6,
4, 0, 2,
4, 7, 3,
4, 3, 0
};
for (int i = 0; i < cNumFaces; i++)
{
int index0 = indices[i * 3];
int index1 = indices[i * 3 + 1];
int index2 = indices[i * 3 + 2];
float faceVerts[3][3];
faceVerts[0][0] = verts[index0][0];
faceVerts[0][1] = verts[index0][1];
faceVerts[0][2] = verts[index0][2];
faceVerts[1][0] = verts[index1][0];
faceVerts[1][1] = verts[index1][1];
faceVerts[1][2] = verts[index1][2];
faceVerts[2][0] = verts[index2][0];
faceVerts[2][1] = verts[index2][1];
faceVerts[2][2] = verts[index2][2];
NewtonTreeCollisionAddFace(pCollision, 3, &(faceVerts[0][0]), 12, 0);
}
NewtonTreeCollisionEndBuild(pCollision, 1);
// Add chamfer cylinder
float offsetmtx[16] = { 0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 1, 0, 0, 0.1f, 0, 1 };
NewtonCollision* pCylCollision = NewtonCreateChamferCylinder(world, 0.5f, 0.2f, 1, offsetmtx);
// Matrices of collision tree and cylinder
float treeMtx[16] = { 0.70710677f, 0, 0.70710677f, 0, 0, 1, 0, 0, -0.70710677f, 0, 0.70710677f, 0, 26.652052f, 0.5f, 43.713711f, 1 };
float cylMtx[16] = { -0.882393219f, -0.00228729658f, 0.469481796f, 0,
-0.00185807608f, 0.999997318f, 0.00137752341f, 0,
-0.469483703f, 0.000343936495f, -0.882941127f, 0,
26.0855798f, 0.495723963f, 44.80299f, 1 };
// Do collision
const int cMaxContacts = 15;
float contacts[cMaxContacts][3];
float normals[cMaxContacts][3];
float penetrations[cMaxContacts];
int numContacts = NewtonCollisionCollide(world, cMaxContacts, pCylCollision, cylMtx, pCollision, treeMtx, &(contacts[0][0]), &(normals[0][0]), &(penetrations[0]), 0);
The code above will report numContacts as 5, and all 5 values in the penetrations array are 0.
Is there something wrong in my code, or is there possibly a bug here? Thanks.