provide a tighter accuracy (but slower) _VectorNormalize for the tools

This commit is contained in:
Bill Currie 2002-09-25 21:35:49 +00:00
parent 43d8cf9640
commit d25ee82838
14 changed files with 45 additions and 24 deletions

View File

@ -95,6 +95,7 @@ void _VectorScale (const vec3_t in, vec_t scale, vec3_t out);
void _VectorSubtract (const vec3_t veca, const vec3_t vecb, vec3_t out);
void CrossProduct (const vec3_t v1, const vec3_t v2, vec3_t cross);
float VectorNormalize (vec3_t v); // returns vector length
vec_t _VectorNormalize (vec3_t v); // returns vector length
void VectorInverse (vec3_t v);
int Q_log2(int val);

View File

@ -425,6 +425,25 @@ VectorNormalize (vec3_t v)
return length;
}
vec_t
_VectorNormalize (vec3_t v)
{
int i;
double length;
length = 0;
for (i=0 ; i < 3; i++)
length += v[i] * v[i];
length = sqrt (length);
if (length == 0)
return 0;
for (i=0 ; i <3; i++)
v[i] /= length;
return length;
}
void
VectorInverse (vec3_t v)
{

View File

@ -86,7 +86,7 @@ CheckFace (face_t *f)
Sys_Error ("CheckFace: degenerate edge");
CrossProduct (facenormal, dir, edgenormal);
VectorNormalize (edgenormal);
_VectorNormalize (edgenormal);
edgedist = DotProduct (p1, edgenormal);
edgedist += ON_EPSILON;
@ -569,7 +569,7 @@ AddHullEdge (vec3_t p1, vec3_t p2, int hullnum)
num_hull_edges++;
VectorSubtract (p1, p2, edgevec);
VectorNormalize (edgevec);
_VectorNormalize (edgevec);
for (a = 0; a < 3; a++) {
b = (a + 1) % 3;

View File

@ -391,7 +391,8 @@ CSGFaces (brushset_t *bs)
// these faces are continued in another brush, so get rid of them
if (b1->contents == CONTENTS_SOLID
&& b2->contents <= CONTENTS_WATER) FreeInside (b2->contents);
&& b2->contents <= CONTENTS_WATER)
FreeInside (b2->contents);
else
FreeInside (CONTENTS_SOLID);
}

View File

@ -323,7 +323,7 @@ ParseBrush (void)
free (f);
break;
}
VectorNormalize (f->plane.normal);
_VectorNormalize (f->plane.normal);
f->plane.dist = DotProduct (t3, f->plane.normal);
// fake proper texture vectors from QuakeEd style

View File

@ -42,11 +42,11 @@ CheckColinear (face_t *f)
// the vector to the next point
j = (i - 1 < 0) ? f->numpoints - 1 : i - 1;
VectorSubtract (f->pts[i], f->pts[j], v1);
VectorNormalize (v1);
_VectorNormalize (v1);
j = (i + 1 == f->numpoints) ? 0 : i + 1;
VectorSubtract (f->pts[j], f->pts[i], v2);
VectorNormalize (v2);
_VectorNormalize (v2);
if (_VectorCompare (v1, v2))
Sys_Error ("Colinear edge");
@ -121,7 +121,7 @@ TryMerge (face_t *f1, face_t *f2)
back = f1->pts[(i + f1->numpoints - 1) % f1->numpoints];
VectorSubtract (p1, back, delta);
CrossProduct (planenormal, delta, normal);
VectorNormalize (normal);
_VectorNormalize (normal);
back = f2->pts[(j + 2) % f2->numpoints];
VectorSubtract (back, p1, delta);
@ -133,7 +133,7 @@ TryMerge (face_t *f1, face_t *f2)
back = f1->pts[(i + 2) % f1->numpoints];
VectorSubtract (back, p2, delta);
CrossProduct (planenormal, delta, normal);
VectorNormalize (normal);
_VectorNormalize (normal);
back = f2->pts[(j + f2->numpoints - 1) % f2->numpoints];
VectorSubtract (back, p2, delta);

View File

@ -93,7 +93,7 @@ MarkLeakTrail (portal_t *n2)
VectorSubtract (p2, p1, dir);
len = VectorLength (dir);
VectorNormalize (dir);
_VectorNormalize (dir);
while (len > 2) {
fprintf (leakfile, "%f %f %f\n", p1[0], p1[1], p1[2]);

View File

@ -200,7 +200,7 @@ PlaneFromWinding (winding_t *w, plane_t *plane)
VectorSubtract (w->points[2], w->points[1], v1);
VectorSubtract (w->points[0], w->points[1], v2);
CrossProduct (v2, v1, plane->normal);
VectorNormalize (plane->normal);
_VectorNormalize (plane->normal);
plane->dist = DotProduct (w->points[0], plane->normal);
}

View File

