]> git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
replaced uses of VectorNormalizeFast with VectorNormalize as it was broken on x86_64...
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Thu, 9 Jun 2005 11:57:24 +0000 (11:57 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Thu, 9 Jun 2005 11:57:24 +0000 (11:57 +0000)
made a lot of internal functions in portals.c static, and replaced two vector subtracts and a crossproduct with TriangleNormal

git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@5414 d7cf8633-e32d-0410-b094-e92efae38249

cg_math.h
cl_particles.c
mathlib.c
mathlib.h
portals.c
r_shadow.c

index e3dcece694218ddb0b951880c4a22a2197f8d38d..d8c539e1aa4cfa63f035f591324d8c71d4aed0fa 100644 (file)
--- a/cg_math.h
+++ b/cg_math.h
@@ -80,17 +80,6 @@ extern vec3_t vec3_origin;
 #define VectorScale(in, scale, out) ((out)[0] = (in)[0] * (scale),(out)[1] = (in)[1] * (scale),(out)[2] = (in)[2] * (scale))
 #define VectorCompare(a,b) (((a)[0]==(b)[0])&&((a)[1]==(b)[1])&&((a)[2]==(b)[2]))
 #define VectorMA(a, scale, b, c) ((c)[0] = (a)[0] + (scale) * (b)[0],(c)[1] = (a)[1] + (scale) * (b)[1],(c)[2] = (a)[2] + (scale) * (b)[2])
-#define VectorNormalizeFast(_v)\
-{\
-       float _y, _number;\
-       _number = DotProduct(_v, _v);\
-       if (_number != 0.0)\
-       {\
-               *((long *)&_y) = 0x5f3759df - ((* (long *) &_number) >> 1);\
-               _y = _y * (1.5f - (_number * 0.5f * _y * _y));\
-               VectorScale(_v, _y, _v);\
-       }\
-}
 #define VectorRandom(v) {do{(v)[0] = CGVM_RandomRange(-1, 1);(v)[1] = CGVM_RandomRange(-1, 1);(v)[2] = CGVM_RandomRange(-1, 1);}while(DotProduct(v, v) > 1);}
 
 void AngleVectors (vec3_t angles, vec3_t forward, vec3_t right, vec3_t up);
index 90f6fda6fdc873c8557ad9840300bb20da33e3b6..2e5d5259c6cdd0160499f71b9301243440d5994d 100644 (file)
@@ -25,7 +25,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #define NUMVERTEXNORMALS       162
 siextern float r_avertexnormals[NUMVERTEXNORMALS][3];
 #define m_bytenormals r_avertexnormals
-#define VectorNormalizeFast VectorNormalize
 #define CL_PointQ1Contents(v) (Mod_PointInLeaf(v,cl.worldmodel)->contents)
 typedef unsigned char qbyte;
 #define cl_stainmaps.integer 0
@@ -46,16 +45,16 @@ void R_CalcBeam_Vertex3f (float *vert, vec3_t org1, vec3_t org2, float width)
        vec3_t right1, right2, diff, normal;
 
        VectorSubtract (org2, org1, normal);
-       VectorNormalizeFast (normal);
+       VectorNormalize (normal);
 
        // calculate 'right' vector for start
        VectorSubtract (r_vieworigin, org1, diff);
-       VectorNormalizeFast (diff);
+       VectorNormalize (diff);
        CrossProduct (normal, diff, right1);
 
        // calculate 'right' vector for end
        VectorSubtract (r_vieworigin, org2, diff);
-       VectorNormalizeFast (diff);
+       VectorNormalize (diff);
        CrossProduct (normal, diff, right2);
 
        vert[ 0] = org1[0] + width * right1[0];
@@ -145,7 +144,7 @@ void VectorVectors(const vec3_t forward, vec3_t right, vec3_t up)
        right[0] -= d * forward[0];
        right[1] -= d * forward[1];
        right[2] -= d * forward[2];
-       VectorNormalizeFast(right);
+       VectorNormalize(right);
        CrossProduct(right, forward, up);
 }
 #if QW
