|
|
I read on this site about a collsion detection method where you determine if a vertice crosses a plane, and (if it does cross) if you create a temporary plane for each edge of the face that the plane belongs to, and calculate the vertex of the intersection and test it using classifyPoint(), if the point is within the region, classify_point will return PLANE_BACK, or something to that effect.
well, I thought it made sense to just check if the vertex you are checking for is behind all the faces that already exist for the 3d poly, instead of checking each infdividual face.
this works in theory, as far as I can tell, but it doesnt quite work in code. I'm not sure if all my planes' normals are facing outward, if I just have an error in my code, or if my theory is incorrect...
(and by the way, how do I do a source box for my code on this forum?)
code example:
// move from *position to *destination void moveIfNoCollision(Vertex3 *position, Vertex3 *destination) { extern WORLD world;
uint g, t, count; bool legal;
for (g=0; g < world.cntBrushes; g++) /* for each 3d shape */ { count = 0;
for (t=0; t < world.brush[g].cntFaces; t++) /* for each face of the shape */ if (classifyPoint(&world.poly[g].face[t], destination) == PLANE_BACK) /* if the point is behind this face's plane */ count++; else break; /* obviously, the destination is not inside this poly */
if (count == t) /* the point is behind every face's plane in the shape, which means that its inside! */ return; }
/** the function would have returned by now if there was a collision **/ *position = *destination;
return; }
|