A place to discuss everything related to Newton Dynamics.
Moderators: Sascha Willems, walaber
by JernejL » Sun Apr 16, 2006 9:16 am
aidave2 wrote:hey Sascha,
how do you get the full 3 normal values from the ray cast callback?
function ClosestWorldRayCastCallBack(
const ABody: PNewtonBody;
const AHitNormal: PFloat;
ACollisionID: Int;
AUserData: Pointer;
AIntersectParam: Float): Float;
use:
var
hitn: TVector3f;
begin
move(hitNormal, hitn, 12);
-
JernejL
-
- Posts: 1578
- Joined: Mon Dec 06, 2004 2:00 pm
- Location: Slovenia
-
by Sascha Willems » Fri May 26, 2006 8:14 am
I just updated the headers to 1.53. The header itself didn't change much, except for that the function NewtonWorldRayCast now has an additional parameter which is a prefilter callback for the raycast. So if you use this functionality, please get the newest header (and dll of course) and recompile your project.
-
Sascha Willems
- Moderator
-
- Posts: 346
- Joined: Fri Aug 27, 2004 10:18 am
- Location: Germany
-
by Dave Gravel » Fri May 26, 2006 1:00 pm
Thanks.
-
Dave Gravel
-
- Posts: 800
- Joined: Sat Apr 01, 2006 9:31 pm
- Location: Quebec in Canada.
-
by Sascha Willems » Sun May 28, 2006 9:45 am
Small updates to the header itself and the custom joint units, thanks to k00m for pointing out the missing function NewtonBodyGetForceAndTorqueCallback in the header and correct code for the limits of the corkscrew joint in the custom joints unit.
-
Sascha Willems
- Moderator
-
- Posts: 346
- Joined: Fri Aug 27, 2004 10:18 am
- Location: Germany
-
by JernejL » Thu Jul 06, 2006 4:59 pm
has anybody gotten the latest version of NGD working properly under latest lazarus / fpc? im getting some problems with major slowdowns, and i dont know whose fault it is..
-
JernejL
-
- Posts: 1578
- Joined: Mon Dec 06, 2004 2:00 pm
- Location: Slovenia
-
by Two » Thu Jul 20, 2006 5:16 am
Are you sure that this is right (the filter parameter)?
- Code: Select all
procedure NewtonWorldRayCast( const newtonWorld : PNewtonWorld; const p0 : PFloat; const p1 : PFloat;
filter : PNewtonWorldRayFilterCallback; userData: Pointer;
prefilter : NewtonWorldRayPrefilterCallback); cdecl; external{$IFDEF __GPC__}name 'NewtonWorldRayCast'{$ELSE}NewtonDLL{$ENDIF __GPC__};
I don't think that a pointer on a function (which is a pointer itself) makes much sense. And as far as I can tell, the NewtonWorldRayCast is defined without the pointer.
But I am not sure which way is right atm, since I can't seem to get the raycasting to work properly. No matter what definition I use and no matter what parameters I use, the filter function is never called at all. I tried the following code, which ensures that the ray goes through the body, but still the filter is never called, no matter what I do.
- Code: Select all
NewtonBodyGetMatrix(ribidBodyBox, @matrix);
target := VectorMake(0, 0, 0, 1);
target := VectorTransform(target, matrix);
raystart := VectorAdd(target, VectorMake(0, -5, 0));
rayend := VectorAdd(target, VectorMake(0, 5, 0));
NewtonWorldRayCast(world, @raystart, @rayend, CBRayFirstHit, nil, nil);
The debugger shows me that the ray coords are set right above and below my box, but I can't seem to get it to work properly.
Last edited by
Two on Thu Jul 20, 2006 7:51 am, edited 1 time in total.
-
Two
-
- Posts: 2
- Joined: Sun Jun 18, 2006 5:03 am
by JernejL » Thu Jul 20, 2006 5:23 am
i use this, which matches the way that all other newtons callback mechanisms work:
- Code: Select all
PNewtonWorldRayFilterCallback = function(const body: PNewtonBody; const hitNormal: Pfloat; collisionID: integer; userData: Pointer; integerersetParam: float): float; cdecl;
procedure NewtonWorldRayCast (const newtonWorld: PNewtonWorld; const p0: Pfloat; const p1: Pfloat; filter: PNewtonWorldRayFilterCallback; userData: Pointer; prefilter: PNewtonWorldRayPrefilterCallback); cdecl; external newtondll;
-
JernejL
-
- Posts: 1578
- Joined: Mon Dec 06, 2004 2:00 pm
- Location: Slovenia
-
by Two » Thu Jul 20, 2006 7:40 am
You could have done easier by just removing the P
- Code: Select all
procedure NewtonWorldRayCast( const newtonWorld : PNewtonWorld; const p0 : PFloat; const p1 : PFloat;
--> filter : NewtonWorldRayFilterCallback; userData: Pointer;
prefilter : NewtonWorldRayPrefilterCallback); cdecl; external{$IFDEF __GPC__}name 'NewtonWorldRayCast'{$ELSE}NewtonDLL{$ENDIF __GPC__};
-
Two
-
- Posts: 2
- Joined: Sun Jun 18, 2006 5:03 am
by firlefanz » Fri Sep 08, 2006 3:17 am
Hello,
I am totally new to Newton.
I am working on a 3D game. There is already a landscape, with static building/tree etc meshes and a moving player and some moving monsters.
I had problems with my collision detection and decided to give Newton a try.
I downloaded Newton, the Delphi headers and the Delphi Developer samples.
I am using Delphi 7 with DanJetX headers (3D headers based on Clooties DX9 headers). My Meshes are stored in an Engine that is based on a TList. I also have an 2 dim array with walkable positions.
First I want to have a simple collision detection, does this also include pathfinding?
Any tutorials or others sources to get a very first start?
Thanks,
Firlefanz
-
firlefanz
-
- Posts: 1
- Joined: Fri Sep 08, 2006 3:08 am
by Sascha Willems » Sat Sep 09, 2006 6:55 am
Pathfinding :
Pathfinding is not a part of NGD (or any other physics-SDK, since pathfinding has nothing to do with physics), there are some AI-engines out there that could do this for you but sadly I don't know of any AI-engine for Delphi/Pascal.
Collision :
Newton allows for you to create your own collision-handling, so if you only need collision detection without physics you can still use Newton's optimized functions for checking for collision. And it also doesn't matter how your meshes are stored as long as you have access to the triangles that you'll need to pass to Newton.
Just take a look (and use) the functions for generic collisions, like NewtonCollisionCollide, NewtonCollisionRayCast and so on.
P.S. : It would be a good idea to open up a separate thread for your question, as this is mainly a thread for feedback on the header conversion.
-
Sascha Willems
- Moderator
-
- Posts: 346
- Joined: Fri Aug 27, 2004 10:18 am
- Location: Germany
-
by aidave2 » Fri Mar 30, 2007 4:50 pm
Hi, I'm trying to figure out custom joints for the first time... its really confusing... I want to add something to the NewtonCustomJoints.pas file, like:
TNewtonCustomJointAnchor
It would just be a joint for one body,
the other body would be NULL,
then you can set the position of the joint,
and then the body tries to move to where the joint is.
Is this possible? Need help on this one...
- Code: Select all
// *****************************************************************************
// *****************************************************************************
constructor TNewtonCustomJointAnchor.Create(aChild : PNewtonBody; const AAnchorPointX, AAnchorPointY, AAnchorPointZ: single);
begin
FAnchorPointX := AAnchorPointX;
FAnchorPointY := AAnchorPointY;
FAnchorPointZ := AAnchorPointZ;
inherited
Create(1, aChild, nil);
end;
procedure TNewtonCustomJointAnchor.SubmitConstraint;
Begin
// Restrict the movement on the pivot point along all tree orthonormal direction
NewtonUserJointAddLinearRow(FJoint, @FAnchorPointX, @FAnchorPointY, @FAnchorPointZ);
end;
How do you change the "linearrow" to move the joint
-
aidave2
-
- Posts: 56
- Joined: Sun Jan 08, 2006 7:09 pm
-
by Dave Gravel » Tue Mar 18, 2008 11:01 am
Just a little fix in your TNewtonCustomJointCorkScrew.SubmitConstraint;
- Code: Select all
NewtonUserJointAddLinearRow(FJoint, @LP0[0], @LP1[0], @LMatrix0[1, 0]);
NewtonUserJointAddLInearRow(FJoint, @LP0[0], @LP1[0], @LMatrix1[2, 0]);
// Get a point along the pin axis at some reasonable large distance from the pivot
LQ0 := VAdd(LP0, VScale(V4(LMatrix0,0), MIN_JOINT_PIN_LENGTH));
LQ1 := VAdd(LP1, VScale(V4(LMatrix1,0), MIN_JOINT_PIN_LENGTH));
// Two constraints row perpendiculars to the hinge pin
NewtonUserJointAddLinearRow(FJoint, @LQ0[0], @LQ1[0], @LMatrix0[1, 0]);
NewtonUserJointAddLinearRow(FJoint, @LQ0[0], @LQ1[0], @LMatrix0[2, 0]);
////////////////////////////////////////////////////////////////
You have make a little error on the matrix here the fix.
Replace LMatrix1 by LMatrix0.
////////////////////////////////////////////////////////////////
NewtonUserJointAddLinearRow(FJoint, @LP0[0], @LP1[0], @LMatrix0[1, 0]);
NewtonUserJointAddLInearRow(FJoint, @LP0[0], @LP1[0], @LMatrix0[2, 0]);
// Get a point along the pin axis at some reasonable large distance from the pivot
LQ0 := VAdd(LP0, VScale(V4(LMatrix0,0), MIN_JOINT_PIN_LENGTH));
LQ1 := VAdd(LP1, VScale(V4(LMatrix1,0), MIN_JOINT_PIN_LENGTH));
// Two constraints row perpendiculars to the hinge pin
NewtonUserJointAddLinearRow(FJoint, @LQ0[0], @LQ1[0], @LMatrix0[1, 0]);
NewtonUserJointAddLinearRow(FJoint, @LQ0[0], @LQ1[0], @LMatrix0[2, 0]);
-
Dave Gravel
-
- Posts: 800
- Joined: Sat Apr 01, 2006 9:31 pm
- Location: Quebec in Canada.
-
by Kjow » Mon Dec 15, 2008 7:30 pm
Hi All,
I'm using Lazarus/FPC with GLScene + Newton, but I can't find documentation for learning to use Newton on pascal. Some demos work and compile fine (such as "newton very basic demo"), but I can't find explanations or more complex examples.
I can create a world and apply gravity to simple geometries (for example a cube that falls and collides with a plane) , but I don't know how do this with a 3ds file (it is loaded in a GLFreeForm).
Can you help me?
Thank you!
PS I'm sorry about my poor english!
-
Kjow
-
- Posts: 56
- Joined: Thu Nov 13, 2008 11:33 am
by JernejL » Tue Dec 16, 2008 1:59 pm
Kjow wrote:Hi All,
I'm using Lazarus/FPC with GLScene + Newton, but I can't find documentation for learning to use Newton on pascal. Some demos work and compile fine (such as "newton very basic demo"), but I can't find explanations or more complex examples.
I can create a world and apply gravity to simple geometries (for example a cube that falls and collides with a plane) , but I don't know how do this with a 3ds file (it is loaded in a GLFreeForm).
Can you help me?
Thank you!
PS I'm sorry about my poor english!
You can use oxnewton with glscene, but if you wish to create newton objects from glscene meshes directly, this code can help you out, one creates a convex hull and other creates a trimesh from a freeform:
- Code: Select all
function GetConvexHullFromFreeform(world:PNewtonWorld; aFreeform:TGLFreeform):PNewtonCollision;
var
aVertex: TAffineVector;
vertexList: TAffineVectorList;
vertexBuffer: pointer;
vertexPointer: pfloat;
vertexCount: integer;
begin
vertexList := TAffineVectorList(aFreeform.MeshObjects.ExtractTriangles);
GetMem(vertexBuffer, vertexList.count * 12);
vertexPointer:= vertexBuffer;
for vertexCount := 0 to vertexList.count-1 do
begin
aVertex := vertexList.items[vertexCount];
vertexPointer^ := aVertex[0];
inc(vertexPointer);
vertexPointer^ := aVertex[1];
inc(vertexPointer);
vertexPointer^ := aVertex[2];
inc(vertexPointer);
end;
result := NewtonCreateConvexHull(world,vertexList.count,vertexBuffer,3*sizeof(single),nil);
FreeMem(vertexbuffer);
end;
- Code: Select all
terrain:= NewtonCreateTreeCollision(nWorld, nil);
NewtonTreeCollisionBeginBuild(terrain);
test:= street.MeshObjects.Items[0].ExtractTriangles(nil, nil);
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(terrain, 3, @faces[0], 12, 1);
end;
NewtonTreeCollisionEndBuild(terrain, 1); // with optimization
-
JernejL
-
- Posts: 1578
- Joined: Mon Dec 06, 2004 2:00 pm
- Location: Slovenia
-
by Kjow » Wed Dec 17, 2008 2:08 pm
Thank you for code!
I have a trouble with trimesh...
My application crashes in "faces[0]:= test.Items[i*3 + 0]"... i don't know why, it crashes without errors.
I declared "faces" and "test" as TAffineVectorList.
Can you help me?
-
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 20 guests