| 1 | /**************************************************************************** |
| 2 | * VCGLib o o * |
| 3 | * Visual and Computer Graphics Library o o * |
| 4 | * _ O _ * |
| 5 | * Copyright(C) 2004 \/)\/ * |
| 6 | * Visual Computing Lab /\/| * |
| 7 | * ISTI - Italian National Research Council | * |
| 8 | * \ * |
| 9 | * All rights reserved. * |
| 10 | * * |
| 11 | * This program is free software; you can redistribute it and/or modify * |
| 12 | * it under the terms of the GNU General Public License as published by * |
| 13 | * the Free Software Foundation; either version 2 of the License, or * |
| 14 | * (at your option) any later version. * |
| 15 | * * |
| 16 | * This program is distributed in the hope that it will be useful, * |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
| 19 | * GNU General Public License (http://www.gnu.org/licenses/gpl.txt) * |
| 20 | * for more details. * |
| 21 | * * |
| 22 | ****************************************************************************/ |
| 23 | /**************************************************************************** |
| 24 | History |
| 25 | |
| 26 | $Log: math.h,v $ |
| 27 | Revision 1.11 2006/10/09 19:56:09 cignoni |
| 28 | Removed the default use of the OpenGL transpose extension. Added two method for direct (non transposed) matrix multiplication and getting |
| 29 | |
| 30 | Revision 1.10 2006/02/13 13:05:05 cignoni |
| 31 | Removed glew inclusion |
| 32 | |
| 33 | Revision 1.9 2004/09/30 00:48:07 ponchio |
| 34 | <gl/glew.h> -> <GL/glew.h> |
| 35 | |
| 36 | Revision 1.8 2004/09/28 14:04:36 ganovelli |
| 37 | glGet added |
| 38 | |
| 39 | Revision 1.7 2004/07/13 15:55:57 cignoni |
| 40 | Added test on presence of glTranspose extension (for old hw support) |
| 41 | |
| 42 | Revision 1.6 2004/05/26 15:12:39 cignoni |
| 43 | Removed inclusion of gl extension stuff |
| 44 | |
| 45 | Revision 1.5 2004/05/12 20:54:55 ponchio |
| 46 | *** empty log message *** |
| 47 | |
| 48 | Revision 1.4 2004/05/12 13:07:47 ponchio |
| 49 | Added #include <glew.h> |
| 50 | |
| 51 | Revision 1.3 2004/05/04 23:36:23 cignoni |
| 52 | remove include of gl and added glextgension exploiting, |
| 53 | |
| 54 | Revision 1.2 2004/04/07 10:47:03 cignoni |
| 55 | inlined functions for avoid multiple linking errors |
| 56 | |
| 57 | Revision 1.1 2004/03/31 15:27:17 ponchio |
| 58 | *** empty log message *** |
| 59 | |
| 60 | |
| 61 | ****************************************************************************/ |
| 62 | |
| 63 | #ifndef VCG_GL_MATH_H |
| 64 | #define VCG_GL_MATH_H |
| 65 | |
| 66 | // Please note that this file assume that you have already included your |
| 67 | // gl-extension wrapping utility, and that therefore all the extension symbol are already defined. |
| 68 | |
| 69 | #include <vcg/math/matrix44.h> |
| 70 | #include <vcg/math/similarity.h> |
| 71 | //#include <GL/glew.h> // please do not include it! |
| 72 | |
| 73 | |
| 74 | namespace vcg { |
| 75 | |
| 76 | inline void glMultMatrixE(const Matrix44f &matrix) { |
| 77 | //glMultMatrixf((const GLfloat *)(matrix[0])); |
| 78 | if(glMultTransposeMatrixf) glMultTransposeMatrixf((const GLfloat *)(matrix[0])); |
| 79 | else { |
| 80 | Matrix44f tmp(matrix); |
| 81 | Transpose(tmp); |
| 82 | glMultMatrixf((const GLfloat *)(tmp[0])); |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | inline void glMultMatrix(const Matrix44f &matrix) { |
| 87 | Matrix44f tmp(matrix); |
| 88 | Transpose(tmp); |
| 89 | glMultMatrixf((const GLfloat *)(tmp[0])); |
| 90 | } |
| 91 | |
| 92 | inline void glMultMatrixE(const Matrix44d &matrix) { |
| 93 | if(glMultTransposeMatrixd) glMultTransposeMatrixd((const GLdouble *)(matrix[0])); |
| 94 | else { |
| 95 | Matrix44d tmp(matrix); |
| 96 | Transpose(tmp); |
| 97 | glMultMatrixd((const GLdouble *)(tmp[0])); |
| 98 | } |
| 99 | } |
| 100 | inline void glMultMatrix(const Matrix44d &matrix) { |
| 101 | Matrix44d tmp(matrix); |
| 102 | Transpose(tmp); |
| 103 | glMultMatrixd((const GLdouble *)(tmp[0])); |
| 104 | } |
| 105 | |
| 106 | inline void glMultMatrixDirect(const Matrix44f &matrix) { |
| 107 | glMultMatrixf((const GLfloat *)(matrix[0])); |
| 108 | } |
| 109 | |
| 110 | inline void glMultMatrixDirect(const Matrix44d &matrix) { |
| 111 | glMultMatrixd((const GLdouble *)(matrix[0])); |
| 112 | } |
| 113 | |
| 114 | inline void glMultMatrix(const Similarityf &s) { |
| 115 | glTranslatef(s.tra[0], s.tra[1], s.tra[2]); |
| 116 | glScalef(s.sca, s.sca, s.sca); |
| 117 | float alpha; |
| 118 | Point3f axis; |
| 119 | s.rot.ToAxis(alpha, axis); |
| 120 | glRotatef(math::ToDeg(alpha), axis[0], axis[1], axis[2]); |
| 121 | |
| 122 | } |
| 123 | |
| 124 | inline void glMultMatrix(const Similarityd &s) { |
| 125 | glTranslated(s.tra[0], s.tra[1], s.tra[2]); |
| 126 | double alpha; |
| 127 | Point3d axis; |
| 128 | s.rot.ToAxis(alpha, axis); |
| 129 | glRotated(math::ToDeg(alpha), axis[0], axis[1], axis[2]); |
| 130 | glScaled(s.sca, s.sca, s.sca); |
| 131 | } |
| 132 | |
| 133 | inline void glGetv(const GLenum pname, Matrix44f & m){ |
| 134 | glGetFloatv(pname,&m[0][0]); |
| 135 | Transpose(m); |
| 136 | } |
| 137 | |
| 138 | inline void glGetv(const GLenum pname, Matrix44d & m){ |
| 139 | glGetDoublev(pname,&m[0][0]); |
| 140 | Transpose(m); |
| 141 | } |
| 142 | |
| 143 | inline void glGetDirectv(const GLenum pname, Matrix44f & m){ |
| 144 | glGetFloatv(pname,&m[0][0]); |
| 145 | } |
| 146 | |
| 147 | inline void glGetDirecv(const GLenum pname, Matrix44d & m){ |
| 148 | glGetDoublev(pname,&m[0][0]); |
| 149 | } |
| 150 | |
| 151 | |
| 152 | }//namespace |
| 153 | #endif |