[Havok] Extracting vertices and indices for Mesh collision

Started by
0 comments, last by n3Xus 13 years, 9 months ago
Ok, I have started to implement Havok in my game and for terraing collision detection I am using hkpExtendedMeshShape and to text it I have created a rigidbody of box type. However there is no collision between the terrain and the box. I have tried for 2 days and still no result. Here is my code for extracting the mesh vertices and indices :

1.float* vertices ;
2.void* indices = 0;
3.char *DXMeshPtr;
4.int numVertices = meshBlock->GetNumVertices();
5.DWORD FVFSize = D3DXGetFVFVertexSize(meshBlock->GetFVF());
6.vertices = new float[numVertices * 3];
7.meshBlock->LockVertexBuffer(D3DLOCK_READONLY, (void**)&DXMeshPtr);
8.for(int i = 0; i < numVertices; i++)
9.{
10. Mesh_FVF *DXMeshFVF = (Mesh_FVF*)DXMeshPtr;
11. int vertex = i * 3;
12. vertices[vertex + 0] = DXMeshFVF->VertexPos.x;
13. vertices[vertex + 1] = DXMeshFVF->VertexPos.y;
14. vertices[vertex + 2] = DXMeshFVF->VertexPos.z;
15. DXMeshPtr += FVFSize;
16.
17.}
18.
19.
20.
21.
22.meshBlock->LockIndexBuffer(0, (void**)&indices);
23.int numTriangles = meshBlock->GetNumFaces();
24.
25.
26.hkpExtendedMeshShape* m_mesh = new hkpExtendedMeshShape();
27.{
28. hkpExtendedMeshShape::TrianglesSubpart part;
29.
30. part.m_vertexBase = vertices;
31. part.m_vertexStriding = sizeof(float) * 3;
32. part.m_numVertices = numVertices;
33.
34. part.m_indexBase = indices;
35. part.m_indexStriding = sizeof(unsigned short) * 3;
36. part.m_numTriangleShapes = numTriangles;
37.
38. part.m_stridingType = hkpExtendedMeshShape::INDICES_INT16;
39.
40. m_mesh->addTrianglesSubpart(part);
41.}
42.
43.meshBlock->UnlockIndexBuffer();
44.meshBlock->UnlockVertexBuffer();
45.
46.hkpRigidBodyCinfo blockInfo;
47.
48.blockInfo.m_shape = m_mesh;
49.blockInfo.m_motionType = hkpMotion::MOTION_FIXED;
50.
51.
52.rb = new hkpRigidBody(blockInfo);
53.
54.m_world->addEntity(rb);
55.m_world()->addEntity(rb);
56.rb->removeReference();
57.m_mesh->removeReference();
58.
59.m_world->unlock();

Please help. Thanks.
Advertisement
Have you checked it with the visual debugger if the rigid bodies have the correct collision geometry/position?

This topic is closed to new replies.

Advertisement