From ludwig: This one fixes a rendering error

This commit is contained in:
Zachary Slater 2005-08-27 18:11:08 +00:00
parent 916cb54d72
commit d54f831dd7
2 changed files with 14 additions and 10 deletions

View File

@ -551,15 +551,17 @@ void VectorRotate( vec3_t in, vec3_t matrix[3], vec3_t out )
*/ */
float Q_rsqrt( float number ) float Q_rsqrt( float number )
{ {
long i; union {
float f;
int i;
} t;
float x2, y; float x2, y;
const float threehalfs = 1.5F; const float threehalfs = 1.5F;
x2 = number * 0.5F; x2 = number * 0.5F;
y = number; t.f = number;
i = * ( long * ) &y; // evil floating point bit level hacking t.i = 0x5f3759df - ( t.i >> 1 ); // what the fuck?
i = 0x5f3759df - ( i >> 1 ); // what the fuck? y = t.f;
y = * ( float * ) &i;
y = y * ( threehalfs - ( x2 * y * y ) ); // 1st iteration y = y * ( threehalfs - ( x2 * y * y ) ); // 1st iteration
// y = y * ( threehalfs - ( x2 * y * y ) ); // 2nd iteration, this can be removed // y = y * ( threehalfs - ( x2 * y * y ) ); // 2nd iteration, this can be removed

View File

@ -131,15 +131,17 @@ SquareRootFloat
================ ================
*/ */
float SquareRootFloat(float number) { float SquareRootFloat(float number) {
long i; union {
float f;
int i;
} t;
float x, y; float x, y;
const float f = 1.5F; const float f = 1.5F;
x = number * 0.5F; x = number * 0.5F;
y = number; t.f = number;
i = * ( long * ) &y; t.i = 0x5f3759df - ( t.i >> 1 );
i = 0x5f3759df - ( i >> 1 ); y = t.f;
y = * ( float * ) &i;
y = y * ( f - ( x * y * y ) ); y = y * ( f - ( x * y * y ) );
y = y * ( f - ( x * y * y ) ); y = y * ( f - ( x * y * y ) );
return number * y; return number * y;