Hi,
I have a terrain, and i want to use newton for collision detection.. i have the terrain working and the physics of course in not working to good,
my code is:
Code:
procedure TMTFloor.CreateCollisionTree;
var
Face: Array [0..3] Of Geometry.TVector3f;
M: Geometry.TMatrix4f;
Min,Max: Geometry.TVector3f;
X,Z: Integer;
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, height[xz], Z*lBlock);
Face[1] := Vector3fMake((X+1)*lBlock, height[x1z], Z*lBlock);
Face[2] := Vector3fMake((X+1)*lBlock, height[x1z1], (Z+1)*lBlock);
Face[3] := Vector3fMake(X*lBlock, height[xz1], (Z+1)*lBlock);
NewtonTreeCollisionAddFace(nCollTree, 4, @Face[0], SizeOf(TVector3f), 1);
End;
End;
NewtonTreeCollisionEndBuild(nCollTree, 0);
nBody := NewtonCreateBody(nWorld, nCollTree);
M := 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;
lBlock is a const value set at 8.001, this is because the terrain is scaled by 8.001, 1, 8.001..
If i dont use scale and i take out lBlock then the physics works fine, so im positive its something to with the scale, so i removed glScale from the terrain, and i am now using the same coordinates given to Newton, the terrain renders correctly yet still the collision detection does'nt.. am i missing something??
Thanks for any help
Bookmarks