@@ -977,7 +976,7 @@ void CL_Stardust (vec3_t mins, vec3_t maxs, int count)
                o[1] = lhrandom(mins[1], maxs[1]);
                o[2] = lhrandom(mins[2], maxs[2]);
                VectorSubtract(o, center, v);
-               VectorNormalizeFast(v);
+               VectorNormalize(v);
                VectorScale(v, 100, v);
                v[2] += sv_gravity.value * 0.15f;
                particle(particletype + pt_static, 0x903010, 0xFFD030, tex_particle, 1.5, lhrandom(64, 128) / cl_particles_quality.value, 128 / cl_particles_quality.value, 1, 0, o[0], o[1], o[2], v[0], v[1], v[2], 0.2);
@@ -2011,7 +2010,7 @@ void R_DrawParticleCallback(const void *calldata1, int calldata2)
        {
                R_CalcBeam_Vertex3f(particle_vertex3f, p->org, p->vel, size);
                VectorSubtract(p->vel, p->org, up);
-               VectorNormalizeFast(up);
+               VectorNormalize(up);
                v[0] = DotProduct(p->org, up) * (1.0f / 64.0f);
                v[1] = DotProduct(p->vel, up) * (1.0f / 64.0f);
                particle_texcoord2f[0] = 1;particle_texcoord2f[1] = v[0];
index 60a1a29dd781a5e506888895dafefe75963a5a7e..cdbe036466888fe9746ffbe5c5c311a485de6f62 100644 (file)
--- a/mathlib.c
+++ b/mathlib.c
@@ -141,17 +141,6 @@ void ByteToNormal(qbyte num, vec3_t n)
                VectorClear(n); // FIXME: complain?
 }
 
-float Q_RSqrt(float number)
-{
-       float y;
-
-       if (number == 0.0f)
-               return 0.0f;
-
-       *((int *)&y) = 0x5f3759df - ((* (int *) &number) >> 1);
-       return y * (1.5f - (number * 0.5f * y * y));
-}
-
 // assumes "src" is normalized
 void PerpendicularVector( vec3_t dst, const vec3_t src )
 {
@@ -216,7 +205,7 @@ void VectorVectors(const vec3_t forward, vec3_t right, vec3_t up)
 
        d = DotProduct(forward, right);
        VectorMA(right, -d, forward, right);
-       VectorNormalizeFast(right);
+       VectorNormalize(right);
        CrossProduct(right, forward, up);
 }
 
index 30d5b1d7f4c93d3c98939015ef318bfe2c3b353a..d5f6ee070da70d43541add0c8e6ad3528989e79e 100644 (file)
--- a/mathlib.h
+++ b/mathlib.h
@@ -83,17 +83,6 @@ extern vec3_t vec3_origin;
 #define VectorMAM(scale1, b1, scale2, b2, c) ((c)[0] = (scale1) * (b1)[0] + (scale2) * (b2)[0],(c)[1] = (scale1) * (b1)[1] + (scale2) * (b2)[1],(c)[2] = (scale1) * (b1)[2] + (scale2) * (b2)[2])
 #define VectorMAMAM(scale1, b1, scale2, b2, scale3, b3, c) ((c)[0] = (scale1) * (b1)[0] + (scale2) * (b2)[0] + (scale3) * (b3)[0],(c)[1] = (scale1) * (b1)[1] + (scale2) * (b2)[1] + (scale3) * (b3)[1],(c)[2] = (scale1) * (b1)[2] + (scale2) * (b2)[2] + (scale3) * (b3)[2])
 #define VectorMAMAMAM(scale1, b1, scale2, b2, scale3, b3, scale4, b4, c) ((c)[0] = (scale1) * (b1)[0] + (scale2) * (b2)[0] + (scale3) * (b3)[0] + (scale4) * (b4)[0],(c)[1] = (scale1) * (b1)[1] + (scale2) * (b2)[1] + (scale3) * (b3)[1] + (scale4) * (b4)[1],(c)[2] = (scale1) * (b1)[2] + (scale2) * (b2)[2] + (scale3) * (b3)[2] + (scale4) * (b4)[2])
