FixedPoint.h
Go to the documentation of this file.
1 /* ========================================================================
2  * PROJECT: ARToolKitPlus
3  * ========================================================================
4  * This work is based on the original ARToolKit developed by
5  * Hirokazu Kato
6  * Mark Billinghurst
7  * HITLab, University of Washington, Seattle
8  * http://www.hitl.washington.edu/artoolkit/
9  *
10  * Copyright of the derived and new portions of this work
11  * (C) 2006 Graz University of Technology
12  *
13  * This framework is free software; you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License as published by
15  * the Free Software Foundation; either version 2 of the License, or
16  * (at your option) any later version.
17  *
18  * This framework is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this framework; if not, write to the Free Software
25  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26  *
27  * For further information please contact
28  * Dieter Schmalstieg
29  * <schmalstieg@icg.tu-graz.ac.at>
30  * Graz University of Technology,
31  * Institut for Computer Graphics and Vision,
32  * Inffeldgasse 16a, 8010 Graz, Austria.
33  * ========================================================================
34  ** @author Daniel Wagner
35  *
36  * $Id$
37  * @file
38  * ======================================================================== */
39 
40 
41 #ifndef __FIXEDPOINT_HEADERFILE__
42 #define __FIXEDPOINT_HEADERFILE__
43 
44 
45 namespace ARToolKitPlus {
46 
47 
48 #define FIXED_Float_To_Fixed_n(x, n) ((I32)(x * (float)(1 << n) + 0.5f))
49 #define FIXED_Fixed_n_To_Float(x, n) ((float)x / (float)(1 << n))
50 
51 
52 
53 #ifdef _USEGPP_
54 # include <gpp.h>
55 # define _USE_GPP_ARITHMETIC_
56 # define _USE_GPP_TRIGONOMETRIC_
57 # define _USE_GPP_VECTOR_
58 # define _FIXEDPOINT_MATH_ACTIVATED_
59 
60 // autolink against Intel GPP
61 # ifdef DEBUG
62 # pragma comment( lib, "gpp_WMMX40_d.lib" )
63 # else
64 # pragma comment( lib, "gpp_WMMX40_r.lib" )
65 # endif
66 #endif
67 
68 
69 #ifdef _USEFIXED_
70 # if defined(_WIN32) || defined(WIN32)
71  typedef unsigned __int64 U64;
72  typedef __int64 I64;
73  typedef unsigned int U32;
74  typedef int I32;
75 # endif
76 # define _USE_GENERIC_ARITHMETIC_
77 # define _USE_GENERIC_TRIGONOMETRIC_
78 # define _USE_GENERIC_VECTOR_
79 # define _FIXEDPOINT_MATH_ACTIVATED_
80 #endif
81 
82 
83 #ifdef _USE_GPP_ARITHMETIC_
84 
85 #define FIXED_MUL2(a,b, res, bits) \
86  gppMul_n_32s((a), (b), &res, bits);
87 
88 #define FIXED_MUL3(a,b,c, res, bits) \
89  gppMul_n_32s((a), (b), &_tmp1, bits); \
90  gppMul_n_32s(_tmp1, (c), &res, bits);
91 
92 #define FIXED_MUL4(a,b,c,d, res, bits) \
93  gppMul_n_32s((a), (b), &_tmp1, bits); \
94  gppMul_n_32s(_tmp1, (c), &_tmp2, bits); \
95  gppMul_n_32s(_tmp2, (d), &res, bits);
96 
97 #define FIXED_DIV2(a,b, res, bits) \
98  gppDiv_n_32s((a), (b), &res, bits);
99 
100 #endif //_USE_GPP_ARITHMETIC_
101 
102 
103 #ifdef _USE_GPP_TRIGONOMETRIC_
104 
105 #define FIXED_SIN(theta, sin_theta, n) \
106  gppSinHP_n_32s((theta), sin_theta, n);
107 
108 #define FIXED_COS(theta, cos_theta, n) \
109  gppCosHP_n_32s((theta), cos_theta, n);
110 
111 #define FIXED_SINCOS(theta, sin_theta, cos_theta, n) \
112  gppSinCosHP_n_32s((theta), sin_theta, cos_theta, n);
113 
114 #endif // _USE_GPP_TRIGONOMETRIC_
115 
116 
117 #ifdef _USE_GPP_VECTOR_
118 
119 typedef GPP_VEC3D FIXED_VEC3D;
120 
121 #define FIXED_VEC3_DOT(vec1, vec2, res, n) \
122  gppVec3DDot_n_32s((vec1), (vec2), (res), (n));
123 
124 #define FIXED_VEC3_SUB(vec1, vec2, res) \
125  gppVec3DSub_n_32s((vec1), (vec2), (res));
126 
127 #define FIXED_VEC3_LENGTH_SQ(vec, res, n) \
128  gppVec3DLengthSq_n_32s((vec), (res), (n));
129 
130 #endif // _USE_GPP_VECTOR_
131 
132 
133 
134 #ifdef _USE_GENERIC_ARITHMETIC_
135 
136 # define FIXED_MUL2(a,b, res, bits) \
137  res = ((I32) (((I64)a * (I64)b) >> bits));
138 
139 # define FIXED_MUL3(a,b,c, res, bits) \
140  FIXED_MUL2((a), (b), (res), bits); \
141  FIXED_MUL2((res), (c), (res), bits);
142 
143 # define FIXED_MUL4(a,b,c,d, res, bits) \
144  FIXED_MUL2((a), (b), (res), bits); \
145  FIXED_MUL2((res), (c), (res), bits); \
146  FIXED_MUL2((res), (d), (res), bits);
147 
148 # define FIXED_DIV2(a,b, res, bits) \
149  res = (I32) ((((I64)a)<<bits)/(I64)b);
150 
151 #endif //_USE_GENERIC_ARITHMETIC_
152 
153 
154 #ifdef _USE_GENERIC_TRIGONOMETRIC_
155 
156 void Fixed28_Init();
157 void Fixed28_Deinit();
158 
159 inline void Fixed28_SinCos(I32 phi, I32 &sin, I32 &cos);
160 
161 #define FIXED_SINCOS(theta, sin_theta, cos_theta, n) \
162  Fixed28_SinCos((theta), *(sin_theta), *(cos_theta));
163 
164 #endif //_USE_GENERIC_TRIGONOMETRIC_
165 
166 
167 #ifdef _USE_GENERIC_VECTOR_
168 
169 typedef struct{
170  I32 x, y, z;
171 } FIXED_VEC3D;
172 
173 inline void FIXED_VEC3_DOT(FIXED_VEC3D* vec1, FIXED_VEC3D* vec2, I32* res, I32 n)
174 {
175  I32 x,y,z;
176  FIXED_MUL2(vec1->x, vec2->x, x, n);
177  FIXED_MUL2(vec1->y, vec2->y, y, n);
178  FIXED_MUL2(vec1->z, vec2->z, z, n);
179 
180  *res = x+y+z;
181 }
182 
183 inline void FIXED_VEC3_SUB(FIXED_VEC3D* vec1, FIXED_VEC3D* vec2, FIXED_VEC3D* res)
184 {
185  res->x = vec1->x - vec2->x;
186  res->y = vec1->y - vec2->y;
187  res->z = vec1->z - vec2->z;
188 }
189 
190 inline void FIXED_VEC3_LENGTH_SQ(FIXED_VEC3D* vec, U32* res, I32 n)
191 {
192  I32 x,y,z;
193  FIXED_MUL2(vec->x, vec->x, x, n);
194  FIXED_MUL2(vec->y, vec->y, y, n);
195  FIXED_MUL2(vec->z, vec->z, z, n);
196 
197  *res = x+y+z;
198 }
199 
200 #endif //_USE_GENERIC_VECTOR_
201 
202 
203 } // namespace ARToolKitPlus
204 
205 
206 #endif //__FIXEDPOINT_HEADERFILE__
TFSIMD_FORCE_INLINE const tfScalar & y() const
This file should only be compiled when using ARToolKitPlus as a DLL.
Definition: ar.h:60
TFSIMD_FORCE_INLINE const tfScalar & x() const
TFSIMD_FORCE_INLINE const tfScalar & z() const
unsigned long long U64
unsigned int U32


tuw_artoolkitplus
Author(s): Markus Bader
autogenerated on Sun Sep 4 2016 03:24:33