1 //******************************************************************************************** 2 //* 3 //* This file is part of Egoboo. 4 //* 5 //* Egoboo is free software: you can redistribute it and/or modify it 6 //* under the terms of the GNU General Public License as published by 7 //* the Free Software Foundation, either version 3 of the License, or 8 //* (at your option) any later version. 9 //* 10 //* Egoboo is distributed in the hope that it will be useful, but 11 //* WITHOUT ANY WARRANTY; without even the implied warranty of 12 //* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 //* General Public License for more details. 14 //* 15 //* You should have received a copy of the GNU General Public License 16 //* along with Egoboo. If not, see <http://www.gnu.org/licenses/>. 17 //* 18 //******************************************************************************************** 19 20 /// @file egoboo_math.c 21 /// @brief The name's pretty self explanatory, doncha think? 22 /// @details This is the remainder of non-inlined math functions that deal with initialization 23 24 #include "egoboo_math.inl" 25 26 //-------------------------------------------------------------------------------------------- 27 //-------------------------------------------------------------------------------------------- 28 float turntosin[TRIG_TABLE_SIZE]; // Convert chrturn>>2... to sine 29 float turntocos[TRIG_TABLE_SIZE]; // Convert chrturn>>2... to cosine 30 31 Uint32 randindex = 0; 32 Uint16 randie[RANDIE_COUNT]; 33 34 //-------------------------------------------------------------------------------------------- make_turntosin(void)35void make_turntosin( void ) 36 { 37 /// @details ZZ@> This function makes the lookup table for chrturn... 38 int cnt; 39 float ftmp = TWO_PI / ( float )TRIG_TABLE_SIZE; 40 41 for ( cnt = 0; cnt < TRIG_TABLE_SIZE; cnt++ ) 42 { 43 turntosin[cnt] = SIN( cnt * ftmp ); 44 turntocos[cnt] = COS( cnt * ftmp ); 45 } 46 } 47 48 //-------------------------------------------------------------------------------------------- make_randie()49void make_randie() 50 { 51 /// @details ZZ@> This function makes the random number table 52 int tnc, cnt; 53 54 // Fill in the basic values 55 for ( cnt = 0; cnt < RANDIE_COUNT; cnt++ ) 56 { 57 randie[cnt] = 0; 58 } 59 60 // Keep adjusting those values 61 for ( tnc = 0; tnc < 20; tnc++ ) 62 { 63 for ( cnt = 0; cnt < RANDIE_COUNT; cnt++ ) 64 { 65 randie[cnt] = ( randie[cnt] << 1 ) + rand(); 66 } 67 } 68 69 // All done 70 randindex = 0; 71 } 72 float32_to_uint32(float f)73Uint32 float32_to_uint32( float f ) 74 { 75 union { Uint32 i; float f; } val; 76 77 val.f = f; 78 79 return val.i; 80 } 81 uint32_to_float32(Uint32 i)82float uint32_to_float32( Uint32 i ) 83 { 84 union { Uint32 i; float f; } val; 85 86 val.i = i; 87 88 return val.f; 89 90 } 91 92 #define IEEE32_FRACTION 0x007FFFFFL 93 #define IEEE32_EXPONENT 0x7F800000L 94 #define IEEE32_SIGN 0x80000000L 95 ieee32_infinite(float f)96bool_t ieee32_infinite( float f ) 97 { 98 Uint32 u = float32_to_uint32( f ); 99 100 return ( 0 == ( u & IEEE32_FRACTION ) && IEEE32_EXPONENT == ( u & IEEE32_EXPONENT ) ); 101 } 102 ieee32_nan(float f)103bool_t ieee32_nan( float f ) 104 { 105 Uint32 u = float32_to_uint32( f ); 106 107 return ( 0 != ( u&IEEE32_FRACTION ) && IEEE32_EXPONENT == ( u&IEEE32_EXPONENT ) ); 108 } 109