00001 /* 00002 Copyright (c) 2007-2009 Takashi Kitao 00003 All rights reserved. 00004 00005 Redistribution and use in source and binary forms, with or without 00006 modification, are permitted provided that the following conditions 00007 are met: 00008 00009 1. Redistributions of source code must retain the above copyright 00010 ` notice, this list of conditions and the following disclaimer. 00011 00012 2. Redistributions in binary form must reproduce the above copyright 00013 ` notice, this list of conditions and the following disclaimer in the 00014 ` documentation and/or other materials provided with the distribution. 00015 00016 3. The name of the author may not be used to endorse or promote products 00017 ` derived from this software without specific prior written permission. 00018 00019 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 00020 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00021 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 00022 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 00023 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 00024 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00025 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00026 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00027 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 00028 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00029 */ 00030 00031 00036 class PG_API pgMath 00037 { 00038 public: 00039 static const r32 EPSILON; 00040 static const r32 PI; 00041 static const r32 DEG_TO_RAD; 00042 static const r32 RAD_TO_DEG; 00043 00050 template<class T> static T abs(T x) 00051 { 00052 return (x >= 0) ? x : -x; 00053 } 00054 00062 template<class T> static T min(T a, T b) 00063 { 00064 return (a <= b) ? a : b; 00065 } 00066 00074 template<class T> static T max(T a, T b) 00075 { 00076 return (a >= b) ? a : b; 00077 } 00078 00087 template<class T> static T clamp(T x, T min, T max) 00088 { 00089 return (x < min) ? min : ((x > max) ? max : x); 00090 } 00091 00097 static r32 sqrt(r32 x); 00098 00104 static r32 sin_r32(r32 deg); 00105 00111 static r32 cos_r32(r32 deg); 00112 00119 static r32 sin_s32(s32 deg); 00120 00127 static r32 cos_s32(s32 deg); 00128 00134 static r32 asin(r32 x); 00135 00141 static r32 acos(r32 x); 00142 00149 static r32 atan2(r32 y, r32 x); 00150 00155 static void srand(u32 seed); 00156 00163 static s32 rand(s32 from, s32 to); 00164 00172 static r32 rand(r32 from, r32 to, r32 interval); 00173 00181 static r32 interp(r32 from, r32 to, r32 ratio); 00182 };
1.5.8