csplugincommon/opengl/glhelper.h
Go to the documentation of this file.00001 /* 00002 Copyright (C) 2002 by Marten Svanfeldt 00003 Anders Stenberg 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Library General Public 00007 License as published by the Free Software Foundation; either 00008 version 2 of the License, or (at your option) any later version. 00009 00010 This library 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 GNU 00013 Library 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 library; if not, write to the Free 00017 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00018 */ 00019 00020 #ifndef __CS_CSPLUGINCOMMON_OPENGL_GLHELPER_H__ 00021 #define __CS_CSPLUGINCOMMON_OPENGL_GLHELPER_H__ 00022 00027 #include "csgeom/matrix3.h" 00028 #include "csgeom/matrix4.h" 00029 #include "csgeom/transfrm.h" 00030 #include "csgeom/vector3.h" 00031 00035 00036 static inline void makeGLMatrix (const csReversibleTransform& t, 00037 float matrix[16], bool rowMajor = false) 00038 { 00039 const csMatrix3 &orientation = t.GetO2T(); 00040 const csVector3 &translation = t.GetO2TTranslation(); 00041 00042 int row, col; 00043 if (rowMajor) 00044 { 00045 col = 1; row = 4; 00046 } 00047 else 00048 { 00049 col = 4; row = 1; 00050 } 00051 00052 matrix[col*0+row*0] = orientation.m11; 00053 matrix[col*0+row*1] = orientation.m12; 00054 matrix[col*0+row*2] = orientation.m13; 00055 matrix[col*0+row*3] = 0.0f; 00056 00057 matrix[col*1+row*0] = orientation.m21; 00058 matrix[col*1+row*1] = orientation.m22; 00059 matrix[col*1+row*2] = orientation.m23; 00060 matrix[col*1+row*3] = 0.0f; 00061 00062 matrix[col*2+row*0] = orientation.m31; 00063 matrix[col*2+row*1] = orientation.m32; 00064 matrix[col*2+row*2] = orientation.m33; 00065 matrix[col*2+row*3] = 0.0f; 00066 00067 matrix[col*3+row*0] = translation.x; 00068 matrix[col*3+row*1] = translation.y; 00069 matrix[col*3+row*2] = translation.z; 00070 matrix[col*3+row*3] = 1.0f; 00071 } 00072 00076 static inline void makeGLMatrixInverted (const csReversibleTransform& t, 00077 float matrix[16], bool rowMajor = false) 00078 { 00079 const csMatrix3 &orientation = t.GetT2O(); 00080 const csVector3 &translation = t.GetO2TTranslation(); 00081 00082 int row, col; 00083 if (rowMajor) 00084 { 00085 col = 1; row = 4; 00086 } 00087 else 00088 { 00089 col = 4; row = 1; 00090 } 00091 00092 matrix[col*0+row*0] = orientation.m11; 00093 matrix[col*0+row*1] = orientation.m12; 00094 matrix[col*0+row*2] = orientation.m13; 00095 matrix[col*0+row*3] = 0.0f; 00096 00097 matrix[col*1+row*0] = orientation.m21; 00098 matrix[col*1+row*1] = orientation.m22; 00099 matrix[col*1+row*2] = orientation.m23; 00100 matrix[col*1+row*3] = 0.0f; 00101 00102 matrix[col*2+row*0] = orientation.m31; 00103 matrix[col*2+row*1] = orientation.m32; 00104 matrix[col*2+row*2] = orientation.m33; 00105 matrix[col*2+row*3] = 0.0f; 00106 00107 matrix[col*3+row*0] = translation.x; 00108 matrix[col*3+row*1] = translation.y; 00109 matrix[col*3+row*2] = translation.z; 00110 matrix[col*3+row*3] = 1.0f; 00111 } 00112 00114 static inline void makeGLMatrix (const csMatrix3& m, float matrix[16], 00115 bool rowMajor = false) 00116 { 00117 int row, col; 00118 if (rowMajor) 00119 { 00120 col = 1; row = 4; 00121 } 00122 else 00123 { 00124 col = 4; row = 1; 00125 } 00126 00127 matrix[col*0+row*0] = m.m11; 00128 matrix[col*0+row*1] = m.m12; 00129 matrix[col*0+row*2] = m.m13; 00130 matrix[col*0+row*3] = 0.0f; 00131 00132 matrix[col*1+row*0] = m.m21; 00133 matrix[col*1+row*1] = m.m22; 00134 matrix[col*1+row*2] = m.m23; 00135 matrix[col*1+row*3] = 0.0f; 00136 00137 matrix[col*2+row*0] = m.m31; 00138 matrix[col*2+row*1] = m.m32; 00139 matrix[col*2+row*2] = m.m33; 00140 matrix[col*2+row*3] = 0.0f; 00141 00142 matrix[col*3+row*0] = 0.0f; 00143 matrix[col*3+row*1] = 0.0f; 00144 matrix[col*3+row*2] = 0.0f; 00145 matrix[col*3+row*3] = 1.0f; 00146 } 00147 00148 namespace CS 00149 { 00150 namespace PluginCommon 00151 { 00153 static inline void MakeGLMatrix3x3 (const csMatrix3& m, float matrix[9], 00154 bool rowMajor = false) 00155 { 00156 int row, col; 00157 if (rowMajor) 00158 { 00159 col = 1; row = 3; 00160 } 00161 else 00162 { 00163 col = 3; row = 1; 00164 } 00165 00166 matrix[col*0+row*0] = m.m11; 00167 matrix[col*0+row*1] = m.m12; 00168 matrix[col*0+row*2] = m.m13; 00169 00170 matrix[col*1+row*0] = m.m21; 00171 matrix[col*1+row*1] = m.m22; 00172 matrix[col*1+row*2] = m.m23; 00173 00174 matrix[col*2+row*0] = m.m31; 00175 matrix[col*2+row*1] = m.m32; 00176 matrix[col*2+row*2] = m.m33; 00177 } 00178 00180 static inline void MakeGLMatrix4x4 (const CS::Math::Matrix4& m, float matrix[16], 00181 bool rowMajor = false) 00182 { 00183 int row, col; 00184 if (rowMajor) 00185 { 00186 col = 1; row = 4; 00187 } 00188 else 00189 { 00190 col = 4; row = 1; 00191 } 00192 00193 matrix[col*0+row*0] = m.m11; 00194 matrix[col*0+row*1] = m.m21; 00195 matrix[col*0+row*2] = m.m31; 00196 matrix[col*0+row*3] = m.m41; 00197 00198 matrix[col*1+row*0] = m.m12; 00199 matrix[col*1+row*1] = m.m22; 00200 matrix[col*1+row*2] = m.m32; 00201 matrix[col*1+row*3] = m.m42; 00202 00203 matrix[col*2+row*0] = m.m13; 00204 matrix[col*2+row*1] = m.m23; 00205 matrix[col*2+row*2] = m.m33; 00206 matrix[col*2+row*3] = m.m43; 00207 00208 matrix[col*3+row*0] = m.m14; 00209 matrix[col*3+row*1] = m.m24; 00210 matrix[col*3+row*2] = m.m34; 00211 matrix[col*3+row*3] = m.m44; 00212 } 00213 00214 } // namespace PluginCommon 00215 } // namespace CS 00216 00219 #endif
Generated for Crystal Space 2.1 by doxygen 1.6.1
