artkpFixedBase_gpp.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 __ARTKPFIXEDBASE_GPP_HEADERFILE__
00042 #define __ARTKPFIXEDBASE_GPP_HEADERFILE__
00043 
00044 
00045 #include <gpp.h>
00046 #ifdef DEBUG
00047   #pragma comment( lib, "gpp_WMMX40_d.lib" )
00048 #else
00049   #pragma comment( lib, "gpp_WMMX40_r.lib" )
00050 #endif //DEBUG
00051 
00052 
00053 template <int PBITS_>
00054 class artkpFixedBase_gpp
00055 {
00056 public:
00057         enum {
00058                 PBITS = PBITS_,
00059                 CHECK = 0
00060         };
00061 
00062         static float floatFromFixed(int nFixed)
00063         {
00064                 return nFixed/(float)(1 << PBITS);
00065         }
00066 
00067         static double doubleFromFixed(int nFixed)
00068         {
00069                 return nFixed/(double)(1 << PBITS);
00070         }
00071 
00072         static int fixedFromInt(int nV)
00073         {
00074                 return nV<<PBITS;
00075         }
00076 
00077         static int fixedFromFloat(float nV)
00078         {
00079                 return (int)(nV *  (float)(1 << PBITS) + 0.5f);
00080         }
00081 
00082         static int fixedFromDouble(double nV)
00083         {
00084                 return (int)(nV * (double)(1 << PBITS) + 0.5f);
00085         }
00086 
00087         static int inverse(int nFixed)
00088         {
00089                 int ret=0;
00090                 gppInvHP_n_32s(nFixed, &ret, PBITS);
00091                 return ret;
00092         }
00093 
00094         static int multiply(int nLeftFixed, int nRightFixed)
00095         {
00096                 int ret;
00097                 gppMul_n_32s(nLeftFixed, nRightFixed, &ret, PBITS);
00098                 return ret;
00099         }
00100 
00101         static int divide(int nLeftFixed, int nRightFixed)
00102         {
00103                 int ret;
00104                 gppDiv_n_32s(nLeftFixed, nRightFixed, &ret, PBITS);
00105                 return ret;
00106         }
00107 
00108         static int cos(int nFixed)
00109         {
00110                 int ret;
00111                 gppCosHP_n_32s(nFixed, &ret, PBITS);
00112                 return ret;
00113         }
00114 
00115         static int sin(int nFixed)
00116         {
00117                 int ret;
00118                 gppSinHP_n_32s(nFixed, &ret, PBITS);
00119                 return ret;
00120         }
00121 
00122         static int fabs(int nFixed)
00123         {
00124                 return nFixed<0 ? -nFixed : nFixed;
00125         }
00126 
00127         static int sqrt(int nFixed)
00128         {
00129                 unsigned int ret;
00130                 gppSqrtHP_n_32s(nFixed, &ret, PBITS);
00131                 return (int)ret;
00132         }
00133 
00134         static int inverseSqrt(int nFixed)
00135         {
00136                 unsigned int ret;
00137                 gppInvSqrtHP_n_32s(nFixed, &ret, PBITS);
00138                 return (int)ret;
00139         }
00140 
00141         static int ceil(int nFixed)
00142         {
00143                 int ret = (nFixed>>PBITS)<<PBITS;
00144 
00145                 if(nFixed>=0 && ret<nFixed)
00146                         ret += fixedFromInt(1);
00147 
00148                 return ret;
00149         }
00150 };
00151 
00152 
00153 #endif //__ARTKPFIXEDBASE_GPP_HEADERFILE__


v4r_artoolkitplus
Author(s): Markus Bader
autogenerated on Wed Aug 26 2015 16:41:52