Page 5 of 6 FirstFirst ... 3456 LastLast
Results 41 to 50 of 55

Thread: 3d Engine Collision

  1. #41

    Re: 3d Engine Collision

    I think this will interest you:

    http://msdn.microsoft.com/en-us/libr...91(VS.85).aspx

    Take a look at LineLists and LineStrips. It shows you how to draw lines by using vertexbuffers and a DrawPrimitive call.

    Hope it helps.
    Coders rule nr 1: Face ur bugz.. dont cage them with code, kill'em with ur cursor.

  2. #42

    Re: 3d Engine Collision

    is already late, 4.29am.. almost falling asleep

    but anyways

    Code:
    procedure Polycallback(const body: PNewtonBody; vertexCount: Integer; const FaceArray: PFloat; faceId: Integer); cdecl;
    var
     i: Integer;
     p01: array[0..1] of TD3DXVector3;
    begin
     i := vertexCount - 1;
     p01[0] := D3DXVector3( PSingle(Cardinal(FaceArray) + i * 3 )^, PSingle(Cardinal(FaceArray) + i * 3 + 1 )^, PSingle(Cardinal(FaceArray) + i * 3 + 2)^);
    
     for i := 0 to vertexCount-1 do begin
      p01[1] := D3DXVector3( PSingle(Cardinal(FaceArray) + i * 3 )^, PSingle(Cardinal(FaceArray) + i * 3 + 1 )^, PSingle(Cardinal(FaceArray) + i * 3 + 2)^);
    
      Engine.ResMan.DX_Device.DrawPrimitiveUP(D3DPT_LINELIST, 1, p01, SizeOf(TD3DXVector3));
    
      p01[0] := p01[1];
     end;
    end;
    
    procedure DebugCallback(const body : PNewtonBody); cdecl;
    begin
     NewtonBodyForEachPolygonDo(body, @Polycallback);
    end;
    this is what i've tried but i can't get it to work, all lines all over the place... lol

  3. #43

    Re: 3d Engine Collision

    ok i've now wrote an extra proc for testing..

    Code:
    procedure DrawLine(x1, y1, z1: Single; x2, y2, z2: Single);
    type
     TVertex = record
      x: Single;
      y: Single;
      z: Single;
      color: DWord;
      tu: Single;
      tv: Single;
     end;
    var
     triData: array[1..2] of TVertex;
    
     procedure SetVertex(ver: TVertex; _x,_y,_z: Single; _col: DWord; _tu, _tv: Single);
     begin
      with ver do begin
       x := _x; y := _y; z := _z;
       color := _col;
       tu := _tu; tv := _tv;
      end;
     end;
    begin
     SetVertex(triData[1], x1, y1, z1, $FFFFFF, 0, 0);
     SetVertex(triData[2], x2, y2, z2, $FFFFFF, 0, 0);
    
     Engine.ResMan.DX_Device.DrawPrimitiveUP(D3DPT_LINELIST, 1, triData, SizeOf(TVertex));
    end;
    
    procedure Polycallback(const body: PNewtonBody; vertexCount: Integer; const FaceArray: PFloat; faceId: Integer); cdecl;
    var
     i: Integer;
     p0, p1: TD3DXVector3;
     pList: array of TD3DXVector3;
    begin
     SetLength(pList, vertexCount);
     CopyMemory(pList, FaceArray, vertexCount * SizeOf(TD3DXVector3));
    
     p0 := pList[0];
     for i := 1 to VertexCount - 1 do begin
      p1 := pList[i];
    
      DrawLine(p0.x, p0.y, p0.z, p1.x, p1.y, p1.z);
      p0 := p1;
     end;
    end;
    
    procedure DebugCallback(const body : PNewtonBody); cdecl;
    begin
     NewtonBodyForEachPolygonDo(body, @Polycallback);
    end;
    so this is what im doing now, but this draws a point in the sky, as the boxes fall lines are drawn towards the box... i just cant work it out...

  4. #44

    Re: 3d Engine Collision

    One thing you should to is change SetVertex:

    SetVertex(var ver: TVertex; ...

    Otherwise it is only modifying a copy of the record.
    ZGameEditor - Develop 64kb games for Windows.
    Thrust for Vectrex - ROM-file and 6809 source code.

  5. #45

    Re: 3d Engine Collision

    ah damn i didnt realise i did that, thanks very much for spotting that, that has kind of fixed it, now i see a cube, but it is drawn no where near my actual cube lol

    here is example....

    Download Here

  6. #46

    Re: 3d Engine Collision

    ok i think i have solved it, i forgot to - the matrix

    Code:
      DrawLine(matrix._41-p0.x, matrix._42-p0.y, matrix._43-p0.z, matrix._41-p1.x, matrix._42-p1.y, matrix._43-p1.z);

    so now this is sorted, the actual physical cube is drawn different to the rendered .x model... also the physics cube goes slighty through the ground/grass



    Sample Here

  7. #47

    Re: 3d Engine Collision

    Draw the debug geometry with no transformation (original plain world matrix).
    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

  8. #48

    Re: 3d Engine Collision

    sorry i dont understand.

    after rendering my land i do

    Code:
     for v := Low(boxs) to High(boxs) do begin
     //for v := 1 to 1 do begin
      boxs[v].Render;
      DebugCallback(boxs[v].NewtonBody);
     end;
    
     NewtonUpdate(NewtonWorld, PerfCount.DeltaTime);
    Code:
    procedure TNewtonBox.Render;
    var
     v: Integer;
     matWorld: TD3DMatrix;
    begin
     NewtonBodyGetMatrix(NewtonBody, @matWorld.m[0,0]);
     Engine.ResMan.DX_Device.SetTransform(D3DTS_WORLD, matWorld);
    
     v := 0;
     while (v < Model.NumMaterials) do begin
      // Set the material and texture for this subset
      Engine.ResMan.DX_Device.SetMaterial(Model.pMeshMaterials[v]);
      Engine.ResMan.DX_Device.SetTexture(0, Model.pMeshTextures[v]);
    
      // Draw the mesh subset
      Model.pMesh.DrawSubset(v);
    
      Inc(v);
     end;
    end;

  9. #49

    Re: 3d Engine Collision

    ok i found what the problem was, the model (.x) had to be centered... so what i mean is...

    if the model is 1, 1, 1 in 3dsmax

    i had to move the z co-ordinate to -0.5 why is this? and is there a way to set the mesh even if it has not been centered in 3ds max?

    thanks in advance.

    ---

    another problem.. on my computer. the box's drop at a steady rate, on my wifes laptop, they drop very fast and even bounce.

    which looks like it has something todo with newton update? when my FPS is low they drop fast. when it is high, they drop slow.

  10. #50

    Re: 3d Engine Collision

    Quote Originally Posted by Memphis
    ok i found what the problem was, the model (.x) had to be centered... so what i mean is...

    if the model is 1, 1, 1 in 3dsmax

    i had to move the z co-ordinate to -0.5 why is this? and is there a way to set the mesh even if it has not been centered in 3ds max?

    thanks in advance.

    ---

    another problem.. on my computer. the box's drop at a steady rate, on my wifes laptop, they drop very fast and even bounce.

    which looks like it has something todo with newton update? when my FPS is low they drop fast. when it is high, they drop slow.
    1. mesh may be transformed by a matrix or by vertices.

    2. you are sending fixed update time with a dynamic fps simulation.. send the proper deltatime to newton!
    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 5 of 6 FirstFirst ... 3456 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
  •