Code: procedure CreateBSPCollisionTree(const pSceneBSP : TQuake3BSP); var TmpFace : array[0..20] of TVector3f; TmpM : TMatrix4f; Min : TVector3f; Max : TVector3f; m,f : Integer; begin CollTreeBSP := NewtonCreateTreeCollision(NewtonWorld, nil); // Go through all meshes and add the faces of it to the tree collision NewtonTreeCollisionBeginBuild(CollTreeBSP); if pSceneBSP.numOfFaces > 0 then for f := 0 to pSceneBSP.numOfFaces-1 do If pSceneBSP.Faces[f].FaceType = 1 then begin for m := 0 to pSceneBSP.Faces[f].numOfVerts-1 do TmpFace[m] := pSceneBSP.Vertices[pSceneBSP.Faces[f].startVertIndex+m].Position; NewtonTreeCollisionAddFace(CollTreeBSP, m, @TmpFace[0], SizeOf(TVector3f), 1); end; NewtonTreeCollisionEndBuild(CollTreeBSP, 0); BodyBSP := NewtonCreateBody(NewtonWorld, CollTreeBSP); // Set position to 0/0/0 Matrix_SetIdentity(TmpM); NewtonBodySetMatrix(BodyBSP, @TmpM[0,0]); // Set material NewtonBodySetMaterialGroupID(BodyBSP, MatWorld); // Get AABB and set limits of the newton world NewtonCollisionCalculateAABB(CollTreeBSP, @TmpM[0,0], @Min, @Max); NewtonSetWorldSize(NewtonWorld, @Min, @Max); NewtonReleaseCollision(NewtonWorld, CollTreeBSP); end;
the only face that seems to have collision is the ceiling...... everything else the ball goes through.
To make the ball spawn above the ceiling:
Code: Matrix_SetTransform(BallMatrix, V4(-5,800,2));
EDIT: does the order u supply the vertex's in change anything? i.e with rendering it determins which side is visible (well with cull)
Code: Matrix_SetTransform(BallMatrix, V4(160,500,100));
the ball goes through the top of the box, and collides with the bottom...
EDIT2: reversing the order of the faces doesn't work, stops the box in the corner from having any collision.
EDIT3: above edit is wrong (made an error int he code), the collision thing should be the following (note: not all the faces have collisions, iv only noticed the roof and the box in the corner having collision):
Code: procedure CreateBSPCollisionTree(const pSceneBSP : TQuake3BSP); var TmpFace : array[0..20] of TVector3f; TmpM : TMatrix4f; Min : TVector3f; Max : TVector3f; m,f : Integer; begin CollTreeBSP := NewtonCreateTreeCollision(NewtonWorld, nil); // Go through all meshes and add the faces of it to the tree collision NewtonTreeCollisionBeginBuild(CollTreeBSP); if pSceneBSP.numOfFaces > 0 then for f := 0 to pSceneBSP.numOfFaces-1 do If pSceneBSP.Faces[f].FaceType = 1 then begin for m := 0 to pSceneBSP.Faces[f].numOfVerts-1 do TmpFace[m] := pSceneBSP.Vertices[pSceneBSP.Faces[f].startVertIndex+(pSceneBSP.Faces[f].numOfVerts-1-m)].Position; NewtonTreeCollisionAddFace(CollTreeBSP, m, @TmpFace[0], SizeOf(TVector3f), 1); end; NewtonTreeCollisionEndBuild(CollTreeBSP, 0); BodyBSP := NewtonCreateBody(NewtonWorld, CollTreeBSP); // Set position to 0/0/0 Matrix_SetIdentity(TmpM); NewtonBodySetMatrix(BodyBSP, @TmpM[0,0]); // Set material NewtonBodySetMaterialGroupID(BodyBSP, MatWorld); // Get AABB and set limits of the newton world NewtonCollisionCalculateAABB(CollTreeBSP, @TmpM[0,0], @Min, @Max); NewtonSetWorldSize(NewtonWorld, @Min, @Max); NewtonReleaseCollision(NewtonWorld, CollTreeBSP); end;
EDIT4: last edit did it, the problem was that the size of the ball was too small for the world (if im correct sometimes it had to much downward force for its size, so it jumped past the collision bit since it was so small. Increasing its size fixed the prob.).
What do i need to modify to make the ball move faster?
Dateianhänge: |
Dateikommentar: Collision now works!
glNewtonSceneBSP.zip [107.21 KiB]
378-mal heruntergeladen
|
|