@ -104,7 +104,7 @@ BaseWindingForPlane (plane_t *p)
v = DotProduct (vup, p->normal);
VectorMA (vup, -v, p->normal, vup);
VectorNormalize (vup);
_VectorNormalize (vup);
VectorScale (p->normal, p->dist, org);

View File

@ -246,7 +246,7 @@ HealEdges (int e1, int e2)
ed2 = &bsp->edges[e2];
VectorSubtract (bsp->vertexes[ed->v[1]].point,
bsp->vertexes[ed->v[0]].point, v1);
VectorNormalize (v1);
_VectorNormalize (v1);
if (ed->v[0] == ed2->v[0])
ed->v[0] = ed2->v[1];
@ -261,7 +261,7 @@ HealEdges (int e1, int e2)
VectorSubtract (bsp->vertexes[ed->v[1]].point,
bsp->vertexes[ed->v[0]].point, v2);
VectorNormalize (v2);
_VectorNormalize (v2);
if (!_VectorCompare (v1, v2))
Sys_Error ("HealEdges: edges not colinear");

View File

@ -87,7 +87,7 @@ SubdivideFace (face_t *f, face_t **prevptr)
VectorCopy (tex->vecs[axis], plane.normal);
v = VectorLength (plane.normal);
VectorNormalize (plane.normal);
_VectorNormalize (plane.normal);
plane.dist = (mins + options.subdivide_size - 16) / v;
next = f->next;
SplitFace (f, &plane, &front, &back);

View File

@ -110,7 +110,7 @@ HashVec (vec3_t vec)
void
CanonicalVector (vec3_t vec)
{
VectorNormalize (vec);
_VectorNormalize (vec);
if (vec[0] > EQUAL_EPSILON)
return;
else if (vec[0] < -EQUAL_EPSILON) {
@ -285,10 +285,10 @@ SplitFaceForTjunc (face_t *f, face_t *original)
restart:
// find the last corner
VectorSubtract (f->pts[f->numpoints - 1], f->pts[0], dir);
VectorNormalize (dir);
_VectorNormalize (dir);
for (lastcorner = f->numpoints - 1; lastcorner > 0; lastcorner--) {
VectorSubtract (f->pts[lastcorner - 1], f->pts[lastcorner], test);
VectorNormalize (test);
_VectorNormalize (test);
v = DotProduct (test, dir);
if (v < 0.9999 || v > 1.00001)
break;
@ -296,11 +296,11 @@ SplitFaceForTjunc (face_t *f, face_t *original)
// find the first corner
VectorSubtract (f->pts[1], f->pts[0], dir);
VectorNormalize (dir);
_VectorNormalize (dir);
for (firstcorner = 1; firstcorner < f->numpoints - 1; firstcorner++) {
VectorSubtract (f->pts[firstcorner + 1], f->pts[firstcorner],
test);
VectorNormalize (test);
_VectorNormalize (test);
v = DotProduct (test, dir);
if (v < 0.9999 || v > 1.00001)
break;

View File

@ -157,7 +157,7 @@ CalcFaceVectors (lightinfo_t *l)
tex->vecs[1][0] * tex->vecs[0][2];
texnormal[2] = tex->vecs[1][0] * tex->vecs[0][1] -
tex->vecs[1][1] * tex->vecs[0][0];
VectorNormalize (texnormal);
_VectorNormalize (texnormal);
// flip it towards plane normal
distscale = DotProduct (texnormal, l->facenormal);
@ -328,7 +328,7 @@ CalcPoints (lightinfo_t *l)
// move surf 8 pixels towards the center
VectorSubtract (facemid, surf, move);
VectorNormalize (move);
_VectorNormalize (move);
VectorMA (surf, 8, move, surf);
}
if (i == 2)
@ -361,7 +361,7 @@ SingleLightFace (entity_t *light, lightinfo_t *l)
if (light->targetent) {
VectorSubtract (light->targetent->origin, light->origin, spotvec);
VectorNormalize (spotvec);
_VectorNormalize (spotvec);
if (!light->angle)
falloff = -cos (20 * M_PI / 180);
else
@ -395,7 +395,7 @@ SingleLightFace (entity_t *light, lightinfo_t *l)
continue; // light doesn't reach
VectorSubtract (light->origin, surf, incoming);
VectorNormalize (incoming);
_VectorNormalize (incoming);
angle = DotProduct (incoming, l->facenormal);
if (light->targetent) {
// spotlight cutoff

View File

@ -101,7 +101,7 @@ PlaneFromWinding (winding_t *winding, plane_t *plane)
VectorSubtract (winding->points[2], winding->points[1], v1);
VectorSubtract (winding->points[0], winding->points[1], v2);
CrossProduct (v2, v1, plane->normal);
VectorNormalize (plane->normal);
_VectorNormalize (plane->normal);
plane->dist = DotProduct (winding->points[0], plane->normal);
}