1. ## Newton Terrain Physics

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&#58; Array &#91;0..3&#93; Of Geometry.TVector3f;
M&#58; Geometry.TMatrix4f;
Min,Max&#58; Geometry.TVector3f;
X,Z&#58; Integer;
begin
nCollTree &#58;= NewtonCreateTreeCollision&#40;nWorld, Nil&#41;;
NewtonTreeCollisionBeginBuild&#40;nCollTree&#41;;

For X &#58;= 0 To MAP_SIZE Do
Begin
For Z &#58;= 0 To MAP_SIZE Do
Begin
xz &#58;= floorIndex&#40;X, Z&#41;;
x1z &#58;= floorIndex&#40;X+1, Z&#41;;
xz1 &#58;= floorIndex&#40;X, Z+1&#41;;
x1z1 &#58;= floorIndex&#40;X+1, Z+1&#41;;

Face&#91;0&#93; &#58;= Vector3fMake&#40;X*lBlock,     height&#91;xz&#93;,   Z*lBlock&#41;;
Face&#91;1&#93; &#58;= Vector3fMake&#40;&#40;X+1&#41;*lBlock, height&#91;x1z&#93;,  Z*lBlock&#41;;
Face&#91;2&#93; &#58;= Vector3fMake&#40;&#40;X+1&#41;*lBlock, height&#91;x1z1&#93;, &#40;Z+1&#41;*lBlock&#41;;
Face&#91;3&#93; &#58;= Vector3fMake&#40;X*lBlock,     height&#91;xz1&#93;,  &#40;Z+1&#41;*lBlock&#41;;

End;
End;

NewtonTreeCollisionEndBuild&#40;nCollTree, 0&#41;;
nBody &#58;= NewtonCreateBody&#40;nWorld, nCollTree&#41;;

M &#58;= IdentityHmgMatrix;
NewtonBodySetMatrix&#40;nBody, @M&#91;0, 0&#93;&#41;;
NewtonCollisionCalculateAABB&#40;nCollTree, @M&#91;0, 0&#93;, @Min&#91;0&#93;, @Max&#91;0&#93;&#41;;
NewtonSetWorldSize&#40;nWorld, @Min&#91;0&#93;, @Max&#91;0&#93;&#41;;
NewtonReleaseCollision&#40;nWorld, nCollTree&#41;;
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

2. ## Newton Terrain Physics

what exactly happens wrong? make a debug renderer of the scene.

3. ## Newton Terrain Physics

there is a form of collision detection, it just does'nt match the terrain.. how would i go about doing a debug render, i am rendering the terrain with exaclty the same vertex data that i am putting into newton.

4. ## Newton Terrain Physics

Originally Posted by M109uk
there is a form of collision detection, it just does'nt match the terrain.. how would i go about doing a debug render, i am rendering the terrain with exaclty the same vertex data that i am putting into newton.
see how newton examples implement debug rendering, and the geometry comes from newton's internals - not your app.

5. ## Newton Terrain Physics

I have put in debug rendering, and it is correct, exactly the same as the terrain im rendering...

Heres the app to show whats wrong, the debug lines on on automaticlly.

