From 662c04dfdc66188973b46cc2aa295100832c11d9 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Tue, 15 Nov 2011 20:21:08 +0900 Subject: [PATCH] Add a function to obtain the unit vectors of a winding's edges. --- include/QF/winding.h | 9 +++++++++ libs/models/winding.c | 18 ++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/include/QF/winding.h b/include/QF/winding.h index f1a779003..ca116dc20 100644 --- a/include/QF/winding.h +++ b/include/QF/winding.h @@ -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 diff --git a/libs/models/winding.c b/libs/models/winding.c index c5b06cb3a..e75be9731 100644 --- a/libs/models/winding.c +++ b/libs/models/winding.c @@ -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) {