00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "math.h"
00021
00022 #include <QtGui/QImage>
00023
00024 using namespace GluonGraphics;
00025
00026 void
00027 Math::qmatrixToGLMatrix( const QMatrix4x4& matrix, float* out )
00028 {
00029 qreal* data = matrix.transposed().data();
00030
00031 for( int i = 0; i < 16; ++i )
00032 {
00033 out[i] = static_cast<float>( data[i] );
00034 }
00035 }
00036
00037 QMatrix4x4
00038 Math::calculateModelViewProj( const QMatrix4x4& model, const QMatrix4x4& view, const QMatrix4x4& projection )
00039 {
00040 return projection * ( view * model );
00041 }
00042
00043 void
00044 Math::qImageToGL( const QImage& image, uchar* out )
00045 {
00046 int w = image.width();
00047 int h = image.height();
00048 int i = 0;
00049
00050 for( int r = 0; r < h; ++r )
00051 {
00052 for( int c = 0; c < w; ++c )
00053 {
00054 QRgb pixel = image.pixel( c, r );
00055 out[i++] = qRed( pixel );
00056 out[i++] = qGreen( pixel );
00057 out[i++] = qBlue( pixel );
00058 out[i++] = qAlpha( pixel );
00059 }
00060 }
00061 }
00062
00063 const QVector3D Math::VECTOR_UNIT_X = QVector3D( 1.f, 0.f, 0.f );
00064 const QVector3D Math::VECTOR_UNIT_Y = QVector3D( 0.f, 1.f, 0.f );
00065 const QVector3D Math::VECTOR_UNIT_Z = QVector3D( 0.f, 0.f, 1.f );
00066 const QVector3D Math::VECTOR_UNIT_SCALE = QVector3D( 1.f, 1.f, 1.f );