-#define VectorNormalizeFast(_v)\
-{\
-       float _y, _number;\
-       _number = DotProduct(_v, _v);\
-       if (_number != 0.0)\
-       {\
-               *((long *)&_y) = 0x5f3759df - ((* (long *) &_number) >> 1);\
-               _y = _y * (1.5f - (_number * 0.5f * _y * _y));\
-               VectorScale(_v, _y, _v);\
-       }\
-}
 #define VectorRandom(v) do{(v)[0] = lhrandom(-1, 1);(v)[1] = lhrandom(-1, 1);(v)[2] = lhrandom(-1, 1);}while(DotProduct(v, v) > 1)
 #define VectorLerp(v1,lerp,v2,c) ((c)[0] = (v1)[0] + (lerp) * ((v2)[0] - (v1)[0]), (c)[1] = (v1)[1] + (lerp) * ((v2)[1] - (v1)[1]), (c)[2] = (v1)[2] + (lerp) * ((v2)[2] - (v1)[2]))
 #define VectorReflect(a,r,b,c) do{double d;d = DotProduct((a), (b)) * -(1.0 + (r));VectorMA((a), (d), (b), (c));}while(0)
index 88896dd7f04bff983c30f2caa8d9744b8b3f4e13..6df894264d40c563e552060ef3f3da7692b78ea4 100644 (file)
--- a/portals.c
+++ b/portals.c
@@ -13,7 +13,7 @@ static float portaltemppoints2[256][3];
 static int portal_markid = 0;
 static float boxpoints[4*3];
 
