📄 q_shared.c
字号:
fmul ds:dword ptr[ebx]
fxch st(2)
fld st(0)
fmul ds:dword ptr[4+ecx]
fld ds:dword ptr[0+8+edx]
fxch st(2)
fmul ds:dword ptr[4+ebx]
fxch st(2)
fld st(0)
fmul ds:dword ptr[8+ecx]
fxch st(5)
faddp st(3),st(0)
fmul ds: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 ds:dword ptr[12+edx]
xor ecx,ecx
fnstsw ax
fcomp ds: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
void ClearBounds (vec3_t mins, vec3_t maxs)
{
mins[0] = mins[1] = mins[2] = 99999;
maxs[0] = maxs[1] = maxs[2] = -99999;
}
void AddPointToBounds (vec3_t v, vec3_t mins, vec3_t maxs)
{
int i;
vec_t val;
for (i=0 ; i<3 ; i++)
{
val = v[i];
if (val < mins[i])
mins[i] = val;
if (val > maxs[i])
maxs[i] = val;
}
}
int VectorCompare (vec3_t v1, vec3_t v2)
{
if (v1[0] != v2[0] || v1[1] != v2[1] || v1[2] != v2[2])
return 0;
return 1;
}
vec_t VectorNormalize (vec3_t v)
{
float length, ilength;
length = v[0]*v[0] + v[1]*v[1] + v[2]*v[2];
length = sqrt (length); // FIXME
if (length)
{
ilength = 1/length;
v[0] *= ilength;
v[1] *= ilength;
v[2] *= ilength;
}
return length;
}
vec_t VectorNormalize2 (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); // FIXME
if (length)
{
ilength = 1/length;
out[0] = v[0]*ilength;
out[1] = v[1]*ilength;
out[2] = v[2]*ilength;
}
return length;
}
void VectorMA (vec3_t veca, float scale, 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 (vec3_t v1, vec3_t v2)
{
return v1[0]*v2[0] + v1[1]*v2[1] + v1[2]*v2[2];
}
void _VectorSubtract (vec3_t veca, 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 (vec3_t veca, 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 (vec3_t in, vec3_t out)
{
out[0] = in[0];
out[1] = in[1];
out[2] = in[2];
}
void CrossProduct (vec3_t v1, vec3_t v2, vec3_t cross)
{
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];
}
double sqrt(double x);
vec_t VectorLength(vec3_t v)
{
int i;
float length;
length = 0;
for (i=0 ; i< 3 ; i++)
length += v[i]*v[i];
length = sqrt (length); // FIXME
return length;
}
void VectorInverse (vec3_t v)
{
v[0] = -v[0];
v[1] = -v[1];
v[2] = -v[2];
}
void VectorScale (vec3_t in, vec_t scale, vec3_t out)
{
out[0] = in[0]*scale;
out[1] = in[1]*scale;
out[2] = in[2]*scale;
}
int Q_log2(int val)
{
int answer=0;
while (val>>=1)
answer++;
return answer;
}
#ifdef SIN
/*
=================
CalculateRotatedBounds
=================
*/
void CalculateRotatedBounds( vec3_t angles, vec3_t mins, vec3_t maxs )
{
int i;
vec3_t forward,right,up;
vec3_t rotmins, rotmaxs;
float trans[3][3];
AngleVectors( angles, forward, right, up );
for (i=0 ; i<3 ; i++)
{
trans[i][0] = forward[i];
trans[i][1] = -right[i];
trans[i][2] = up[i];
}
ClearBounds( rotmins, rotmaxs );
for ( i = 0; i < 8; i++ )
{
vec3_t tmp, rottemp;
if ( i & 1 )
tmp[0] = mins[0];
else
tmp[0] = maxs[0];
if ( i & 2 )
tmp[1] = mins[1];
else
tmp[1] = maxs[1];
if ( i & 4 )
tmp[2] = mins[2];
else
tmp[2] = maxs[2];
MatrixTransformVector( tmp, trans, rottemp );
AddPointToBounds( rottemp, rotmins, rotmaxs );
}
VectorCopy( rotmins, mins );
VectorCopy( rotmaxs, maxs );
}
/*
=================
CalculateRotatedBounds2
=================
*/
void CalculateRotatedBounds2( float trans[3][3], vec3_t mins, vec3_t maxs )
{
int i;
vec3_t rotmins, rotmaxs;
ClearBounds( rotmins, rotmaxs );
for ( i = 0; i < 8; i++ )
{
vec3_t tmp, rottemp;
if ( i & 1 )
tmp[0] = mins[0];
else
tmp[0] = maxs[0];
if ( i & 2 )
tmp[1] = mins[1];
else
tmp[1] = maxs[1];
if ( i & 4 )
tmp[2] = mins[2];
else
tmp[2] = maxs[2];
MatrixTransformVector( tmp, trans, rottemp );
AddPointToBounds( rottemp, rotmins, rotmaxs );
}
VectorCopy( rotmins, mins );
VectorCopy( rotmaxs, maxs );
}
/*
=================
OriginFromTriangle
=================
*/
// coordinate system at center
void OriginFromTriangle( const float tri[3][3], vec3_t pos )
{
int i;
VectorClear( pos );
for (i=0;i<3;i++)
pos[i] = (tri[0][i] + tri[1][i] + tri[2][i])/3;
}
/*
=================
TransformFromTriangle
=================
*/
// 0
// /\
// / \
// 0 / \ 2
// / \
// / \
// /----------\
// 1 1 2
//
// ((type>>2)&0x3)
// 0 - edge 0 is first edge
// 1 - edge 1 is first edge
// 2 - edge 2 is first edge
//
// (type>>4)
// 0 - forward is perpendicular, up is first edge, right is on the same plane as the triangle
// 1 - forward is perpendicular, up is first edge, right is on the same plane as the triangle(inverted)
// 2 - forward is first edge, up is on the same plane as the triangle, up is perpendicular
// 3 - forward is first edge, up is on the same plane as the triangle(inverted), up is perpendicular
// 4 - forward is perpendicular to first edge, up is perpendicular, right is first edge
// 5 - forward is perpendicular to first edge, up is perpendicular, right is first edge(inverted)
// 6 - forward is perpendicular, up is first edge, right is on the same plane as the triangle
// 7 - forward is perpendicular, up is first edge, right is on the same plane as the triangle(inverted)
//
void TransformFromTriangle( const float tri[3][3], float trans[3][3], vec3_t pos )
{
vec3_t edge[2];
vec3_t cross;
vec3_t other;
vec3_t forward, right, up;
OriginFromTriangle( tri, pos );
VectorSubtract( tri[2], tri[0], edge[0] );
VectorSubtract( tri[1], tri[0], edge[1] );
VectorNormalize( edge[0] );
VectorNormalize( edge[1] );
CrossProduct( edge[1], edge[0], cross );
CrossProduct( edge[1], cross, other );
VectorCopy( cross, forward );
VectorCopy( other, right );
VectorNegate( edge[1], up );
VectorCopy( forward, trans[0] );
VectorCopy( right, trans[1] );
VectorCopy( up, trans[2] );
/*
switch( (type>>2)&0x3 )
{
case 0:
VectorSubtract( tri[2], tri[0], edge[0] );
VectorSubtract( tri[1], tri[0], edge[1] );
break;
case 1:
VectorSubtract( tri[0], tri[1], edge[0] );
VectorSubtract( tri[2], tri[1], edge[1] );
break;
case 2:
VectorSubtract( tri[1], tri[2], edge[0] );
VectorSubtract( tri[0], tri[2], edge[1] );
break;
default:
VectorSubtract( tri[2], tri[0], edge[0] );
VectorSubtract( tri[1], tri[0], edge[1] );
break;
}
VectorNormalize( edge[0] );
VectorNormalize( edge[1] );
CrossProduct( edge[1], edge[0], cross );
CrossProduct( edge[1], cross, other );
switch( type>>4 )
{
case 0:
VectorCopy( cross, forward );
VectorCopy( other, right );
VectorNegate( edge[1], up );
break;
case 1:
VectorCopy( cross, forward );
VectorCopy( other, right );
VectorCopy( edge[1], up );
break;
case 2:
VectorCopy( cross, forward );
VectorCopy( other, right );
VectorNegate( edge[0], up );
break;
case 3:
VectorCopy( cross, forward );
VectorCopy( other, right );
VectorCopy( edge[0], up );
break;
case 4:
VectorCopy( edge[0], forward );
VectorNegate( other, up );
VectorCopy( cross, right );
break;
case 5:
VectorCopy( edge[0], forward );
VectorCopy( other, up );
VectorCopy( cross, right );
break;
case 6:
VectorCopy( other, forward );
VectorNegate( edge[0], right );
VectorCopy( cross, up );
break;
case 7:
VectorCopy( other, forward );
VectorCopy( edge[0], right );
VectorCopy( cross, up );
break;
case 8:
VectorCopy( edge[0], forward );
VectorNegate( other, right );
VectorCopy( cross, up );
break;
case 9:
VectorCopy( edge[0], forward );
VectorCopy( other, right );
VectorCopy( cross, up );
break;
default:
VectorCopy( edge[0], forward );
VectorNegate( other, right );
VectorCopy( cross, up );
break;
}
// fill in the matrix
VectorCopy( forward, trans[0] );
VectorCopy( right, trans[1] );
VectorCopy( up, trans[2] );
*/
}
// 2015 code
void TransformFromTriangle_2015(const float tri[3][3], float trans[3][3], vec3_t pos)
{
vec3_t edge[2];
vec3_t cross;
vec3_t other;
vec3_t forward, right, up;
OriginFromTriangle( tri, pos );
VectorSubtract( tri[2], tri[0], edge[0] );
VectorSubtract( tri[1], tri[0], edge[1] );
VectorNormalize( edge[0] );
VectorNormalize( edge[1] );
CrossProduct( edge[1], edge[0], cross );
VectorNormalize( cross ); //
CrossProduct( edge[1], cross, other );
VectorNormalize( other ); //
VectorCopy( cross, forward );
VectorCopy( other, right );
// VectorNegate( edge[1], up );
VectorCopy( edge[1], up );
VectorCopy( forward, trans[0] );
VectorCopy( right, trans[1] );
VectorCopy( up, trans[2] );
}
static char musicmoods[ mood_totalnumber ][ 16 ] =
{
"none",
"normal",
"action",
"suspense",
"mystery",
"success",
"failure",
"surprise",
"special",
"aux1",
"aux2",
"aux3",
"aux4",
"aux5",
"aux6",
"aux7"
};
/*
=================
MusicMood_NameToNum
=================
*/
int MusicMood_NameToNum( const char * name )
{
int i;
if ( !name )
return -1;
for ( i = 0; i < mood_totalnumber; i++ )
{
if ( !strcmpi( name, musicmoods[ i ] ) )
{
return i;
}
}
return -1;
}
/*
=================
MusicMood_NumToName
=================
*/
const char * MusicMood_NumToName( int num )
{
if ( ( num < 0 ) || ( num >= mood_totalnumber ) )
return "";
else
return musicmoods[ num ];
}
/*
===============
SURFACE_DamageMultiplier
===============
*/
float SURFACE_DamageMultiplier( int flags )
{
float mult;
mult = 0;
switch ( flags )
{
case SURF_TYPE_FLESH:
case SURF_TYPE_FABRIC:
case SURF_TYPE_VEGETATION:
case SURF_TYPE_WATER:
case SURF_TYPE_PAPER:
mult = 0;
break;
case SURF_TYPE_DIRT:
mult = 0.2;
break;
case SURF_TYPE_WOOD:
mult = 0.5;
break;
case SURF_TYPE_METAL:
case SURF_TYPE_DUCT:
case SURF_TYPE_GRILL:
mult = 1;
break;
case SURF_TYPE_GRAVEL:
case SURF_TYPE_STONE:
case SURF_TYPE_CONCRETE:
mult = 1.5;
break;
case SURF_TYPE_GLASS:
case SURF_TYPE_MONITOR:
mult = 3;
break;
default:
break;
}
return mult;
}
#endif
//====================================================================================
/*
============
COM_SkipPath
============
*/
#ifdef SIN
const char *COM_SkipPath (const char *pathname)
{
const char *last;
#else
char *COM_SkipPath (char *pathname)
{
char *last;
#endif
last = pathname;
while (*pathname)
{
if (*pathname=='/')
last = pathname+1;
pathname++;
}
return last;
}
/*
============
COM_ParseHex
============
*/
int COM_ParseHex (const char *hex)
{
const char *str;
int num;
num = 0;
str = hex;
while (*str)
{
num <<= 4;
if (*str >= '0' && *str <= '9')
num += *str-'0';
else if (*str >= 'a' && *str <= 'f')
num += 10 + *str-'a';
else if (*str >= 'A' && *str <= 'F')
num += 10 + *str-'A';
else
Com_Printf("Bad hex number: %s",hex);
str++;
}
return num;
}
/*
============
COM_StripExtension
============
*/
#ifdef SIN
void COM_StripExtension (const char *in, char *out)
#else
void COM_StripExtension (char *in, char *out)
#endif
{
while (*in && *in != '.')
*out++ = *in++;
*out = 0;
}
/*
============
COM_FileExtension
============
*/
#ifdef SIN
char *COM_FileExtension (const char *in)
#else
char *COM_FileExtension (char *in)
#endif
{
static char exten[8];
int i;
while (*in && *in != '.')
in++;
if (!*in)
return "";
in++;
for (i=0 ; i<7 && *in ; i++,in++)
exten[i] = *in;
exten[i] = 0;
return exten;
}
/*
============
COM_FileBase
============
*/
#ifdef SIN
void COM_FileBase (const char *in, char *out)
{
const char *s;
const char *s2;
#else
void COM_FileBase (char *in, char *out)
{
char *s, *s2;
#endif
s = in + strlen(in) - 1;
while (s != in && *s != '.')
s--;
for (s2 = s ; s2 != in && *s2 != '/' ; s2--)
;
if (s-s2 < 2)
out[0] = 0;
else
{
s--;
strncpy (out,s2+1, s-s2);
out[s-s2] = 0;
}
}
/*
============
COM_FilePath
Returns the path up to, but not including the last /
============
*/
#ifdef SIN
void COM_FilePath (const char *in, char *out)
{
const char *s;
#else
void COM_FilePath (char *in, char *out)
{
char *s;
#endif
s = in + strlen(in) - 1;
while (s != in && *s != '/')
s--;
strncpy (out,in, s-in);
out[s-in] = 0;
}
/*
==================
COM_DefaultExtension
==================
*/
#ifdef SIN
void COM_DefaultExtension (char *path, const char *extension)
#else
void COM_DefaultExtension (char *path, char *extension)
#endif
{
char *src;
//
// if path doesn't have a .EXT, append extension
// (extension should include the .)
//
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -