Jedi Outcast v056
This commit is contained in:
parent
ccbb2c0000
commit
b2f9cf6f08
1054 changed files with 451439 additions and 46076 deletions
BIN
CODE-mp/Final/jk2/winquake.res
Normal file
BIN
CODE-mp/Final/jk2/winquake.res
Normal file
Binary file not shown.
BIN
CODE-mp/Release/jk2/winquake.res
Normal file
BIN
CODE-mp/Release/jk2/winquake.res
Normal file
Binary file not shown.
|
@ -1,129 +0,0 @@
|
|||
#include "q_shared.h"
|
||||
#include <float.h>
|
||||
|
||||
angles_t ang_zero( 0.0f, 0.0f, 0.0f );
|
||||
|
||||
void toAngles( mat3_t &src, angles_t &dst ) {
|
||||
double theta;
|
||||
double cp;
|
||||
double sp;
|
||||
|
||||
sp = src[ 0 ][ 2 ];
|
||||
|
||||
// cap off our sin value so that we don't get any NANs
|
||||
if ( sp > 1.0 ) {
|
||||
sp = 1.0;
|
||||
} else if ( sp < -1.0 ) {
|
||||
sp = -1.0;
|
||||
}
|
||||
|
||||
theta = -asin( sp );
|
||||
cp = cos( theta );
|
||||
|
||||
if ( cp > 8192 * FLT_EPSILON ) {
|
||||
dst.pitch = theta * 180 / M_PI;
|
||||
dst.yaw = atan2( src[ 0 ][ 1 ], src[ 0 ][ 0 ] ) * 180 / M_PI;
|
||||
dst.roll = atan2( src[ 1 ][ 2 ], src[ 2 ][ 2 ] ) * 180 / M_PI;
|
||||
} else {
|
||||
dst.pitch = theta * 180 / M_PI;
|
||||
dst.yaw = -atan2( src[ 1 ][ 0 ], src[ 1 ][ 1 ] ) * 180 / M_PI;
|
||||
dst.roll = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void toAngles( quat_t &src, angles_t &dst ) {
|
||||
mat3_t temp;
|
||||
|
||||
toMatrix( src, temp );
|
||||
toAngles( temp, dst );
|
||||
}
|
||||
|
||||
void toAngles( idVec3_t &src, angles_t &dst ) {
|
||||
dst.pitch = src[ 0 ];
|
||||
dst.yaw = src[ 1 ];
|
||||
dst.roll = src[ 2 ];
|
||||
}
|
||||
|
||||
void angles_t::toVectors( idVec3_t *forward, idVec3_t *right, idVec3_t *up ) {
|
||||
float angle;
|
||||
static float sr, sp, sy, cr, cp, cy; // static to help MS compiler fp bugs
|
||||
|
||||
angle = yaw * ( M_PI * 2 / 360 );
|
||||
sy = sin( angle );
|
||||
cy = cos( angle );
|
||||
|
||||
angle = pitch * ( M_PI * 2 / 360 );
|
||||
sp = sin( angle );
|
||||
cp = cos( angle );
|
||||
|
||||
angle = roll * ( M_PI * 2 / 360 );
|
||||
sr = sin( angle );
|
||||
cr = cos( angle );
|
||||
|
||||
if ( forward ) {
|
||||
forward->set( cp * cy, cp * sy, -sp );
|
||||
}
|
||||
|
||||
if ( right ) {
|
||||
right->set( -sr * sp * cy + cr * sy, -sr * sp * sy + -cr * cy, -sr * cp );
|
||||
}
|
||||
|
||||
if ( up ) {
|
||||
up->set( cr * sp * cy + -sr * -sy, cr * sp * sy + -sr * cy, cr * cp );
|
||||
}
|
||||
}
|
||||
|
||||
idVec3_t angles_t::toForward( void ) {
|
||||
float angle;
|
||||
static float sp, sy, cp, cy; // static to help MS compiler fp bugs
|
||||
|
||||
angle = yaw * ( M_PI * 2 / 360 );
|
||||
sy = sin( angle );
|
||||
cy = cos( angle );
|
||||
|
||||
angle = pitch * ( M_PI * 2 / 360 );
|
||||
sp = sin( angle );
|
||||
cp = cos( angle );
|
||||
|
||||
return idVec3_t( cp * cy, cp * sy, -sp );
|
||||
}
|
||||
|
||||
/*
|
||||
=================
|
||||
Normalize360
|
||||
|
||||
returns angles normalized to the range [0 <= angle < 360]
|
||||
=================
|
||||
*/
|
||||
angles_t& angles_t::Normalize360( void ) {
|
||||
pitch = (360.0 / 65536) * ( ( int )( pitch * ( 65536 / 360.0 ) ) & 65535 );
|
||||
yaw = (360.0 / 65536) * ( ( int )( yaw * ( 65536 / 360.0 ) ) & 65535 );
|
||||
roll = (360.0 / 65536) * ( ( int )( roll * ( 65536 / 360.0 ) ) & 65535 );
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
=================
|
||||
Normalize180
|
||||
|
||||
returns angles normalized to the range [-180 < angle <= 180]
|
||||
=================
|
||||
*/
|
||||
angles_t& angles_t::Normalize180( void ) {
|
||||
Normalize360();
|
||||
|
||||
if ( pitch > 180.0 ) {
|
||||
pitch -= 360.0;
|
||||
}
|
||||
|
||||
if ( yaw > 180.0 ) {
|
||||
yaw -= 360.0;
|
||||
}
|
||||
|
||||
if ( roll > 180.0 ) {
|
||||
roll -= 360.0;
|
||||
}
|
||||
return *this;
|
||||
}
|
|
@ -1,174 +0,0 @@
|
|||
#ifndef __MATH_ANGLES_H__
|
||||
#define __MATH_ANGLES_H__
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "math_vector.h"
|
||||
|
||||
class mat3_t;
|
||||
class quat_t;
|
||||
class idVec3_t;
|
||||
typedef idVec3_t &vec3_p;
|
||||
|
||||
class angles_t {
|
||||
public:
|
||||
float pitch;
|
||||
float yaw;
|
||||
float roll;
|
||||
|
||||
angles_t();
|
||||
angles_t( float pitch, float yaw, float roll );
|
||||
angles_t( const idVec3_t &vec );
|
||||
|
||||
friend void toAngles( idVec3_t &src, angles_t &dst );
|
||||
friend void toAngles( quat_t &src, angles_t &dst );
|
||||
friend void toAngles( mat3_t &src, angles_t &dst );
|
||||
|
||||
operator vec3_p();
|
||||
|
||||
float operator[]( int index ) const;
|
||||
float& operator[]( int index );
|
||||
|
||||
void set( float pitch, float yaw, float roll );
|
||||
|
||||
void operator=( angles_t const &a );
|
||||
void operator=( idVec3_t const &a );
|
||||
|
||||
friend angles_t operator+( const angles_t &a, const angles_t &b );
|
||||
angles_t &operator+=( angles_t const &a );
|
||||
angles_t &operator+=( idVec3_t const &a );
|
||||
|
||||
friend angles_t operator-( angles_t &a, angles_t &b );
|
||||
angles_t &operator-=( angles_t &a );
|
||||
|
||||
friend angles_t operator*( const angles_t &a, float b );
|
||||
friend angles_t operator*( float a, const angles_t &b );
|
||||
angles_t &operator*=( float a );
|
||||
|
||||
friend int operator==( angles_t &a, angles_t &b );
|
||||
|
||||
friend int operator!=( angles_t &a, angles_t &b );
|
||||
|
||||
void toVectors( idVec3_t *forward, idVec3_t *right = NULL, idVec3_t *up = NULL );
|
||||
idVec3_t toForward( void );
|
||||
|
||||
angles_t &Zero( void );
|
||||
|
||||
angles_t &Normalize360( void );
|
||||
angles_t &Normalize180( void );
|
||||
};
|
||||
|
||||
extern angles_t ang_zero;
|
||||
|
||||
inline angles_t::angles_t() {}
|
||||
|
||||
inline angles_t::angles_t( float pitch, float yaw, float roll ) {
|
||||
this->pitch = pitch;
|
||||
this->yaw = yaw;
|
||||
this->roll = roll;
|
||||
}
|
||||
|
||||
inline angles_t::angles_t( const idVec3_t &vec ) {
|
||||
this->pitch = vec.x;
|
||||
this->yaw = vec.y;
|
||||
this->roll = vec.z;
|
||||
}
|
||||
|
||||
inline float angles_t::operator[]( int index ) const {
|
||||
assert( ( index >= 0 ) && ( index < 3 ) );
|
||||
return ( &pitch )[ index ];
|
||||
}
|
||||
|
||||
inline float& angles_t::operator[]( int index ) {
|
||||
assert( ( index >= 0 ) && ( index < 3 ) );
|
||||
return ( &pitch )[ index ];
|
||||
}
|
||||
|
||||
inline angles_t::operator vec3_p( void ) {
|
||||
return *( idVec3_t * )&pitch;
|
||||
}
|
||||
|
||||
inline void angles_t::set( float pitch, float yaw, float roll ) {
|
||||
this->pitch = pitch;
|
||||
this->yaw = yaw;
|
||||
this->roll = roll;
|
||||
}
|
||||
|
||||
inline void angles_t::operator=( angles_t const &a ) {
|
||||
pitch = a.pitch;
|
||||
yaw = a.yaw;
|
||||
roll = a.roll;
|
||||
}
|
||||
|
||||
inline void angles_t::operator=( idVec3_t const &a ) {
|
||||
pitch = a[ 0 ];
|
||||
yaw = a[ 1 ];
|
||||
roll = a[ 2 ];
|
||||
}
|
||||
|
||||
inline angles_t operator+( const angles_t &a, const angles_t &b ) {
|
||||
return angles_t( a.pitch + b.pitch, a.yaw + b.yaw, a.roll + b.roll );
|
||||
}
|
||||
|
||||
inline angles_t& angles_t::operator+=( angles_t const &a ) {
|
||||
pitch += a.pitch;
|
||||
yaw += a.yaw;
|
||||
roll += a.roll;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline angles_t& angles_t::operator+=( idVec3_t const &a ) {
|
||||
pitch += a.x;
|
||||
yaw += a.y;
|
||||
roll += a.z;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline angles_t operator-( angles_t &a, angles_t &b ) {
|
||||
return angles_t( a.pitch - b.pitch, a.yaw - b.yaw, a.roll - b.roll );
|
||||
}
|
||||
|
||||
inline angles_t& angles_t::operator-=( angles_t &a ) {
|
||||
pitch -= a.pitch;
|
||||
yaw -= a.yaw;
|
||||
roll -= a.roll;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline angles_t operator*( const angles_t &a, float b ) {
|
||||
return angles_t( a.pitch * b, a.yaw * b, a.roll * b );
|
||||
}
|
||||
|
||||
inline angles_t operator*( float a, const angles_t &b ) {
|
||||
return angles_t( a * b.pitch, a * b.yaw, a * b.roll );
|
||||
}
|
||||
|
||||
inline angles_t& angles_t::operator*=( float a ) {
|
||||
pitch *= a;
|
||||
yaw *= a;
|
||||
roll *= a;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline int operator==( angles_t &a, angles_t &b ) {
|
||||
return ( ( a.pitch == b.pitch ) && ( a.yaw == b.yaw ) && ( a.roll == b.roll ) );
|
||||
}
|
||||
|
||||
inline int operator!=( angles_t &a, angles_t &b ) {
|
||||
return ( ( a.pitch != b.pitch ) || ( a.yaw != b.yaw ) || ( a.roll != b.roll ) );
|
||||
}
|
||||
|
||||
inline angles_t& angles_t::Zero( void ) {
|
||||
pitch = 0.0f;
|
||||
yaw = 0.0f;
|
||||
roll = 0.0f;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
#endif /* !__MATH_ANGLES_H__ */
|
|
@ -1,113 +0,0 @@
|
|||
#include "q_shared.h"
|
||||
|
||||
mat3_t mat3_default( idVec3_t( 1, 0, 0 ), idVec3_t( 0, 1, 0 ), idVec3_t( 0, 0, 1 ) );
|
||||
|
||||
void toMatrix( quat_t const &src, mat3_t &dst ) {
|
||||
float wx, wy, wz;
|
||||
float xx, yy, yz;
|
||||
float xy, xz, zz;
|
||||
float x2, y2, z2;
|
||||
|
||||
x2 = src.x + src.x;
|
||||
y2 = src.y + src.y;
|
||||
z2 = src.z + src.z;
|
||||
|
||||
xx = src.x * x2;
|
||||
xy = src.x * y2;
|
||||
xz = src.x * z2;
|
||||
|
||||
yy = src.y * y2;
|
||||
yz = src.y * z2;
|
||||
zz = src.z * z2;
|
||||
|
||||
wx = src.w * x2;
|
||||
wy = src.w * y2;
|
||||
wz = src.w * z2;
|
||||
|
||||
dst[ 0 ][ 0 ] = 1.0f - ( yy + zz );
|
||||
dst[ 0 ][ 1 ] = xy - wz;
|
||||
dst[ 0 ][ 2 ] = xz + wy;
|
||||
|
||||
dst[ 1 ][ 0 ] = xy + wz;
|
||||
dst[ 1 ][ 1 ] = 1.0f - ( xx + zz );
|
||||
dst[ 1 ][ 2 ] = yz - wx;
|
||||
|
||||
dst[ 2 ][ 0 ] = xz - wy;
|
||||
dst[ 2 ][ 1 ] = yz + wx;
|
||||
dst[ 2 ][ 2 ] = 1.0f - ( xx + yy );
|
||||
}
|
||||
|
||||
void toMatrix( angles_t const &src, mat3_t &dst ) {
|
||||
float angle;
|
||||
static float sr, sp, sy, cr, cp, cy; // static to help MS compiler fp bugs
|
||||
|
||||
angle = src.yaw * ( M_PI * 2.0f / 360.0f );
|
||||
sy = sin( angle );
|
||||
cy = cos( angle );
|
||||
|
||||
angle = src.pitch * ( M_PI * 2.0f / 360.0f );
|
||||
sp = sin( angle );
|
||||
cp = cos( angle );
|
||||
|
||||
angle = src.roll * ( M_PI * 2.0f / 360.0f );
|
||||
sr = sin( angle );
|
||||
cr = cos( angle );
|
||||
|
||||
dst[ 0 ].set( cp * cy, cp * sy, -sp );
|
||||
dst[ 1 ].set( sr * sp * cy + cr * -sy, sr * sp * sy + cr * cy, sr * cp );
|
||||
dst[ 2 ].set( cr * sp * cy + -sr * -sy, cr * sp * sy + -sr * cy, cr * cp );
|
||||
}
|
||||
|
||||
void toMatrix( idVec3_t const &src, mat3_t &dst ) {
|
||||
angles_t sup = src;
|
||||
toMatrix(sup, dst);
|
||||
}
|
||||
|
||||
void mat3_t::ProjectVector( const idVec3_t &src, idVec3_t &dst ) const {
|
||||
dst.x = src * mat[ 0 ];
|
||||
dst.y = src * mat[ 1 ];
|
||||
dst.z = src * mat[ 2 ];
|
||||
}
|
||||
|
||||
void mat3_t::UnprojectVector( const idVec3_t &src, idVec3_t &dst ) const {
|
||||
dst = mat[ 0 ] * src.x + mat[ 1 ] * src.y + mat[ 2 ] * src.z;
|
||||
}
|
||||
|
||||
void mat3_t::Transpose( mat3_t &matrix ) {
|
||||
int i;
|
||||
int j;
|
||||
|
||||
for( i = 0; i < 3; i++ ) {
|
||||
for( j = 0; j < 3; j++ ) {
|
||||
matrix[ i ][ j ] = mat[ j ][ i ];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void mat3_t::Transpose( void ) {
|
||||
float temp;
|
||||
int i;
|
||||
int j;
|
||||
|
||||
for( i = 0; i < 3; i++ ) {
|
||||
for( j = i + 1; j < 3; j++ ) {
|
||||
temp = mat[ i ][ j ];
|
||||
mat[ i ][ j ] = mat[ j ][ i ];
|
||||
mat[ j ][ i ] = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mat3_t mat3_t::Inverse( void ) const {
|
||||
mat3_t inv( *this );
|
||||
|
||||
inv.Transpose();
|
||||
|
||||
return inv;
|
||||
}
|
||||
|
||||
void mat3_t::Clear( void ) {
|
||||
mat[0].set( 1, 0, 0 );
|
||||
mat[1].set( 0, 1, 0 );
|
||||
mat[2].set( 0, 0, 1 );
|
||||
}
|
|
@ -1,202 +0,0 @@
|
|||
#ifndef __MATH_MATRIX_H__
|
||||
#define __MATH_MATRIX_H__
|
||||
|
||||
#include <string.h>
|
||||
#include "math_vector.h"
|
||||
|
||||
#ifndef ID_INLINE
|
||||
#ifdef _WIN32
|
||||
#define ID_INLINE __inline
|
||||
#else
|
||||
#define ID_INLINE inline
|
||||
#endif
|
||||
#endif
|
||||
|
||||
class quat_t;
|
||||
class angles_t;
|
||||
|
||||
class mat3_t {
|
||||
public:
|
||||
idVec3_t mat[ 3 ];
|
||||
|
||||
mat3_t();
|
||||
mat3_t( float src[ 3 ][ 3 ] );
|
||||
mat3_t( idVec3_t const &x, idVec3_t const &y, idVec3_t const &z );
|
||||
mat3_t( const float xx, const float xy, const float xz, const float yx, const float yy, const float yz, const float zx, const float zy, const float zz );
|
||||
|
||||
friend void toMatrix( quat_t const &src, mat3_t &dst );
|
||||
friend void toMatrix( angles_t const &src, mat3_t &dst );
|
||||
friend void toMatrix( idVec3_t const &src, mat3_t &dst );
|
||||
|
||||
idVec3_t operator[]( int index ) const;
|
||||
idVec3_t &operator[]( int index );
|
||||
|
||||
idVec3_t operator*( const idVec3_t &vec ) const;
|
||||
mat3_t operator*( const mat3_t &a ) const;
|
||||
mat3_t operator*( float a ) const;
|
||||
mat3_t operator+( mat3_t const &a ) const;
|
||||
mat3_t operator-( mat3_t const &a ) const;
|
||||
|
||||
friend idVec3_t operator*( const idVec3_t &vec, const mat3_t &mat );
|
||||
friend mat3_t operator*( float a, mat3_t const &b );
|
||||
|
||||
mat3_t &operator*=( float a );
|
||||
mat3_t &operator+=( mat3_t const &a );
|
||||
mat3_t &operator-=( mat3_t const &a );
|
||||
|
||||
void Clear( void );
|
||||
|
||||
void ProjectVector( const idVec3_t &src, idVec3_t &dst ) const;
|
||||
void UnprojectVector( const idVec3_t &src, idVec3_t &dst ) const;
|
||||
|
||||
void OrthoNormalize( void );
|
||||
void Transpose( mat3_t &matrix );
|
||||
void Transpose( void );
|
||||
mat3_t Inverse( void ) const;
|
||||
void Identity( void );
|
||||
|
||||
friend void InverseMultiply( const mat3_t &inv, const mat3_t &b, mat3_t &dst );
|
||||
friend mat3_t SkewSymmetric( idVec3_t const &src );
|
||||
};
|
||||
|
||||
ID_INLINE mat3_t::mat3_t() {
|
||||
}
|
||||
|
||||
ID_INLINE mat3_t::mat3_t( float src[ 3 ][ 3 ] ) {
|
||||
memcpy( mat, src, sizeof( src ) );
|
||||
}
|
||||
|
||||
ID_INLINE mat3_t::mat3_t( idVec3_t const &x, idVec3_t const &y, idVec3_t const &z ) {
|
||||
mat[ 0 ].x = x.x; mat[ 0 ].y = x.y; mat[ 0 ].z = x.z;
|
||||
mat[ 1 ].x = y.x; mat[ 1 ].y = y.y; mat[ 1 ].z = y.z;
|
||||
mat[ 2 ].x = z.x; mat[ 2 ].y = z.y; mat[ 2 ].z = z.z;
|
||||
}
|
||||
|
||||
ID_INLINE mat3_t::mat3_t( const float xx, const float xy, const float xz, const float yx, const float yy, const float yz, const float zx, const float zy, const float zz ) {
|
||||
mat[ 0 ].x = xx; mat[ 0 ].y = xy; mat[ 0 ].z = xz;
|
||||
mat[ 1 ].x = yx; mat[ 1 ].y = yy; mat[ 1 ].z = yz;
|
||||
mat[ 2 ].x = zx; mat[ 2 ].y = zy; mat[ 2 ].z = zz;
|
||||
}
|
||||
|
||||
ID_INLINE idVec3_t mat3_t::operator[]( int index ) const {
|
||||
assert( ( index >= 0 ) && ( index < 3 ) );
|
||||
return mat[ index ];
|
||||
}
|
||||
|
||||
ID_INLINE idVec3_t& mat3_t::operator[]( int index ) {
|
||||
assert( ( index >= 0 ) && ( index < 3 ) );
|
||||
return mat[ index ];
|
||||
}
|
||||
|
||||
ID_INLINE idVec3_t mat3_t::operator*( const idVec3_t &vec ) const {
|
||||
return idVec3_t(
|
||||
mat[ 0 ].x * vec.x + mat[ 1 ].x * vec.y + mat[ 2 ].x * vec.z,
|
||||
mat[ 0 ].y * vec.x + mat[ 1 ].y * vec.y + mat[ 2 ].y * vec.z,
|
||||
mat[ 0 ].z * vec.x + mat[ 1 ].z * vec.y + mat[ 2 ].z * vec.z );
|
||||
}
|
||||
|
||||
ID_INLINE mat3_t mat3_t::operator*( const mat3_t &a ) const {
|
||||
return mat3_t(
|
||||
mat[0].x * a[0].x + mat[0].y * a[1].x + mat[0].z * a[2].x,
|
||||
mat[0].x * a[0].y + mat[0].y * a[1].y + mat[0].z * a[2].y,
|
||||
mat[0].x * a[0].z + mat[0].y * a[1].z + mat[0].z * a[2].z,
|
||||
mat[1].x * a[0].x + mat[1].y * a[1].x + mat[1].z * a[2].x,
|
||||
mat[1].x * a[0].y + mat[1].y * a[1].y + mat[1].z * a[2].y,
|
||||
mat[1].x * a[0].z + mat[1].y * a[1].z + mat[1].z * a[2].z,
|
||||
mat[2].x * a[0].x + mat[2].y * a[1].x + mat[2].z * a[2].x,
|
||||
mat[2].x * a[0].y + mat[2].y * a[1].y + mat[2].z * a[2].y,
|
||||
mat[2].x * a[0].z + mat[2].y * a[1].z + mat[2].z * a[2].z );
|
||||
}
|
||||
|
||||
ID_INLINE mat3_t mat3_t::operator*( float a ) const {
|
||||
return mat3_t(
|
||||
mat[0].x * a, mat[0].y * a, mat[0].z * a,
|
||||
mat[1].x * a, mat[1].y * a, mat[1].z * a,
|
||||
mat[2].x * a, mat[2].y * a, mat[2].z * a );
|
||||
}
|
||||
|
||||
ID_INLINE mat3_t mat3_t::operator+( mat3_t const &a ) const {
|
||||
return mat3_t(
|
||||
mat[0].x + a[0].x, mat[0].y + a[0].y, mat[0].z + a[0].z,
|
||||
mat[1].x + a[1].x, mat[1].y + a[1].y, mat[1].z + a[1].z,
|
||||
mat[2].x + a[2].x, mat[2].y + a[2].y, mat[2].z + a[2].z );
|
||||
}
|
||||
|
||||
ID_INLINE mat3_t mat3_t::operator-( mat3_t const &a ) const {
|
||||
return mat3_t(
|
||||
mat[0].x - a[0].x, mat[0].y - a[0].y, mat[0].z - a[0].z,
|
||||
mat[1].x - a[1].x, mat[1].y - a[1].y, mat[1].z - a[1].z,
|
||||
mat[2].x - a[2].x, mat[2].y - a[2].y, mat[2].z - a[2].z );
|
||||
}
|
||||
|
||||
ID_INLINE idVec3_t operator*( const idVec3_t &vec, const mat3_t &mat ) {
|
||||
return idVec3_t(
|
||||
mat[ 0 ].x * vec.x + mat[ 1 ].x * vec.y + mat[ 2 ].x * vec.z,
|
||||
mat[ 0 ].y * vec.x + mat[ 1 ].y * vec.y + mat[ 2 ].y * vec.z,
|
||||
mat[ 0 ].z * vec.x + mat[ 1 ].z * vec.y + mat[ 2 ].z * vec.z );
|
||||
}
|
||||
|
||||
ID_INLINE mat3_t operator*( float a, mat3_t const &b ) {
|
||||
return mat3_t(
|
||||
b[0].x * a, b[0].y * a, b[0].z * a,
|
||||
b[1].x * a, b[1].y * a, b[1].z * a,
|
||||
b[2].x * a, b[2].y * a, b[2].z * a );
|
||||
}
|
||||
|
||||
ID_INLINE mat3_t &mat3_t::operator*=( float a ) {
|
||||
mat[0].x *= a; mat[0].y *= a; mat[0].z *= a;
|
||||
mat[1].x *= a; mat[1].y *= a; mat[1].z *= a;
|
||||
mat[2].x *= a; mat[2].y *= a; mat[2].z *= a;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
ID_INLINE mat3_t &mat3_t::operator+=( mat3_t const &a ) {
|
||||
mat[0].x += a[0].x; mat[0].y += a[0].y; mat[0].z += a[0].z;
|
||||
mat[1].x += a[1].x; mat[1].y += a[1].y; mat[1].z += a[1].z;
|
||||
mat[2].x += a[2].x; mat[2].y += a[2].y; mat[2].z += a[2].z;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
ID_INLINE mat3_t &mat3_t::operator-=( mat3_t const &a ) {
|
||||
mat[0].x -= a[0].x; mat[0].y -= a[0].y; mat[0].z -= a[0].z;
|
||||
mat[1].x -= a[1].x; mat[1].y -= a[1].y; mat[1].z -= a[1].z;
|
||||
mat[2].x -= a[2].x; mat[2].y -= a[2].y; mat[2].z -= a[2].z;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
ID_INLINE void mat3_t::OrthoNormalize( void ) {
|
||||
mat[ 0 ].Normalize();
|
||||
mat[ 2 ].Cross( mat[ 0 ], mat[ 1 ] );
|
||||
mat[ 2 ].Normalize();
|
||||
mat[ 1 ].Cross( mat[ 2 ], mat[ 0 ] );
|
||||
mat[ 1 ].Normalize();
|
||||
}
|
||||
|
||||
ID_INLINE void mat3_t::Identity( void ) {
|
||||
mat[ 0 ].x = 1.f; mat[ 0 ].y = 0.f; mat[ 0 ].z = 0.f;
|
||||
mat[ 1 ].x = 0.f; mat[ 1 ].y = 1.f; mat[ 1 ].z = 0.f;
|
||||
mat[ 2 ].x = 0.f; mat[ 2 ].y = 0.f; mat[ 2 ].z = 1.f;
|
||||
}
|
||||
|
||||
ID_INLINE void InverseMultiply( const mat3_t &inv, const mat3_t &b, mat3_t &dst ) {
|
||||
dst[0].x = inv[0].x * b[0].x + inv[1].x * b[1].x + inv[2].x * b[2].x;
|
||||
dst[0].y = inv[0].x * b[0].y + inv[1].x * b[1].y + inv[2].x * b[2].y;
|
||||
dst[0].z = inv[0].x * b[0].z + inv[1].x * b[1].z + inv[2].x * b[2].z;
|
||||
dst[1].x = inv[0].y * b[0].x + inv[1].y * b[1].x + inv[2].y * b[2].x;
|
||||
dst[1].y = inv[0].y * b[0].y + inv[1].y * b[1].y + inv[2].y * b[2].y;
|
||||
dst[1].z = inv[0].y * b[0].z + inv[1].y * b[1].z + inv[2].y * b[2].z;
|
||||
dst[2].x = inv[0].z * b[0].x + inv[1].z * b[1].x + inv[2].z * b[2].x;
|
||||
dst[2].y = inv[0].z * b[0].y + inv[1].z * b[1].y + inv[2].z * b[2].y;
|
||||
dst[2].z = inv[0].z * b[0].z + inv[1].z * b[1].z + inv[2].z * b[2].z;
|
||||
}
|
||||
|
||||
ID_INLINE mat3_t SkewSymmetric( idVec3_t const &src ) {
|
||||
return mat3_t( 0.0f, -src.z, src.y, src.z, 0.0f, -src.x, -src.y, src.x, 0.0f );
|
||||
}
|
||||
|
||||
extern mat3_t mat3_default;
|
||||
|
||||
#endif /* !__MATH_MATRIX_H__ */
|
|
@ -1,57 +0,0 @@
|
|||
#include "math_quaternion.h"
|
||||
#include "math_matrix.h"
|
||||
|
||||
void toQuat( idVec3_t &src, quat_t &dst ) {
|
||||
dst.x = src.x;
|
||||
dst.y = src.y;
|
||||
dst.z = src.z;
|
||||
dst.w = 0.0f;
|
||||
}
|
||||
|
||||
void toQuat( angles_t &src, quat_t &dst ) {
|
||||
mat3_t temp;
|
||||
|
||||
toMatrix( src, temp );
|
||||
toQuat( temp, dst );
|
||||
}
|
||||
|
||||
void toQuat( mat3_t &src, quat_t &dst ) {
|
||||
float trace;
|
||||
float s;
|
||||
int i;
|
||||
int j;
|
||||
int k;
|
||||
|
||||
static int next[ 3 ] = { 1, 2, 0 };
|
||||
|
||||
trace = src[ 0 ][ 0 ] + src[ 1 ][ 1 ] + src[ 2 ][ 2 ];
|
||||
if ( trace > 0.0f ) {
|
||||
s = ( float )sqrt( trace + 1.0f );
|
||||
dst.w = s * 0.5f;
|
||||
s = 0.5f / s;
|
||||
|
||||
dst.x = ( src[ 2 ][ 1 ] - src[ 1 ][ 2 ] ) * s;
|
||||
dst.y = ( src[ 0 ][ 2 ] - src[ 2 ][ 0 ] ) * s;
|
||||
dst.z = ( src[ 1 ][ 0 ] - src[ 0 ][ 1 ] ) * s;
|
||||
} else {
|
||||
i = 0;
|
||||
if ( src[ 1 ][ 1 ] > src[ 0 ][ 0 ] ) {
|
||||
i = 1;
|
||||
}
|
||||
if ( src[ 2 ][ 2 ] > src[ i ][ i ] ) {
|
||||
i = 2;
|
||||
}
|
||||
|
||||
j = next[ i ];
|
||||
k = next[ j ];
|
||||
|
||||
s = ( float )sqrt( ( src[ i ][ i ] - ( src[ j ][ j ] + src[ k ][ k ] ) ) + 1.0f );
|
||||
dst[ i ] = s * 0.5f;
|
||||
|
||||
s = 0.5f / s;
|
||||
|
||||
dst.w = ( src[ k ][ j ] - src[ j ][ k ] ) * s;
|
||||
dst[ j ] = ( src[ j ][ i ] + src[ i ][ j ] ) * s;
|
||||
dst[ k ] = ( src[ k ][ i ] + src[ i ][ k ] ) * s;
|
||||
}
|
||||
}
|
|
@ -1,169 +0,0 @@
|
|||
#ifndef __MATH_QUATERNION_H__
|
||||
#define __MATH_QUATERNION_H__
|
||||
|
||||
#include <assert.h>
|
||||
#include <math.h>
|
||||
|
||||
class idVec3_t;
|
||||
class angles_t;
|
||||
class mat3_t;
|
||||
|
||||
class quat_t {
|
||||
public:
|
||||
float x;
|
||||
float y;
|
||||
float z;
|
||||
float w;
|
||||
|
||||
quat_t();
|
||||
quat_t( float x, float y, float z, float w );
|
||||
|
||||
friend void toQuat( idVec3_t &src, quat_t &dst );
|
||||
friend void toQuat( angles_t &src, quat_t &dst );
|
||||
friend void toQuat( mat3_t &src, quat_t &dst );
|
||||
|
||||
float *vec4( void );
|
||||
|
||||
float operator[]( int index ) const;
|
||||
float &operator[]( int index );
|
||||
|
||||
void set( float x, float y, float z, float w );
|
||||
|
||||
void operator=( quat_t a );
|
||||
|
||||
friend quat_t operator+( quat_t a, quat_t b );
|
||||
quat_t &operator+=( quat_t a );
|
||||
|
||||
friend quat_t operator-( quat_t a, quat_t b );
|
||||
quat_t &operator-=( quat_t a );
|
||||
|
||||
friend quat_t operator*( quat_t a, float b );
|
||||
friend quat_t operator*( float a, quat_t b );
|
||||
quat_t &operator*=( float a );
|
||||
|
||||
friend int operator==( quat_t a, quat_t b );
|
||||
friend int operator!=( quat_t a, quat_t b );
|
||||
|
||||
float Length( void );
|
||||
quat_t &Normalize( void );
|
||||
|
||||
quat_t operator-();
|
||||
};
|
||||
|
||||
inline quat_t::quat_t() {
|
||||
}
|
||||
|
||||
inline quat_t::quat_t( float x, float y, float z, float w ) {
|
||||
this->x = x;
|
||||
this->y = y;
|
||||
this->z = z;
|
||||
this->w = w;
|
||||
}
|
||||
|
||||
inline float *quat_t::vec4( void ) {
|
||||
return &x;
|
||||
}
|
||||
|
||||
inline float quat_t::operator[]( int index ) const {
|
||||
assert( ( index >= 0 ) && ( index < 4 ) );
|
||||
return ( &x )[ index ];
|
||||
}
|
||||
|
||||
inline float& quat_t::operator[]( int index ) {
|
||||
assert( ( index >= 0 ) && ( index < 4 ) );
|
||||
return ( &x )[ index ];
|
||||
}
|
||||
|
||||
inline void quat_t::set( float x, float y, float z, float w ) {
|
||||
this->x = x;
|
||||
this->y = y;
|
||||
this->z = z;
|
||||
this->w = w;
|
||||
}
|
||||
|
||||
inline void quat_t::operator=( quat_t a ) {
|
||||
x = a.x;
|
||||
y = a.y;
|
||||
z = a.z;
|
||||
w = a.w;
|
||||
}
|
||||
|
||||
inline quat_t operator+( quat_t a, quat_t b ) {
|
||||
return quat_t( a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w );
|
||||
}
|
||||
|
||||
inline quat_t& quat_t::operator+=( quat_t a ) {
|
||||
x += a.x;
|
||||
y += a.y;
|
||||
z += a.z;
|
||||
w += a.w;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline quat_t operator-( quat_t a, quat_t b ) {
|
||||
return quat_t( a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w );
|
||||
}
|
||||
|
||||
inline quat_t& quat_t::operator-=( quat_t a ) {
|
||||
x -= a.x;
|
||||
y -= a.y;
|
||||
z -= a.z;
|
||||
w -= a.w;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline quat_t operator*( quat_t a, float b ) {
|
||||
return quat_t( a.x * b, a.y * b, a.z * b, a.w * b );
|
||||
}
|
||||
|
||||
inline quat_t operator*( float a, quat_t b ) {
|
||||
return b * a;
|
||||
}
|
||||
|
||||
inline quat_t& quat_t::operator*=( float a ) {
|
||||
x *= a;
|
||||
y *= a;
|
||||
z *= a;
|
||||
w *= a;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline int operator==( quat_t a, quat_t b ) {
|
||||
return ( ( a.x == b.x ) && ( a.y == b.y ) && ( a.z == b.z ) && ( a.w == b.w ) );
|
||||
}
|
||||
|
||||
inline int operator!=( quat_t a, quat_t b ) {
|
||||
return ( ( a.x != b.x ) || ( a.y != b.y ) || ( a.z != b.z ) && ( a.w != b.w ) );
|
||||
}
|
||||
|
||||
inline float quat_t::Length( void ) {
|
||||
float length;
|
||||
|
||||
length = x * x + y * y + z * z + w * w;
|
||||
return ( float )sqrt( length );
|
||||
}
|
||||
|
||||
inline quat_t& quat_t::Normalize( void ) {
|
||||
float length;
|
||||
float ilength;
|
||||
|
||||
length = this->Length();
|
||||
if ( length ) {
|
||||
ilength = 1 / length;
|
||||
x *= ilength;
|
||||
y *= ilength;
|
||||
z *= ilength;
|
||||
w *= ilength;
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline quat_t quat_t::operator-() {
|
||||
return quat_t( -x, -y, -z, -w );
|
||||
}
|
||||
|
||||
#endif /* !__MATH_QUATERNION_H__ */
|
|
@ -1,123 +0,0 @@
|
|||
//#include "../game/q_shared.h"
|
||||
#include "math_vector.h"
|
||||
#include <assert.h>
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#define M_PI 3.14159265358979323846 // matches value in gcc v2 math.h
|
||||
|
||||
#define LERP_DELTA 1e-6
|
||||
|
||||
idVec3_t vec_zero( 0.0f, 0.0f, 0.0f );
|
||||
|
||||
Bounds boundsZero;
|
||||
|
||||
float idVec3_t::toYaw( void ) {
|
||||
float yaw;
|
||||
|
||||
if ( ( y == 0 ) && ( x == 0 ) ) {
|
||||
yaw = 0;
|
||||
} else {
|
||||
yaw = atan2( y, x ) * 180 / M_PI;
|
||||
if ( yaw < 0 ) {
|
||||
yaw += 360;
|
||||
}
|
||||
}
|
||||
|
||||
return yaw;
|
||||
}
|
||||
|
||||
float idVec3_t::toPitch( void ) {
|
||||
float forward;
|
||||
float pitch;
|
||||
|
||||
if ( ( x == 0 ) && ( y == 0 ) ) {
|
||||
if ( z > 0 ) {
|
||||
pitch = 90;
|
||||
} else {
|
||||
pitch = 270;
|
||||
}
|
||||
} else {
|
||||
forward = ( float )idSqrt( x * x + y * y );
|
||||
pitch = atan2( z, forward ) * 180 / M_PI;
|
||||
if ( pitch < 0 ) {
|
||||
pitch += 360;
|
||||
}
|
||||
}
|
||||
|
||||
return pitch;
|
||||
}
|
||||
|
||||
/*
|
||||
angles_t idVec3_t::toAngles( void ) {
|
||||
float forward;
|
||||
float yaw;
|
||||
float pitch;
|
||||
|
||||
if ( ( x == 0 ) && ( y == 0 ) ) {
|
||||
yaw = 0;
|
||||
if ( z > 0 ) {
|
||||
pitch = 90;
|
||||
} else {
|
||||
pitch = 270;
|
||||
}
|
||||
} else {
|
||||
yaw = atan2( y, x ) * 180 / M_PI;
|
||||
if ( yaw < 0 ) {
|
||||
yaw += 360;
|
||||
}
|
||||
|
||||
forward = ( float )idSqrt( x * x + y * y );
|
||||
pitch = atan2( z, forward ) * 180 / M_PI;
|
||||
if ( pitch < 0 ) {
|
||||
pitch += 360;
|
||||
}
|
||||
}
|
||||
|
||||
return angles_t( -pitch, yaw, 0 );
|
||||
}
|
||||
*/
|
||||
|
||||
idVec3_t LerpVector( idVec3_t &w1, idVec3_t &w2, const float t ) {
|
||||
float omega, cosom, sinom, scale0, scale1;
|
||||
|
||||
cosom = w1 * w2;
|
||||
if ( ( 1.0 - cosom ) > LERP_DELTA ) {
|
||||
omega = acos( cosom );
|
||||
sinom = sin( omega );
|
||||
scale0 = sin( ( 1.0 - t ) * omega ) / sinom;
|
||||
scale1 = sin( t * omega ) / sinom;
|
||||
} else {
|
||||
scale0 = 1.0 - t;
|
||||
scale1 = t;
|
||||
}
|
||||
|
||||
return ( w1 * scale0 + w2 * scale1 );
|
||||
}
|
||||
|
||||
/*
|
||||
=============
|
||||
idVec3_t::string
|
||||
|
||||
This is just a convenience function
|
||||
for printing vectors
|
||||
=============
|
||||
*/
|
||||
char *idVec3_t::string( void ) {
|
||||
static int index = 0;
|
||||
static char str[ 8 ][ 36 ];
|
||||
char *s;
|
||||
|
||||
// use an array so that multiple toString's won't collide
|
||||
s = str[ index ];
|
||||
index = (index + 1)&7;
|
||||
|
||||
sprintf( s, "%.2f %.2f %.2f", x, y, z );
|
||||
|
||||
return s;
|
||||
}
|
|
@ -1,553 +0,0 @@
|
|||
#ifndef __MATH_VECTOR_H__
|
||||
#define __MATH_VECTOR_H__
|
||||
|
||||
#if defined(_WIN32)
|
||||
#pragma warning(disable : 4244)
|
||||
#endif
|
||||
|
||||
#include <math.h>
|
||||
#include <assert.h>
|
||||
|
||||
//#define DotProduct(a,b) ((a)[0]*(b)[0]+(a)[1]*(b)[1]+(a)[2]*(b)[2])
|
||||
//#define VectorSubtract(a,b,c) ((c)[0]=(a)[0]-(b)[0],(c)[1]=(a)[1]-(b)[1],(c)[2]=(a)[2]-(b)[2])
|
||||
//#define VectorAdd(a,b,c) ((c)[0]=(a)[0]+(b)[0],(c)[1]=(a)[1]+(b)[1],(c)[2]=(a)[2]+(b)[2])
|
||||
//#define VectorCopy(a,b) ((b)[0]=(a)[0],(b)[1]=(a)[1],(b)[2]=(a)[2])
|
||||
//#define VectorCopy(a,b) ((b).x=(a).x,(b).y=(a).y,(b).z=(a).z])
|
||||
|
||||
//#define VectorScale(v, s, o) ((o)[0]=(v)[0]*(s),(o)[1]=(v)[1]*(s),(o)[2]=(v)[2]*(s))
|
||||
#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))
|
||||
//#define CrossProduct(a,b,c) ((c)[0]=(a)[1]*(b)[2]-(a)[2]*(b)[1],(c)[1]=(a)[2]*(b)[0]-(a)[0]*(b)[2],(c)[2]=(a)[0]*(b)[1]-(a)[1]*(b)[0])
|
||||
|
||||
#define DotProduct4(x,y) ((x)[0]*(y)[0]+(x)[1]*(y)[1]+(x)[2]*(y)[2]+(x)[3]*(y)[3])
|
||||
#define VectorSubtract4(a,b,c) ((c)[0]=(a)[0]-(b)[0],(c)[1]=(a)[1]-(b)[1],(c)[2]=(a)[2]-(b)[2],(c)[3]=(a)[3]-(b)[3])
|
||||
#define VectorAdd4(a,b,c) ((c)[0]=(a)[0]+(b)[0],(c)[1]=(a)[1]+(b)[1],(c)[2]=(a)[2]+(b)[2],(c)[3]=(a)[3]+(b)[3])
|
||||
#define VectorCopy4(a,b) ((b)[0]=(a)[0],(b)[1]=(a)[1],(b)[2]=(a)[2],(b)[3]=(a)[3])
|
||||
#define VectorScale4(v, s, o) ((o)[0]=(v)[0]*(s),(o)[1]=(v)[1]*(s),(o)[2]=(v)[2]*(s),(o)[3]=(v)[3]*(s))
|
||||
#define VectorMA4(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),(o)[3]=(v)[3]+(b)[3]*(s))
|
||||
|
||||
|
||||
//#define VectorClear(a) ((a)[0]=(a)[1]=(a)[2]=0)
|
||||
#define VectorNegate(a,b) ((b)[0]=-(a)[0],(b)[1]=-(a)[1],(b)[2]=-(a)[2])
|
||||
//#define VectorSet(v, x, y, z) ((v)[0]=(x), (v)[1]=(y), (v)[2]=(z))
|
||||
#define Vector4Copy(a,b) ((b)[0]=(a)[0],(b)[1]=(a)[1],(b)[2]=(a)[2],(b)[3]=(a)[3])
|
||||
|
||||
#define SnapVector(v) {v[0]=(int)v[0];v[1]=(int)v[1];v[2]=(int)v[2];}
|
||||
|
||||
|
||||
//#include "util_heap.h"
|
||||
|
||||
#ifndef EQUAL_EPSILON
|
||||
#define EQUAL_EPSILON 0.001
|
||||
#endif
|
||||
|
||||
float Q_fabs( float f );
|
||||
|
||||
#ifndef ID_INLINE
|
||||
#ifdef _WIN32
|
||||
#define ID_INLINE __inline
|
||||
#else
|
||||
#define ID_INLINE inline
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// if this is defined, vec3 will take four elements, which may allow
|
||||
// easier SIMD optimizations
|
||||
//#define FAT_VEC3
|
||||
//#ifdef __ppc__
|
||||
//#pragma align(16)
|
||||
//#endif
|
||||
|
||||
class angles_t;
|
||||
#ifdef __ppc__
|
||||
// Vanilla PPC code, but since PPC has a reciprocal square root estimate instruction,
|
||||
// runs *much* faster than calling sqrt(). We'll use two Newton-Raphson
|
||||
// refinement steps to get bunch more precision in the 1/sqrt() value for very little cost.
|
||||
// We'll then multiply 1/sqrt times the original value to get the sqrt.
|
||||
// This is about 12.4 times faster than sqrt() and according to my testing (not exhaustive)
|
||||
// it returns fairly accurate results (error below 1.0e-5 up to 100000.0 in 0.1 increments).
|
||||
|
||||
static inline float idSqrt(float x) {
|
||||
const float half = 0.5;
|
||||
const float one = 1.0;
|
||||
float B, y0, y1;
|
||||
|
||||
// This'll NaN if it hits frsqrte. Handle both +0.0 and -0.0
|
||||
if (fabs(x) == 0.0)
|
||||
return x;
|
||||
B = x;
|
||||
|
||||
#ifdef __GNUC__
|
||||
asm("frsqrte %0,%1" : "=f" (y0) : "f" (B));
|
||||
#else
|
||||
y0 = __frsqrte(B);
|
||||
#endif
|
||||
/* First refinement step */
|
||||
|
||||
y1 = y0 + half*y0*(one - B*y0*y0);
|
||||
|
||||
/* Second refinement step -- copy the output of the last step to the input of this step */
|
||||
|
||||
y0 = y1;
|
||||
y1 = y0 + half*y0*(one - B*y0*y0);
|
||||
|
||||
/* Get sqrt(x) from x * 1/sqrt(x) */
|
||||
return x * y1;
|
||||
}
|
||||
#else
|
||||
static inline double idSqrt(double x) {
|
||||
return sqrt(x);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
//class idVec3_t : public idHeap<idVec3_t> {
|
||||
class idVec3_t {
|
||||
public:
|
||||
#ifndef FAT_VEC3
|
||||
float x,y,z;
|
||||
#else
|
||||
float x,y,z,dist;
|
||||
#endif
|
||||
|
||||
#ifndef FAT_VEC3
|
||||
idVec3_t() {};
|
||||
#else
|
||||
idVec3_t() {dist = 0.0f;};
|
||||
#endif
|
||||
idVec3_t( const float x, const float y, const float z );
|
||||
|
||||
operator float *();
|
||||
|
||||
float operator[]( const int index ) const;
|
||||
float &operator[]( const int index );
|
||||
|
||||
void set( const float x, const float y, const float z );
|
||||
|
||||
idVec3_t operator-() const;
|
||||
|
||||
idVec3_t &operator=( const idVec3_t &a );
|
||||
|
||||
float operator*( const idVec3_t &a ) const;
|
||||
idVec3_t operator*( const float a ) const;
|
||||
friend idVec3_t operator*( float a, idVec3_t b );
|
||||
|
||||
idVec3_t operator+( const idVec3_t &a ) const;
|
||||
idVec3_t operator-( const idVec3_t &a ) const;
|
||||
|
||||
idVec3_t &operator+=( const idVec3_t &a );
|
||||
idVec3_t &operator-=( const idVec3_t &a );
|
||||
idVec3_t &operator*=( const float a );
|
||||
|
||||
int operator==( const idVec3_t &a ) const;
|
||||
int operator!=( const idVec3_t &a ) const;
|
||||
|
||||
idVec3_t Cross( const idVec3_t &a ) const;
|
||||
idVec3_t &Cross( const idVec3_t &a, const idVec3_t &b );
|
||||
|
||||
float Length( void ) const;
|
||||
float Normalize( void );
|
||||
|
||||
void Zero( void );
|
||||
void Snap( void );
|
||||
void SnapTowards( const idVec3_t &to );
|
||||
|
||||
float toYaw( void );
|
||||
float toPitch( void );
|
||||
angles_t toAngles( void );
|
||||
friend idVec3_t LerpVector( const idVec3_t &w1, const idVec3_t &w2, const float t );
|
||||
|
||||
char *string( void );
|
||||
};
|
||||
|
||||
extern idVec3_t vec_zero;
|
||||
|
||||
ID_INLINE idVec3_t::idVec3_t( const float x, const float y, const float z ) {
|
||||
this->x = x;
|
||||
this->y = y;
|
||||
this->z = z;
|
||||
#ifdef FAT_VEC3
|
||||
this->dist = 0.0f;
|
||||
#endif
|
||||
}
|
||||
|
||||
ID_INLINE float idVec3_t::operator[]( const int index ) const {
|
||||
return ( &x )[ index ];
|
||||
}
|
||||
|
||||
ID_INLINE float &idVec3_t::operator[]( const int index ) {
|
||||
return ( &x )[ index ];
|
||||
}
|
||||
|
||||
ID_INLINE idVec3_t::operator float *( void ) {
|
||||
return &x;
|
||||
}
|
||||
|
||||
ID_INLINE idVec3_t idVec3_t::operator-() const {
|
||||
return idVec3_t( -x, -y, -z );
|
||||
}
|
||||
|
||||
ID_INLINE idVec3_t &idVec3_t::operator=( const idVec3_t &a ) {
|
||||
x = a.x;
|
||||
y = a.y;
|
||||
z = a.z;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
ID_INLINE void idVec3_t::set( const float x, const float y, const float z ) {
|
||||
this->x = x;
|
||||
this->y = y;
|
||||
this->z = z;
|
||||
}
|
||||
|
||||
ID_INLINE idVec3_t idVec3_t::operator-( const idVec3_t &a ) const {
|
||||
return idVec3_t( x - a.x, y - a.y, z - a.z );
|
||||
}
|
||||
|
||||
ID_INLINE float idVec3_t::operator*( const idVec3_t &a ) const {
|
||||
return x * a.x + y * a.y + z * a.z;
|
||||
}
|
||||
|
||||
ID_INLINE idVec3_t idVec3_t::operator*( const float a ) const {
|
||||
return idVec3_t( x * a, y * a, z * a );
|
||||
}
|
||||
|
||||
ID_INLINE idVec3_t operator*( const float a, const idVec3_t b ) {
|
||||
return idVec3_t( b.x * a, b.y * a, b.z * a );
|
||||
}
|
||||
|
||||
ID_INLINE idVec3_t idVec3_t::operator+( const idVec3_t &a ) const {
|
||||
return idVec3_t( x + a.x, y + a.y, z + a.z );
|
||||
}
|
||||
|
||||
ID_INLINE idVec3_t &idVec3_t::operator+=( const idVec3_t &a ) {
|
||||
x += a.x;
|
||||
y += a.y;
|
||||
z += a.z;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
ID_INLINE idVec3_t &idVec3_t::operator-=( const idVec3_t &a ) {
|
||||
x -= a.x;
|
||||
y -= a.y;
|
||||
z -= a.z;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
ID_INLINE idVec3_t &idVec3_t::operator*=( const float a ) {
|
||||
x *= a;
|
||||
y *= a;
|
||||
z *= a;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
ID_INLINE int idVec3_t::operator==( const idVec3_t &a ) const {
|
||||
if ( Q_fabs( x - a.x ) > EQUAL_EPSILON ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( Q_fabs( y - a.y ) > EQUAL_EPSILON ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( Q_fabs( z - a.z ) > EQUAL_EPSILON ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
ID_INLINE int idVec3_t::operator!=( const idVec3_t &a ) const {
|
||||
if ( Q_fabs( x - a.x ) > EQUAL_EPSILON ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( Q_fabs( y - a.y ) > EQUAL_EPSILON ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( Q_fabs( z - a.z ) > EQUAL_EPSILON ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
ID_INLINE idVec3_t idVec3_t::Cross( const idVec3_t &a ) const {
|
||||
return idVec3_t( y * a.z - z * a.y, z * a.x - x * a.z, x * a.y - y * a.x );
|
||||
}
|
||||
|
||||
ID_INLINE idVec3_t &idVec3_t::Cross( const idVec3_t &a, const idVec3_t &b ) {
|
||||
x = a.y * b.z - a.z * b.y;
|
||||
y = a.z * b.x - a.x * b.z;
|
||||
z = a.x * b.y - a.y * b.x;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
ID_INLINE float idVec3_t::Length( void ) const {
|
||||
float length;
|
||||
|
||||
length = x * x + y * y + z * z;
|
||||
return ( float )idSqrt( length );
|
||||
}
|
||||
|
||||
ID_INLINE float idVec3_t::Normalize( void ) {
|
||||
float length;
|
||||
float ilength;
|
||||
|
||||
length = this->Length();
|
||||
if ( length ) {
|
||||
ilength = 1.0f / length;
|
||||
x *= ilength;
|
||||
y *= ilength;
|
||||
z *= ilength;
|
||||
}
|
||||
|
||||
return length;
|
||||
}
|
||||
|
||||
ID_INLINE void idVec3_t::Zero( void ) {
|
||||
x = 0.0f;
|
||||
y = 0.0f;
|
||||
z = 0.0f;
|
||||
}
|
||||
|
||||
ID_INLINE void idVec3_t::Snap( void ) {
|
||||
x = float( int( x ) );
|
||||
y = float( int( y ) );
|
||||
z = float( int( z ) );
|
||||
}
|
||||
|
||||
/*
|
||||
======================
|
||||
SnapTowards
|
||||
|
||||
Round a vector to integers for more efficient network
|
||||
transmission, but make sure that it rounds towards a given point
|
||||
rather than blindly truncating. This prevents it from truncating
|
||||
into a wall.
|
||||
======================
|
||||
*/
|
||||
ID_INLINE void idVec3_t::SnapTowards( const idVec3_t &to ) {
|
||||
if ( to.x <= x ) {
|
||||
x = float( int( x ) );
|
||||
} else {
|
||||
x = float( int( x ) + 1 );
|
||||
}
|
||||
|
||||
if ( to.y <= y ) {
|
||||
y = float( int( y ) );
|
||||
} else {
|
||||
y = float( int( y ) + 1 );
|
||||
}
|
||||
|
||||
if ( to.z <= z ) {
|
||||
z = float( int( z ) );
|
||||
} else {
|
||||
z = float( int( z ) + 1 );
|
||||
}
|
||||
}
|
||||
|
||||
//===============================================================
|
||||
|
||||
class Bounds {
|
||||
public:
|
||||
idVec3_t b[2];
|
||||
|
||||
Bounds();
|
||||
Bounds( const idVec3_t &mins, const idVec3_t &maxs );
|
||||
|
||||
void Clear();
|
||||
void Zero();
|
||||
float Radius(); // radius from origin, not from center
|
||||
idVec3_t Center();
|
||||
void AddPoint( const idVec3_t &v );
|
||||
void AddBounds( const Bounds &bb );
|
||||
bool IsCleared();
|
||||
bool ContainsPoint( const idVec3_t &p );
|
||||
bool IntersectsBounds( const Bounds &b2 ); // touching is NOT intersecting
|
||||
};
|
||||
|
||||
extern Bounds boundsZero;
|
||||
|
||||
ID_INLINE Bounds::Bounds(){
|
||||
}
|
||||
|
||||
ID_INLINE bool Bounds::IsCleared() {
|
||||
return b[0][0] > b[1][0];
|
||||
}
|
||||
|
||||
ID_INLINE bool Bounds::ContainsPoint( const idVec3_t &p ) {
|
||||
if ( p[0] < b[0][0] || p[1] < b[0][1] || p[2] < b[0][2]
|
||||
|| p[0] > b[1][0] || p[1] > b[1][1] || p[2] > b[1][2] ) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
ID_INLINE bool Bounds::IntersectsBounds( const Bounds &b2 ) {
|
||||
if ( b2.b[1][0] < b[0][0] || b2.b[1][1] < b[0][1] || b2.b[1][2] < b[0][2]
|
||||
|| b2.b[0][0] > b[1][0] || b2.b[0][1] > b[1][1] || b2.b[0][2] > b[1][2] ) {
|
||||
< |