- procedure CreateBSPCollisionTree(const pSceneBSP : TQuake3BSP);
- var
- TmpFace : array[0..20] of TVector3f;
- TmpM : TMatrix4f;
- Min : TVector3f;
- Max : TVector3f;
- m,f : Integer;
- begin
- CollTreeBSP := NewtonCreateTreeCollision(NewtonWorld, nil);
- // Go through all meshes and add the faces of it to the tree collision
- NewtonTreeCollisionBeginBuild(CollTreeBSP);
- if pSceneBSP.numOfFaces > 0 then
- for f := 0 to pSceneBSP.numOfFaces-1 do
- If pSceneBSP.Faces[f].FaceType = 1 then
- begin
- for m := 0 to pSceneBSP.Faces[f].numOfVerts-1 do
- TmpFace[m] := pSceneBSP.Vertices[pSceneBSP.Faces[f].startVertIndex+m].Position;
- NewtonTreeCollisionAddFace(CollTreeBSP, m, @TmpFace[0], SizeOf(TVector3f), 1);
- end;
- NewtonTreeCollisionEndBuild(CollTreeBSP, 0);
- BodyBSP := NewtonCreateBody(NewtonWorld, CollTreeBSP);
- // Set position to 0/0/0
- Matrix_SetIdentity(TmpM);
- NewtonBodySetMatrix(BodyBSP, @TmpM[0,0]);
- // Set material
- NewtonBodySetMaterialGroupID(BodyBSP, MatWorld);
- // Get AABB and set limits of the newton world
- NewtonCollisionCalculateAABB(CollTreeBSP, @TmpM[0,0], @Min, @Max);
- NewtonSetWorldSize(NewtonWorld, @Min, @Max);
- NewtonReleaseCollision(NewtonWorld, CollTreeBSP);
- end;