Official Pascal-Header (SDK 1.53), last update 26.05.2006

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Re: Official Pascal-Header (SDK 1.53), last update 26.05.2006

Postby Dave Gravel » Wed Dec 17, 2008 2:59 pm

You not really need to use this syntax ExtractTriangles(nil, nil); you can use ExtractTriangles; directly.
test:= street.MeshObjects.Items[0].ExtractTriangles;

Don't forget to create the list before try to use it.
You can do something like this:
test:=TAffineVectorList.create;
Load your data in your list.
test:= street.MeshObjects.Items[0].ExtractTriangles;
And sent it to the newton tree.
On final free your tmp list.
test.Free;

PS: don't forget too, the Faces is only a TVector3f and not a list.
NewtonTreeCollisionAddFace(terrain, 3, @faces[0], 12, 1);

12 is the pointer size: one single = 4 the TVector3f = 3 x 4 = 12.
On this case you can replace the 12 by the size of the data type that you use.
Exemple NewtonTreeCollisionAddFace(terrain, 3, @faces[0], SizeOf(TVector3f), 1);
On this way your all times sure to don't make error if exemple you use a other type like TVector because this one = 4 single.
SizeOf(TVector3f) = 12 and SizeOf(TVector) = 16

Good luck.
You search a nice physics solution, if you can read this message you're at the good place :wink:
OrionX3D Projects & Demos:
https://www.facebook.com/dave.gravel1
http://orionx3d.googlepages.com/
https://www.youtube.com/user/EvadLevarg/videos
User avatar
Dave Gravel
 
Posts: 725
Joined: Sat Apr 01, 2006 9:31 pm
Location: Quebec in Canada.

Re: Official Pascal-Header (SDK 1.53), last update 26.05.2006

Postby Kjow » Wed Dec 17, 2008 3:56 pm

Hi! Thank you for help me!

No luck at moment... here there is my codes.

This code crashes:

Code: Select all
  GLFreeForm1.LoadFromFile('rx8.3ds');
  Fcollision:= NewtonCreateTreeCollision(FNewtonworld, nil);

  NewtonTreeCollisionBeginBuild(Fcollision);

  test:=TAffineVectorList.create;
  faces:=TAffineVectorList.create;

  test:= GLFreeForm1.MeshObjects.Items[0].ExtractTriangles;

  for i:= 0 to test.Count div 3 do
   begin
    faces[0]:= test.Items[i*3 + 0]; //It crashes with this line
    //faces[1]:= test.Items[i*3 + 1];
    //faces[2]:= test.Items[i*3 + 2];

    NewtonTreeCollisionAddFace(Fcollision, 3, faces[0], 12, 1);
   end;

  //NewtonTreeCollisionEndBuild(Fcollision, 1);


This code freeze (problem with NewtonTreeCollisionEndBuild):

Code: Select all
  GLFreeForm1.LoadFromFile('rx8.3ds');
  Fcollision:= NewtonCreateTreeCollision(FNewtonworld, nil);

  NewtonTreeCollisionBeginBuild(Fcollision);

  test:=TAffineVectorList.create;
  faces:=TAffineVectorList.create;

  test:= GLFreeForm1.MeshObjects.Items[0].ExtractTriangles;

  for i:= 0 to test.Count div 3 do
   begin
    //faces[0]:= test.Items[i*3 + 0];
    //faces[1]:= test.Items[i*3 + 1];
    //faces[2]:= test.Items[i*3 + 2];

    NewtonTreeCollisionAddFace(Fcollision, 3, test.Items[i*3 + 0], 12, 1);
   end;

  NewtonTreeCollisionEndBuild(Fcollision, 1); // Freeze + crash here. With this line commented it works, but it doesn't collide with a cube that falls


Thank you again.
Kjow
 
Posts: 56
Joined: Thu Nov 13, 2008 11:33 am

Re: Official Pascal-Header (SDK 1.53), last update 26.05.2006

Postby Dave Gravel » Wed Dec 17, 2008 4:48 pm

