debugshow collision Lazarus Newton V3.14 [SOLVED]

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

debugshow collision Lazarus Newton V3.14 [SOLVED]

Postby blackbird_dream » Tue Oct 18, 2022 10:08 am

Absolute newbie question, sorry:
I'm currently tackling with lazarus & ND3.14
I'd like to display geometry collisions. I tried:
Code: Select all
procedure Debug_ShowGeometryCollision(userData: Pointer; vertexCount: integer; const faceVertex: PDFloat; id: integer) ; cdecl ;
var p0, p1: TVector3f;
    VerArr: PSingle;
    i: integer;
begin
  VerArr := PSingle(faceVertex);
  p0.V[0] := VerArr[(vertexCount - 1) * 3 + 0] ;
  p0.V[1] :=VerArr[(vertexCount - 1) * 3 + 1];
  p0.V[2] :=VerArr[(vertexCount - 1) * 3 + 2];
  for i := 0 to vertexCount -1 do begin
    p1.V[0] :=VerArr[(i * 3) + 0];
    p1.V[1] :=VerArr[(i * 3) + 1];
    p1.V[2] :=VerArr[(i * 3) + 2];
    form1.GLLines1.AddNode(VectorMake(p0.V[0], p0.V[1], p0.V[2]));
    form1.GLLines1.AddNode(VectorMake(p1.V[0], p1.V[1], p1.V[2]));
    form1.GLLines1.AddNode(VectorMake(1,1,1,1));
    form1.GLLines1.AddNode(VectorMake(1,1,1,1));
    p0 := p1;
  end;                                             
end ;                   

procedure Debug_ShowBodyCollision ; cdecl ;
var p0,p1:array[0..2] of single;
begin
 p0[0]:=-100.; p0[1]:=-100.; p0[2]:=-100.;
 p1[0]:=100.; p1[1]:=100.; p1[2]:=100.;
 NewtonWorldForEachBodyInAABBDo(form1.FNewtonWorld, p0, p1, @Debug_ShowGeometryCollision, nil);
end ;

procedure TForm1.GLSceneViewer1PostRender(Sender: TObject);
begin
  Debug_ShowBodyCollision ;
end;       


I tried to mix some pieces of codes from delphi, C++ unsuccessfully.
Last edited by blackbird_dream on Wed Oct 19, 2022 5:36 am, edited 1 time in total.
User avatar
blackbird_dream
 
Posts: 354
Joined: Wed Jun 07, 2006 3:08 pm
Location: France

Re: debugshow collision Lazarus Newton V3.14

Postby Dave Gravel » Tue Oct 18, 2022 3:11 pm

Hi blackbird_dream,
Sorry i'm late, I don't have get time to test in the code before today.

You can try to loop all body and use this function.
Here just a quick exemple with a single body, You can change it for loop all body.
Code: Select all
procedure Debug_ShowBodyCollision ; cdecl ;
var p0,p1:array[0..2] of single;
    amatrix: TMatrix;
begin
 p0[0]:=-100.; p0[1]:=-100.; p0[2]:=-100.;
 p1[0]:=100.; p1[1]:=100.; p1[2]:=100.;
 NewtonBodyGetMatrix(form1.boite, @amatrix.V[0].V[0]);
 NewtonCollisionForEachPolygonDo (NewtonBodyGetCollision(form1.boite), @amatrix.V[0].V[0], @Debug_ShowGeometryCollision, nil);
end ; 

Take a look inside this file newton-dynamics-master\newton-3.14\applications\demosSandbox\sdkDemos\toolBox\DebugDisplay.cpp


Code: Select all
procedure TForm1.GLSceneViewer1PostRender(Sender: TObject);
begin
  form1.GLLines1.Nodes.Clear;
  Debug_ShowBodyCollision ;
end; 


It surely needs some tweaking, but it seems to work from a quick test.
https://ibb.co/M88hqL7
You search a nice physics solution, if you can read this message you're at the good place :wink:
OrionX3D Projects & Demos:
https://orionx3d.sytes.net
https://www.facebook.com/dave.gravel1
https://www.youtube.com/user/EvadLevarg/videos
User avatar
Dave Gravel
 
Posts: 800
Joined: Sat Apr 01, 2006 9:31 pm
Location: Quebec in Canada.

Re: debugshow collision Lazarus Newton V3.14

Postby blackbird_dream » Wed Oct 19, 2022 4:01 am

thks to Dave's support, now it works.
Here is a way to make it work:

Code: Select all
procedure Debug_ShowGeometryCollision(userData: Pointer; vertexCount: integer; const faceVertex: PDFloat; id: integer) ; cdecl ;
var p0, p1: TVector3f;
    VerArr: PSingle;
    i: integer;
begin

  VerArr := PSingle(faceVertex);
  p0.V[0] := VerArr[(vertexCount - 1) * 3 + 0] ;
  p0.V[1] :=VerArr[(vertexCount - 1) * 3 + 1];
  p0.V[2] :=VerArr[(vertexCount - 1) * 3 + 2];
  for i := 0 to vertexCount -1 do begin
    p1.V[0] :=VerArr[(i * 3) + 0];
    p1.V[1] :=VerArr[(i * 3) + 1];
    p1.V[2] :=VerArr[(i * 3) + 2];
    form1.GLLines1.AddNode(VectorMake(p0.V[0], p0.V[1], p0.V[2]));
    form1.GLLines1.AddNode(VectorMake(p1.V[0], p1.V[1], p1.V[2]));
    p0 := p1;
  end;
end ;

procedure Debug_ShowBodyCollision ; cdecl ;
var
    body:Newtonbody;
    p0,p1:array[0..2] of single;
    amatrix: TMatrix;
begin
 body:=NewtonWorldGetFirstBody(form1.FNewtonworld);
 while Body <> nil do begin
   NewtonBodyGetMatrix(body, @amatrix.V[0].V[0]);
   NewtonCollisionForEachPolygonDo (NewtonBodyGetCollision(body), @amatrix.V[0].V[0], @Debug_ShowGeometryCollision, nil);
   Body:=NewtonWorldGetNextBody(form1.FNewtonWorld, Body);
 end;
end ;

procedure TForm1.GLSceneViewer1PostRender(Sender: TObject);
begin
  form1.GLLines1.Nodes.Clear;
  Debug_ShowBodyCollision ;
end;       


NB: in this snippet, glscene was used for OpenGL rendering stuffs
User avatar
blackbird_dream
 
Posts: 354
Joined: Wed Jun 07, 2006 3:08 pm
Location: France


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 35 guests