X-Git-Url: https://git.xonotic.org/?a=blobdiff_plain;f=libs%2Fmathlib%2Fmathlib.c;h=ce6cfdc2d87fcf87e4920af33657deded791b020;hb=c7f847f583be9934f2b7b2a18e84bfaaf60eeda6;hp=e422877c678c2b8c6216af8d4944dc801d2f91fc;hpb=830125fad042fad35dc029b6eb57c8156ad7e176;p=xonotic%2Fnetradiant.git diff --git a/libs/mathlib/mathlib.c b/libs/mathlib/mathlib.c index e422877c..ce6cfdc2 100644 --- a/libs/mathlib/mathlib.c +++ b/libs/mathlib/mathlib.c @@ -1,5 +1,5 @@ /* - Copyright (C) 1999-2007 id Software, Inc. and contributors. + Copyright (C) 1999-2006 Id Software, Inc. and contributors. For a list of contributors, see the accompanying CONTRIBUTORS file. This file is part of GtkRadiant. @@ -24,7 +24,11 @@ // we use memcpy and memset #include -vec3_t vec3_origin = {0.0f,0.0f,0.0f}; +const vec3_t vec3_origin = {0.0f,0.0f,0.0f}; + +const vec3_t g_vec3_axis_x = { 1, 0, 0, }; +const vec3_t g_vec3_axis_y = { 0, 1, 0, }; +const vec3_t g_vec3_axis_z = { 0, 0, 1, }; /* ================ @@ -92,7 +96,7 @@ void MakeNormalVectors( vec3_t forward, vec3_t right, vec3_t up ){ CrossProduct( right, forward, up ); } -vec_t VectorLength( vec3_t v ){ +vec_t VectorLength( const vec3_t v ){ int i; float length; @@ -104,7 +108,7 @@ vec_t VectorLength( vec3_t v ){ return length; } -qboolean VectorCompare( vec3_t v1, vec3_t v2 ){ +qboolean VectorCompare( const vec3_t v1, const vec3_t v2 ){ int i; for ( i = 0 ; i < 3 ; i++ ) @@ -115,18 +119,6 @@ qboolean VectorCompare( vec3_t v1, vec3_t v2 ){ return qtrue; } -/* - // FIXME TTimo this implementation has to be particular to radiant - // through another name I'd say - vec_t Q_rint (vec_t in) - { - if (g_PrefsDlg.m_bNoClamp) - return in; - else - return (float)floor (in + 0.5); - } - */ - void VectorMA( const vec3_t va, vec_t scale, const vec3_t vb, vec3_t vc ){ vc[0] = va[0] + scale * vb[0]; vc[1] = va[1] + scale * vb[1]; @@ -290,7 +282,7 @@ void VectorSnap( vec3_t v ){ int i; for ( i = 0; i < 3; i++ ) { - v[i] = (vec_t)floor( v[i] + 0.5 ); + v[i] = (vec_t)FLOAT_TO_INTEGER( v[i] ); } } @@ -298,7 +290,7 @@ void VectorISnap( vec3_t point, int snap ){ int i; for ( i = 0 ; i < 3 ; i++ ) { - point[i] = (vec_t)floor( point[i] / snap + 0.5 ) * snap; + point[i] = (vec_t)FLOAT_SNAP( point[i], snap ); } } @@ -306,7 +298,7 @@ void VectorFSnap( vec3_t point, float snap ){ int i; for ( i = 0 ; i < 3 ; i++ ) { - point[i] = (vec_t)floor( point[i] / snap + 0.5 ) * snap; + point[i] = (vec_t)FLOAT_SNAP( point[i], snap ); } } @@ -333,15 +325,23 @@ void _Vector53Copy( vec5_t in, vec3_t out ){ } // NOTE: added these from Ritual's Q3Radiant +#define INVALID_BOUNDS 99999 void ClearBounds( vec3_t mins, vec3_t maxs ){ - mins[0] = mins[1] = mins[2] = 99999; - maxs[0] = maxs[1] = maxs[2] = -99999; + mins[0] = mins[1] = mins[2] = +INVALID_BOUNDS; + maxs[0] = maxs[1] = maxs[2] = -INVALID_BOUNDS; } void AddPointToBounds( vec3_t v, vec3_t mins, vec3_t maxs ){ int i; vec_t val; + if ( mins[0] == +INVALID_BOUNDS ) { + if ( maxs[0] == -INVALID_BOUNDS ) { + VectorCopy( v, mins ); + VectorCopy( v, maxs ); + } + } + for ( i = 0 ; i < 3 ; i++ ) { val = v[i]; @@ -354,25 +354,18 @@ void AddPointToBounds( vec3_t v, vec3_t mins, vec3_t maxs ){ } } -#define PITCH 0 // up / down -#define YAW 1 // left / right -#define ROLL 2 // fall over -#ifndef M_PI -#define M_PI 3.14159265358979323846f // matches value in gcc v2 math.h -#endif - void AngleVectors( 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.0f / 360.0f ); + angle = angles[YAW] * ( Q_PI * 2.0f / 360.0f ); sy = (vec_t)sin( angle ); cy = (vec_t)cos( angle ); - angle = angles[PITCH] * ( M_PI * 2.0f / 360.0f ); + angle = angles[PITCH] * ( Q_PI * 2.0f / 360.0f ); sp = (vec_t)sin( angle ); cp = (vec_t)cos( angle ); - angle = angles[ROLL] * ( M_PI * 2.0f / 360.0f ); + angle = angles[ROLL] * ( Q_PI * 2.0f / 360.0f ); sr = (vec_t)sin( angle ); cr = (vec_t)cos( angle ); @@ -409,13 +402,13 @@ void VectorToAngles( vec3_t vec, vec3_t angles ){ } else { - yaw = (vec_t)atan2( vec[ 1 ], vec[ 0 ] ) * 180 / M_PI; + yaw = (vec_t)atan2( vec[ 1 ], vec[ 0 ] ) * 180 / Q_PI; if ( yaw < 0 ) { yaw += 360; } forward = ( float )sqrt( vec[ 0 ] * vec[ 0 ] + vec[ 1 ] * vec[ 1 ] ); - pitch = (vec_t)atan2( vec[ 2 ], forward ) * 180 / M_PI; + pitch = (vec_t)atan2( vec[ 2 ], forward ) * 180 / Q_PI; if ( pitch < 0 ) { pitch += 360; } @@ -627,7 +620,7 @@ void RotatePointAroundVector( vec3_t dst, const vec3_t dir, const vec3_t point, memset( zrot, 0, sizeof( zrot ) ); zrot[0][0] = zrot[1][1] = zrot[2][2] = 1.0F; - rad = DEG2RAD( degrees ); + rad = (float)DEG2RAD( degrees ); zrot[0][0] = (vec_t)cos( rad ); zrot[0][1] = (vec_t)sin( rad ); zrot[1][0] = (vec_t)-sin( rad );