A place to discuss everything related to Newton Dynamics.
Moderators: Sascha Willems, walaber
by Carli » Fri Jul 02, 2010 7:07 pm
- Code: Select all
main.pas(146,125) Error: Incompatible type for arg no. 4: Got "<address of procedure(const PNewtonBody);CDecl>", expected "PNewtonBodyIterator"
NewtonImport.pas(596,11) Hint: Found declaration: NewtonWorldForEachBodyInAABBDo(const PNewtonWorld,const PFloat,const PFloat,PNewtonBodyIterator,Pointer); CDecl;
that's a problem with the pascal header.
There are wrong type names but you can change that.
"PNewtonBodyIterator" is a pointer to the function pointer but it only needs to be a pointer to the function.
Just change "type PNewtonBodyIterator = ^NewtonBodyIterator" to "type PNewtonBodyIterator = NewtonBodyIterator" and everything is fine. (and just ignore stucuks suggestions with delphi compatibility flags.)
-
Carli
-
- Posts: 245
- Joined: Fri Oct 02, 2009 5:28 am
by Kjow » Sat Jul 03, 2010 4:02 am
Thank you, but no luck for me:
main.pas(136,103) Error: Incompatible type for arg no. 3: Got "<address of procedure(const PNewtonBody,LongInt,const PFloat,LongInt);CDecl>", expected "<procedure variable type of procedure(Pointer,LongInt,const PFloat,LongInt);CDecl>"
NewtonImport.pas(864,11) Hint: Found declaration: NewtonCollisionForEachPolygonDo(const PNewtonCollision,const PFloat,NewtonCollisionIterator,Pointer); CDecl;
main.pas(146,125) Error: Incompatible type for arg no. 4: Got "<address of procedure(const PNewtonBody);CDecl>", expected "<procedure variable type of procedure(const PNewtonBody,Pointer);CDecl>"
NewtonImport.pas(596,11) Hint: Found declaration: NewtonWorldForEachBodyInAABBDo(const PNewtonWorld,const PFloat,const PFloat,NewtonBodyIterator,Pointer); CDecl;
main.pas(426) Fatal: There were 2 errors compiling module, stopping
I tried changing each one or all together (from row 496 to row 506 of NewtonImport):
- Code: Select all
// 2.15 - Added parameter "userData" - SW
NewtonBodyIterator = procedure( const body : PNewtonBody; userData : Pointer ); cdecl;
PNewtonBodyIterator = {^}NewtonBodyIterator;
// 2.15 - Added parameter "userData" - SW
NewtonJointIterator = procedure( const joint : PNewtonJoint; userData : Pointer ); cdecl;
PNewtonJointIterator = {^}NewtonJointIterator;
NewtonCollisionIterator = procedure( userData : Pointer; vertexCount : int; const FaceArray : PFloat; faceId : int ); cdecl;
PNewtonCollisionIterator = {^}NewtonCollisionIterator;
-
Kjow
-
- Posts: 56
- Joined: Thu Nov 13, 2008 11:33 am
by Carli » Sat Jul 03, 2010 5:03 am
how did you address the function?
seems like you did not really edit the header.
-
Carli
-
- Posts: 245
- Joined: Fri Oct 02, 2009 5:28 am
by Kjow » Sat Jul 03, 2010 5:17 am
Carli wrote:how did you address the function?
seems like you did not really edit the header.
The code I'm using is the one in
this post, so:
- Code: Select all
// =============================================================================
// Debug_ShowGeometryCollision
// =============================================================================
// Callback that shows collision geometry of a body
// =============================================================================
procedure Debug_ShowGeometryCollision(const Body : PNewtonBody; VertexCount : Integer; const FaceArray : PFloat; FaceId : int); cdecl;
var
...
begin
...
end;
procedure Debug_ShowBodyCollision(const Body : PNewtonBody); cdecl;
var
...
begin
NewtonBodyGetMatrix(Body, @TmpM[0,0]);
NewtonCollisionForEachPolygonDo(NewtonBodyGetCollision(Body), @TmpM[0,0], @Debug_ShowGeometryCollision, nil);
end;
procedure Debug_ShowCollision;
begin
NewtonWorldForEachBodyInAABBDo(Form1.NewtonWorld, @(Form1.WorldSizeMin[0]), @(Form1.WorldSizeMax), @Debug_ShowBodyCollision, nil);
end;
And the header that I edited::
- Code: Select all
...
NewtonContactsProcess = procedure( const contact : PNewtonJoint; timestep : Float; threadIndex : int ); cdecl;
PNewtonContactsProcess = ^NewtonContactsProcess;
// 2.15 - Added parameter "userData" - SW
NewtonBodyIterator = procedure( const body : PNewtonBody; userData : Pointer ); cdecl;
PNewtonBodyIterator = NewtonBodyIterator;
// 2.15 - Added parameter "userData" - SW
NewtonJointIterator = procedure( const joint : PNewtonJoint; userData : Pointer ); cdecl;
PNewtonJointIterator = NewtonJointIterator;
NewtonCollisionIterator = procedure( userData : Pointer; vertexCount : int; const FaceArray : PFloat; faceId : int ); cdecl;
PNewtonCollisionIterator = NewtonCollisionIterator;
NewtonBallCallBack = procedure( const ball : PNewtonJoint; timestep : Float ); cdecl;
PNewtonBallCallBack = ^NewtonBallCallBack;
...
-
Kjow
-
- Posts: 56
- Joined: Thu Nov 13, 2008 11:33 am
by Stucuk » Sat Jul 03, 2010 5:19 am
Or he could just enable the Delphi Flag when compiling.
-

