Trig.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 "Trig.hpp"
00023 #include "util/type/util_type.hpp"
00024 
00025 
00026 namespace se_core {
00027 
00028     bray_t Trig
00029     ::clockwise8Direction(coor_t xp, coor_t yp) {
00030         const static bray_t directions[][3] = {
00031             { 224, 0, 32 },
00032             { 192, 0, 64 },
00033             { 160, 128, 92 }
00034         };
00035 
00036         short ns, ew;
00037         if(xp < -COOR_RES)
00038             ew = 0;
00039         else if(xp > COOR_RES)
00040             ew = 2;
00041         else
00042             ew = 1;
00043 
00044         if(yp < -COOR_RES)
00045             ns = 0;
00046         else if(yp > COOR_RES)
00047             ns = 2;
00048         else
00049             ns = 1;
00050 
00051         return directions[ ns ] [ ew ];
00052     }
00053 
00054 #ifdef SE_FIXED_POINT
00055 
00056     const trig_t Trig
00057     ::sinesAbs[] = {
00058         0, 201, 401, 602, 802, 1002, 1202, 1400, // 0
00059         1598, 1794, 1990, 2184, 2378, 2569, 2759, 2948,
00060         3134, 3319, 3502, 3683, 3861, 4037, 4211, 4382,
00061         4551, 4717, 4879, 5039, 5196, 5350, 5501, 5648,
00062         5792, 5933, 6069, 6203, 6332, 6458, 6579, 6697, // 32
00063         6811, 6921, 7026, 7127, 7224, 7317, 7405, 7489,
00064         7568, 7643, 7713, 7778, 7839, 7895, 7946, 7992,
00065         8034, 8071, 8103, 8130, 8152, 8169, 8182, 8189,
00066         8192, 8189, 8182, 8169, 8152, 8130, 8103, 8071, // 64
00067         8034, 7992, 7946, 7895, 7839, 7778, 7713, 7643,
00068         7568, 7489, 7405, 7317, 7224, 7127, 7026, 6921,
00069         6811, 6697, 6579, 6458, 6332, 6203, 6069, 5933,
00070         5792, 5648, 5501, 5350, 5196, 5039, 4879, 4717, // 96
00071         4551, 4382, 4211, 4037, 3861, 3683, 3502, 3319,
00072         3134, 2948, 2759, 2569, 2378, 2184, 1990, 1794,
00073         1598, 1400, 1202, 1002, 802, 602, 401, 201,
00074         0, 201, 401, 602, 802, 1002, 1202, 1400, // 128
00075         1598, 1794, 1990, 2184, 2378, 2569, 2759, 2948,
00076         3134, 3319, 3502, 3683, 3861, 4037, 4211, 4382,
00077         4551, 4717, 4879, 5039, 5196, 5350, 5501, 5648,
00078         5792, 5933, 6069, 6203, 6332, 6458, 6579, 6697, // 160
00079         6811, 6921, 7026, 7127, 7224, 7317, 7405, 7489,
00080         7568, 7643, 7713, 7778, 7839, 7895, 7946, 7992,
00081         8034, 8071, 8103, 8130, 8152, 8169, 8182, 8189,
00082         8192, 8189, 8182, 8169, 8152, 8130, 8103, 8071, // 192
00083         8034, 7992, 7946, 7895, 7839, 7778, 7713, 7643,
00084         7568, 7489, 7405, 7317, 7224, 7127, 7026, 6921,
00085         6811, 6697, 6579, 6458, 6332, 6203, 6069, 5933,
00086         5792, 5648, 5501, 5350, 5196, 5039, 4879, 4717, // 224
00087         4551, 4382, 4211, 4037, 3861, 3683, 3502, 3319,
00088         3134, 2948, 2759, 2569, 2378, 2184, 1990, 1794,
00089         1598, 1400, 1202, 1002, 802, 602, 401, 201
00090     };
00091 
00092 
00093     const trig_sign_t Trig
00094     ::sinesSign[] = {
00095         1,  1,  1,  1,  1,  1,  1,  1, // 0
00096         1,  1,  1,  1,  1,  1,  1,  1,
00097         1,  1,  1,  1,  1,  1,  1,  1,
00098         1,  1,  1,  1,  1,  1,  1,  1,
00099         1,  1,  1,  1,  1,  1,  1,  1, // 32
00100         1,  1,  1,  1,  1,  1,  1,  1,
00101         1,  1,  1,  1,  1,  1,  1,  1,
00102         1,  1,  1,  1,  1,  1,  1,  1,
00103         1,  1,  1,  1,  1,  1,  1,  1, // 64
00104         1,  1,  1,  1,  1,  1,  1,  1,
00105         1,  1,  1,  1,  1,  1,  1,  1,
00106         1,  1,  1,  1,  1,  1,  1,  1,
00107         1,  1,  1,  1,  1,  1,  1,  1, // 96
00108         1,  1,  1,  1,  1,  1,  1,  1,
00109         1,  1,  1,  1,  1,  1,  1,  1,
00110         1,  1,  1,  1,  1,  1,  1,  1,
00111         -1, -1, -1, -1, -1, -1, -1, -1, // 128
00112         -1, -1, -1, -1, -1, -1, -1, -1,
00113         -1, -1, -1, -1, -1, -1, -1, -1,
00114         -1, -1, -1, -1, -1, -1, -1, -1,
00115         -1, -1, -1, -1, -1, -1, -1, -1, // 160
00116         -1, -1, -1, -1, -1, -1, -1, -1,
00117         -1, -1, -1, -1, -1, -1, -1, -1,
00118         -1, -1, -1, -1, -1, -1, -1, -1,
00119         -1, -1, -1, -1, -1, -1, -1, -1, // 192
00120         -1, -1, -1, -1, -1, -1, -1, -1,
00121         -1, -1, -1, -1, -1, -1, -1, -1,
00122         -1, -1, -1, -1, -1, -1, -1, -1,
00123         -1, -1, -1, -1, -1, -1, -1, -1, // 224
00124         -1, -1, -1, -1, -1, -1, -1, -1,
00125         -1, -1, -1, -1, -1, -1, -1, -1,
00126         -1, -1, -1, -1, -1, -1, -1, -1
00127     };
00128 
00129 
00130     const trig_t Trig
00131     ::cosinesAbs[] = {
00132         8192, 8189, 8182, 8169, 8152, 8130, 8103, 8071, // 0
00133         8034, 7992, 7946, 7895, 7839, 7778, 7713, 7643,
00134         7568, 7489, 7405, 7317, 7224, 7127, 7026, 6921,
00135         6811, 6697, 6579, 6458, 6332, 6203, 6069, 5933,
00136         5792, 5648, 5501, 5350, 5196, 5039, 4879, 4717, // 32
00137         4551, 4382, 4211, 4037, 3861, 3683, 3502, 3319,
00138         3134, 2948, 2759, 2569, 2378, 2184, 1990, 1794,
00139         1598, 1400, 1202, 1002, 802, 602, 401, 201,
00140         0, 201, 401, 602, 802, 1002, 1202, 1400, // 64
00141         1598, 1794, 1990, 2184, 2378, 2569, 2759, 2948,
00142         3134, 3319, 3502, 3683, 3861, 4037, 4211, 4382,
00143         4551, 4717, 4879, 5039, 5196, 5350, 5501, 5648,
00144         5792, 5933, 6069, 6203, 6332, 6458, 6579, 6697, // 96
00145         6811, 6921, 7026, 7127, 7224, 7317, 7405, 7489,
00146         7568, 7643, 7713, 7778, 7839, 7895, 7946, 7992,
00147         8034, 8071, 8103, 8130, 8152, 8169, 8182, 8189,
00148         8192, 8189, 8182, 8169, 8152, 8130, 8103, 8071, // 128
00149         8034, 7992, 7946, 7895, 7839, 7778, 7713, 7643,
00150         7568, 7489, 7405, 7317, 7224, 7127, 7026, 6921,
00151         6811, 6697, 6579, 6458, 6332, 6203, 6069, 5933,
00152         5792, 5648, 5501, 5350, 5196, 5039, 4879, 4717, // 160
00153         4551, 4382, 4211, 4037, 3861, 3683, 3502, 3319,
00154         3134, 2948, 2759, 2569, 2378, 2184, 1990, 1794,
00155         1598, 1400, 1202, 1002, 802, 602, 401, 201,
00156         0, 201, 401, 602, 802, 1002, 1202, 1400, // 192
00157         1598, 1794, 1990, 2184, 2378, 2569, 2759, 2948,
00158         3134, 3319, 3502, 3683, 3861, 4037, 4211, 4382,
00159         4551, 4717, 4879, 5039, 5196, 5350, 5501, 5648,
00160         5792, 5933, 6069, 6203, 6332, 6458, 6579, 6697, // 224
00161         6811, 6921, 7026, 7127, 7224, 7317, 7405, 7489,
00162         7568, 7643, 7713, 7778, 7839, 7895, 7946, 7992,
00163         8034, 8071, 8103, 8130, 8152, 8169, 8182, 8189
00164     };
00165 
00166 
00167     const trig_t Trig
00168     ::cosinesSign[] = {
00169         1,  1,  1,  1,  1,  1,  1,  1, // 0
00170         1,  1,  1,  1,  1,  1,  1,  1,
00171         1,  1,  1,  1,  1,  1,  1,  1,
00172         1,  1,  1,  1,  1,  1,  1,  1,
00173         1,  1,  1,  1,  1,  1,  1,  1, // 32
00174         1,  1,  1,  1,  1,  1,  1,  1,
00175         1,  1,  1,  1,  1,  1,  1,  1,
00176         1,  1,  1,  1,  1,  1,  1,  1,
00177         1, -1, -1, -1, -1, -1, -1, -1, // 64
00178         -1, -1, -1, -1, -1, -1, -1, -1,
00179         -1, -1, -1, -1, -1, -1, -1, -1,
00180         -1, -1, -1, -1, -1, -1, -1, -1,
00181         -1, -1, -1, -1, -1, -1, -1, -1, // 96
00182         -1, -1, -1, -1, -1, -1, -1, -1,
00183         -1, -1, -1, -1, -1, -1, -1, -1,
00184         -1, -1, -1, -1, -1, -1, -1, -1,
00185         -1, -1, -1, -1, -1, -1, -1, -1, // 128
00186         -1, -1, -1, -1, -1, -1, -1, -1,
00187         -1, -1, -1, -1, -1, -1, -1, -1,
00188         -1, -1, -1, -1, -1, -1, -1, -1,
00189         -1, -1, -1, -1, -1, -1, -1, -1, // 160
00190         -1, -1, -1, -1, -1, -1, -1, -1,
00191         -1, -1, -1, -1, -1, -1, -1, -1,
00192         -1, -1, -1, -1, -1, -1, -1, -1,
00193         -1,  1,  1,  1,  1,  1,  1,  1, // 192
00194         1,  1,  1,  1,  1,  1,  1,  1,
00195         1,  1,  1,  1,  1,  1,  1,  1,
00196         1,  1,  1,  1,  1,  1,  1,  1,
00197         1,  1,  1,  1,  1,  1,  1,  1, // 224
00198         1,  1,  1,  1,  1,  1,  1,  1,
00199         1,  1,  1,  1,  1,  1,  1,  1,
00200         1,  1,  1,  1,  1,  1,  1,  1
00201     };
00202 
00203 
00204     const trig_t Trig
00205     ::tangents[] = {
00206         0, 12, 25, 37, 50, 63, 75, 88, // 0
00207         101, 114, 128, 141, 155, 169, 183, 197,
00208         212, 226, 242, 257, 273, 290, 306, 324,
00209         342, 360, 379, 399, 420, 441, 464, 487,
00210         511, 537, 564, 593, 623, 656, 690, 726, // 32
00211         766, 808, 854, 903, 957, 1017, 1082, 1155,
00212         1236, 1327, 1430, 1549, 1687, 1850, 2044, 2280,
00213         2573, 2950, 3451, 4151, 5198, 6941, 10421, 20856,
00214         //8.36159454883603e+18,
00215         0x7fffffff, -20856, -10421, -6941, -5198, -4151, -3451, -2950, // 64
00216         -2573, -2280, -2044, -1850, -1687, -1549, -1430, -1327,
00217         -1236, -1155, -1082, -1017, -957, -903, -854, -808,
00218         -766, -726, -690, -656, -623, -593, -564, -537,
00219         -512, -487, -464, -441, -420, -399, -379, -360, // 96
00220         -342, -324, -306, -290, -273, -257, -242, -226,
00221         -212, -197, -183, -169, -155, -141, -128, -114,
00222         -101, -88, -75, -63, -50, -37, -25, -12,
00223         0, 12, 25, 37, 50, 63, 75, 88, // 128
00224         101, 114, 128, 141, 155, 169, 183, 197,
00225         212, 226, 242, 257, 273, 290, 306, 324,
00226         342, 360, 379, 399, 420, 441, 464, 487,
00227         511, 537, 564, 593, 623, 656, 690, 726, // 160
00228         766, 808, 854, 903, 957, 1017, 1082, 1155,
00229         1236, 1327, 1430, 1549, 1687, 1850, 2044, 2280,
00230         2573, 2950, 3451, 4151, 5198, 6941, 10421, 20856,
00231         //2.78719818294534e+18
00232         0x7fffffff, -20856, -10421, -6941, -5198, -4151, -3451, -2950, // 192
00233         -2573, -2280, -2044, -1850, -1687, -1549, -1430, -1327,
00234         -1236, -1155, -1082, -1017, -957, -903, -854, -808,
00235         -766, -726, -690, -656, -623, -593, -564, -537,
00236         -512, -487, -464, -441, -420, -399, -379, -360, // 224
00237         -342, -324, -306, -290, -273, -257, -242, -226,
00238         -212, -197, -183, -169, -155, -141, -128, -114,
00239         -101, -88, -75, -63, -50, -37, -25, -12
00240     };
00241 #endif
00242 
00243 }
00244 

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