CoorT_FloatingPoint.hpp

Go to the documentation of this file.
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 CoorT.hpp
00023 
00024 
00025 #ifndef CoorT_FloatingPoint_hpp
00026 #define CoorT_FloatingPoint_hpp
00027 
00028 #include "util_math.hpp"
00029 #include "util/type/util_type.hpp"
00030 
00031 #ifndef SE_FIXED_POINT
00032 
00033 #ifdef max
00034 #undef max
00035 #endif
00036 
00037 namespace se_core {
00038     class _SeCoreExport CoorT {
00039     public:
00040         inline static coor_t half(coor_t t) { return t / 2.0f; }
00041         inline static coor_t quarter(coor_t t) { return t / 4.0f; }
00042 
00043         inline static coor_t abs(coor_t t) { return t > 0 ? t : -t; }
00044         inline static coor_double_t absd(coor_double_t t) { return t > 0 ? t : -t; }
00045         inline static coor_t sign(coor_t t) { return t > 0 ? (coor_t)1 : (coor_t)-1; }
00046         inline static coor_t signd(coor_double_t t) { return t > 0 ? (coor_double_t)1 : (coor_double_t)-1; }
00047         inline static coor_t max(coor_t a, coor_t b) { return (a < b) ? b : a; }
00048         inline static coor_t max(coor_t a, coor_t b, coor_t c) { return max(max(a, b), c); }
00049         inline static coor_t max(coor_t a, coor_t b, coor_t c, coor_t d) { return max(max(a, b), max(c, d)); }
00050 
00051         static coor_t sqrt(coor_double_t v);
00052 
00058         static scale_t heightScaler(coor_t dy);
00059 
00060         inline static coor_double_t pow2(coor_double_t v) {
00061             return v * v;
00062         }
00063 
00064         inline static coor_t fromd(coor_double_t v) {
00065             return v;
00066         }
00067 
00068         inline static coor_t fromScale(coor_double_t v) {
00069             return v;
00070         }
00071 
00072         inline static coor_double_t muld(coor_t p1, coor_t p2) {
00073             return p1 * p2;
00074         }
00075 
00076         inline static coor_t mul(coor_t p1, coor_t p2) {
00077             return p1 * p2;
00078         }
00079 
00080 
00081         inline static coor_t div(coor_t p1, coor_t p2) {
00082             return p1 / p2;
00083         }
00084 
00085         inline static float toFloat(coor_t value) {
00086             return value;
00087         }
00088 
00089         inline static coor_t fromFloat(float value) {
00090             return value;
00091         }
00092 
00093         inline static coor_t fromInt(int value) {
00094             return static_cast<coor_t>(value);
00095         }
00096 
00097         inline static int toInt(coor_t value) {
00098             //TODO: Something rotten here
00099             // (different results for fixed point and floating point)
00100             return static_cast<int>(value);
00101         }
00102 
00103         inline static coor_t scale(scale_t s, coor_t c) {
00104             return s * c;
00105         }
00106 
00107 
00108         inline static coor_tile_t tile(coor_t v) { 
00109             return static_cast<coor_tile_t>(v); 
00110         }
00111 
00112         inline static coor_in_t inTile(coor_t v) { 
00113             return v - static_cast<coor_tile_t>(v); 
00114         }
00115 
00116         inline static coor_t fromTile(coor_tile_t value) {
00117             return static_cast<coor_t>(value);
00118         }
00119 
00120     };
00121 
00122 }
00123 
00124 
00125 #endif // SE_FIXED_POINT
00126 
00127 #endif
00128 

Home Page | SagaEngine trunk (updated nightly) reference generated Sun Dec 2 20:06:12 2007 by Doxygen version 1.3.9.1.

SourceForge.net Logo