QuatT.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 #ifndef QuatT_hpp
00023 #define QuatT_hpp
00024 
00025 #include "util_math.hpp"
00026 #include "util/type/util_type.hpp"
00027 
00028 namespace se_core {
00029     class _SeCoreExport QuatT {
00030     public:
00031         inline static quat_t sign(coor_t t) { return t > 0 ? (quat_t)1 : (quat_t)(-1); }
00032         inline static quat_t abs(quat_t t) { return t > 0 ? t : -t; }
00033         inline static quat_t max(quat_t a, quat_t b) { return a < b ? b : a; }
00034         inline static quat_t max(quat_t a, quat_t b, quat_t c) { return max(max(a, b), c); }
00035         inline static quat_t max(quat_t a, quat_t b, quat_t c, quat_t d) { return max(max(a, b), max(c, d)); }
00036 
00037         static quat_t sqrt(quat_t v) {
00038             //@TODO: Not implemnted yet
00039             return 0;
00040         }
00041 
00042         inline static float toFloat(quat_t value) {
00043 #ifdef SE_FIXED_POINT
00044             return value / (float)QUAT_RES;
00045 #else
00046             return value;
00047 #endif
00048         }
00049 
00050         inline static quat_t fromFloat(float value) {
00051             return static_cast<quat_t>(value * QUAT_RES);
00052         }
00053 
00054         inline static quat_t fromCoorT(coor_t value) {
00055             // quat_t and coor_t should be same basic type
00056             return value;
00057         }
00058 
00059         inline static quat_t fmul(quat_t v1, quat_t v2) {
00060             // quat_t and coor_t should be same basic type
00061 #ifdef SE_FIXED_POINT
00062             return (v1 >> QUAT_HALF_SHIFT) * (v2 >> QUAT_HALF_SHIFT);
00063 #else
00064             return v1 * v2;
00065 #endif
00066 
00067         }
00068 
00069         inline static quat_t pow2(quat_t v1) {
00070             // quat_t and coor_t should be same basic type
00071 #ifdef SE_FIXED_POINT
00072             quat_t v = (v1 >> QUAT_HALF_SHIFT);
00073             return v * v;
00074 #else
00075             return v1 * v1;
00076 #endif
00077 
00078         }
00079 
00080 
00081         inline static scale_t oneOver(quat_t v) {
00082             // quat_t and coor_t should be same basic type
00083 #ifdef SE_FIXED_POINT
00084             return (QUAT_RES << QUAT_HALF_SHIFT) / (v >> QUAT_HALF_SHIFT);
00085 #else
00086             return 1 / v;
00087 #endif
00088 
00089         }
00090 
00091 
00092         inline static quat_t scale(scale_t s, quat_t c) {
00093 #ifdef SE_FIXED_POINT
00094             return static_cast<coor_t>(sign(c) * ((s * abs(c)) >> SCALE_SHIFT));
00095 #else
00096             return s * c;
00097 #endif
00098         }
00099 
00100 
00101     };
00102 
00103 }
00104 
00105 #endif

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