The modified code:
Code:
```procedure TMTFloor.CreateCollisionTree;
var
Face&#58; Array &#91;0..3&#93; Of Geometry.TVector3f;
M&#58; Geometry.TMatrix4f;
Min,Max&#58; Geometry.TVector3f;
X,Z,x1,z1,x1t,z1t,xz,x1z,xz1,x1z1&#58; Integer;
xt,zt&#58; Double;
begin
nCollTree &#58;= NewtonCreateTreeCollision&#40;nWorld, Nil&#41;;
NewtonTreeCollisionBeginBuild&#40;nCollTree&#41;;

For X &#58;= 0 To MAP_SIZE Do
Begin
For Z &#58;= 0 To MAP_SIZE Do
Begin
xz &#58;= floorIndex&#40;X, Z&#41;;
x1z &#58;= floorIndex&#40;X+1, Z&#41;;
xz1 &#58;= floorIndex&#40;X, Z+1&#41;;
x1z1 &#58;= floorIndex&#40;X+1, Z+1&#41;;

Face&#91;0&#93; &#58;= Vector3fMake&#40;X*lBlock,     hf&#91;xz&#93;,   Z*lBlock&#41;;
Face&#91;1&#93; &#58;= Vector3fMake&#40;&#40;X+1&#41;*lBlock, hf&#91;x1z&#93;,  Z*lBlock&#41;;
Face&#91;2&#93; &#58;= Vector3fMake&#40;&#40;X+1&#41;*lBlock, hf&#91;x1z1&#93;, &#40;Z+1&#41;*lBlock&#41;;
Face&#91;3&#93; &#58;= Vector3fMake&#40;X*lBlock,     hf&#91;xz1&#93;,  &#40;Z+1&#41;*lBlock&#41;;

End;
End;

NewtonTreeCollisionEndBuild&#40;nCollTree, 0&#41;;
nBody &#58;= NewtonCreateBody&#40;nWorld, nCollTree&#41;;

tmpM &#58;= IdentityHmgMatrix;
NewtonBodySetMatrix&#40;nBody, @M&#91;0,0&#93;&#41;;
NewtonCollisionCalculateAABB&#40;nCollTree, @M&#91;0,0&#93;, @Min&#91;0&#93;, @Max&#91;0&#93;&#41;;
NewtonSetWorldSize&#40;nWorld, @Min&#91;0&#93;, @Max&#91;0&#93;&#41;;
NewtonReleaseCollision&#40;nWorld, nCollTree&#41;;
end;```
Many thanks..

6. ## Newton Terrain Physics

Originally Posted by M109uk
I have put in debug rendering, and it is correct, exactly the same as the terrain im rendering...
did you use the actual NewtonBodyForEachPolygonDo ?

your app is totally non-interactive, i cant even see myself how the physics are supposedly "wrong".

and how about some instructions to go with the test app?

7. ## Newton Terrain Physics

For debug im using:
Code:
```procedure Debug_ShowGeometryCollision&#40;const Body&#58; PNewtonBody; VertexCount&#58; Integer; const FaceArray&#58; PFloat; FaceId&#58; Int&#41;; cdecl;
var
i&#58; Integer;
v0,v1&#58; TVector3f;
vA&#58; Array Of Single;
begin
If VertexCount = 0 Then Exit;
SetLength&#40;vA, VertexCount*3&#41;;
Move&#40;FaceArray^, vA&#91;0&#93;, VertexCount*3*SizeOf&#40;Single&#41;&#41;;
v0&#91;0&#93; &#58;= vA&#91;&#40;VertexCount-1&#41;*3&#93;;
v0&#91;1&#93; &#58;= vA&#91;&#40;VertexCount-1&#41;*3+1&#93;;
v0&#91;2&#93; &#58;= vA&#91;&#40;VertexCount-1&#41;*3+2&#93;;
For i &#58;= 0 To VertexCount-1 Do
Begin
v1&#91;0&#93; &#58;= vA&#91;i*3&#93;;
v1&#91;1&#93; &#58;= vA&#91;i*3+1&#93;;
v1&#91;2&#93; &#58;= vA&#91;i*3+2&#93;;
glVertex3f&#40;v0&#91;0&#93;, v0&#91;1&#93;, v0&#91;2&#93;&#41;;
glVertex3f&#40;v1&#91;0&#93;, v1&#91;1&#93;, v1&#91;2&#93;&#41;;
v0 &#58;= v1;
End;
end;

procedure Debug_ShowBodyCollision&#40;const Body&#58; PNewtonBody&#41;; cdecl;
begin
NewtonBodyForEachPolygonDo&#40;Body, Debug_ShowGeometryCollision&#41;;
end;```
Sorry my bad, completly forgot :s

forward=W
backward=S
turn left=A
turn right=D
run=SHIFT
Quit=ESC
Regenerate terrain=F1

8. ## Newton Terrain Physics

what about, dropping some cubes onto terrain? :/

9. ## Newton Terrain Physics

Originally Posted by Delfi
what about, dropping some cubes onto terrain? :/
I dont have any other objects except for the camera and the terrain atm... i will implement some cubes in tonight

10. ## Newton Terrain Physics

Then how do you know that something is wrong in newton if you only got the terrain in without even testing?

what is the actual problem?

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•