| ## Public API Reference

- Main Page
- Modules
- Namespaces
- Classes
- Files
- Related Pages

- File List
- File Members

# 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/transfrm.h"
    00029 #include "csgeom/vector3.h"
    00030
    00034
    00035 static inline void makeGLMatrix (const csReversibleTransform& t,
    00036   float matrix[16], bool rowMajor = false)
    00037 {
    00038   const csMatrix3 &orientation = t.GetO2T();
    00039   const csVector3 &translation = t.GetO2TTranslation();
    00040
    00041   int row, col;
    00042   if (rowMajor)
    00043   {
    00044     col = 1; row = 4;
    00045   }
    00046   else
    00047   {
    00048     col = 4; row = 1;
    00049   }
    00050
    00051   matrix[col*0+row*0] = orientation.m11;
    00052   matrix[col*0+row*1] = orientation.m12;
    00053   matrix[col*0+row*2] = orientation.m13;
    00054   matrix[col*0+row*3] = 0.0f;
    00055
    00056   matrix[col*1+row*0] = orientation.m21;
    00057   matrix[col*1+row*1] = orientation.m22;
    00058   matrix[col*1+row*2] = orientation.m23;
    00059   matrix[col*1+row*3] = 0.0f;
    00060
    00061   matrix[col*2+row*0] = orientation.m31;
    00062   matrix[col*2+row*1] = orientation.m32;
    00063   matrix[col*2+row*2] = orientation.m33;
    00064   matrix[col*2+row*3] = 0.0f;
    00065
    00066   matrix[col*3+row*0] = translation.x;
    00067   matrix[col*3+row*1] = translation.y;
    00068   matrix[col*3+row*2] = translation.z;
    00069   matrix[col*3+row*3] = 1.0f;
    00070 }
    00071
    00073 static inline void makeGLMatrix (const csMatrix3& m, float matrix[16],
    00074                                  bool rowMajor = false)
    00075 {
    00076   int row, col;
    00077   if (rowMajor)
    00078   {
    00079     col = 1; row = 4;
    00080   }
    00081   else
    00082   {
    00083     col = 4; row = 1;
    00084   }
    00085
    00086   matrix[col*0+row*0] = m.m11;
    00087   matrix[col*0+row*1] = m.m12;
    00088   matrix[col*0+row*2] = m.m13;
    00089   matrix[col*0+row*3] = 0.0f;
    00090
    00091   matrix[col*1+row*0] = m.m21;
    00092   matrix[col*1+row*1] = m.m22;
    00093   matrix[col*1+row*2] = m.m23;
    00094   matrix[col*1+row*3] = 0.0f;
    00095
    00096   matrix[col*2+row*0] = m.m31;
    00097   matrix[col*2+row*1] = m.m32;
    00098   matrix[col*2+row*2] = m.m33;
    00099   matrix[col*2+row*3] = 0.0f;
    00100
    00101   matrix[col*3+row*0] = 0.0f;
    00102   matrix[col*3+row*1] = 0.0f;
    00103   matrix[col*3+row*2] = 0.0f;
    00104   matrix[col*3+row*3] = 1.0f;
    00105 }
    00106
    00109 #endif