CrystalSpace

Public API Reference

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 
00074 static inline void makeGLMatrix (const csMatrix3& m, float matrix[16], 
00075                                  bool rowMajor = false)
00076 {
00077   int row, col;
00078   if (rowMajor)
00079   {
00080     col = 1; row = 4;
00081   }
00082   else
00083   {
00084     col = 4; row = 1;
00085   }
00086 
00087   matrix[col*0+row*0] = m.m11;
00088   matrix[col*0+row*1] = m.m12;
00089   matrix[col*0+row*2] = m.m13;
00090   matrix[col*0+row*3] = 0.0f;
00091 
00092   matrix[col*1+row*0] = m.m21;
00093   matrix[col*1+row*1] = m.m22;
00094   matrix[col*1+row*2] = m.m23;
00095   matrix[col*1+row*3] = 0.0f;
00096 
00097   matrix[col*2+row*0] = m.m31;
00098   matrix[col*2+row*1] = m.m32;
00099   matrix[col*2+row*2] = m.m33;
00100   matrix[col*2+row*3] = 0.0f;
00101 
00102   matrix[col*3+row*0] = 0.0f;
00103   matrix[col*3+row*1] = 0.0f;
00104   matrix[col*3+row*2] = 0.0f;
00105   matrix[col*3+row*3] = 1.0f;
00106 }
00107 
00108 namespace CS
00109 {
00110   namespace PluginCommon
00111   {
00113     static inline void MakeGLMatrix3x3 (const csMatrix3& m, float matrix[9], 
00114                                         bool rowMajor = false)
00115     {
00116       int row, col;
00117       if (rowMajor)
00118       {
00119         col = 1; row = 3;
00120       }
00121       else
00122       {
00123         col = 3; row = 1;
00124       }
00125     
00126       matrix[col*0+row*0] = m.m11;
00127       matrix[col*0+row*1] = m.m12;
00128       matrix[col*0+row*2] = m.m13;
00129     
00130       matrix[col*1+row*0] = m.m21;
00131       matrix[col*1+row*1] = m.m22;
00132       matrix[col*1+row*2] = m.m23;
00133     
00134       matrix[col*2+row*0] = m.m31;
00135       matrix[col*2+row*1] = m.m32;
00136       matrix[col*2+row*2] = m.m33;
00137     }
00138 
00140     static inline void MakeGLMatrix4x4 (const CS::Math::Matrix4& m, float matrix[16], 
00141                                         bool rowMajor = false)
00142     {
00143       int row, col;
00144       if (rowMajor)
00145       {
00146         col = 1; row = 4;
00147       }
00148       else
00149       {
00150         col = 4; row = 1;
00151       }
00152     
00153       matrix[col*0+row*0] = m.m11;
00154       matrix[col*0+row*1] = m.m21;
00155       matrix[col*0+row*2] = m.m31;
00156       matrix[col*0+row*3] = m.m41;
00157     
00158       matrix[col*1+row*0] = m.m12;
00159       matrix[col*1+row*1] = m.m22;
00160       matrix[col*1+row*2] = m.m32;
00161       matrix[col*1+row*3] = m.m42;
00162     
00163       matrix[col*2+row*0] = m.m13;
00164       matrix[col*2+row*1] = m.m23;
00165       matrix[col*2+row*2] = m.m33;
00166       matrix[col*2+row*3] = m.m43;
00167     
00168       matrix[col*3+row*0] = m.m14;
00169       matrix[col*3+row*1] = m.m24;
00170       matrix[col*3+row*2] = m.m34;
00171       matrix[col*3+row*3] = m.m44;
00172     }
00173     
00174   } // namespace PluginCommon
00175 } // namespace CS
00176 
00179 #endif

Generated for Crystal Space 2.0 by doxygen 1.7.6.1