📄 q_math.c
字号:
fld dword ptr[0+8+edx]
fxch st(2)
fmul dword ptr[4+ecx]
fxch st(2)
fld st(0)
fmul dword ptr[8+ebx]
fxch st(5)
faddp st(3),st(0)
fmul dword ptr[8+ecx]
fxch st(1)
faddp st(3),st(0)
fxch st(3)
faddp st(2),st(0)
jmp LSetSides
Lcase2:
fmul dword ptr[ebx]
fld dword ptr[0+4+edx]
fxch st(2)
fmul dword ptr[ecx]
fxch st(2)
fld st(0)
fmul dword ptr[4+ecx]
fld dword ptr[0+8+edx]
fxch st(2)
fmul dword ptr[4+ebx]
fxch st(2)
fld st(0)
fmul dword ptr[8+ebx]
fxch st(5)
faddp st(3),st(0)
fmul dword ptr[8+ecx]
fxch st(1)
faddp st(3),st(0)
fxch st(3)
faddp st(2),st(0)
jmp LSetSides
Lcase3:
fmul dword ptr[ecx]
fld dword ptr[0+4+edx]
fxch st(2)
fmul dword ptr[ebx]
fxch st(2)
fld st(0)
fmul dword ptr[4+ecx]
fld dword ptr[0+8+edx]
fxch st(2)
fmul dword ptr[4+ebx]
fxch st(2)
fld st(0)
fmul dword ptr[8+ebx]
fxch st(5)
faddp st(3),st(0)
fmul dword ptr[8+ecx]
fxch st(1)
faddp st(3),st(0)
fxch st(3)
faddp st(2),st(0)
jmp LSetSides
Lcase4:
fmul dword ptr[ebx]
fld dword ptr[0+4+edx]
fxch st(2)
fmul dword ptr[ecx]
fxch st(2)
fld st(0)
fmul dword ptr[4+ebx]
fld dword ptr[0+8+edx]
fxch st(2)
fmul dword ptr[4+ecx]
fxch st(2)
fld st(0)
fmul dword ptr[8+ecx]
fxch st(5)
faddp st(3),st(0)
fmul dword ptr[8+ebx]
fxch st(1)
faddp st(3),st(0)
fxch st(3)
faddp st(2),st(0)
jmp LSetSides
Lcase5:
fmul dword ptr[ecx]
fld dword ptr[0+4+edx]
fxch st(2)
fmul dword ptr[ebx]
fxch st(2)
fld st(0)
fmul dword ptr[4+ebx]
fld dword ptr[0+8+edx]
fxch st(2)
fmul dword ptr[4+ecx]
fxch st(2)
fld st(0)
fmul dword ptr[8+ecx]
fxch st(5)
faddp st(3),st(0)
fmul dword ptr[8+ebx]
fxch st(1)
faddp st(3),st(0)
fxch st(3)
faddp st(2),st(0)
jmp LSetSides
Lcase6:
fmul dword ptr[ebx]
fld dword ptr[0+4+edx]
fxch st(2)
fmul dword ptr[ecx]
fxch st(2)
fld st(0)
fmul dword ptr[4+ecx]
fld dword ptr[0+8+edx]
fxch st(2)
fmul dword ptr[4+ebx]
fxch st(2)
fld st(0)
fmul dword ptr[8+ecx]
fxch st(5)
faddp st(3),st(0)
fmul dword ptr[8+ebx]
fxch st(1)
faddp st(3),st(0)
fxch st(3)
faddp st(2),st(0)
jmp LSetSides
Lcase7:
fmul dword ptr[ecx]
fld dword ptr[0+4+edx]
fxch st(2)
fmul dword ptr[ebx]
fxch st(2)
fld st(0)
fmul dword ptr[4+ecx]
fld dword ptr[0+8+edx]
fxch st(2)
fmul dword ptr[4+ebx]
fxch st(2)
fld st(0)
fmul dword ptr[8+ecx]
fxch st(5)
faddp st(3),st(0)
fmul dword ptr[8+ebx]
fxch st(1)
faddp st(3),st(0)
fxch st(3)
faddp st(2),st(0)
LSetSides:
faddp st(2),st(0)
fcomp dword ptr[12+edx]
xor ecx,ecx
fnstsw ax
fcomp dword ptr[12+edx]
and ah,1
xor ah,1
add cl,ah
fnstsw ax
and ah,1
add ah,ah
add cl,ah
pop ebx
mov eax,ecx
ret
Lerror:
int 3
}
}
#pragma warning( default: 4035 )
#endif
#endif
/*
=================
RadiusFromBounds
=================
*/
float RadiusFromBounds( const vec3_t mins, const vec3_t maxs ) {
int i;
vec3_t corner;
float a, b;
for (i=0 ; i<3 ; i++) {
a = fabs( mins[i] );
b = fabs( maxs[i] );
corner[i] = a > b ? a : b;
}
return VectorLength (corner);
}
void ClearBounds( vec3_t mins, vec3_t maxs ) {
mins[0] = mins[1] = mins[2] = 99999;
maxs[0] = maxs[1] = maxs[2] = -99999;
}
void AddPointToBounds( const vec3_t v, vec3_t mins, vec3_t maxs ) {
if ( v[0] < mins[0] ) {
mins[0] = v[0];
}
if ( v[0] > maxs[0]) {
maxs[0] = v[0];
}
if ( v[1] < mins[1] ) {
mins[1] = v[1];
}
if ( v[1] > maxs[1]) {
maxs[1] = v[1];
}
if ( v[2] < mins[2] ) {
mins[2] = v[2];
}
if ( v[2] > maxs[2]) {
maxs[2] = v[2];
}
}
vec_t VectorNormalize( vec3_t v ) {
// NOTE: TTimo - Apple G4 altivec source uses double?
float length, ilength;
length = v[0]*v[0] + v[1]*v[1] + v[2]*v[2];
length = sqrt (length);
if ( length ) {
ilength = 1/length;
v[0] *= ilength;
v[1] *= ilength;
v[2] *= ilength;
}
return length;
}
vec_t VectorNormalize2( const vec3_t v, vec3_t out) {
float length, ilength;
length = v[0]*v[0] + v[1]*v[1] + v[2]*v[2];
length = sqrt (length);
if (length)
{
#ifndef Q3_VM // bk0101022 - FPE related
// assert( ((Q_fabs(v[0])!=0.0f) || (Q_fabs(v[1])!=0.0f) || (Q_fabs(v[2])!=0.0f)) );
#endif
ilength = 1/length;
out[0] = v[0]*ilength;
out[1] = v[1]*ilength;
out[2] = v[2]*ilength;
} else {
#ifndef Q3_VM // bk0101022 - FPE related
// assert( ((Q_fabs(v[0])==0.0f) && (Q_fabs(v[1])==0.0f) && (Q_fabs(v[2])==0.0f)) );
#endif
VectorClear( out );
}
return length;
}
void _VectorMA( const vec3_t veca, float scale, const vec3_t vecb, vec3_t vecc) {
vecc[0] = veca[0] + scale*vecb[0];
vecc[1] = veca[1] + scale*vecb[1];
vecc[2] = veca[2] + scale*vecb[2];
}
vec_t _DotProduct( const vec3_t v1, const vec3_t v2 ) {
return v1[0]*v2[0] + v1[1]*v2[1] + v1[2]*v2[2];
}
void _VectorSubtract( const vec3_t veca, const vec3_t vecb, vec3_t out ) {
out[0] = veca[0]-vecb[0];
out[1] = veca[1]-vecb[1];
out[2] = veca[2]-vecb[2];
}
void _VectorAdd( const vec3_t veca, const vec3_t vecb, vec3_t out ) {
out[0] = veca[0]+vecb[0];
out[1] = veca[1]+vecb[1];
out[2] = veca[2]+vecb[2];
}
void _VectorCopy( const vec3_t in, vec3_t out ) {
out[0] = in[0];
out[1] = in[1];
out[2] = in[2];
}
void _VectorScale( const vec3_t in, vec_t scale, vec3_t out ) {
out[0] = in[0]*scale;
out[1] = in[1]*scale;
out[2] = in[2]*scale;
}
void Vector4Scale( const vec4_t in, vec_t scale, vec4_t out ) {
out[0] = in[0]*scale;
out[1] = in[1]*scale;
out[2] = in[2]*scale;
out[3] = in[3]*scale;
}
int Q_log2( int val ) {
int answer;
answer = 0;
while ( ( val>>=1 ) != 0 ) {
answer++;
}
return answer;
}
/*
=================
PlaneTypeForNormal
=================
*/
/*
int PlaneTypeForNormal (vec3_t normal) {
if ( normal[0] == 1.0 )
return PLANE_X;
if ( normal[1] == 1.0 )
return PLANE_Y;
if ( normal[2] == 1.0 )
return PLANE_Z;
return PLANE_NON_AXIAL;
}
*/
/*
================
MatrixMultiply
================
*/
void MatrixMultiply(float in1[3][3], float in2[3][3], float out[3][3]) {
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[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[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];
}
void AngleVectors( const vec3_t angles, vec3_t forward, vec3_t right, vec3_t up) {
float angle;
static float sr, sp, sy, cr, cp, cy;
// static to help MS compiler fp bugs
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);
if (forward)
{
forward[0] = cp*cy;
forward[1] = cp*sy;
forward[2] = -sp;
}
if (right)
{
right[0] = (-1*sr*sp*cy+-1*cr*-sy);
right[1] = (-1*sr*sp*sy+-1*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;
}
}
/*
** assumes "src" is normalized
*/
void PerpendicularVector( vec3_t dst, const vec3_t src )
{
int pos;
int i;
float minelem = 1.0F;
vec3_t tempvec;
/*
** find the smallest magnitude axially aligned vector
*/
for ( pos = 0, i = 0; i < 3; i++ )
{
if ( fabs( src[i] ) < minelem )
{
pos = i;
minelem = fabs( src[i] );
}
}
tempvec[0] = tempvec[1] = tempvec[2] = 0.0F;
tempvec[pos] = 1.0F;
/*
** project the point onto the plane defined by src
*/
ProjectPointOnPlane( dst, tempvec, src );
/*
** normalize the result
*/
VectorNormalize( dst );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -