Moderators: Sascha Willems, walaber
JoeJ wrote:Fixed tri is TF, lying on plane PF
Moving tri is T0 & T1, at planes P0 & P1
1. Check if all vertices T0 & T1 are on one side of PF - if so no intersection.
2. Take each moving vertex path (a line) and intersect with PF, giving a new triangle.
3. Clip this triangle between both planes P0 & P1 (like frustum clipping) giving a new polygon.
If this polygon has zero vertices, no intersection.
4. Clip this polygon inside TF (could be done in 2D). If polygon now has zero vertices, no intersection.
Else check distance poly vertices with plane P0 to find point of first intersection and time.
I'm not sure this works but think so. There should be something to find with google
I'm sure there are optimisations...
/////////////////////////////////////////////////////////////////////
// Clip a polygon to a plane.
/////////////////////////////////////////////////////////////////////
int ClipToPlane(polygon_t *pin, plane_t *pplane, polygon_t *pout)
{
int i, j, nextvert, curin, nextin;
double curdot, nextdot, scale;
point_t *pinvert, *poutvert;
pinvert = pin->verts;
poutvert = pout->verts;
curdot = DotProduct(pinvert, &pplane->normal);
curin = (curdot >= pplane->distance);
for (i=0 ; i<pin->numverts ; i++)
{
nextvert = (i + 1) % pin->numverts;
// Keep the current vertex if it's inside the plane
if (curin)
*poutvert++ = *pinvert;
nextdot = DotProduct(&pin->verts[nextvert], &pplane->normal);
nextin = (nextdot >= pplane->distance);
// Add a clipped vertex if one end of the current edge is
// inside the plane and the other is outside
if (curin != nextin)
{
scale = (pplane->distance - curdot) /
(nextdot - curdot);
for (j=0 ; j<3 ; j++)
{
poutvert->v[j] = pinvert->v[j] +
((pin->verts[nextvert].v[j] - pinvert->v[j]) *
scale);
}
poutvert++;
}
curdot = nextdot;
curin = nextin;
pinvert++;
}
pout->numverts = poutvert - pout->verts;
if (pout->numverts < 3)
return 0;
pout->color = pin->color;
return 1;
}
JoeJ wrote:Turing test failed
Users browsing this forum: No registered users and 3 guests