Shadowrun: Awakened 29 September 2011 - Build 871
Scalar.hpp
Go to the documentation of this file.
00001 /*
00002     Copyright (c) 2009 Christopher A. Taylor.  All rights reserved.
00003 
00004     Redistribution and use in source and binary forms, with or without
00005     modification, are permitted provided that the following conditions are met:
00006 
00007     * Redistributions of source code must retain the above copyright notice,
00008       this list of conditions and the following disclaimer.
00009     * Redistributions in binary form must reproduce the above copyright notice,
00010       this list of conditions and the following disclaimer in the documentation
00011       and/or other materials provided with the distribution.
00012     * Neither the name of LibCat nor the names of its contributors may be used
00013       to endorse or promote products derived from this software without
00014       specific prior written permission.
00015 
00016     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00017     AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00018     IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00019     ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
00020     LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00021     CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00022     SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00023     INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00024     CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00025     ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00026     POSSIBILITY OF SUCH DAMAGE.
00027 */
00028 
00029 #ifndef CAT_SCALAR_HPP
00030 #define CAT_SCALAR_HPP
00031 
00032 #include <cat/Platform.hpp>
00033 #include <cmath>
00034 
00035 namespace cat {
00036 
00037 
00038 // PI
00039 #define CAT_TWO_PI_64 6.283185307179586476925286766559
00040 #define CAT_TWO_PI_32 6.28318531f
00041 #define CAT_PI_64 3.1415926535897932384626433832795
00042 #define CAT_PI_32 3.14159265f
00043 #define CAT_HALF_PI_64 1.5707963267948966192313216916398
00044 #define CAT_HALF_PI_32 1.5707963268f
00045 #define CAT_QUARTER_PI_64 0.78539816339744830961566084581988
00046 #define CAT_QUARTER_PI_32 0.7853981634f
00047 #define CAT_INV_PI_64 0.31830988618379067153776752674503
00048 #define CAT_INV_PI_32 0.3183098862f
00049 
00050 
00051 // Angle conversion
00052 inline f64 Deg2Rad(f64 angle)
00053 {
00054     return angle * CAT_TWO_PI_64 / 360.0;
00055 }
00056 inline f32 Deg2Rad(f32 angle)
00057 {
00058     return angle * CAT_TWO_PI_32 / 360.0f;
00059 }
00060 inline f64 Rad2Deg(f64 angle)
00061 {
00062     return angle * 360.0 / CAT_TWO_PI_64;
00063 }
00064 inline f32 Rad2Deg(f32 angle)
00065 {
00066     return angle * 360.0f / CAT_TWO_PI_32;
00067 }
00068 
00069 
00070 // Generic clamp() function
00071 template<class Scalar>
00072 void Clamp(Scalar &x, Scalar low, Scalar high)
00073 {
00074     if (x < low) x = low;
00075     else if (x > high) x = high;
00076 }
00077 
00078 
00079 // Fast inverse square root
00080 f32 InvSqrt(f32 x);
00081 
00082 
00083 } // namespace cat
00084 
00085 #endif // CAT_SCALAR_HPP

Copyright © 2007-2010 by The Shadowrun: Awakened Team. This work is licensed under the GNU Lesser General Public License 3.

GNU Lesser General Public License 3 Sourceforge.net