-int Portal_PortalThroughPortalPlanes(tinyplane_t *clipplanes, int clipnumplanes, float *targpoints, int targnumpoints, float *out, int maxpoints)
+static int Portal_PortalThroughPortalPlanes(tinyplane_t *clipplanes, int clipnumplanes, float *targpoints, int targnumpoints, float *out, int maxpoints)
 {
        int numpoints, i;
        if (targnumpoints < 3)
@@ -35,7 +35,7 @@ int Portal_PortalThroughPortalPlanes(tinyplane_t *clipplanes, int clipnumplanes,
        return numpoints;
 }
 
-int Portal_RecursiveFlowSearch (mleaf_t *leaf, vec3_t eye, int firstclipplane, int numclipplanes)
+static int Portal_RecursiveFlowSearch (mleaf_t *leaf, vec3_t eye, int firstclipplane, int numclipplanes)
 {
        mportal_t *p;
        int newpoints, i, prev;
@@ -71,7 +71,7 @@ int Portal_RecursiveFlowSearch (mleaf_t *leaf, vec3_t eye, int firstclipplane, i
                                        VectorSubtract(eye, portaltemppoints2[i], v1);
                                        VectorSubtract(portaltemppoints2[prev], portaltemppoints2[i], v2);
                                        CrossProduct(v1, v2, newplanes[i].normal);
-                                       VectorNormalizeFast(newplanes[i].normal);
+                                       VectorNormalize(newplanes[i].normal);
                                        newplanes[i].dist = DotProduct(eye, newplanes[i].normal);
                                        if (DotProduct(newplanes[i].normal, center) <= newplanes[i].dist)
                                        {
@@ -96,7 +96,7 @@ int Portal_RecursiveFlowSearch (mleaf_t *leaf, vec3_t eye, int firstclipplane, i
        return false;
 }
 
-void Portal_PolygonRecursiveMarkLeafs(mnode_t *node, float *polypoints, int numpoints)
+static void Portal_PolygonRecursiveMarkLeafs(mnode_t *node, float *polypoints, int numpoints)
 {
        int i, front;
        float *p;
@@ -158,7 +158,7 @@ int Portal_CheckPolygon(model_t *model, vec3_t eye, float *polypoints, int numpo
                VectorSubtract(eye, (&polypoints[i * 3]), v1);
                VectorSubtract((&polypoints[prev * 3]), (&polypoints[i * 3]), v2);
                CrossProduct(v1, v2, portalplanes[i].normal);
-               VectorNormalizeFast(portalplanes[i].normal);
+               VectorNormalize(portalplanes[i].normal);
                portalplanes[i].dist = DotProduct(eye, portalplanes[i].normal);
                if (DotProduct(portalplanes[i].normal, center) <= portalplanes[i].dist)
                {
@@ -265,8 +265,6 @@ int Portal_CheckBox(model_t *model, vec3_t eye, vec3_t a, vec3_t b)
        return false;
 }
 
-vec3_t trianglepoints[3];
-
 typedef struct portalrecursioninfo_s
 {
        int exact;
@@ -286,7 +284,7 @@ typedef struct portalrecursioninfo_s
 }
 portalrecursioninfo_t;
 
-void Portal_RecursiveFlow (portalrecursioninfo_t *info, mleaf_t *leaf, int firstclipplane, int numclipplanes)
+static void Portal_RecursiveFlow (portalrecursioninfo_t *info, mleaf_t *leaf, int firstclipplane, int numclipplanes)
 {
        mportal_t *p;
        int newpoints, i, prev;
@@ -382,18 +380,16 @@ void Portal_RecursiveFlow (portalrecursioninfo_t *info, mleaf_t *leaf, int first
                                        VectorAdd(center, portaltemppoints2[i], center);
                                // ixtable is a 1.0f / N table
                                VectorScale(center, ixtable[newpoints], center);
-                               // calculate the planes, and make sure the polygon can see it's own center
+                               // calculate the planes, and make sure the polygon can see its own center
                                newplanes = &portalplanes[firstclipplane + numclipplanes];
                                for (prev = newpoints - 1, i = 0;i < newpoints;prev = i, i++)
                                {
-                                       VectorSubtract(portaltemppoints2[prev], portaltemppoints2[i], v1);
-                                       VectorSubtract(info->eye, portaltemppoints2[i], v2);
-                                       CrossProduct(v1, v2, newplanes[i].normal);
-                                       VectorNormalizeFast(newplanes[i].normal);
+                                       TriangleNormal(portaltemppoints2[prev], portaltemppoints2[i], info->eye, newplanes[i].normal);
+                                       VectorNormalize(newplanes[i].normal);
                                        newplanes[i].dist = DotProduct(info->eye, newplanes[i].normal);
                                        if (DotProduct(newplanes[i].normal, center) <= newplanes[i].dist)
                                        {
-                                               // polygon can't see it's own center, discard and use parent portal
+                                               // polygon can't see its own center, discard and use parent portal
                                                break;
                                        }
                                }
@@ -406,7 +402,7 @@ void Portal_RecursiveFlow (portalrecursioninfo_t *info, mleaf_t *leaf, int first
        }
 }
 
-void Portal_RecursiveFindLeafForFlow(portalrecursioninfo_t *info, mnode_t *node)
+static void Portal_RecursiveFindLeafForFlow(portalrecursioninfo_t *info, mnode_t *node)
 {
        if (node->plane)
        {
index 523457a00cd92508c2a057bbb5fc15761103e262..b6f15c8d7f089076391c3826a8697cf210038d23 100644 (file)
@@ -1556,9 +1556,9 @@ static void R_Shadow_GenTexCoords_Specular_NormalCubeMap(float *out3f, int numve
        for (i = 0;i < numverts;i++, vertex3f += 3, svector3f += 3, tvector3f += 3, normal3f += 3, out3f += 3)
        {
                VectorSubtract(vertex3f, relativelightorigin, lightdir);
-               VectorNormalizeFast(lightdir);
+               VectorNormalize(lightdir);
                VectorSubtract(vertex3f, relativeeyeorigin, eyedir);
-               VectorNormalizeFast(eyedir);
+               VectorNormalize(eyedir);
                VectorAdd(lightdir, eyedir, halfdir);
                // the cubemap normalizes this for us
                out3f[0] = DotProduct(svector3f, halfdir);