It is more something like this:
Code: Select all
var
  faces: TVector3f;

  GLFreeForm1.LoadFromFile('rx8.3ds');
  Fcollision:= NewtonCreateTreeCollision(FNewtonworld, nil);

  NewtonTreeCollisionBeginBuild(Fcollision);

  test:=TAffineVectorList.create;

  test:= GLFreeForm1.MeshObjects.Items[0].ExtractTriangles;

  for i:= 0 to test.Count div 3 do
   begin
    faces[0]:= test.Items[i*3 + 0];
    faces[1]:= test.Items[i*3 + 1];
    faces[2]:= test.Items[i*3 + 2];

    NewtonTreeCollisionAddFace(Fcollision, 3, @faces[0], SizeOf(TVector3f), 1);
   end;

  NewtonTreeCollisionEndBuild(Fcollision, 1);
  test.Free;
You search a nice physics solution, if you can read this message you're at the good place :wink:
OrionX3D Projects & Demos:
https://www.facebook.com/dave.gravel1
http://orionx3d.googlepages.com/
https://www.youtube.com/user/EvadLevarg/videos
User avatar
Dave Gravel
 
Posts: 725
Joined: Sat Apr 01, 2006 9:31 pm
Location: Quebec in Canada.

Re: Official Pascal-Header (SDK 1.53), last update 26.05.2006

Postby Kjow » Wed Dec 17, 2008 5:11 pm

It doesn't work :(

I have the same problems :(
Kjow
 
Posts: 56
Joined: Thu Nov 13, 2008 11:33 am

Re: Official Pascal-Header (SDK 1.53), last update 26.05.2006

Postby Dave Gravel » Wed Dec 17, 2008 6:47 pm

Take more times to read the code exemple, maybe your better to learn more GLScene before too.
Examin my code your code and the delfi exemple and i'm pretty sure after you can see more where is your error.

Make sure to have the newton visual debug implemented in your project, because GLScene is a little bit a mess to use with physics engine.
GLScene is create at the base like a physics engine but without any auto force apply and auto collision.
You can active the collision and apply some force but it is not complet like a real physics engine, because it is a 3d tools first.
You can get problem about some matrix method, like the scale, and the children and parent system.
You need to deal with this both situation because newton work differently when you use a scaled matrix and newton can't work with the GLScene parent and children matrix system.
You need to make sure that your parented object is all times at position zero, and scale 1 if it is not the case you need to rest the scale in the matrix and you need to calcul the absolute matrix.
In this case you really need to know how GLScene work really.
You search a nice physics solution, if you can read this message you're at the good place :wink:
OrionX3D Projects & Demos:
https://www.facebook.com/dave.gravel1
http://orionx3d.googlepages.com/
https://www.youtube.com/user/EvadLevarg/videos
User avatar
Dave Gravel
 
Posts: 725
Joined: Sat Apr 01, 2006 9:31 pm
Location: Quebec in Canada.

Re: Official Pascal-Header (SDK 1.53), last update 26.05.2006

Postby Kjow » Wed Dec 17, 2008 7:35 pm

I know that I have much work to do... :)
But there is really poor documentation about glscene and newton... I need a working demo to learn better, but I can't find anything.

Can you post me a link to download a demo source with mesh collisions?

Thank you so much!
Kjow
 
Posts: 56
Joined: Thu Nov 13, 2008 11:33 am

Re: Official Pascal-Header (SDK 1.53), last update 26.05.2006

Postby JernejL » Thu Dec 18, 2008 3:16 pm

My code shoud not freeze, but i did only use it with small models, it could look as if it froze if you sent it larger mesh, try not using optimization in NewtonTreeCollisionEndBuild (second parameter).
Help improving the Newton Game Dynamics WIKI
User avatar
JernejL
 
Posts: 1531
Joined: Mon Dec 06, 2004 2:00 pm
Location: Slovenia

Re: Official Pascal-Header (SDK 1.53), last update 26.05.2006

