00001 /* 00002 SagaEngine library 00003 Copyright (c) 2002-2006 Skalden Studio AS 00004 00005 This software is provided 'as-is', without any express or implied 00006 warranty. In no event will the authors be held liable for any 00007 damages arising from the use of this software. 00008 00009 Permission is granted to distribute the library under the terms of the 00010 Q Public License version 1.0. Be sure to read and understand the license 00011 before using the library. It should be included here, or you may read it 00012 at http://www.trolltech.com/products/qt/licenses/licensing/qpl 00013 00014 The original version of this library can be located at: 00015 http://www.sagaengine.com/ 00016 00017 Rune Myrland 00018 rune@skalden.com 00019 */ 00020 00021 00022 // Don't include this directly. Instead include Trig.hpp 00023 00024 00025 00026 #ifndef base_math_Trig_FloatingPoint_hpp 00027 #define base_math_Trig_FloatingPoint_hpp 00028 00029 #include "util_math.hpp" 00030 #include "util/type/util_type.hpp" 00031 #include "BrayT.hpp" 00032 #include <cmath> 00033 00034 #ifndef SE_FIXED_POINT 00035 00036 namespace se_core { 00037 class _SeCoreExport Trig { 00038 public: 00039 inline static float trigToFloat(trig_t value) { 00040 return value; 00041 } 00042 00043 static quat_t cosQuat(bray_t bray) { 00044 return ::cos(BrayT::toRad(bray)); 00045 } 00046 00047 static quat_t sinQuat(bray_t bray) { 00048 return ::sin(BrayT::toRad(bray)); 00049 } 00050 00051 inline static coor_t cosScale(coor_t len, bray_t bray) { 00052 return ::cos(BrayT::toRad(bray)) * len; 00053 } 00054 00055 inline static coor_t sinScale(coor_t len, bray_t bray) { 00056 return ::sin(BrayT::toRad(bray)) * len; 00057 } 00058 00059 inline static trig_t tan(bray_t bray) { 00060 return ::tan(BrayT::toRad(bray)); 00061 } 00062 00063 00064 inline static bray_t asin(trig_t t) { 00065 return BrayT::fromRad(::asin(t)); 00066 } 00067 00068 00069 inline static bray_t acos(trig_t t) { 00070 return BrayT::fromRad(::acos(t)); 00071 } 00072 00073 00074 inline static bray_t atan(trig_t t) { 00075 return BrayT::fromRad(::atan(t)); 00076 } 00077 00078 00079 inline static bray_t atan2(coor_t xp, coor_t yp) { 00080 if(yp != 0) { 00081 //Calculate angle of vector 00082 bray_t angle=0; 00083 if (xp!=0) { 00084 if((xp >= 0) && (yp >= 0)) 00085 angle = atan(yp / xp); 00086 else if((xp < 0) && (yp >= 0)) 00087 angle = BrayT::DEG180 - atan(yp / -xp); 00088 else if((xp < 0) && (yp < 0)) 00089 angle = BrayT::DEG180 + atan(-yp / -xp); 00090 else if((xp >= 0) && (yp < 0)) 00091 angle = BrayT::DEG360 - atan(-yp / xp); 00092 } 00093 else { 00094 if(yp >= 0) 00095 angle = BrayT::DEG90; 00096 else 00097 angle = BrayT::DEG270; 00098 } 00099 return angle; 00100 } 00101 else { 00102 if(xp == 0 && yp == 0) return BrayT::DEG0; 00103 if(xp == 0 && yp > 0) return BrayT::DEG90; 00104 if(xp == 0 && yp < 0) return BrayT::DEG270; 00105 if(yp == 0 && xp > 0) return BrayT::DEG0; 00106 else return BrayT::DEG180; 00107 } 00108 } 00109 00110 static bray_t clockwise8Direction(coor_t xp, coor_t yp); 00111 }; 00112 00113 } 00114 00115 #endif // SE_FIXED_POINT 00116 00117 #endif 00118 00119
Home Page | SagaEngine trunk (updated nightly) reference generated Sun Dec 2 20:06:12 2007 by Doxygen version 1.3.9.1.