1 /***************************************************************************
2 * This file is part of Tecorrec. *
3 * Copyright 2008 James Hogan <james@albanarts.com> *
5 * Tecorrec is free software: you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation, either version 2 of the License, or *
8 * (at your option) any later version. *
10 * Tecorrec is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with Tecorrec. If not, write to the Free Software Foundation, *
17 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
18 ***************************************************************************/
20 #ifndef _maths_glVector_h
21 #define _maths_glVector_h
26 * Inline function helpers for maths::gl::vec<n><t> classes (from maths library)
27 * These are overloaded to take multiple data types
35 // Make use of maths library vector classes
36 typedef maths::Vector
<2,GLfloat
> vec2f
;
37 typedef maths::Vector
<3,GLfloat
> vec3f
;
38 typedef maths::Vector
<4,GLfloat
> vec4f
;
39 typedef maths::Vector
<2,GLdouble
> vec2d
;
40 typedef maths::Vector
<3,GLdouble
> vec3d
;
41 typedef maths::Vector
<4,GLdouble
> vec4d
;
45 typedef maths::gl::vec2f GLvec2f
;
46 typedef maths::gl::vec3f GLvec3f
;
47 typedef maths::gl::vec4f GLvec4f
;
48 typedef maths::gl::vec2d GLvec2d
;
49 typedef maths::gl::vec3d GLvec3d
;
50 typedef maths::gl::vec4d GLvec4d
;
52 // Send a two dimentional vertex to OpenGL
53 inline void glVertex2(const maths::gl::vec2f
& v
) { glVertex2fv(v
); }
54 inline void glVertex2(const maths::gl::vec2d
& v
) { glVertex2dv(v
); }
56 // Send a three dimentional vertex to OpenGL
57 inline void glVertex3(const maths::gl::vec3f
& v
) { glVertex3fv(v
); }
58 inline void glVertex3(const maths::gl::vec3d
& v
) { glVertex3dv(v
); }
60 // Send a four dimentional vertex to OpenGL
61 inline void glVertex4(const maths::gl::vec4f
& v
) { glVertex4fv(v
); }
62 inline void glVertex4(const maths::gl::vec4d
& v
) { glVertex4dv(v
); }
64 // Send a normal vector to OpenGL
65 inline void glNormal(const maths::gl::vec3f
& v
) { glNormal3fv(v
); }
66 inline void glNormal(const maths::gl::vec4f
& v
) { glNormal3fv(v
); }
67 inline void glNormal(const maths::gl::vec3d
& v
) { glNormal3dv(v
); }
68 inline void glNormal(const maths::gl::vec4d
& v
) { glNormal3dv(v
); }
70 // Send a two dimentional texture coordinate to OpenGL
71 inline void glTexCoord2(const maths::gl::vec2f
& v
) { glTexCoord2fv(v
); }
72 inline void glTexCoord2(const maths::gl::vec2d
& v
) { glTexCoord2dv(v
); }
74 // Send a three dimentional texture coordinate to OpenGL
75 inline void glTexCoord3(const maths::gl::vec3f
& v
) { glTexCoord3fv(v
); }
76 inline void glTexCoord3(const maths::gl::vec3d
& v
) { glTexCoord3dv(v
); }
78 // Send a two dimentional mulitexture coordinate to OpenGL
79 inline void glMultiTexCoord2(GLenum target
, const maths::gl::vec2f
& v
) { glMultiTexCoord2fv(target
, v
); }
80 inline void glMultiTexCoord2(GLenum target
, const maths::gl::vec2d
& v
) { glMultiTexCoord2dv(target
, v
); }
82 // Send a three dimentional mulitexture coordinate to OpenGL
83 inline void glMultiTexCoord3(GLenum target
, const maths::gl::vec3f
& v
) { glMultiTexCoord3fv(target
, v
); }
84 inline void glMultiTexCoord3(GLenum target
, const maths::gl::vec3d
& v
) { glMultiTexCoord3dv(target
, v
); }
86 // Translate the modelview matrix by a vector
87 inline void glTranslate(const maths::gl::vec2f
& v
, GLfloat z
= 0.0f
) { glTranslatef(v
[0], v
[1], z
); }
88 inline void glTranslate(const maths::gl::vec3f
& v
) { glTranslatef(v
[0], v
[1], v
[2]); }
89 inline void glTranslate(const maths::gl::vec4f
& v
) { glTranslatef(v
[0], v
[1], v
[2]); }
90 inline void glTranslate(const maths::gl::vec2d
& v
, GLdouble z
= 0.0 ) { glTranslated(v
[0], v
[1], z
); }
91 inline void glTranslate(const maths::gl::vec3d
& v
) { glTranslated(v
[0], v
[1], v
[2]); }
92 inline void glTranslate(const maths::gl::vec4d
& v
) { glTranslated(v
[0], v
[1], v
[2]); }
94 // Rotate the modelview matrix rad radians about axis
95 inline void glRotate(const float rad
, const maths::gl::vec3f
& axis
) { glRotatef(rad
*57.29577951f
, axis
[0], axis
[1], axis
[2]); }
96 inline void glRotate(const double rad
, const maths::gl::vec3d
& axis
) { glRotated(rad
*57.29577951, axis
[0], axis
[1], axis
[2]); }