Colin

17-01-2011, 12:06 PM

Hi there, long time no see, looking for a little help, i am currently using Irrlicht 1.71 and Newton 2.29. i have so far got everything working apart from convex hull objects, i read that newton and irrlicht both use different sizes, i have fiddled around trying to get it to work with no luck, it "kind of" works, anyways this is my code for creating the collision hull

function CreateConvexHullCollisionFromMesh(nWorld: PNewtonWorld; node: ISceneNode; irr_mesh: IMesh): PNewtonCollision;

var

nMeshBuffer : Integer; //Mesh Buffer count

nVertices : LongWord;

mesh_buffer : IMeshBuffer;

tCounter : LongWord;

vertices : array of Vector3df;

_vertices : PS3DVertex;

i : Integer;

begin

nMeshBuffer := 0;

nVertices := 0;

//get number of vertices

for nMeshBuffer := 0 to irr_mesh.getMeshBufferCount() - 1 do begin

nVertices := nVertices + irr_mesh.getMeshBuffer(nMeshBuffer).getVertexCount ();

end;

//create buffer for vertices

SetLength(vertices, nVertices);

tCounter := 0;

//get (irr_)mesh buffers and copy face vertices

for nMeshBuffer := 0 to irr_mesh.getMeshBufferCount() - 1 do begin

mesh_buffer := irr_mesh.getMeshBuffer(nMeshBuffer);

//get pointer to vertices and indices

_vertices := PS3DVertex(mesh_buffer.getVertices());

{$POINTERMATH ON}

//copy vertices from mesh to buffer

for i := 0 to mesh_buffer.getVertexCount() - 1 do begin

vertices[tCounter].x := _vertices[i].Pos.x;

vertices[tCounter].y := _vertices[i].Pos.y;

vertices[tCounter].z := _vertices[i].Pos.z;

Inc(tCounter);

end;

{$POINTERMATH OFF}

end;

//Create Newton collision object

Result := NewtonCreateConvexHull(nWorld, nVertices, @vertices[0].x, sizeof(vector3df), 0, 0, nil);

//remove from mem space

vertices := nil;

end;

currently i have tried with several objects, i am loading it with a cube just to test with... what happens is the cube falls, hits the ground, then gradually (slowly) falls through and then off it goes falling to bottom of newton world size. im guessing my ground is fine since creating newtonbox works just fine, all physics work for this with many objects, 1000s even, just not the convex hull, hope you can help, thanks.

function CreateConvexHullCollisionFromMesh(nWorld: PNewtonWorld; node: ISceneNode; irr_mesh: IMesh): PNewtonCollision;

var

nMeshBuffer : Integer; //Mesh Buffer count

nVertices : LongWord;

mesh_buffer : IMeshBuffer;

tCounter : LongWord;

vertices : array of Vector3df;

_vertices : PS3DVertex;

i : Integer;

begin

nMeshBuffer := 0;

nVertices := 0;

//get number of vertices

for nMeshBuffer := 0 to irr_mesh.getMeshBufferCount() - 1 do begin

nVertices := nVertices + irr_mesh.getMeshBuffer(nMeshBuffer).getVertexCount ();

end;

//create buffer for vertices

SetLength(vertices, nVertices);

tCounter := 0;

//get (irr_)mesh buffers and copy face vertices

for nMeshBuffer := 0 to irr_mesh.getMeshBufferCount() - 1 do begin

mesh_buffer := irr_mesh.getMeshBuffer(nMeshBuffer);

//get pointer to vertices and indices

_vertices := PS3DVertex(mesh_buffer.getVertices());

{$POINTERMATH ON}

//copy vertices from mesh to buffer

for i := 0 to mesh_buffer.getVertexCount() - 1 do begin

vertices[tCounter].x := _vertices[i].Pos.x;

vertices[tCounter].y := _vertices[i].Pos.y;

vertices[tCounter].z := _vertices[i].Pos.z;

Inc(tCounter);

end;

{$POINTERMATH OFF}

end;

//Create Newton collision object

Result := NewtonCreateConvexHull(nWorld, nVertices, @vertices[0].x, sizeof(vector3df), 0, 0, nil);

//remove from mem space

vertices := nil;

end;

currently i have tried with several objects, i am loading it with a cube just to test with... what happens is the cube falls, hits the ground, then gradually (slowly) falls through and then off it goes falling to bottom of newton world size. im guessing my ground is fine since creating newtonbox works just fine, all physics work for this with many objects, 1000s even, just not the convex hull, hope you can help, thanks.