29 #ifndef __MATH_VECTOR_H__
30 #define __MATH_VECTOR_H__
40 #define VECTOR_EPSILON 0.001f
58 explicit idVec2(
const float x,
const float y );
60 void Set(
const float x,
const float y );
84 float Length(
void )
const;
98 const char *
ToString(
int precision = 2 )
const;
104 #define vec2_zero vec2_origin
124 return ( (
x == a.
x ) && (
y == a.
y ) );
162 sqrLength =
x *
x +
y *
y;
167 return (
x *
x +
y *
y );
171 float sqrLength, invLength;
173 sqrLength =
x *
x +
y *
y;
177 return invLength * sqrLength;
181 float lengthSqr, invLength;
183 lengthSqr =
x *
x +
y *
y;
187 return invLength * lengthSqr;
199 if ( length2 > length * length ) {
212 }
else if (
x > max.
x ) {
217 }
else if (
y > max.
y ) {
223 x = floor(
x + 0.5
f );
224 y = floor(
y + 0.5
f );
241 return x * a.
x +
y * a.
y;
249 float inva = 1.0f /
a;
250 return idVec2(
x * inva,
y * inva );
276 float inva = 1.0f /
a;
323 explicit idVec3(
const float x,
const float y,
const float z );
325 void Set(
const float x,
const float y,
const float z );
355 float Length(
void )
const;
367 float ToYaw(
void )
const;
376 const char *
ToString(
int precision = 2 )
const;
390 #define vec3_zero vec3_origin
435 return x * a.
x +
y * a.
y +
z * a.
z;
443 float inva = 1.0f /
a;
444 return idVec3(
x * inva,
y * inva,
z * inva );
448 return idVec3( b.
x * a, b.
y * a, b.
z * a );
472 float inva = 1.0f /
a;
497 return ( (
x == a.
x ) && (
y == a.
y ) && (
z == a.
z ) );
525 float sqrLength, invLength;
527 sqrLength =
x *
x +
y *
y +
z *
z;
532 return invLength * sqrLength;
550 }
else if (
z == 0.0
f ) {
564 }
else if (
y == 0.0
f ) {
581 if (
y != 0.0
f ||
z != 0.0
f ) {
587 if (
x != 0.0
f ||
z != 0.0
f ) {
593 if (
x != 0.0
f ||
y != 0.0
f ) {
603 bool denormal =
false;
604 if ( fabs(
x ) < 1e-30
f ) {
608 if ( fabs(
y ) < 1e-30
f ) {
612 if ( fabs(
z ) < 1e-30
f ) {
624 x = a.
y * b.
z - a.
z * b.
y;
625 y = a.
z * b.
x - a.
x * b.
z;
626 z = a.
x * b.
y - a.
y * b.
x;
636 return (
x *
x +
y *
y +
z *
z );
642 sqrLength =
x *
x +
y *
y +
z *
z;
647 float sqrLength, invLength;
649 sqrLength =
x *
x +
y *
y +
z *
z;
654 return invLength * sqrLength;
666 if ( length2 > length * length ) {
680 }
else if (
x > max.
x ) {
685 }
else if (
y > max.
y ) {
690 }
else if (
z > max.
z ) {
696 x = floor(
x + 0.5
f );
697 y = floor(
y + 0.5
f );
698 z = floor(
z + 0.5
f );
712 return *
reinterpret_cast<const idVec2 *
>(
this);
716 return *
reinterpret_cast<idVec2 *
>(
this);
741 down = left.
Cross( *
this );
754 left[1] = -
x * up[2];
763 up[0] = -
z * left[1];
772 backoff = *
this * normal;
774 if ( overBounce != 1.0 ) {
776 backoff *= overBounce;
778 backoff /= overBounce;
782 *
this -= backoff * normal;
789 cross = this->
Cross( normal ).
Cross( (*
this) );
792 len = normal *
cross;
796 cross *= overBounce * ( normal * (*this) ) / len;
816 explicit idVec4(
const float x,
const float y,
const float z,
const float w );
818 void Set(
const float x,
const float y,
const float z,
const float w );
842 float Length(
void )
const;
855 const char *
ToString(
int precision = 2 )
const;
861 #define vec4_zero vec4_origin
873 ID_INLINE
void idVec4::Set(
const float x,
const float y,
const float z,
const float w ) {
881 x =
y =
z =
w = 0.0f;
901 return x * a.
x +
y * a.
y +
z * a.
z +
w * a.
w;
909 float inva = 1.0f /
a;
910 return idVec4(
x * inva,
y * inva,
z * inva,
w * inva );
914 return idVec4( b.
x * a, b.
y * a, b.
z * a, b.
w * a );
940 float inva = 1.0f /
a;
968 return ( (
x == a.
x ) && (
y == a.
y ) && (
z == a.
z ) &&
w == a.
w );
1004 return (
x *
x +
y *
y +
z *
z +
w *
w );
1008 float sqrLength, invLength;
1010 sqrLength =
x *
x +
y *
y +
z *
z +
w *
w;
1016 return invLength * sqrLength;
1020 float sqrLength, invLength;
1022 sqrLength =
x *
x +
y *
y +
z *
z +
w *
w;
1028 return invLength * sqrLength;
1036 return *
reinterpret_cast<const idVec2 *
>(
this);
1040 return *
reinterpret_cast<idVec2 *
>(
this);
1044 return *
reinterpret_cast<const idVec3 *
>(
this);
1048 return *
reinterpret_cast<idVec3 *
>(
this);
1076 explicit idVec5(
const float x,
const float y,
const float z,
const float s,
const float t );
1088 const char *
ToString(
int precision = 2 )
const;
1094 #define vec5_zero vec5_origin
1136 return *
reinterpret_cast<const idVec3 *
>(
this);
1140 return *
reinterpret_cast<idVec3 *
>(
this);
1161 explicit idVec6(
const float *
a );
1162 explicit idVec6(
const float a1,
const float a2,
const float a3,
const float a4,
const float a5,
const float a6 );
1164 void Set(
const float a1,
const float a2,
const float a3,
const float a4,
const float a5,
const float a6 );
1187 float Length(
void )
const;
1198 const char *
ToString(
int precision = 2 )
const;
1205 #define vec6_zero vec6_origin
1212 memcpy(
p, a, 6 *
sizeof(
float ) );
1215 ID_INLINE
idVec6::idVec6(
const float a1,
const float a2,
const float a3,
const float a4,
const float a5,
const float a6 ) {
1225 return idVec6( -
p[0], -
p[1], -
p[2], -
p[3], -
p[4], -
p[5] );
1237 return idVec6(
p[0]*a,
p[1]*a,
p[2]*a,
p[3]*a,
p[4]*a,
p[5]*a );
1241 return p[0] * a[0] +
p[1] * a[1] +
p[2] * a[2] +
p[3] * a[3] +
p[4] * a[4] +
p[5] * a[5];
1249 return idVec6(
p[0]*inva,
p[1]*inva,
p[2]*inva,
p[3]*inva,
p[4]*inva,
p[5]*inva );
1253 return idVec6(
p[0] + a[0],
p[1] + a[1],
p[2] + a[2],
p[3] + a[3],
p[4] + a[4],
p[5] + a[5] );
1257 return idVec6(
p[0] - a[0],
p[1] - a[1],
p[2] - a[2],
p[3] - a[3],
p[4] - a[4],
p[5] - a[5] );
1309 return ( (
p[0] == a[0] ) && (
p[1] == a[1] ) && (
p[2] == a[2] ) &&
1310 (
p[3] == a[3] ) && (
p[4] == a[4] ) && (
p[5] == a[5] ) );
1349 ID_INLINE
void idVec6::Set(
const float a1,
const float a2,
const float a3,
const float a4,
const float a5,
const float a6 ) {
1359 p[0] =
p[1] =
p[2] =
p[3] =
p[4] =
p[5] = 0.0f;
1367 return (
p[0] *
p[0] +
p[1] *
p[1] +
p[2] *
p[2] +
p[3] *
p[3] +
p[4] *
p[4] +
p[5] *
p[5] );
1371 float sqrLength, invLength;
1373 sqrLength =
p[0] *
p[0] +
p[1] *
p[1] +
p[2] *
p[2] +
p[3] *
p[3] +
p[4] *
p[4] +
p[5] *
p[5];
1381 return invLength * sqrLength;
1385 float sqrLength, invLength;
1387 sqrLength =
p[0] *
p[0] +
p[1] *
p[1] +
p[2] *
p[2] +
p[3] *
p[3] +
p[4] *
p[4] +
p[5] *
p[5];
1395 return invLength * sqrLength;
1403 return *
reinterpret_cast<const idVec3 *
>(
p + index * 3);
1407 return *
reinterpret_cast<idVec3 *
>(
p + index * 3);
1429 #define VECX_MAX_TEMP 1024
1430 #define VECX_QUAD( x ) ( ( ( ( x ) + 3 ) & ~3 ) * sizeof( float ) )
1431 #define VECX_CLEAREND() int s = size; while( s < ( ( s + 3) & ~3 ) ) { p[s++] = 0.0f; }
1432 #define VECX_ALLOCA( n ) ( (float *) _alloca16( VECX_QUAD( n ) ) )
1471 void Random(
int seed,
float l = 0.0
f,
float u = 1.0
f );
1477 float Length(
void )
const;
1490 const char *
ToString(
int precision = 2 )
const;
1545 for ( i = 0; i <
size; i++ ) {
1556 memcpy(
p, a.
p, a.
size *
sizeof(
float ) );
1571 for ( i = 0; i <
size; i++ ) {
1587 for ( i = 0; i <
size; i++ ) {
1600 for ( i = 0; i <
size; i++ ) {
1614 for ( i = 0; i <
size; i++ ) {
1630 for ( i = 0; i <
size; i++ ) {
1642 for ( i = 0; i <
size; i++ ) {
1651 return (*
this) * ( 1.0f /
a );
1656 (*this) *= ( 1.0f /
a );
1669 for ( i = 0; i <
size; i++ ) {
1670 sum +=
p[
i] * a.
p[
i];
1679 for ( i = 0; i <
size; i++ ) {
1680 if (
p[i] != a.
p[i] ) {
1691 for ( i = 0; i <
size; i++ ) {
1708 int alloc = ( newSize + 3 ) & ~3;
1721 int alloc = ( newSize + 3 ) & ~3;
1727 for (
int i = 0;
i <
size;
i++ ) {
1734 for (
int i =
size;
i < newSize;
i++ ) {
1746 alloced = ( newSize + 3 ) & ~3;
1760 assert( ( ( (
int) data ) & 15 ) == 0 );
1771 memset(
p, 0,
size *
sizeof(
float ) );
1780 memset(
p, 0,
size *
sizeof(
float ) );
1790 for ( i = 0; i <
size; i++ ) {
1802 for ( i = 0; i <
size; i++ ) {
1812 for ( i = 0; i <
size; i++ ) {
1820 for ( i = 0; i <
size; i++ ) {
1823 }
else if (
p[i] > max ) {
1841 for ( i = 0; i <
size; i++ ) {
1851 for ( i = 0; i <
size; i++ ) {
1860 float invSqrt, sum = 0.0f;
1863 for ( i = 0; i <
size; i++ ) {
1867 for ( i = 0; i <
size; i++ ) {
1868 m.
p[
i] =
p[
i] * invSqrt;
1874 float invSqrt, sum = 0.0f;
1876 for ( i = 0; i <
size; i++ ) {
1880 for ( i = 0; i <
size; i++ ) {
1883 return invSqrt * sum;
1891 assert( index >= 0 && index * 3 + 3 <=
size );
1892 return *
reinterpret_cast<idVec3 *
>(
p + index * 3);
1896 assert( index >= 0 && index * 3 + 3 <=
size );
1897 return *
reinterpret_cast<const idVec3 *
>(
p + index * 3);
1901 assert( index >= 0 && index * 6 + 6 <=
size );
1902 return *
reinterpret_cast<idVec6 *
>(
p + index * 6);
1906 assert( index >= 0 && index * 6 + 6 <=
size );
1907 return *
reinterpret_cast<const idVec6 *
>(
p + index * 6);
1948 this->theta =
theta;
1952 ID_INLINE
void idPolar3::Set(
const float radius,
const float theta,
const float phi ) {
1955 this->theta =
theta;
1979 float sp, cp,
st, ct;
1994 #define DotProduct( a, b) ((a)[0]*(b)[0]+(a)[1]*(b)[1]+(a)[2]*(b)[2])
1995 #define VectorSubtract( a, b, c ) ((c)[0]=(a)[0]-(b)[0],(c)[1]=(a)[1]-(b)[1],(c)[2]=(a)[2]-(b)[2])
1996 #define VectorAdd( a, b, c ) ((c)[0]=(a)[0]+(b)[0],(c)[1]=(a)[1]+(b)[1],(c)[2]=(a)[2]+(b)[2])
1997 #define VectorScale( v, s, o ) ((o)[0]=(v)[0]*(s),(o)[1]=(v)[1]*(s),(o)[2]=(v)[2]*(s))
1998 #define VectorMA( v, s, b, o ) ((o)[0]=(v)[0]+(b)[0]*(s),(o)[1]=(v)[1]+(b)[1]*(s),(o)[2]=(v)[2]+(b)[2]*(s))
1999 #define VectorCopy( a, b ) ((b)[0]=(a)[0],(b)[1]=(a)[1],(b)[2]=(a)[2])
idVec3 & operator/=(const idVec3 &a)
bool operator!=(const idVec2 &a) const
float operator*(const idVec2 &a) const
idVec6 & operator*=(const float a)
float operator[](const int index) const
idMat3 ToMat3(void) const
bool Compare(const idVec3 &a) const
bool Compare(const idVec4 &a) const
virtual void VPCALL Sub16(float *dst, const float *src1, const float *src2, const int count)=0
float operator*(const idVec3 &a) const
float LengthSqr(void) const
virtual void VPCALL SubAssign16(float *dst, const float *src, const int count)=0
void cross(float a[], float b[], float c[])
assert(prefInfo.fullscreenBtn)
void Set(const float a1, const float a2, const float a3, const float a4, const float a5, const float a6)
idVec2 & operator/=(const idVec2 &a)
float operator[](const int index) const
bool ProjectAlongPlane(const idVec3 &normal, const float epsilon, const float overBounce=1.0f)
const idVec3 & ToVec3(void) const
const float * ToFloatPtr(void) const
bool Compare(const idVec2 &a) const
int GetDimension(void) const
void Set(const float x, const float y, const float z)
const char * ToString(int precision=2) const
idVec2 operator/(const float a) const
idVecX & operator*=(const float a)
bool operator==(const idVec3 &a) const
idVecX operator*(const float a) const
float NormalizeFast(void)
idVec6 operator+(const idVec6 &a) const
const idVec3 & SubVec3(int index) const
idVecX & SwapElements(int e1, int e2)
void Set(const float radius, const float theta, const float phi)
static float Sqrt(float x)
idVec2 & Truncate(float length)
idVec6 & operator+=(const idVec6 &a)
bool operator==(const idVec4 &a) const
void Lerp(const idVec2 &v1, const idVec2 &v2, const float l)
idVecX & operator/=(const float a)
idVec3 Cross(const idVec3 &a) const
const char * ToString(int precision=2) const
const float * ToFloatPtr(void) const
void OrthogonalBasis(idVec3 &left, idVec3 &up) const
static void SinCos(float a, float &s, float &c)
virtual void VPCALL Zero16(float *dst, const int count)=0
const idVec2 & ToVec2(void) const
float NormalizeSelf(void)
void Clamp(const idVec3 &min, const idVec3 &max)
idVec3 & operator+=(const idVec3 &a)
idVec2 & operator-=(const idVec2 &a)
float operator[](const int index) const
float LengthFast(void) const
idVec6 operator/(const float a) const
idPolar3 & operator=(const idPolar3 &a)
GLfloat GLfloat GLfloat v2
ID_INLINE idVec2 operator*(const float a, const idVec2 b)
idVec3 & Truncate(float length)
void Random(int seed, float l=0.0f, float u=1.0f)
idVec3 & operator*=(const float a)
idVec4 & operator-=(const idVec4 &a)
idAngles ToAngles(void) const
idVec4 & operator*=(const float a)
GLubyte GLubyte GLubyte GLubyte w
virtual void VPCALL AddAssign16(float *dst, const float *src, const int count)=0
const idVec3 & SubVec3(int index) const
idVec3 & operator=(const idVec3 &a)
static float temp[VECX_MAX_TEMP+4]
static float Fabs(float f)
const char * ToString(int precision=2) const
float LengthSqr(void) const
idVec4 operator+(const idVec4 &a) const
const float * ToFloatPtr(void) const
GLsizei GLsizei GLenum GLenum const GLvoid * data
idVec3 ToVec3(void) const
virtual void VPCALL MulAssign16(float *dst, const float constant, const int count)=0
virtual void VPCALL Mul16(float *dst, const float *src1, const float constant, const int count)=0
void * Mem_Alloc16(const int size)
idVec6 & operator/=(const float a)
const char * ToString(int precision=2) const
bool Compare(const idVec6 &a) const
idVecX operator/(const float a) const
bool operator!=(const idVec3 &a) const
bool operator==(const idVecX &a) const
bool operator!=(const idVec6 &a) const
float NormalizeFast(void)
float operator[](int index) const
idVecX operator+(const idVecX &a) const
static float InvSqrt(float x)
float ToPitch(void) const
float LengthSqr(void) const
virtual void VPCALL Add16(float *dst, const float *src1, const float *src2, const int count)=0
GLubyte GLubyte GLubyte a
virtual void VPCALL Copy16(float *dst, const float *src, const int count)=0
const idVec6 & SubVec6(int index) const
bool FixDegenerateNormal(void)
const float * ToFloatPtr(void) const
idVec4 operator/(const float a) const
idVec4 & operator/=(const idVec4 &a)
const char * ToString(int precision=2) const
int GetDimension(void) const
const float * ToFloatPtr(void) const
float LengthSqr(void) const
idVecX Normalize(void) const
float operator*(const idVec4 &a) const
void ProjectSelfOntoSphere(const float radius)
void Clamp(const idVec2 &min, const idVec2 &max)
void ProjectOntoPlane(const idVec3 &normal, const float overBounce=1.0f)
bool operator!=(const idVecX &a) const
idVec2 operator+(const idVec2 &a) const
idVec2 & operator+=(const idVec2 &a)
idVec4 & operator+=(const idVec4 &a)
void Lerp(const idVec4 &v1, const idVec4 &v2, const float l)
const float * ToFloatPtr(void) const
void ChangeSize(int size, bool makeZero=false)
bool operator==(const idVec6 &a) const
void Mem_Free16(void *ptr)
idVec5 & operator=(const idVec3 &a)
idPolar3 operator-() const
idVecX & operator=(const idVecX &a)
GLsizei const GLcharARB const GLint * length
idVec6 operator*(const float a) const
bool operator==(const idVec2 &a) const
float operator[](const int index) const
void SetData(int length, float *data)
float LengthFast(void) const
float operator[](int index) const
bool Compare(const idVecX &a) const
const idVec3 & ToVec3(void) const
float NormalizeFast(void)
void Set(const float x, const float y)
void Lerp(const idVec5 &v1, const idVec5 &v2, const float l)
idVec3 operator+(const idVec3 &a) const
void Lerp(const idVec3 &v1, const idVec3 &v2, const float l)
int GetDimension(void) const
idVec2 & operator*=(const float a)
void Clamp(float min, float max)
bool operator!=(const idVec4 &a) const
void SLerp(const idVec3 &v1, const idVec3 &v2, const float l)
const idVec2 & ToVec2(void) const
idVecX & operator-=(const idVecX &a)
virtual void VPCALL Negate16(float *dst, const int count)=0
idVecX & operator+=(const idVecX &a)
int GetDimension(void) const
int GetDimension(void) const
idVec3 operator/(const float a) const
idVec6 & operator-=(const idVec6 &a)
void Set(const float x, const float y, const float z, const float w)
float operator[](const int index) const
const char * ToString(int precision=2) const
void NormalVectors(idVec3 &left, idVec3 &down) const
void SetTempSize(int size)
float LengthSqr(void) const
static float RSqrt(float x)
float NormalizeFast(void)
idPolar3 ToPolar(void) const
idVec3 & operator-=(const idVec3 &a)
int GetDimension(void) const
idSIMDProcessor * SIMDProcessor