FixedPoint.h
Go to the documentation of this file.
00001 /* ========================================================================
00002  * PROJECT: ARToolKitPlus
00003  * ========================================================================
00004  * This work is based on the original ARToolKit developed by
00005  *   Hirokazu Kato
00006  *   Mark Billinghurst
00007  *   HITLab, University of Washington, Seattle
00008  * http://www.hitl.washington.edu/artoolkit/
00009  *
00010  * Copyright of the derived and new portions of this work
00011  *     (C) 2006 Graz University of Technology
00012  *
00013  * This framework is free software; you can redistribute it and/or modify
00014  * it under the terms of the GNU General Public License as published by
00015  * the Free Software Foundation; either version 2 of the License, or
00016  * (at your option) any later version.
00017  *
00018  * This framework is distributed in the hope that it will be useful,
00019  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00020  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00021  * GNU General Public License for more details.
00022  *
00023  * You should have received a copy of the GNU General Public License
00024  * along with this framework; if not, write to the Free Software
00025  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00026  *
00027  * For further information please contact 
00028  *   Dieter Schmalstieg
00029  *   <schmalstieg@icg.tu-graz.ac.at>
00030  *   Graz University of Technology, 
00031  *   Institut for Computer Graphics and Vision,
00032  *   Inffeldgasse 16a, 8010 Graz, Austria.
00033  * ========================================================================
00034  ** @author   Daniel Wagner
00035  *
00036  * $Id$
00037  * @file
00038  * ======================================================================== */
00039 
00040 
00041 #ifndef __FIXEDPOINT_HEADERFILE__
00042 #define __FIXEDPOINT_HEADERFILE__
00043 
00044 
00045 namespace ARToolKitPlus {
00046 
00047 
00048 #define FIXED_Float_To_Fixed_n(x, n)       ((I32)(x * (float)(1 << n) + 0.5f))
00049 #define FIXED_Fixed_n_To_Float(x, n)    ((float)x / (float)(1 << n))    
00050 
00051 
00052 
00053 #ifdef _USEGPP_
00054 #  include <gpp.h>
00055 #  define _USE_GPP_ARITHMETIC_
00056 #  define _USE_GPP_TRIGONOMETRIC_
00057 #  define _USE_GPP_VECTOR_
00058 #  define _FIXEDPOINT_MATH_ACTIVATED_
00059 
00060 // autolink against Intel GPP
00061 #  ifdef DEBUG
00062 #    pragma comment( lib, "gpp_WMMX40_d.lib" )
00063 #  else
00064 #    pragma comment( lib, "gpp_WMMX40_r.lib" )
00065 #  endif
00066 #endif
00067 
00068 
00069 #ifdef _USEFIXED_
00070 #  if defined(_WIN32) || defined(WIN32)
00071         typedef unsigned __int64        U64;
00072         typedef __int64                         I64;
00073         typedef unsigned int U32;
00074         typedef int I32;
00075 #  endif
00076 #  define _USE_GENERIC_ARITHMETIC_
00077 #  define _USE_GENERIC_TRIGONOMETRIC_
00078 #  define _USE_GENERIC_VECTOR_
00079 #  define _FIXEDPOINT_MATH_ACTIVATED_
00080 #endif
00081 
00082 
00083 #ifdef _USE_GPP_ARITHMETIC_
00084 
00085 #define FIXED_MUL2(a,b, res, bits)  \
00086         gppMul_n_32s((a), (b), &res, bits);
00087 
00088 #define FIXED_MUL3(a,b,c, res, bits)  \
00089         gppMul_n_32s((a), (b), &_tmp1, bits);  \
00090         gppMul_n_32s(_tmp1, (c), &res, bits);
00091 
00092 #define FIXED_MUL4(a,b,c,d, res, bits)  \
00093         gppMul_n_32s((a), (b), &_tmp1, bits);  \
00094         gppMul_n_32s(_tmp1, (c), &_tmp2, bits);  \
00095         gppMul_n_32s(_tmp2, (d), &res, bits);
00096 
00097 #define FIXED_DIV2(a,b, res, bits)  \
00098         gppDiv_n_32s((a), (b), &res, bits);
00099 
00100 #endif //_USE_GPP_ARITHMETIC_
00101 
00102 
00103 #ifdef _USE_GPP_TRIGONOMETRIC_
00104 
00105 #define FIXED_SIN(theta, sin_theta, n) \
00106         gppSinHP_n_32s((theta), sin_theta, n);
00107 
00108 #define FIXED_COS(theta, cos_theta, n) \
00109         gppCosHP_n_32s((theta), cos_theta, n);
00110 
00111 #define FIXED_SINCOS(theta, sin_theta, cos_theta, n) \
00112         gppSinCosHP_n_32s((theta), sin_theta, cos_theta, n);
00113 
00114 #endif // _USE_GPP_TRIGONOMETRIC_
00115 
00116 
00117 #ifdef _USE_GPP_VECTOR_
00118 
00119 typedef GPP_VEC3D FIXED_VEC3D;
00120 
00121 #define FIXED_VEC3_DOT(vec1, vec2, res, n) \
00122         gppVec3DDot_n_32s((vec1), (vec2), (res), (n));
00123 
00124 #define FIXED_VEC3_SUB(vec1, vec2, res) \
00125         gppVec3DSub_n_32s((vec1), (vec2), (res));
00126 
00127 #define FIXED_VEC3_LENGTH_SQ(vec, res, n) \
00128         gppVec3DLengthSq_n_32s((vec), (res), (n));
00129 
00130 #endif // _USE_GPP_VECTOR_
00131 
00132 
00133 
00134 #ifdef _USE_GENERIC_ARITHMETIC_
00135 
00136 #  define FIXED_MUL2(a,b, res, bits)  \
00137         res = ((I32) (((I64)a * (I64)b)  >> bits));
00138 
00139 #  define FIXED_MUL3(a,b,c, res, bits)  \
00140         FIXED_MUL2((a), (b), (res), bits);  \
00141         FIXED_MUL2((res), (c), (res), bits);
00142 
00143 #  define FIXED_MUL4(a,b,c,d, res, bits)  \
00144         FIXED_MUL2((a), (b), (res), bits);  \
00145         FIXED_MUL2((res), (c), (res), bits);  \
00146         FIXED_MUL2((res), (d), (res), bits);
00147 
00148 #  define FIXED_DIV2(a,b, res, bits)  \
00149         res = (I32) ((((I64)a)<<bits)/(I64)b);
00150 
00151 #endif //_USE_GENERIC_ARITHMETIC_
00152 
00153 
00154 #ifdef _USE_GENERIC_TRIGONOMETRIC_
00155 
00156 void Fixed28_Init();
00157 void Fixed28_Deinit();
00158 
00159 inline void Fixed28_SinCos(I32 phi, I32 &sin, I32 &cos);
00160 
00161 #define FIXED_SINCOS(theta, sin_theta, cos_theta, n) \
00162         Fixed28_SinCos((theta), *(sin_theta), *(cos_theta));
00163 
00164 #endif //_USE_GENERIC_TRIGONOMETRIC_
00165 
00166 
00167 #ifdef _USE_GENERIC_VECTOR_
00168 
00169 typedef struct{
00170         I32     x, y, z;
00171 } FIXED_VEC3D;
00172 
00173 inline void FIXED_VEC3_DOT(FIXED_VEC3D* vec1, FIXED_VEC3D* vec2, I32* res, I32 n)
00174 {
00175         I32 x,y,z;
00176         FIXED_MUL2(vec1->x, vec2->x, x, n);
00177         FIXED_MUL2(vec1->y, vec2->y, y, n);
00178         FIXED_MUL2(vec1->z, vec2->z, z, n);
00179 
00180         *res = x+y+z;
00181 }
00182 
00183 inline void FIXED_VEC3_SUB(FIXED_VEC3D* vec1, FIXED_VEC3D* vec2, FIXED_VEC3D* res)
00184 {
00185         res->x = vec1->x - vec2->x;
00186         res->y = vec1->y - vec2->y;
00187         res->z = vec1->z - vec2->z;
00188 }
00189 
00190 inline void FIXED_VEC3_LENGTH_SQ(FIXED_VEC3D* vec, U32* res, I32 n)
00191 {
00192         I32 x,y,z;
00193         FIXED_MUL2(vec->x, vec->x, x, n);
00194         FIXED_MUL2(vec->y, vec->y, y, n);
00195         FIXED_MUL2(vec->z, vec->z, z, n);
00196 
00197         *res = x+y+z;
00198 }
00199 
00200 #endif //_USE_GENERIC_VECTOR_
00201 
00202 
00203 }  // namespace ARToolKitPlus
00204 
00205 
00206 #endif //__FIXEDPOINT_HEADERFILE__


tuw_artoolkitplus
Author(s): Markus Bader
autogenerated on Sun May 29 2016 02:50:12