Code:
procedure TMTFloor.CreateCollisionTree;
var
Face: Array [0..3] Of Geometry.TVector3f;
M: Geometry.TMatrix4f;
Min,Max: Geometry.TVector3f;
X,Z,x1,z1,x1t,z1t,xz,x1z,xz1,x1z1: Integer;
xt,zt: Double;
begin
nCollTree := NewtonCreateTreeCollision(nWorld, Nil);
NewtonTreeCollisionBeginBuild(nCollTree);
For X := 0 To MAP_SIZE Do
Begin
For Z := 0 To MAP_SIZE Do
Begin
xz := floorIndex(X, Z);
x1z := floorIndex(X+1, Z);
xz1 := floorIndex(X, Z+1);
x1z1 := floorIndex(X+1, Z+1);
Face[0] := Vector3fMake(X*lBlock, hf[xz], Z*lBlock);
Face[1] := Vector3fMake((X+1)*lBlock, hf[x1z], Z*lBlock);
Face[2] := Vector3fMake((X+1)*lBlock, hf[x1z1], (Z+1)*lBlock);
Face[3] := Vector3fMake(X*lBlock, hf[xz1], (Z+1)*lBlock);
NewtonTreeCollisionAddFace(nCollTree, 4, @Face[0], SizeOf(TVector3f), 1);
End;
End;
NewtonTreeCollisionEndBuild(nCollTree, 0);
nBody := NewtonCreateBody(nWorld, nCollTree);
tmpM := IdentityHmgMatrix;
NewtonBodySetMatrix(nBody, @M[0,0]);
NewtonCollisionCalculateAABB(nCollTree, @M[0,0], @Min[0], @Max[0]);
NewtonSetWorldSize(nWorld, @Min[0], @Max[0]);
NewtonReleaseCollision(nWorld, nCollTree);
end;
Many thanks..
Bookmarks