PDA

View Full Version : Newton physics and faces...



M109uk
20-01-2005, 09:51 PM
Hi all,

Yet another question :lol:

Iv choosen to use the Newton dynamics library for collision and physics, how ever i have no idea on how to implement this in to my world structure, i have looked around on the net but they either show how to use it with complete models or with predefined objects.

My world structure mostly consists of faces of course, 2 types i have a simple face, or a wall which consist of 6 faces in a cube shape, and i would like to assign each of these in to newton unless otherwise stated. I looked at some sources but they use the position value, which is fine if i use my simple face class but for my wall class it doesnt have a position for each of the faces.

I was thinking about doing it as the world being a huge model, but i will get problems with moving platforms, doors, and faces i dont want included in the collision detection?!

Secondly how can i go about using newton for stairs and other general actor actions?

Any help will be greatly appreciated :) thanx

tux
21-01-2005, 08:19 AM
for the level, terrain etc you can use a tree collision. but all moving parts of the world must not be included (tree collisions are static)

for other objects, you could use a convex hull

M109uk
21-01-2005, 05:30 PM
for the level, terrain etc you can use a tree collision. but all moving parts of the world must not be included (tree collisions are static)

for other objects, you could use a convex hull


Hey tux, thanx for the reply,

Ok i have built a function to generate the worlds collision tree from all the faces, a question before i use this:

For a face with 3 points :-

var
vertex: Array [0..2] Of TVertex3f;
begin
vertex[0] := Face.vertex[0];
vertex[1] := Face.vertex[1];
vertex[2] := Face.vertex[2];
NewtonTreeCollisionAddFace(nCollisionTree, 3, @vertex[0], SizeOf(TVertex3f), 1);
end;


But my face's contain 4 points, and have written it like :-

var
vertex: Array [0..3] Of TVertex3f;
begin
vertex[0] := Face.vertex[0];
vertex[1] := Face.vertex[1];
vertex[2] := Face.vertex[2];
vertex[3] := Face.vertex[3];
NewtonTreeCollisionAddFace(nCollisionTree, 4, @vertex[0], SizeOf(TVertex3f), 1);
end;


Is this the way to do this?


How do i use the convex hull procedure?

I have an actor mesh which is animated via a skeleton, how will i implement this in, i dont really want to use the sphere because the actors can be of all sorts of shapes and sizes?!

Thanx for your patients :)

tux
21-01-2005, 06:44 PM
from my testing app

V[0] := V3(-150, -150, 1.0);
V[1] := V3( 150, -150, 1.0);
V[2] := V3( 150, 150, 1.0);
NewtonTreeCollisionAddFace(Collider, 3, @V, SizeOf(TVector3f), 1);

V[0] := V3( 150, 150, 1.0);
V[1] := V3(-150, 150, 1.0);
V[2] := V3(-150, -150, 1.0);
NewtonTreeCollisionAddFace(Collider, 3, @V, SizeOf(TVector3f), 1);

you must have at least 2 faces in a collision tree.

is the actor mesh a ragdoll? in the next big release of newton there will be a ragdoll animation system

M109uk
21-01-2005, 07:44 PM
Yeah i have several faces, there inside a loop and a function is called to add a found face to the collision tree, e.g.

procedure AddFaceToCollisionTree(const Face: TFace);
var
vertex: Array [0..3] Of TVertex3f;
i: Integer;
begin
For i := 0 To 3 Do
vertex[i] := Face.Vertices[i];
NewtonTreeCollisionAddFace(nCollisionTree, 4, @vertex, SizeOf(TVertex3f), 1);
end;

procedure AddWorldToCollisionTree;

procedure CheckItem(WorldObj: TxnWorldObject);
var
i: Integer;
begin
If WorldObj is {Face object} Then
AddFaceToCollisionTree({Face Object}.Face);
If WorldObj is {Wall object} Then
For i := 0 To 5 Do AddFaceToCollisionTree({Wall object}.Faces[i]);
If WorldObj is {Polygon object} Then
For i := 0 To {Polygon object}.Children.Count-1 Do
CheckItem({Polygon object}.Children[i]);
If WorldObj is {Group object} Then
For i := 0 To {Group object}.Children.Count-1 Do
CheckItem({Group object}.Children[i]);
end;

var
i: Integer;
min,max: TVertex3f;
Matrix: TMatrix;
begin
nCollisionTree := NewtonCreateTreeCollision(nWorld, Nil);
NewtonTreeCollisionBeginBuild(nCollisionTree);

For i := 0 To World.Objects.Count-1 Do CheckItem(World.Objects[i]);

NewtonTreeCollisionEndBuild(nCollisionTree, 0);

StaticnWorld := NewtonCreateBody(nWorld, nCollisionTree);
SetIdentity(Matrix);
NewtonBodySetMatrix(staticnWorld, @Matrix[0,0]);
NewtonCollisionCalculateAABB(nCollisionTree, @Matrix[0,0], @min[0], @max[0]);
NewtonSetWorldSize(nWorld, @min[0], @max[0]);
end;

From most examples and sources i have seen the following function:

NewtonTreeCollisionAddFace(nCollisionTree, 3, @vertex, SizeOf(TVertex3f), 1);

uses a face that consists of 3 vertices, and vertex would be an array [0..2] of TVertex3f how ever i want to pass 4 vertices instead...



is the actor mesh a ragdoll? in the next big release of newton there will be a ragdoll animation system

Urm, i dont reall need any moving joints on it controlled via Newton. The only movments i need would be from the skeleton (walking, etc).

What advantages would there be for using it as a ragdoll and what kinda modifications would i need to do to my actor and its skeleton??

How ever i want to have a vehicle mesh with collision detection with each of the body parts, e.g the bumpers, doors, etc and when a damage level is reached the part falls off, would the ragdoll be usefull for this?

tux
22-01-2005, 07:21 PM
i cant really see anything wrong with the code. try asking at the newton forums

http://www.newtongamedynamics.com