Page 1 of 2 12 LastLast
Results 1 to 10 of 16

Thread: Newton Terrain Physics

  1. #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: 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
    M109uk
    <br />--------------------------------------------------------
    <br />www.pulse-soft.oneuk.com

  2. #2

    Newton Terrain Physics

    what exactly happens wrong? make a debug renderer of the scene.
    This is my game project - Top Down City:
    http://www.pascalgamedevelopment.com...y-Topic-Reboot

    My OpenAL audio wrapper with Intelligent Source Manager to use unlimited:
    http://www.pascalgamedevelopment.com...source+manager

  3. #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.
    M109uk
    <br />--------------------------------------------------------
    <br />www.pulse-soft.oneuk.com

  4. #4

    Newton Terrain Physics

    Quote 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.
    This is my game project - Top Down City:
    http://www.pascalgamedevelopment.com...y-Topic-Reboot

    My OpenAL audio wrapper with Intelligent Source Manager to use unlimited:
    http://www.pascalgamedevelopment.com...source+manager

  5. #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.
    www.pulse-soft.oneuk.com/downloads/mt.zip

    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;;
    
          NewtonTreeCollisionAddFace&#40;nCollTree, 4, @Face&#91;0&#93;, SizeOf&#40;TVector3f&#41;, 1&#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..
    M109uk
    <br />--------------------------------------------------------
    <br />www.pulse-soft.oneuk.com

  6. #6

    Newton Terrain Physics

    Quote 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?
    This is my game project - Top Down City:
    http://www.pascalgamedevelopment.com...y-Topic-Reboot

    My OpenAL audio wrapper with Intelligent Source Manager to use unlimited:
    http://www.pascalgamedevelopment.com...source+manager

  7. #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
    M109uk
    <br />--------------------------------------------------------
    <br />www.pulse-soft.oneuk.com

  8. #8

    Newton Terrain Physics

    what about, dropping some cubes onto terrain? :/
    This is my game project - Top Down City:
    http://www.pascalgamedevelopment.com...y-Topic-Reboot

    My OpenAL audio wrapper with Intelligent Source Manager to use unlimited:
    http://www.pascalgamedevelopment.com...source+manager

  9. #9

    Newton Terrain Physics

    Quote 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
    M109uk
    <br />--------------------------------------------------------
    <br />www.pulse-soft.oneuk.com

  10. #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?
    This is my game project - Top Down City:
    http://www.pascalgamedevelopment.com...y-Topic-Reboot

    My OpenAL audio wrapper with Intelligent Source Manager to use unlimited:
    http://www.pascalgamedevelopment.com...source+manager

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

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