Click here to Skip to main content
15,894,106 members
Articles / Desktop Programming / MFC

OAG Library (OpenGL) Part 1 - Setting Up the Library for an MFC Application

Rate me:
Please Sign up or sign in to vote.
4.40/5 (11 votes)
7 Aug 2011CPOL3 min read 56.3K   56  
OAG is a library written in C++. With this library, you can create OpenGL based applications.
#pragma once

#include <math.h>
#include "VectorFloat.h"
#include "OAGMatrix4x4.h"
#include "..\..\OpenGL\include\rglModel\aiQuaternion.h"

// ----------------------------------------------------------------------------------------
inline void Matrix4x4Decompose (const oag::Matrix4x4& matSource, oag::CVectorFloat& scaling, aiQuaternion& rotation,
	oag::CVectorFloat& position)
{
	//const oag::Matrix4x4& _this = *this;

	// extract translation
	//position.x = _this[0][3];
	//position.y = _this[1][3];
	//position.z = _this[2][3];

	//// extract the rows of the matrix
	//aiVector3D vRows[3] = {
	//	aiVector3D(_this[0][0],_this[1][0],_this[2][0]),
	//	aiVector3D(_this[0][1],_this[1][1],_this[2][1]),
	//	aiVector3D(_this[0][2],_this[1][2],_this[2][2])
	//};

	//// extract the scaling factors
	//scaling.x = vRows[0].Length();
	//scaling.y = vRows[1].Length();
	//scaling.z = vRows[2].Length();

	//// and remove all scaling from the matrix
	//if(scaling.x)
	//{
	//	vRows[0] /= scaling.x;
	//}
	//if(scaling.y)
	//{
	//	vRows[1] /= scaling.y;
	//}
	//if(scaling.z)
	//{
	//	vRows[2] /= scaling.z;
	//}

	//// build a 3x3 rotation matrix
	//aiMatrix3x3 m(vRows[0].x,vRows[1].x,vRows[2].x,
	//	vRows[0].y,vRows[1].y,vRows[2].y,
	//	vRows[0].z,vRows[1].z,vRows[2].z);

	//// and generate the rotation quaternion from it
	//rotation = aiQuaternion(m);
}

inline oag::Matrix4x4 RotationZ(float a, oag::Matrix4x4& out)
{
	/*
	     |  cos(A)  -sin(A)   0   0 |
     M = |  sin(A)   cos(A)   0   0 |
         |  0        0        1   0 |
         |  0        0        0   1 |	*/
	oag::Matrix4x4 localMat;
	out = localMat;
	out.MakeIdentity();

	out.m00 = out.m11 = cos(a); //out.a1 = out.b2 = cos(a);
	out.m01 = -(out.m10 = sin(a) ); //out.a2 = -(out.b1 = sin(a));
	return out;
}

/** Transformation of a vector by a 3x3 matrix */
inline oag::CVectorFloat MultiplyMatrix3x3ByVector(const oag::Matrix3x3& pMatrix, const oag::CVectorFloat& pVector)
{
	oag::CVectorFloat res;
	res.m_X = (pMatrix.m00 * pVector.m_X) + (pMatrix.m01 * pVector.m_Y) + (pMatrix.m02 * pVector.m_Z);
	res.m_Y = (pMatrix.m10 * pVector.m_X) + (pMatrix.m11 * pVector.m_Y) + (pMatrix.m12 * pVector.m_Z);
	res.m_Z = (pMatrix.m20 * pVector.m_X) + (pMatrix.m21 * pVector.m_Y) + (pMatrix.m22 * pVector.m_Z);
	return res;
}

inline oag::CVectorFloat MultiplyMatrix4x4ByVectorFloat(const oag::Matrix4x4* pMatrix, const oag::CVectorFloat pVector)
{
	oag::CVectorFloat res;
	res.m_X = (pMatrix->m00 * pVector.m_X) + (pMatrix->m01 * pVector.m_Y) + (pMatrix->m02 * pVector.m_Z + pMatrix->m03);
	res.m_Y = (pMatrix->m10 * pVector.m_X) + (pMatrix->m11 * pVector.m_Y) + (pMatrix->m12 * pVector.m_Z + pMatrix->m13);
	res.m_Z = (pMatrix->m20 * pVector.m_X) + (pMatrix->m21 * pVector.m_Y) + (pMatrix->m22 * pVector.m_Z + pMatrix->m23);
	return res;
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
Brazil Brazil
I live in Matão, a small city in Brazil. I studied as Programmer in a College for Software Development in Database.
After finishing the College I have been working with java, c# and Computer Graphics with searches for OpenGL.

Comments and Discussions