mirror of
https://github.com/Q3Rally-Team/q3rally.git
synced 2025-02-21 03:21:50 +00:00
Add Q_acos and Q_asin trap calls for qvms (cgame had acos, renamed to Q_acos for consistancy with engine).
Change the range check on acos to be 0 to PI, not -PI to PI. Fix memcmp for qvms?
This commit is contained in:
parent
c42db21b59
commit
19a7bc3429
16 changed files with 114 additions and 99 deletions
|
@ -1064,7 +1064,7 @@ static void CG_TeamBase( centity_t *cent ) {
|
|||
cent->muzzleFlashTime = 1;
|
||||
}
|
||||
VectorCopy(cent->currentState.angles, angles);
|
||||
angles[YAW] += (float) 16 * acos(1-c) * 180 / M_PI;
|
||||
angles[YAW] += (float) 16 * Q_acos(1-c) * 180 / M_PI;
|
||||
AnglesToAxis( angles, model.axis );
|
||||
|
||||
VectorScale( model.axis[0], c, model.axis[0]);
|
||||
|
|
|
@ -2141,7 +2141,7 @@ static void CG_PlayerFlag( centity_t *cent, qhandle_t hSkin, refEntity_t *torso
|
|||
else if (d < -1.0f) {
|
||||
d = -1.0f;
|
||||
}
|
||||
angle = acos(d);
|
||||
angle = Q_acos(d);
|
||||
|
||||
d = DotProduct(pole.axis[1], dir);
|
||||
if (d < 0) {
|
||||
|
|
|
@ -183,7 +183,10 @@ typedef enum {
|
|||
CG_CEIL,
|
||||
CG_TESTPRINTINT,
|
||||
CG_TESTPRINTFLOAT,
|
||||
CG_ACOS
|
||||
CG_ACOS,
|
||||
|
||||
// ZTM: New to Q3Rally
|
||||
CG_ASIN,
|
||||
} cgameImport_t;
|
||||
|
||||
|
||||
|
|
|
@ -49,38 +49,6 @@ static void CG_Free( int size ) {
|
|||
}
|
||||
*/
|
||||
|
||||
#ifdef Q3_VM
|
||||
int memcmp( const unsigned char *dest, const unsigned char *src, size_t count ) {
|
||||
int i;
|
||||
|
||||
for (i = 0; i < count; i++){
|
||||
if (dest != src)
|
||||
return qfalse;
|
||||
|
||||
dest++;
|
||||
src++;
|
||||
}
|
||||
|
||||
return qtrue;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
static qboolean CG_Memcmp(byte *s1, byte *s2, int size) {
|
||||
int i;
|
||||
|
||||
for (i = 0; i < size; i++){
|
||||
if (s1 != s2)
|
||||
return qfalse;
|
||||
|
||||
s1++;
|
||||
s2++;
|
||||
}
|
||||
|
||||
return qtrue;
|
||||
}
|
||||
*/
|
||||
|
||||
typedef struct
|
||||
{
|
||||
byte *imageData; // Image Data (Up To 32 Bits)
|
||||
|
|
|
@ -102,6 +102,7 @@ equ floor -108
|
|||
equ ceil -109
|
||||
equ testPrintInt -110
|
||||
equ testPrintFloat -111
|
||||
equ acos -112
|
||||
equ Q_acos -112
|
||||
equ Q_asin -113
|
||||
|
||||
|
||||
|
|
|
@ -643,6 +643,8 @@ intptr_t CL_CgameSystemCalls( intptr_t *args ) {
|
|||
return FloatAsInt( ceil( VMF(1) ) );
|
||||
case CG_ACOS:
|
||||
return FloatAsInt( Q_acos( VMF(1) ) );
|
||||
case CG_ASIN:
|
||||
return FloatAsInt( Q_asin( VMF(1) ) );
|
||||
|
||||
case CG_PC_ADD_GLOBAL_DEFINE:
|
||||
return botlib_export->PC_AddGlobalDefine( VMA(1) );
|
||||
|
|
|
@ -1016,6 +1016,12 @@ intptr_t CL_UISystemCalls( intptr_t *args ) {
|
|||
case UI_CEIL:
|
||||
return FloatAsInt( ceil( VMF(1) ) );
|
||||
|
||||
case UI_ACOS:
|
||||
return FloatAsInt( Q_acos( VMF(1) ) );
|
||||
|
||||
case UI_ASIN:
|
||||
return FloatAsInt( Q_asin( VMF(1) ) );
|
||||
|
||||
case UI_PC_ADD_GLOBAL_DEFINE:
|
||||
return botlib_export->PC_AddGlobalDefine( VMA(1) );
|
||||
case UI_PC_LOAD_SOURCE:
|
||||
|
|
|
@ -316,6 +316,18 @@ void *memmove(void *dest, const void *src, size_t count)
|
|||
return dest;
|
||||
}
|
||||
|
||||
// STONELANCE - used in cg_rally_platetools
|
||||
int memcmp( const void *lhs, const void *rhs, size_t count ) {
|
||||
int i;
|
||||
|
||||
for (i = 0; i < count; i++){
|
||||
if (((char *) lhs)[i] != ((char *) rhs)[i])
|
||||
return ((char *) lhs)[i] - ((char *) rhs)[i];
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
// END
|
||||
|
||||
#if 0
|
||||
|
||||
|
@ -374,7 +386,6 @@ double sqrt( double x ) {
|
|||
return y;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
float sintable[1024] = {
|
||||
0.000000,0.001534,0.003068,0.004602,0.006136,0.007670,0.009204,0.010738,
|
||||
|
@ -507,8 +518,6 @@ float sintable[1024] = {
|
|||
0.999925,0.999942,0.999958,0.999971,0.999981,0.999989,0.999995,0.999999
|
||||
};
|
||||
|
||||
#if 0
|
||||
|
||||
double sin( double x ) {
|
||||
int index;
|
||||
int quad;
|
||||
|
@ -550,9 +559,7 @@ double cos( double x ) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifndef CGAME
|
||||
/*
|
||||
void create_acostable( void ) {
|
||||
int i;
|
||||
|
@ -703,7 +710,7 @@ float acostable[] = {
|
|||
0.17700769,0.16554844,0.15324301,0.13986823,0.12508152,0.10830610,0.08841715,0.06251018,
|
||||
};
|
||||
|
||||
double acos( double x ) {
|
||||
float Q_acos( float x ) {
|
||||
int index;
|
||||
|
||||
if (x < -1)
|
||||
|
@ -714,9 +721,26 @@ double acos( double x ) {
|
|||
return acostable[index];
|
||||
}
|
||||
|
||||
#endif
|
||||
float Q_asin( float x ) {
|
||||
float dir;
|
||||
int i;
|
||||
|
||||
#if 0
|
||||
float x2 = (float)x;
|
||||
|
||||
dir = 1.0f;
|
||||
if (x2 < 0.0f){
|
||||
dir = -1.0f;
|
||||
x2 *= -1.0f;
|
||||
}
|
||||
|
||||
for ( i = 0 ; i < 1024 ; i++ ) {
|
||||
if ( sintable[i] >= (x2 - 0.000001f) ) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return (dir * i * (M_PI/2048));
|
||||
}
|
||||
|
||||
double atan2( double y, double x ) {
|
||||
float base;
|
||||
|
@ -818,35 +842,6 @@ double tan( double x ) {
|
|||
return sin(x) / cos(x);
|
||||
}
|
||||
|
||||
double asin( double x ) {
|
||||
|
||||
float dir;
|
||||
int i;
|
||||
|
||||
float x2 = (float)x;
|
||||
|
||||
dir = 1.0f;
|
||||
if (x2 < 0.0f){
|
||||
dir = -1.0f;
|
||||
x2 *= -1.0f;
|
||||
}
|
||||
|
||||
for ( i = 0 ; i < 1024 ; i++ ) {
|
||||
if ( sintable[i] >= (x2 - 0.000001f) ) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return (dir * i * (M_PI/2048));
|
||||
|
||||
/*
|
||||
Com_Printf( "x: %f\n", x );
|
||||
Com_Printf( "acos(x): %f\n", acos( x ) );
|
||||
|
||||
return ( M_PI_2 - acos( x ) );
|
||||
*/
|
||||
}
|
||||
|
||||
float exptable[] = {
|
||||
1.00000000,1.00097800,1.00195695,1.00293686,1.00391772,1.00489955,1.00588234,1.00686608,
|
||||
1.00785079,1.00883647,1.00982310,1.01081071,1.01179927,1.01278881,1.01377931,1.01477078,
|
||||
|
|
|
@ -112,8 +112,7 @@ void *memset( void *dest, int c, size_t count );
|
|||
void *memcpy( void *dest, const void *src, size_t count );
|
||||
|
||||
// STONELANCE - used in cg_rally_platetools
|
||||
int memcmp( const unsigned char *dest, const unsigned char *src, size_t count );
|
||||
void *malloc( size_t count );
|
||||
int memcmp( const void *dest, const void *src, size_t count );
|
||||
// END
|
||||
|
||||
// Math functions
|
||||
|
@ -122,15 +121,15 @@ double floor( double x );
|
|||
double sqrt( double x );
|
||||
double sin( double x );
|
||||
double cos( double x );
|
||||
float Q_acos( float c );
|
||||
float Q_asin( float c );
|
||||
double atan2( double y, double x );
|
||||
// STONELANCE
|
||||
double asin( double x );
|
||||
double exp( double x );
|
||||
// END
|
||||
double tan( double x );
|
||||
int abs( int n );
|
||||
double fabs( double x );
|
||||
double acos( double x );
|
||||
|
||||
// STONELANCE
|
||||
double exp( double x );
|
||||
// END
|
||||
|
||||
#endif // BG_LIB_H
|
||||
|
||||
|
|
|
@ -58,6 +58,8 @@ equ floor -111
|
|||
equ ceil -112
|
||||
equ testPrintInt -113
|
||||
equ testPrintFloat -114
|
||||
equ Q_acos -115
|
||||
equ Q_asin -116
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1125,7 +1125,7 @@ void AnglesToDeltaAngles( vec3_t angles, const vec3_t w, vec3_t deltaAngles ) {
|
|||
s2 = sin( angles[1] * M_PI_180 );
|
||||
s3 = sin( angles[2] * M_PI_180 );
|
||||
|
||||
p = 2.0f * acos( c1*c2*c3 - s1*s2*s3 );
|
||||
p = 2.0f * Q_acos( c1*c2*c3 - s1*s2*s3 );
|
||||
sp = p / sin( p / 2.0f ) ;
|
||||
|
||||
deltaAngles[0] = (c1*s2*c3 + s1*c2*c3) * sp * M_180_PI;
|
||||
|
@ -1154,7 +1154,7 @@ void OrientationToDeltaAngles( float t[3][3], const vec3_t w, vec3_t delta_angle
|
|||
up[2] = -w[1] * t[2][0] + w[0] * t[2][1];
|
||||
right[2] = -w[1] * t[0][0] + w[0] * t[0][1];
|
||||
|
||||
delta_angles[PITCH] = asin( -forward[2] ) * M_180_PI;
|
||||
delta_angles[PITCH] = Q_asin( -forward[2] ) * M_180_PI;
|
||||
if (up[2] < 0.0f)
|
||||
delta_angles[PITCH] = 180 - delta_angles[PITCH];
|
||||
|
||||
|
@ -1165,7 +1165,7 @@ void OrientationToDeltaAngles( float t[3][3], const vec3_t w, vec3_t delta_angle
|
|||
as = forward[1] / cp > 1.00f ? 1.00f : forward[1] / cp;
|
||||
as = as < -1.00f ? -1.00f : as;
|
||||
|
||||
delta_angles[YAW] = asin(as) * M_180_PI;
|
||||
delta_angles[YAW] = Q_asin(as) * M_180_PI;
|
||||
if (forward[0] < 0.0f)
|
||||
delta_angles[YAW] = 180 - delta_angles[YAW];
|
||||
if (up[2] < 0.0f)
|
||||
|
@ -1173,7 +1173,7 @@ void OrientationToDeltaAngles( float t[3][3], const vec3_t w, vec3_t delta_angle
|
|||
|
||||
as = -right[2] / cp > 1.00f ? 1.00f : -right[2] / cp;
|
||||
as = as < -1.00f ? -1.00f : as;
|
||||
delta_angles[ROLL] = asin(as) * M_180_PI;
|
||||
delta_angles[ROLL] = Q_asin(as) * M_180_PI;
|
||||
}
|
||||
else {
|
||||
delta_angles[YAW]=0;
|
||||
|
@ -1204,7 +1204,7 @@ void OrientationToAngles( float t[3][3], vec3_t angles ) {
|
|||
|
||||
OrientationToVectors(t, forward, right, up);
|
||||
|
||||
angles[PITCH] = asin(-forward[2]) * M_180_PI;
|
||||
angles[PITCH] = Q_asin(-forward[2]) * M_180_PI;
|
||||
if (up[2] < 0.0f)
|
||||
angles[PITCH] = 180 - angles[PITCH];
|
||||
|
||||
|
@ -1215,7 +1215,7 @@ void OrientationToAngles( float t[3][3], vec3_t angles ) {
|
|||
as = forward[1] / cp > 1.00f ? 1.00f : forward[1] / cp;
|
||||
as = as < -1.00f ? -1.00f : as;
|
||||
|
||||
angles[YAW] = asin(as) * M_180_PI;
|
||||
angles[YAW] = Q_asin(as) * M_180_PI;
|
||||
if (forward[0] < 0.0f)
|
||||
angles[YAW] = 180 - angles[YAW];
|
||||
if (up[2] < 0.0f)
|
||||
|
@ -1223,7 +1223,7 @@ void OrientationToAngles( float t[3][3], vec3_t angles ) {
|
|||
|
||||
as = -right[2] / cp > 1.00f ? 1.00f : -right[2] / cp;
|
||||
as = as < -1.00f ? -1.00f : as;
|
||||
angles[ROLL] = asin(as) * M_180_PI;
|
||||
angles[ROLL] = Q_asin(as) * M_180_PI;
|
||||
}
|
||||
else {
|
||||
angles[YAW]=0;
|
||||
|
@ -1450,7 +1450,7 @@ void QuaternionSLERP(const vec4_t from, const vec4_t to, float t, vec4_t res){
|
|||
|
||||
// OPTIMIZE: If costheta was squared then i could use the sin(t)^2 = 1-cos(t)^s
|
||||
// Is sintheta ever negative? If not then sin(t)^2 > 0 == sin(t) > 0
|
||||
theta = acos( costheta );
|
||||
theta = Q_acos( costheta );
|
||||
sintheta = sin( theta );
|
||||
if( sintheta > 0.0f )
|
||||
{
|
||||
|
@ -1495,7 +1495,7 @@ void QuaternionSLERP(const vec4_t from, const vec4_t to, float t, vec4_t res){
|
|||
// calculate coefficients
|
||||
if ( (1.0 - cosom) > 0.1f ) {
|
||||
// standard case (slerp)
|
||||
omega = acos(cosom);
|
||||
omega = Q_acos(cosom);
|
||||
sinom = sin(omega);
|
||||
scale0 = sin((1.0 - t) * omega) / sinom;
|
||||
scale1 = sin(t * omega) / sinom;
|
||||
|
@ -1655,7 +1655,7 @@ void QuaternionToAngles( const vec4_t quat, vec3_t angles ){
|
|||
// u[0] = s * (xz - wy); u[1] = s * (yz + wx);
|
||||
u[2] = 1 - s * (xx + yy);
|
||||
|
||||
angles[PITCH] = asin(-f[2]) * 180.0f / M_PI;
|
||||
angles[PITCH] = Q_asin(-f[2]) * 180.0f / M_PI;
|
||||
if (u[2] < 0.0f)
|
||||
angles[PITCH] = 180 - angles[PITCH];
|
||||
|
||||
|
@ -1666,7 +1666,7 @@ void QuaternionToAngles( const vec4_t quat, vec3_t angles ){
|
|||
as = f[1] / cp > 1.00f ? 1.00f : f[1] / cp;
|
||||
as = as < -1.00f ? -1.00f : as;
|
||||
|
||||
angles[YAW] = asin(as) * 180.0f / M_PI;
|
||||
angles[YAW] = Q_asin(as) * 180.0f / M_PI;
|
||||
if (f[0] < 0.0f)
|
||||
angles[YAW] = 180 - angles[YAW];
|
||||
if (u[2] < 0.0f)
|
||||
|
@ -1674,7 +1674,7 @@ void QuaternionToAngles( const vec4_t quat, vec3_t angles ){
|
|||
|
||||
as = -r[2] / cp > 1.00f ? 1.00f : -r[2] / cp;
|
||||
as = as < -1.00f ? -1.00f : as;
|
||||
angles[ROLL] = asin(as) * 180 / M_PI;
|
||||
angles[ROLL] = Q_asin(as) * 180 / M_PI;
|
||||
}
|
||||
else {
|
||||
angles[YAW]=0;
|
||||
|
@ -2057,7 +2057,7 @@ int Q_isnan( float x )
|
|||
=====================
|
||||
Q_acos
|
||||
|
||||
the msvc acos doesn't always return a value between -PI and PI:
|
||||
the msvc acos doesn't always return a value between 0 and PI:
|
||||
|
||||
int i;
|
||||
i = 1065353246;
|
||||
|
@ -2071,10 +2071,32 @@ float Q_acos(float c) {
|
|||
angle = acos(c);
|
||||
|
||||
if (angle > M_PI) {
|
||||
return (float)M_PI;
|
||||
return M_PI;
|
||||
}
|
||||
if (angle < -M_PI) {
|
||||
return (float)M_PI;
|
||||
if (angle < 0.0f) {
|
||||
return 0.0f;
|
||||
}
|
||||
return angle;
|
||||
}
|
||||
|
||||
/*
|
||||
=====================
|
||||
Q_asin
|
||||
|
||||
the msvc asin probably has same type of behavior as acos
|
||||
|
||||
=====================
|
||||
*/
|
||||
float Q_asin(float c) {
|
||||
float angle;
|
||||
|
||||
angle = asin(c);
|
||||
|
||||
if (angle > M_PI_2) {
|
||||
return M_PI_2;
|
||||
}
|
||||
if (angle < -M_PI_2) {
|
||||
return -M_PI_2;
|
||||
}
|
||||
return angle;
|
||||
}
|
||||
|
|
|
@ -705,6 +705,7 @@ void VectorRotate( vec3_t in, vec3_t matrix[3], vec3_t out );
|
|||
int Q_log2(int val);
|
||||
|
||||
float Q_acos(float c);
|
||||
float Q_asin(float c);
|
||||
|
||||
int Q_rand( int *seed );
|
||||
float Q_random( int *seed );
|
||||
|
|
|
@ -351,7 +351,11 @@ typedef enum {
|
|||
TRAP_CEIL,
|
||||
|
||||
TRAP_TESTPRINTINT,
|
||||
TRAP_TESTPRINTFLOAT
|
||||
TRAP_TESTPRINTFLOAT,
|
||||
|
||||
// ZTM: New to Q3Rally
|
||||
TRAP_ACOS,
|
||||
TRAP_ASIN,
|
||||
} sharedTraps_t;
|
||||
|
||||
void VM_Init( void );
|
||||
|
|
|
@ -836,6 +836,11 @@ intptr_t SV_GameSystemCalls( intptr_t *args ) {
|
|||
case TRAP_CEIL:
|
||||
return FloatAsInt( ceil( VMF(1) ) );
|
||||
|
||||
case TRAP_ACOS:
|
||||
return FloatAsInt( Q_acos( VMF(1) ) );
|
||||
|
||||
case TRAP_ASIN:
|
||||
return FloatAsInt( Q_asin( VMF(1) ) );
|
||||
|
||||
default:
|
||||
Com_Error( ERR_DROP, "Bad game system trap: %ld", (long int) args[0] );
|
||||
|
|
|
@ -133,7 +133,12 @@ typedef enum {
|
|||
UI_ATAN2,
|
||||
UI_SQRT,
|
||||
UI_FLOOR,
|
||||
UI_CEIL
|
||||
UI_CEIL,
|
||||
|
||||
// ZTM: New to Q3Rally
|
||||
UI_ACOS,
|
||||
UI_ASIN,
|
||||
|
||||
} uiImport_t;
|
||||
|
||||
typedef enum {
|
||||
|
|
|
@ -98,4 +98,6 @@ equ atan2 -106
|
|||
equ sqrt -107
|
||||
equ floor -108
|
||||
equ ceil -109
|
||||
equ Q_acos -110
|
||||
equ Q_asin -111
|
||||
|
||||
|
|
Loading…
Reference in a new issue