Stucuk
-
- Posts: 801
- Joined: Sat Mar 12, 2005 3:54 pm
- Location: Scotland
-
by Kjow » Sat Jul 03, 2010 6:12 am
Stucuk wrote:Or he could just enable the Delphi Flag when compiling.
Do you mean
- Code: Select all
{$IFDEF FPC}
{$MODE Delphi} { use Delphi compatibility mode } //This row
{$H+}
...
in delphinewton.inc OR i need to add {$MODE Delphi} at the beginning of NewtonImport.pas?
In delphinewton.inc it is already enabled and if I add it to NewtonImport.pas I need to disable it in delphinewton.inc. However, it doesn't work.
Editing it from {$MODE Delphi} to { $MODE Delphi} (to disable delphi mode), it doesn't work at the same way of posts above.
-
Kjow
-
- Posts: 56
- Joined: Thu Nov 13, 2008 11:33 am
by Carli » Sat Jul 03, 2010 6:58 am
Stucuk wrote:Or he could just enable the Delphi Flag when compiling.
with delphi flag, a buggy program will crash.
with objfpc-flag, it will just throw a compiling error.
AND: You have a wrong signature in the pascal header.
You have: NewtonContactsProcess = procedure( const contact : PNewtonJoint; timestep : Float; threadIndex : int ); cdecl;
You need: NewtonContactsProcess = function( const contact : PNewtonJoint; timestep : Float; threadIndex : int ): int; cdecl;
@Topic:
- Code: Select all
<address of procedure(const PNewtonBody,LongInt,const PFloat,LongInt);CDecl>
<procedure variable type of procedure(Pointer,LongInt,const PFloat,LongInt);CDecl>
Your header just expects "Pointer", your function expects "const PNewtonBody".
You can try two things:
- disable delphi flags in the header
- use "Pointer" as parameter data type for your Callback
-
Carli
-
- Posts: 245
- Joined: Fri Oct 02, 2009 5:28 am
by Kjow » Sat Jul 03, 2010 7:19 am
Carli wrote:@Topic:
- Code: Select all
<address of procedure(const PNewtonBody,LongInt,const PFloat,LongInt);CDecl>
<procedure variable type of procedure(Pointer,LongInt,const PFloat,LongInt);CDecl>
Your header just expects "Pointer", your function expects "const PNewtonBody".
You can try two things:
- disable delphi flags in the header
- use "Pointer" as parameter data type for your Callback
Thanks, now it works. I made these modifies in the header (in bold):
598: procedure NewtonWorldForEachBodyInAABBDo (const newtonWorld : PNewtonWorld; const p0 : PFloat; const p1 : PFloat; callback : Pointer
{PNewtonBodyIterator}; userData : Pointer); cdecl; external{$IFDEF __GPC__}name 'NewtonWorldForEachBodyInAABBDo'{$ELSE}NewtonDLL{$ENDIF __GPC__};
...
866: procedure NewtonCollisionForEachPolygonDo (const collision : PNewtonCollision; const matrix : PFloat; callback : Pointer
{NewtonCollisionIterator}; UserData : Pointer);cdecl; external{$IFDEF __GPC__}name 'NewtonCollisionForEachPolygonDo'{$ELSE}NewtonDLL{$ENDIF __GPC__};
Now I need to refine "Debug_ShowGeometryCollision" procedure... it add nodes every frame, slowing down very soon, but I THINK it works

Thank you!
PS enabling/disabling {$MODE Delphi} in delphinewton.inc has no effect to compiling/functionalities for me.
-
Kjow
-
- Posts: 56
- Joined: Thu Nov 13, 2008 11:33 am
by Kjow » Sat Jul 03, 2010 8:09 pm
Thanks, but it should be only for Delphi, not Lazarus (and it seems to be too customized).
-
Kjow
-
- Posts: 56
- Joined: Thu Nov 13, 2008 11:33 am
by Kjow » Sun Jul 04, 2010 6:02 am
With Iterators I saw that ConvewHull wasn't created correctly, so I fixed it and now it seems to be ok:

But I have an other problem: I create the GLFreeForm and I position it BEFORE to create the newton object (at the same way I do with GLCube), this is the result:

The only difference between the two builds is that in the 2nd I do GLFreeForm.Position.Y:=25;
Do you know why?
-
Kjow
-
- Posts: 56
- Joined: Thu Nov 13, 2008 11:33 am
by Stucuk » Sun Jul 04, 2010 8:49 am
Noone can know why based on screenshots. Noone knows what you have changed.
-

Stucuk
-
- Posts: 801
- Joined: Sat Mar 12, 2005 3:54 pm
- Location: Scotland
-
by Kjow » Sun Jul 04, 2010 6:14 pm
Stucuk wrote:Noone can know why based on screenshots. Noone knows what you have changed.
Kjow wrote:The only difference between the two builds is that in the 2nd I do GLFreeForm.Position.Y:=25;
I rephrase the question:
In Newton, are there some things to pay attention, when I create the physic objects?
Both builds are the same code; what 1st build does:
1) create mesh object
2) create physic object from mesh of 1)
The 2nd build:
1) create mesh object
2) positioning mesh on Y=25
3) create physic object from mesh of 1)
So, are there some things to pay attentions when physic objects (convexhull) are created?
Thanks.
PS in the 1st build convexhull (the wheel) is created ok and the cube interact right.
In the 2nd build position of Newton ConvexHull is not corresponding to the graphical mesh, but the convexhull interacts with the cube in the right way.
-
Kjow
-
- Posts: 56
- Joined: Thu Nov 13, 2008 11:33 am
by JernejL » Sun Jul 04, 2010 6:33 pm
to position a newton object you need to set it's matrix properly, but remember that if you want to offset objects, set the separate OFFSET matrix for that.
-

JernejL
-
- Posts: 1587
- Joined: Mon Dec 06, 2004 2:00 pm
- Location: Slovenia
-
by Kjow » Tue Jul 06, 2010 9:45 am
Ok, I finally found the problem. I should set as NIL the offsetMatrix.
- Code: Select all
dyn:= NewtonCreateConvexHull(
Newtonworld,
GLFreeForm.MeshObjects.Items[0].Vertices.Count,
NewtonImport.PFloat(GLFreeForm.MeshObjects.Items[0].Vertices.List),
sizeof(GLFreeForm.MeshObjects.Items[0].Vertices)*3,
0.002,
2,
NIL
);
Instead of:
- Code: Select all
dyn:= NewtonCreateConvexHull(
Newtonworld,
GLFreeForm.MeshObjects.Items[0].Vertices.Count,
NewtonImport.PFloat(GLFreeForm.MeshObjects.Items[0].Vertices.List),
sizeof(GLFreeForm.MeshObjects.Items[0].Vertices)*3,
0.002,
2,
NewtonImport.PFloat(GLFreeForm.AbsoluteMatrixAsAddress)
);
According to NewtonCreateConvexHull:
const dFloat *offsetMatrix - pointer to an array of 16 floats containing the offset matrix of the box relative to the body. If this parameter is NULL, then the primitive is centered at the origin of the body.
Thank you all!
Next step: to make realistic the ConvexHull behavior.
-
Kjow
-
- Posts: 56
- Joined: Thu Nov 13, 2008 11:33 am
Return to General Discussion
Who is online
Users browsing this forum: No registered users and 1 guest