M109uk
21-07-2007, 01:47 PM
Hi,
I'm having some more trouble with newton,
I'm trying to get collision detection with particles, at the moment i want the particle to "die" when it collides with something other than another particle.
In my test app, i have a face along the XZ plane with the particle system above it, dropping like rain (see screenshot).
I have a newton debug rendering (the white boxes in the particles and on the face).
http://www.pulse-soft.oneuk.com/images/stories/newtonparticle.jpg
When the app is created, i create the scene (in which creates an empty newton world object) and a material object, i then create the face using NewtonCreateTreeCollision and set the world size around the face with a height of -200 - 200, i apply the scene's material id to the object.
When i create the particle, i use the newton box, and create a new material that is used on all the particles with in the particle group. I am not using any newton physics with the particles, instead i update the particles matrix and send it to newton.
I have collision callbacks set to the materials, however none of them are called when a particle collides with the face.
Initialize newton for the face:
var
nColl: PNewtonCollision;
i: Integer;
v: Array [0..3] Of TVector3f;
tmpM: Geometry.TMatrix4f;
Min,Max: TVector3f;
begin
nColl := NewtonCreateTreeCollision(_XScene.World, Nil);
NewtonTreeCollisionBeginBuild(nColl);
v[0] := Vertices[3].Point;
v[1] := Vertices[2].Point;
v[2] := Vertices[1].Point;
v[3] := Vertices[0].Point;
NewtonTreeCollisionAddFace(nColl, 4, @v[0], SizeOf(TVector3f), 1);
NewtonTreeCollisionEndBuild(nColl, 0);
If nColl = Nil Then Exit;
_Body := NewtonCreateBody(_XScene.World, nColl);
tmpM := MatrixTransform(Position, Rotation, Vector3fMake(1, 1, 1));
NewtonBodySetMatrix(_Body, @tmpM[0, 0]);
NewtonBodySetMaterialGroupID(_Body, _XScene.MaterialID);
NewtonBodySetUserData(_Body, Self);
NewtonCollisionCalculateAABB(nColl, @tmpM[0, 0], @Min[0], @Max[0]);
If Min[0] > _XScene.WorldSize[0][0] Then _XScene.WorldSize[0][0] := Min[0];
If Min[1] > _XScene.WorldSize[0][1] Then _XScene.WorldSize[0][1] := Min[1];
If Min[2] > _XScene.WorldSize[0][2] Then _XScene.WorldSize[0][2] := Min[2];
If Max[0] > _XScene.WorldSize[1][0] Then _XScene.WorldSize[1][0] := Max[0];
If Max[0] > _XScene.WorldSize[1][1] Then _XScene.WorldSize[1][1] := Max[1];
If Max[0] > _XScene.WorldSize[1][2] Then _XScene.WorldSize[1][2] := Max[2];
_XScene.SetWorldSize;
NewtonReleaseCollision(_XScene.World, nColl);
end;
Scene newton:
fWorld := NewtonCreate(Nil, Nil);
// other code..
DefaultID := NewtonMaterialGetDefaultGroupID(fWorld);
fMaterialID := NewtonMaterialCreateGroupID(fWorld);
NewtonMaterialSetDefaultFriction(fWorld, DefaultID, fMaterialID, 0.01, 0.01);
NewtonMaterialSetDefaultElasticity(fWorld, DefaultID, fMaterialID, 0.01);
Particle Group:
fMaterialID := NewtonMaterialCreateGroupID(_XScene.World);
NewtonMaterialSetCollisionCallback(_XScene.World, _XScene.MaterialID, fMaterialID, @_XScene.MaterialID, @CollisionBegin, @CollisionWorld, Nil);
NewtonMaterialSetCollisionCallback(_XScene.World, fMaterialID, fMaterialID, @fMaterialID, @CollisionBegin, @CollisionParticle, Nil);
On particle move:
If (fParticles[Value].Body = Nil) And (fCollision) Then fParticles[Value].initNewton;
If fParticles[Value].Body <> Nil Then
Begin
tmpM := MatrixTransform(fParticlePosition, Vector3fMake(0, 0, 0), Vector3fMake(1, 1, 1));
NewtonBodySetMatrix(fParticles[Value].Body, @tmpM[0, 0]);
End;
Particle initialize newton:
var
nColl: PNewtonCollision;
Position: TVector3f;
maxSize: Single;
tmpM: TMatrix4f;
begin
If fBody <Nil> maxSize Then maxSize := TXParticleGroup(fOwner).EndSize;
Position := Vector3fMake(TXParticleGroup(fOwner).X, TXParticleGroup(fOwner).Y, TXParticleGroup(fOwner).Z);
nColl := NewtonCreateBox(_XScene.World, maxSize, maxSize, maxSize, Nil);
fBody := NewtonCreateBody(_XScene.World, nColl);
NewtonReleaseCollision(_XScene.World, nColl);
tmpM := MatrixTransform(Position, Vector3fMake(0, 0, 0), Vector3fMake(1, 1, 1));
NewtonBodySetMatrix(fBody, @tmpM[0, 0]);
NewtonBodySetMaterialGroupID(fBody, TXParticleGroup(fOwner).MaterialID);
NewtonBodySetUserData(fBody, Self);
end;
Im uterly stuck on this, and from all the examples i have looked at i can't see anything wrong..
Many thanks
I'm having some more trouble with newton,
I'm trying to get collision detection with particles, at the moment i want the particle to "die" when it collides with something other than another particle.
In my test app, i have a face along the XZ plane with the particle system above it, dropping like rain (see screenshot).
I have a newton debug rendering (the white boxes in the particles and on the face).
http://www.pulse-soft.oneuk.com/images/stories/newtonparticle.jpg
When the app is created, i create the scene (in which creates an empty newton world object) and a material object, i then create the face using NewtonCreateTreeCollision and set the world size around the face with a height of -200 - 200, i apply the scene's material id to the object.
When i create the particle, i use the newton box, and create a new material that is used on all the particles with in the particle group. I am not using any newton physics with the particles, instead i update the particles matrix and send it to newton.
I have collision callbacks set to the materials, however none of them are called when a particle collides with the face.
Initialize newton for the face:
var
nColl: PNewtonCollision;
i: Integer;
v: Array [0..3] Of TVector3f;
tmpM: Geometry.TMatrix4f;
Min,Max: TVector3f;
begin
nColl := NewtonCreateTreeCollision(_XScene.World, Nil);
NewtonTreeCollisionBeginBuild(nColl);
v[0] := Vertices[3].Point;
v[1] := Vertices[2].Point;
v[2] := Vertices[1].Point;
v[3] := Vertices[0].Point;
NewtonTreeCollisionAddFace(nColl, 4, @v[0], SizeOf(TVector3f), 1);
NewtonTreeCollisionEndBuild(nColl, 0);
If nColl = Nil Then Exit;
_Body := NewtonCreateBody(_XScene.World, nColl);
tmpM := MatrixTransform(Position, Rotation, Vector3fMake(1, 1, 1));
NewtonBodySetMatrix(_Body, @tmpM[0, 0]);
NewtonBodySetMaterialGroupID(_Body, _XScene.MaterialID);
NewtonBodySetUserData(_Body, Self);
NewtonCollisionCalculateAABB(nColl, @tmpM[0, 0], @Min[0], @Max[0]);
If Min[0] > _XScene.WorldSize[0][0] Then _XScene.WorldSize[0][0] := Min[0];
If Min[1] > _XScene.WorldSize[0][1] Then _XScene.WorldSize[0][1] := Min[1];
If Min[2] > _XScene.WorldSize[0][2] Then _XScene.WorldSize[0][2] := Min[2];
If Max[0] > _XScene.WorldSize[1][0] Then _XScene.WorldSize[1][0] := Max[0];
If Max[0] > _XScene.WorldSize[1][1] Then _XScene.WorldSize[1][1] := Max[1];
If Max[0] > _XScene.WorldSize[1][2] Then _XScene.WorldSize[1][2] := Max[2];
_XScene.SetWorldSize;
NewtonReleaseCollision(_XScene.World, nColl);
end;
Scene newton:
fWorld := NewtonCreate(Nil, Nil);
// other code..
DefaultID := NewtonMaterialGetDefaultGroupID(fWorld);
fMaterialID := NewtonMaterialCreateGroupID(fWorld);
NewtonMaterialSetDefaultFriction(fWorld, DefaultID, fMaterialID, 0.01, 0.01);
NewtonMaterialSetDefaultElasticity(fWorld, DefaultID, fMaterialID, 0.01);
Particle Group:
fMaterialID := NewtonMaterialCreateGroupID(_XScene.World);
NewtonMaterialSetCollisionCallback(_XScene.World, _XScene.MaterialID, fMaterialID, @_XScene.MaterialID, @CollisionBegin, @CollisionWorld, Nil);
NewtonMaterialSetCollisionCallback(_XScene.World, fMaterialID, fMaterialID, @fMaterialID, @CollisionBegin, @CollisionParticle, Nil);
On particle move:
If (fParticles[Value].Body = Nil) And (fCollision) Then fParticles[Value].initNewton;
If fParticles[Value].Body <> Nil Then
Begin
tmpM := MatrixTransform(fParticlePosition, Vector3fMake(0, 0, 0), Vector3fMake(1, 1, 1));
NewtonBodySetMatrix(fParticles[Value].Body, @tmpM[0, 0]);
End;
Particle initialize newton:
var
nColl: PNewtonCollision;
Position: TVector3f;
maxSize: Single;
tmpM: TMatrix4f;
begin
If fBody <Nil> maxSize Then maxSize := TXParticleGroup(fOwner).EndSize;
Position := Vector3fMake(TXParticleGroup(fOwner).X, TXParticleGroup(fOwner).Y, TXParticleGroup(fOwner).Z);
nColl := NewtonCreateBox(_XScene.World, maxSize, maxSize, maxSize, Nil);
fBody := NewtonCreateBody(_XScene.World, nColl);
NewtonReleaseCollision(_XScene.World, nColl);
tmpM := MatrixTransform(Position, Vector3fMake(0, 0, 0), Vector3fMake(1, 1, 1));
NewtonBodySetMatrix(fBody, @tmpM[0, 0]);
NewtonBodySetMaterialGroupID(fBody, TXParticleGroup(fOwner).MaterialID);
NewtonBodySetUserData(fBody, Self);
end;
Im uterly stuck on this, and from all the examples i have looked at i can't see anything wrong..
Many thanks