2016-06-04 15:24:23 +02:00
|
|
|
|
//========= Copyright <20> 1996-2002, Valve LLC, All rights reserved. ============
|
|
|
|
|
//
|
|
|
|
|
// Purpose:
|
|
|
|
|
//
|
|
|
|
|
// $NoKeywords: $
|
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
|
|
#include <memory.h>
|
|
|
|
|
#include "hud.h"
|
|
|
|
|
#include "cl_util.h"
|
|
|
|
|
#include "const.h"
|
|
|
|
|
#include "com_model.h"
|
|
|
|
|
#include "studio_util.h"
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
====================
|
|
|
|
|
AngleMatrix
|
|
|
|
|
|
|
|
|
|
====================
|
|
|
|
|
*/
|
2016-07-03 15:39:55 +02:00
|
|
|
|
void AngleMatrix( const float *angles, float (*matrix)[4] )
|
2016-06-04 15:24:23 +02:00
|
|
|
|
{
|
2016-07-03 15:39:55 +02:00
|
|
|
|
float angle;
|
|
|
|
|
float sr, sp, sy, cr, cp, cy;
|
|
|
|
|
|
|
|
|
|
angle = angles[YAW] * ( M_PI*2 / 360 );
|
|
|
|
|
sy = sin( angle );
|
|
|
|
|
cy = cos( angle );
|
|
|
|
|
angle = angles[PITCH] * ( M_PI*2 / 360 );
|
|
|
|
|
sp = sin( angle );
|
|
|
|
|
cp = cos( angle );
|
|
|
|
|
angle = angles[ROLL] * ( M_PI*2 / 360 );
|
|
|
|
|
sr = sin( angle );
|
|
|
|
|
cr = cos( angle );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
|
|
// matrix = (YAW * PITCH) * ROLL
|
2016-07-03 15:39:55 +02:00
|
|
|
|
matrix[0][0] = cp * cy;
|
|
|
|
|
matrix[1][0] = cp * sy;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
matrix[2][0] = -sp;
|
2016-07-03 15:39:55 +02:00
|
|
|
|
matrix[0][1] = sr * sp * cy + cr * -sy;
|
|
|
|
|
matrix[1][1] = sr * sp * sy + cr * cy;
|
|
|
|
|
matrix[2][1] = sr * cp;
|
|
|
|
|
matrix[0][2] = (cr * sp * cy + -sr * -sy);
|
|
|
|
|
matrix[1][2] = (cr * sp * sy + -sr* cy);
|
|
|
|
|
matrix[2][2] = cr * cp;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
matrix[0][3] = 0.0;
|
|
|
|
|
matrix[1][3] = 0.0;
|
|
|
|
|
matrix[2][3] = 0.0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
====================
|
|
|
|
|
VectorCompare
|
|
|
|
|
|
|
|
|
|
====================
|
|
|
|
|
*/
|
2016-07-03 15:39:55 +02:00
|
|
|
|
int VectorCompare( const float *v1, const float *v2 )
|
2016-06-04 15:24:23 +02:00
|
|
|
|
{
|
2016-07-03 15:39:55 +02:00
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
for( i = 0; i < 3; i++ )
|
|
|
|
|
if( v1[i] != v2[i] )
|
2016-06-04 15:24:23 +02:00
|
|
|
|
return 0;
|
2016-07-03 15:39:55 +02:00
|
|
|
|
|
2016-06-04 15:24:23 +02:00
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
====================
|
|
|
|
|
CrossProduct
|
|
|
|
|
|
|
|
|
|
====================
|
|
|
|
|
*/
|
2016-07-03 15:39:55 +02:00
|
|
|
|
void CrossProduct( const float *v1, const float *v2, float *cross )
|
2016-06-04 15:24:23 +02:00
|
|
|
|
{
|
|
|
|
|
cross[0] = v1[1]*v2[2] - v1[2]*v2[1];
|
|
|
|
|
cross[1] = v1[2]*v2[0] - v1[0]*v2[2];
|
|
|
|
|
cross[2] = v1[0]*v2[1] - v1[1]*v2[0];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
====================
|
|
|
|
|
VectorTransform
|
|
|
|
|
|
|
|
|
|
====================
|
|
|
|
|
*/
|
2016-07-03 15:39:55 +02:00
|
|
|
|
void VectorTransform( const float *in1, float in2[3][4], float *out )
|
2016-06-04 15:24:23 +02:00
|
|
|
|
{
|
|
|
|
|
out[0] = DotProduct(in1, in2[0]) + in2[0][3];
|
|
|
|
|
out[1] = DotProduct(in1, in2[1]) + in2[1][3];
|
|
|
|
|
out[2] = DotProduct(in1, in2[2]) + in2[2][3];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
================
|
|
|
|
|
ConcatTransforms
|
|
|
|
|
|
|
|
|
|
================
|
|
|
|
|
*/
|
2016-07-03 15:39:55 +02:00
|
|
|
|
void ConcatTransforms( float in1[3][4], float in2[3][4], float out[3][4] )
|
2016-06-04 15:24:23 +02:00
|
|
|
|
{
|
|
|
|
|
out[0][0] = in1[0][0] * in2[0][0] + in1[0][1] * in2[1][0] +
|
|
|
|
|
in1[0][2] * in2[2][0];
|
|
|
|
|
out[0][1] = in1[0][0] * in2[0][1] + in1[0][1] * in2[1][1] +
|
|
|
|
|
in1[0][2] * in2[2][1];
|
|
|
|
|
out[0][2] = in1[0][0] * in2[0][2] + in1[0][1] * in2[1][2] +
|
|
|
|
|
in1[0][2] * in2[2][2];
|
|
|
|
|
out[0][3] = in1[0][0] * in2[0][3] + in1[0][1] * in2[1][3] +
|
|
|
|
|
in1[0][2] * in2[2][3] + in1[0][3];
|
|
|
|
|
out[1][0] = in1[1][0] * in2[0][0] + in1[1][1] * in2[1][0] +
|
|
|
|
|
in1[1][2] * in2[2][0];
|
|
|
|
|
out[1][1] = in1[1][0] * in2[0][1] + in1[1][1] * in2[1][1] +
|
|
|
|
|
in1[1][2] * in2[2][1];
|
|
|
|
|
out[1][2] = in1[1][0] * in2[0][2] + in1[1][1] * in2[1][2] +
|
|
|
|
|
in1[1][2] * in2[2][2];
|
|
|
|
|
out[1][3] = in1[1][0] * in2[0][3] + in1[1][1] * in2[1][3] +
|
|
|
|
|
in1[1][2] * in2[2][3] + in1[1][3];
|
|
|
|
|
out[2][0] = in1[2][0] * in2[0][0] + in1[2][1] * in2[1][0] +
|
|
|
|
|
in1[2][2] * in2[2][0];
|
|
|
|
|
out[2][1] = in1[2][0] * in2[0][1] + in1[2][1] * in2[1][1] +
|
|
|
|
|
in1[2][2] * in2[2][1];
|
|
|
|
|
out[2][2] = in1[2][0] * in2[0][2] + in1[2][1] * in2[1][2] +
|
|
|
|
|
in1[2][2] * in2[2][2];
|
|
|
|
|
out[2][3] = in1[2][0] * in2[0][3] + in1[2][1] * in2[1][3] +
|
|
|
|
|
in1[2][2] * in2[2][3] + in1[2][3];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// angles index are not the same as ROLL, PITCH, YAW
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
====================
|
|
|
|
|
AngleQuaternion
|
|
|
|
|
|
|
|
|
|
====================
|
|
|
|
|
*/
|
|
|
|
|
void AngleQuaternion( float *angles, vec4_t quaternion )
|
|
|
|
|
{
|
2016-07-03 15:39:55 +02:00
|
|
|
|
float angle;
|
|
|
|
|
float sr, sp, sy, cr, cp, cy;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
|
|
// FIXME: rescale the inputs to 1/2 angle
|
|
|
|
|
angle = angles[2] * 0.5;
|
2016-07-03 15:39:55 +02:00
|
|
|
|
sy = sin( angle );
|
|
|
|
|
cy = cos( angle );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
angle = angles[1] * 0.5;
|
2016-07-03 15:39:55 +02:00
|
|
|
|
sp = sin( angle );
|
|
|
|
|
cp = cos( angle );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
angle = angles[0] * 0.5;
|
2016-07-03 15:39:55 +02:00
|
|
|
|
sr = sin( angle );
|
|
|
|
|
cr = cos( angle );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
2016-07-03 15:39:55 +02:00
|
|
|
|
quaternion[0] = sr * cp * cy - cr * sp * sy; // X
|
|
|
|
|
quaternion[1] = cr * sp * cy + sr * cp * sy; // Y
|
|
|
|
|
quaternion[2] = cr * cp * sy - sr * sp * cy; // Z
|
|
|
|
|
quaternion[3] = cr * cp * cy + sr * sp * sy; // W
|
2016-06-04 15:24:23 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
====================
|
|
|
|
|
QuaternionSlerp
|
|
|
|
|
|
|
|
|
|
====================
|
|
|
|
|
*/
|
|
|
|
|
void QuaternionSlerp( vec4_t p, vec4_t q, float t, vec4_t qt )
|
|
|
|
|
{
|
|
|
|
|
int i;
|
2016-07-03 15:39:55 +02:00
|
|
|
|
float omega, cosom, sinom, sclp, sclq;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
|
|
|
|
// decide if one of the quaternions is backwards
|
|
|
|
|
float a = 0;
|
|
|
|
|
float b = 0;
|
|
|
|
|
|
2016-07-03 15:39:55 +02:00
|
|
|
|
for( i = 0; i < 4; i++ )
|
2016-06-04 15:24:23 +02:00
|
|
|
|
{
|
2016-07-03 15:39:55 +02:00
|
|
|
|
a += ( p[i] - q[i] ) * ( p[i] - q[i] );
|
|
|
|
|
b += ( p[i] + q[i] ) * ( p[i] + q[i] );
|
2016-06-04 15:24:23 +02:00
|
|
|
|
}
|
2016-07-03 15:39:55 +02:00
|
|
|
|
if(a > b)
|
2016-06-04 15:24:23 +02:00
|
|
|
|
{
|
2016-07-03 15:39:55 +02:00
|
|
|
|
for( i = 0; i < 4; i++ )
|
2016-06-04 15:24:23 +02:00
|
|
|
|
{
|
|
|
|
|
q[i] = -q[i];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-03 15:39:55 +02:00
|
|
|
|
cosom = p[0] * q[0] + p[1] * q[1] + p[2] * q[2] + p[3] * q[3];
|
2016-06-04 15:24:23 +02:00
|
|
|
|
|
2016-07-03 15:39:55 +02:00
|
|
|
|
if( ( 1.0 + cosom ) > 0.000001 )
|
2016-06-04 15:24:23 +02:00
|
|
|
|
{
|
2016-07-03 15:39:55 +02:00
|
|
|
|
if( ( 1.0 - cosom ) > 0.000001 )
|
2016-06-04 15:24:23 +02:00
|
|
|
|
{
|
|
|
|
|
omega = acos( cosom );
|
|
|
|
|
sinom = sin( omega );
|
2016-07-03 15:39:55 +02:00
|
|
|
|
sclp = sin( ( 1.0 - t ) * omega ) / sinom;
|
|
|
|
|
sclq = sin( t * omega ) / sinom;
|
2016-06-04 15:24:23 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
sclp = 1.0 - t;
|
|
|
|
|
sclq = t;
|
|
|
|
|
}
|
2016-07-03 15:39:55 +02:00
|
|
|
|
for( i = 0; i < 4; i++ )
|
|
|
|
|
{
|
2016-06-04 15:24:23 +02:00
|
|
|
|
qt[i] = sclp * p[i] + sclq * q[i];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
qt[0] = -q[1];
|
|
|
|
|
qt[1] = q[0];
|
|
|
|
|
qt[2] = -q[3];
|
|
|
|
|
qt[3] = q[2];
|
2016-07-03 15:39:55 +02:00
|
|
|
|
sclp = sin( ( 1.0 - t ) * ( 0.5 * M_PI ) );
|
|
|
|
|
sclq = sin( t * ( 0.5 * M_PI ) );
|
|
|
|
|
for( i = 0; i < 3; i++ )
|
2016-06-04 15:24:23 +02:00
|
|
|
|
{
|
|
|
|
|
qt[i] = sclp * p[i] + sclq * qt[i];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
====================
|
|
|
|
|
QuaternionMatrix
|
|
|
|
|
|
|
|
|
|
====================
|
|
|
|
|
*/
|
|
|
|
|
void QuaternionMatrix( vec4_t quaternion, float (*matrix)[4] )
|
|
|
|
|
{
|
|
|
|
|
matrix[0][0] = 1.0 - 2.0 * quaternion[1] * quaternion[1] - 2.0 * quaternion[2] * quaternion[2];
|
|
|
|
|
matrix[1][0] = 2.0 * quaternion[0] * quaternion[1] + 2.0 * quaternion[3] * quaternion[2];
|
|
|
|
|
matrix[2][0] = 2.0 * quaternion[0] * quaternion[2] - 2.0 * quaternion[3] * quaternion[1];
|
|
|
|
|
|
|
|
|
|
matrix[0][1] = 2.0 * quaternion[0] * quaternion[1] - 2.0 * quaternion[3] * quaternion[2];
|
|
|
|
|
matrix[1][1] = 1.0 - 2.0 * quaternion[0] * quaternion[0] - 2.0 * quaternion[2] * quaternion[2];
|
|
|
|
|
matrix[2][1] = 2.0 * quaternion[1] * quaternion[2] + 2.0 * quaternion[3] * quaternion[0];
|
|
|
|
|
|
|
|
|
|
matrix[0][2] = 2.0 * quaternion[0] * quaternion[2] + 2.0 * quaternion[3] * quaternion[1];
|
|
|
|
|
matrix[1][2] = 2.0 * quaternion[1] * quaternion[2] - 2.0 * quaternion[3] * quaternion[0];
|
|
|
|
|
matrix[2][2] = 1.0 - 2.0 * quaternion[0] * quaternion[0] - 2.0 * quaternion[1] * quaternion[1];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
====================
|
|
|
|
|
MatrixCopy
|
|
|
|
|
|
|
|
|
|
====================
|
|
|
|
|
*/
|
|
|
|
|
void MatrixCopy( float in[3][4], float out[3][4] )
|
|
|
|
|
{
|
|
|
|
|
memcpy( out, in, sizeof( float ) * 3 * 4 );
|
2016-07-03 15:39:55 +02:00
|
|
|
|
}
|