};
#if 0
-qbyte NormalToByte(const vec3_t n)
+unsigned char NormalToByte(const vec3_t n)
{
int i, best;
float bestdistance, distance;
}
// note: uses byte partly to force unsigned for the validity check
-void ByteToNormal(qbyte num, vec3_t n)
+void ByteToNormal(unsigned char num, vec3_t n)
{
if (num < NUMVERTEXNORMALS)
VectorCopy(m_bytenormals[num], 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 )
{
d = DotProduct(forward, right);
VectorMA(right, -d, forward, right);
- VectorNormalizeFast(right);
+ VectorNormalize(right);
CrossProduct(right, forward, up);
}
+ (t0 * vr[2] + t1 * vu[2] + vf[2] * vf[2]) * point[2];
}
+/*-----------------------------------------------------------------*/
+
+// returns the smallest integer greater than or equal to "value", or 0 if "value" is too big
+unsigned int CeilPowerOf2(unsigned int value)
+{
+ unsigned int ceilvalue;
+
+ if (value > (1U << (sizeof(int) * 8 - 1)))
+ return 0;
+
+ ceilvalue = 1;
+ while (ceilvalue < value)
+ ceilvalue <<= 1;
+
+ return ceilvalue;
+}
+
+
/*-----------------------------------------------------------------*/
}
}
+#if 0
int BoxOnPlaneSide_Separate(const vec3_t emins, const vec3_t emaxs, const vec3_t normal, const vec_t dist)
{
switch((normal[0] < 0) | ((normal[1] < 0) << 1) | ((normal[2] < 0) << 2))
case 7: return (((normal[0] * emins[0] + normal[1] * emins[1] + normal[2] * emins[2]) >= dist) | (((normal[0] * emaxs[0] + normal[1] * emaxs[1] + normal[2] * emaxs[2]) < dist) << 1));
}
}
+#endif
void BoxPlaneCorners(const vec3_t emins, const vec3_t emaxs, const mplane_t *p, vec3_t outnear, vec3_t outfar)
{
case 5: outnear[0] = emins[0];outnear[1] = emaxs[1];outnear[2] = emins[2];outfar[0] = emaxs[0];outfar[1] = emins[1];outfar[2] = emaxs[2];break;
case 6: outnear[0] = emaxs[0];outnear[1] = emins[1];outnear[2] = emins[2];outfar[0] = emins[0];outfar[1] = emaxs[1];outfar[2] = emaxs[2];break;
case 7: outnear[0] = emins[0];outnear[1] = emins[1];outnear[2] = emins[2];outfar[0] = emaxs[0];outfar[1] = emaxs[1];outfar[2] = emaxs[2];break;
- }
+ }
}
void BoxPlaneCorners_Separate(const vec3_t emins, const vec3_t emaxs, const vec3_t normal, vec3_t outnear, vec3_t outfar)
case 5: outnear[0] = emins[0];outnear[1] = emaxs[1];outnear[2] = emins[2];outfar[0] = emaxs[0];outfar[1] = emins[1];outfar[2] = emaxs[2];break;
case 6: outnear[0] = emaxs[0];outnear[1] = emins[1];outnear[2] = emins[2];outfar[0] = emins[0];outfar[1] = emaxs[1];outfar[2] = emaxs[2];break;
case 7: outnear[0] = emins[0];outnear[1] = emins[1];outnear[2] = emins[2];outfar[0] = emaxs[0];outfar[1] = emaxs[1];outfar[2] = emaxs[2];break;
- }
+ }
}
void BoxPlaneCornerDistances(const vec3_t emins, const vec3_t emaxs, const mplane_t *p, vec_t *outneardist, vec_t *outfardist)
}
if (right || up)
{
- angle = angles[ROLL] * (M_PI*2 / 360);
- sr = sin(angle);
- cr = cos(angle);
- if (right)
+ if (angles[ROLL])
{
- right[0] = -1*(sr*sp*cy+cr*-sy);
- right[1] = -1*(sr*sp*sy+cr*cy);
- right[2] = -1*(sr*cp);
+ angle = angles[ROLL] * (M_PI*2 / 360);
+ sr = sin(angle);
+ cr = cos(angle);
+ if (right)
+ {
+ right[0] = -1*(sr*sp*cy+cr*-sy);
+ right[1] = -1*(sr*sp*sy+cr*cy);
+ right[2] = -1*(sr*cp);
+ }
+ if (up)
+ {
+ up[0] = (cr*sp*cy+-sr*-sy);
+ up[1] = (cr*sp*sy+-sr*cy);
+ up[2] = cr*cp;
+ }
}
- if (up)
+ else
{
- up[0] = (cr*sp*cy+-sr*-sy);
- up[1] = (cr*sp*sy+-sr*cy);
- up[2] = cr*cp;
+ if (right)
+ {
+ right[0] = sy;
+ right[1] = -cy;
+ right[2] = 0;
+ }
+ if (up)
+ {
+ up[0] = (sp*cy);
+ up[1] = (sp*sy);
+ up[2] = cp;
+ }
}
}
}
}
if (left || up)
{
- angle = angles[ROLL] * (M_PI*2 / 360);
- sr = sin(angle);
- cr = cos(angle);
- if (left)
+ if (angles[ROLL])
{
- left[0] = sr*sp*cy+cr*-sy;
- left[1] = sr*sp*sy+cr*cy;
- left[2] = sr*cp;
+ angle = angles[ROLL] * (M_PI*2 / 360);
+ sr = sin(angle);
+ cr = cos(angle);
+ if (left)
+ {
+ left[0] = sr*sp*cy+cr*-sy;
+ left[1] = sr*sp*sy+cr*cy;
+ left[2] = sr*cp;
+ }
+ if (up)
+ {
+ up[0] = cr*sp*cy+-sr*-sy;
+ up[1] = cr*sp*sy+-sr*cy;
+ up[2] = cr*cp;
+ }
}
- if (up)
+ else
{
- up[0] = cr*sp*cy+-sr*-sy;
- up[1] = cr*sp*sy+-sr*cy;
- up[2] = cr*cp;
+ if (left)
+ {
+ left[0] = -sy;
+ left[1] = cy;
+ left[2] = 0;
+ }
+ if (up)
+ {
+ up[0] = sp*cy;
+ up[1] = sp*sy;
+ up[2] = cp;
+ }
}
}
}
#include "matrixlib.h"
-void Matrix4x4_Print (const matrix4x4_t *in)
+void Matrix4x4_Print(const matrix4x4_t *in)
{
Con_Printf("%f %f %f %f\n%f %f %f %f\n%f %f %f %f\n%f %f %f %f\n"
, in->m[0][0], in->m[0][1], in->m[0][2], in->m[0][3]
return i;
}
+void BoxFromPoints(vec3_t mins, vec3_t maxs, int numpoints, vec_t *point3f)
+{
+ int i;
+ VectorCopy(point3f, mins);
+ VectorCopy(point3f, maxs);
+ for (i = 1, point3f += 3;i < numpoints;i++, point3f += 3)
+ {
+ mins[0] = min(mins[0], point3f[0]);maxs[0] = max(maxs[0], point3f[0]);
+ mins[1] = min(mins[1], point3f[1]);maxs[1] = max(maxs[1], point3f[1]);
+ mins[2] = min(mins[2], point3f[2]);maxs[2] = max(maxs[2], point3f[2]);
+ }
+}
+