GLVector.cpp

00001 /***************************************************************************
00002  *   Copyright (C) 2004 by Jacques Gasselin                                *
00003  *   jacquesgasselin@hotmail.com                                           *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU Library General Public License as       *
00007  *   published by the Free Software Foundation; either version 2 of the    *
00008  *   License, or (at your option) any later version.                       *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU Library General Public     *
00016  *   License along with this program; if not, write to the                 *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00019  ***************************************************************************/
00020 
00021 #include "GLVector.h"
00022 
00023 #ifdef GLVECTOR_USE_SSE
00024 typedef int v4sf __attribute__ ((mode(V4SF)));
00025 #endif
00026 
00027 namespace mathglpp
00028 {
00029 
00030 template <>
00031 void GLVector2<GLbyte>::glScale() const
00032 {
00033     ::glScalef(val[0],val[1],0);
00034 }
00035 
00036 template <>
00037 void GLVector2<GLshort>::glScale() const
00038 {
00039     ::glScalef(val[0],val[1],0);
00040 }
00041 
00042 template <>
00043 void GLVector2<GLint>::glScale() const
00044 {
00045     ::glScalef(static_cast<GLfloat>(val[0]),static_cast<GLfloat>(val[1]),0.0);
00046 }
00047 
00048 template <>
00049 void GLVector2<GLfloat>::glScale() const
00050 {
00051     ::glScalef(val[0],val[1],0.0);
00052 }
00053 
00054 template <>
00055 void GLVector2<GLdouble>::glScale() const
00056 {
00057     ::glScaled(val[0],val[1],0.0);
00058 }
00059 
00060 template <>
00061 void GLVector2<GLfloat>::glRotate(const GLfloat& ang) const
00062 {
00063     ::glRotatef(ang,val[0],val[1],0);
00064 }
00065 
00066 template <>
00067 void GLVector2<GLdouble>::glRotate(const GLdouble& ang) const
00068 {
00069     ::glRotated(ang,val[0],val[1],0);
00070 }
00071 
00072 template <>
00073 void GLVector2<GLfloat>::glTranslate() const
00074 {
00075     ::glTranslatef(val[0],val[1],0);
00076 }
00077 
00078 template <>
00079 void GLVector2<GLdouble>::glTranslate() const
00080 {
00081     ::glTranslated(val[0],val[1],0);
00082 }
00083 
00084 template <>
00085 void GLVector2<GLbyte>::glVertex() const
00086 {
00087     ::glVertex2s(x,y); 
00088 }
00089 
00090 template <>
00091 void GLVector2<GLfloat>::glNormal() const
00092 {
00093     ::glNormal3f(val[0],val[1],0);
00094 }
00095 
00096 template <>
00097 void GLVector2<GLdouble>::glNormal() const
00098 {
00099     ::glNormal3d(val[0],val[1],0);
00100 }
00101 
00102 template <>
00103 void GLVector3<GLfloat>::glScale() const
00104 {
00105     ::glScalef(val[0],val[1],val[2]);
00106 }
00107 
00108 template <>
00109 void GLVector3<GLdouble>::glScale() const
00110 {
00111     ::glScaled(val[0],val[1],val[2]);
00112 }
00113 
00114 template <>
00115 void GLVector3<GLfloat>::glRotate(const GLfloat& ang) const
00116 {
00117     ::glRotatef(ang,val[0],val[1],val[2]);
00118 }
00119 
00120 template <>
00121 void GLVector3<GLdouble>::glRotate(const GLdouble& ang) const
00122 {
00123     ::glRotated(ang,val[0],val[1],val[2]);
00124 }
00125 
00126 template <>
00127 void GLVector3<GLfloat>::glTranslate() const
00128 {
00129     ::glTranslatef(val[0],val[1],val[2]);
00130 }
00131 
00132 template <>
00133 void GLVector3<GLdouble>::glTranslate() const
00134 {
00135     ::glTranslated(val[0],val[1],val[2]);
00136 }
00137 
00138 template <>
00139 void GLVector3<GLbyte>::glVertex() const
00140 {
00141     ::glVertex3s(x,y,z); 
00142 }
00143 
00144 template <>
00145 void GLVector3<GLfloat>::glNormal() const
00146 {
00147     ::glNormal3fv(val);
00148 }
00149 
00150 template <>
00151 void GLVector3<GLdouble>::glNormal() const
00152 {
00153     ::glNormal3dv(val);
00154 }
00155 
00156 template <>
00157 GLVector3<GLfloat>& GLVector3<GLfloat>::operator /= (const GLfloat& v)
00158 {
00159     GLfloat r=1.0f/v;
00160     x*=r;
00161     y*=r;
00162     z*=r;
00163     return *this;
00164 }
00165 
00166 template <>
00167 GLVector3<GLdouble>& GLVector3<GLdouble>::operator /= (const GLdouble& v)
00168 {
00169     GLdouble r=1.0/v;
00170     x*=r;
00171     y*=r;
00172     z*=r;
00173     return *this;
00174 }
00175 
00176 template <>
00177 const GLVector3<GLfloat> GLVector3<GLfloat>::operator / (const GLfloat& v) const
00178 {
00179     GLfloat r=1.0f/v;
00180     return GLVector3<GLfloat>(x*r,y*r,z*r);
00181 }
00182 
00183 template <>
00184 const GLVector3<GLdouble> GLVector3<GLdouble>::operator / (const GLdouble& v) const
00185 {
00186     GLdouble r=1.0/v;
00187     return GLVector3<GLdouble>(x*r,y*r,z*r);
00188 }
00189 
00190 template <>
00191 void GLVector4<GLfloat>::glScale() const
00192 {
00193     ::glScalef(val[0],val[1],val[2]);
00194 }
00195 
00196 template <>
00197 void GLVector4<GLdouble>::glScale() const
00198 {
00199     ::glScaled(val[0],val[1],val[2]);
00200 }
00201 
00202 template <>
00203 void GLVector4<GLfloat>::glRotate(const GLfloat& ang) const
00204 {
00205     ::glRotatef(ang,val[0],val[1],val[2]);
00206 }
00207 
00208 template <>
00209 void GLVector4<GLdouble>::glRotate(const GLdouble& ang) const
00210 {
00211     ::glRotated(ang,val[0],val[1],val[2]);
00212 }
00213 
00214 template <>
00215 void GLVector4<GLfloat>::glTranslate() const
00216 {
00217     ::glTranslatef(val[0],val[1],val[2]);
00218 }
00219 
00220 template <>
00221 void GLVector4<GLdouble>::glTranslate() const
00222 {
00223     ::glTranslated(val[0],val[1],val[2]);
00224 }
00225 
00226 template <>
00227 void GLVector4<GLbyte>::glVertex() const
00228 {
00229     ::glVertex4s(x,y,z,w); 
00230 }
00231 
00232 template <>
00233 void GLVector4<GLfloat>::glNormal() const
00234 {
00235     ::glNormal3fv(val);
00236 }
00237 
00238 template <>
00239 void GLVector4<GLdouble>::glNormal() const
00240 {
00241     ::glNormal3dv(val);
00242 }
00243 
00244 template <>
00245 const GLVector4<GLfloat> GLVector4<GLfloat>::operator / (const GLfloat& v) const
00246 {
00247     GLfloat r=1.0f/v;
00248     return GLVector4<GLfloat>(x*r,y*r,z*r,w*r);
00249 }
00250 
00251 template <>
00252 const GLVector4<GLdouble> GLVector4<GLdouble>::operator / (const GLdouble& v) const
00253 {
00254     GLdouble r=1.0/v;
00255     return GLVector4<GLdouble>(x*r,y*r,z*r,w*r);
00256 }
00257 
00258 #ifdef GLVECTOR_USE_SSE
00259 template <>
00260 GLVector4<GLfloat>& GLVector4<GLfloat>::operator += (const GLVector4<GLfloat>& gv)
00261 {
00262     v4sf* a = (v4sf*)val;
00263     v4sf* b = (v4sf*)gv.val;
00264 
00265     *a = __builtin_ia32_addps(*a,*b);
00266     return *this;
00267 }
00268 
00269 template <>
00270 GLVector4<GLfloat>& GLVector4<GLfloat>::operator -= (const GLVector4<GLfloat>& gv)
00271 {
00272     v4sf* a = (v4sf*)val;
00273     v4sf* b = (v4sf*)gv.val;
00274 
00275     *a = __builtin_ia32_subps(*a,*b);
00276     return *this;
00277 }
00278 
00279 #endif
00280 
00281 };

Generated on Wed Oct 3 12:50:49 2007 for MathGL++ by  doxygen 1.5.2