Add a function to obtain the unit vectors of a winding's edges.

This commit is contained in:
Bill Currie 2011-11-15 20:21:08 +09:00
parent e41da2f579
commit 662c04dfdc
2 changed files with 27 additions and 0 deletions

View file

@ -86,6 +86,15 @@ winding_t *CopyWinding (const winding_t *w);
*/
winding_t *CopyWindingReverse (const winding_t *w);
/** Create a new "winding" that holds the unit vectors of the edges of the
given winding.
\param w The winding to convert.
\return The "winding" holding the unit vectors.
\note It is the caller's responsibiltiy to free the new winding.
*/
winding_t *WindingVectors (const winding_t *w);
/** Clip the winding to the plain.
The new winding will be the part of the input winding that is on the

View file

@ -140,6 +140,24 @@ CopyWindingReverse (const winding_t *w)
return c;
}
winding_t *
WindingVectors (const winding_t *w)
{
int i;
size_t size;
winding_t *c;
size = (size_t) (uintptr_t) &((winding_t *) 0)->points[w->numpoints];
c = malloc (size);
c->numpoints = w->numpoints;
for (i = 0; i < w->numpoints; i++) {
VectorSubtract (w->points[(i + 1) % w->numpoints], w->points[i],
c->points[i]);
VectorNormalize (c->points[i]);
}
return c;
}
winding_t *
ClipWinding (winding_t *in, plane_t *split, qboolean keepon)
{