A place to discuss everything related to Newton Dynamics.
Moderators: Sascha Willems, walaber
by 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.
-
blackbird_dream
-
- Posts: 354
- Joined: Wed Jun 07, 2006 3:08 pm
- Location: France
by 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
-
Dave Gravel
-
- Posts: 800
- Joined: Sat Apr 01, 2006 9:31 pm
- Location: Quebec in Canada.
-
by 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
-
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 30 guests