Postby Dave Gravel » Thu Dec 18, 2008 5:02 pm

This is the method that I use personally but don't take care of all part's because some part is proper to my engine.
Anyway I think this code exemple can debug you a little bit.

Code: Select all
procedure oxInitStaMesh(dMesh: TOXNewtonStaMesh); stdcall; cdecl;
var
  mTmpFace: array[0..2] of TOXVector3;
  mTriangles: TAffineVectorList;
  mf: Integer;
  Attrib: Integer;
begin
  if Actived or (Manager=nil) then Exit;
  Attrib:=1;
  with dMesh.Newton do begin
    ContactID:=Manager.WorldDefaultMaterialID;
    Collision:=NewtonCreateTreeCollision(Manager.World);
    NewtonTreeCollisionBeginBuild(Collision);
    mTriangles:=dMesh.MeshObjects.ExtractTriangles;
    if (dMesh.NewtonCollisionScale.VectorLength=0) and
       (dMesh.NewtonCollisionPosition.VectorLength=0) and
       (dMesh.Scale.VectorLength<>0) then begin
      mTriangles.Scale(dMesh.Scale.AsAffineVector);
    end else begin
      if (dMesh.Scale.VectorLength<>0) and
         (dMesh.NewtonCollisionScale.VectorLength=0) then
        dMesh.NewtonCollisionScale.SetVector(dMesh.Scale.AsVector);
      mTriangles.Scale(dMesh.NewtonCollisionScale.AsAffineVector);
      mTriangles.Translate(dMesh.NewtonCollisionPosition.AsAffineVector);
    end;
    if (mTriangles.Count>0) then begin
      mf:=0;
    repeat
      mTmpFace[0]:=oxV3FToV3D(mTriangles[mf+0]);
      mTmpFace[1]:=oxV3FToV3D(mTriangles[mf+1]);
      mTmpFace[2]:=oxV3FToV3D(mTriangles[mf+2]);
      // Here it is a simple way to set face attibute but this method have already change on my version test.
      // The new implementation coming later on the next component version.
      if Assigned( FOnFacesAttribute ) then
        FOnFacesAttribute(mTriangles.Count,mf,Attrib);
      NewtonTreeCollisionAddFace(Collision,3,@mTmpFace[0],SizeOf(TOXVector3),Attrib);
      inc(mf,3);
    until mf>mTriangles.Count-1;
    end;
    NewtonTreeCollisionEndBuild(Collision,dMesh.NewtonTolerance);
    mTriangles.Free;
    Body:=NewtonCreateBody(Manager.World,Collision);
    ContactID:=Manager.WorldDefaultMaterialID;
    oxSetObjectMaterial(Body);
    NewtonBodySetUserData(Body,dMesh.Newton);
    NewtonReleaseCollision(Manager.World,Collision);
    Manager.AddLog('Stactic Mesh: '+dMesh.Name,1,':Info Object');
    Manager.AddLog(dMesh.Name+' InitNewton.',1,':Info Object');
    Actived:=True;
  end;
end;


Good luck.
You search a nice physics solution, if you can read this message you're at the good place :wink:
OrionX3D Projects & Demos:
https://www.facebook.com/dave.gravel1
http://orionx3d.googlepages.com/
https://www.youtube.com/user/EvadLevarg/videos
User avatar
Dave Gravel
 
Posts: 725
Joined: Sat Apr 01, 2006 9:31 pm
Location: Quebec in Canada.

Re: Official Pascal-Header (SDK 1.53), last update 26.05.2006

Postby Kjow » Fri Dec 19, 2008 7:27 pm

OK, now it works!The cube collides with 3ds file perfectly. :)

The problem now is that I can't apply the gravity to it. I can't to reuse cube (box) method... (it compiles, but it doesn't affect meshes)

Very much work to the end... :P

Thank you to all! I'll return soon :P
Kjow
 
Posts: 56
Joined: Thu Nov 13, 2008 11:33 am

Previous

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 2 guests