CoorT.cpp

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 #include "CoorT.hpp"
00023 #include <cmath>
00024 
00025 namespace se_core {
00026 
00027 #ifdef SE_FIXED_POINT
00028     scale_t CoorT
00029     ::heightScaler(coor_t dy) {
00030         // DY as scale
00031         scale_t min = (static_cast<scale_t>(dy) << SCALE_SHIFT >> COOR_SHIFT);
00032         // max + 1
00033         scale_t max = min + SCALE_RES;
00034         // v = min^2 + SCALE_RES ^ 2
00035         scale_t v = (min * min) + (static_cast<scale_t>(1) << SCALE_SHIFT * 2);
00036         // Until max and min are equal
00037         while(max > min + 1) {
00038             // Calc middle
00039             scale_t middle = (max + min) >> 1;
00040             // middle ^ 2 < v ?
00041             if(middle * middle < v)
00042                 min = middle;
00043             else
00044                 max = middle;
00045         }
00046         return (static_cast<scale_t>(1) << (SCALE_SHIFT * 2)) / max;
00047     }
00048 
00049 #else
00050 
00051     scale_t CoorT
00052     ::heightScaler(coor_t dy) {
00053         // DY as scale
00054         scale_t min = dy;
00055         // max + 1
00056         scale_t max = min + SCALE_RES;
00057         // v = min^2 + SCALE_RES ^ 2
00058         scale_t v = (min * min) + 1.0f;
00059         // Until max and min are (nearly) equal
00060         while(max > min + .001) {
00061             // Calc middle
00062             scale_t middle = (max + min) / 2.0f;
00063             // middle ^ 2 < v ?
00064             if(middle * middle < v)
00065                 min = middle;
00066             else
00067                 max = middle;
00068         }
00069         return 1.0f / max;
00070     }
00071 
00072 
00073     coor_t CoorT
00074     ::sqrt(coor_double_t v) {
00075         return ::sqrt(v);
00076     }
00077 
00078 
00079     /*
00080     coor_in_t CoorT
00081     ::inTile(coor_t v) {
00082         return v - floor(v);
00083     }
00084 
00085     static coor_tile_t CoorT
00086     ::tile(coor_t v) {
00087         return static_cast<coor_tile_t>(floor(v));
00088     }
00089     */
00090 
00091 #endif
00092 
00093 }

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