Removed dependencies on GLM

This commit is contained in:
Aruki 2017-03-31 23:33:11 -06:00
parent cd8f4147c2
commit e138cd7035
11 changed files with 24 additions and 61 deletions

View File

@ -74,7 +74,6 @@ LIBS += -L$$EXTERNALS_DIR/glew-2.0.0/lib/Release/x64 -lglew32s \
INCLUDEPATH += $$PWE_MAIN_INCLUDE \ INCLUDEPATH += $$PWE_MAIN_INCLUDE \
$$EXTERNALS_DIR/assimp/include \ $$EXTERNALS_DIR/assimp/include \
$$EXTERNALS_DIR/glew-2.0.0/include \ $$EXTERNALS_DIR/glew-2.0.0/include \
$$EXTERNALS_DIR/glm/glm \
$$EXTERNALS_DIR/lzo-2.09/include \ $$EXTERNALS_DIR/lzo-2.09/include \
$$EXTERNALS_DIR/nodtool/include \ $$EXTERNALS_DIR/nodtool/include \
$$EXTERNALS_DIR/nodtool/logvisor/include \ $$EXTERNALS_DIR/nodtool/logvisor/include \

View File

@ -2,7 +2,6 @@
#include "CGraphics.h" #include "CGraphics.h"
#include <Math/CQuaternion.h> #include <Math/CQuaternion.h>
#include <Math/MathUtil.h> #include <Math/MathUtil.h>
#include <gtc/matrix_transform.hpp>
CCamera::CCamera() CCamera::CCamera()
: mMode(eFreeCamera) : mMode(eFreeCamera)
@ -243,15 +242,17 @@ void CCamera::UpdateTransform() const
void CCamera::UpdateView() const void CCamera::UpdateView() const
{ {
// todo: don't use glm
UpdateTransform(); UpdateTransform();
if (mViewDirty) if (mViewDirty)
{ {
glm::vec3 glmpos(mPosition.X, mPosition.Y, mPosition.Z); mViewMatrix = CMatrix4f(
glm::vec3 glmdir(mDirection.X, mDirection.Y, mDirection.Z); mRightVector.X, mRightVector.Y, mRightVector.Z, -mRightVector.Dot(mPosition),
glm::vec3 glmup(mUpVector.X, mUpVector.Y, mUpVector.Z); mUpVector.X, mUpVector.Y, mUpVector.Z, -mUpVector.Dot(mPosition),
mViewMatrix = CMatrix4f::FromGlmMat4(glm::lookAt(glmpos, glmpos + glmdir, glmup)).Transpose(); -mDirection.X, -mDirection.Y, -mDirection.Z, mDirection.Dot(mPosition),
0.f, 0.f, 0.f, 1.f
);
mViewDirty = false; mViewDirty = false;
} }
} }

View File

@ -11,7 +11,6 @@
#include <fstream> #include <fstream>
#include <vector> #include <vector>
#include <sstream> #include <sstream>
#include <gtx/transform.hpp>
// ************ STATIC MEMBER INITIALIZATION ************ // ************ STATIC MEMBER INITIALIZATION ************
u32 CRenderer::sNumRenderers = 0; u32 CRenderer::sNumRenderers = 0;

View File

@ -101,9 +101,7 @@ void CMaterialPass::SetAnimCurrent(FRenderOptions Options, u32 PassIndex)
case eInverseMV: // Mode 0 case eInverseMV: // Mode 0
case eSimpleMode: // Mode 10 - maybe not correct? case eSimpleMode: // Mode 10 - maybe not correct?
{ {
glm::mat4 InvMV = glm::inverse(glm::transpose(ViewMtx.ToGlmMat4()) * glm::transpose(ModelMtx.ToGlmMat4())); TexMtx = (ModelMtx * ViewMtx).Transpose().Inverse();
InvMV[0][3] = InvMV[1][3] = InvMV[2][3] = 0.f;
TexMtx = CMatrix4f::FromGlmMat4(InvMV);
PostMtx = CMatrix4f(0.5f, 0.0f, 0.0f, 0.5f, PostMtx = CMatrix4f(0.5f, 0.0f, 0.0f, 0.5f,
0.0f, 0.5f, 0.0f, 0.5f, 0.0f, 0.5f, 0.0f, 0.5f,
0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f,
@ -113,8 +111,7 @@ void CMaterialPass::SetAnimCurrent(FRenderOptions Options, u32 PassIndex)
case eInverseMVTranslated: // Mode 1 case eInverseMVTranslated: // Mode 1
{ {
glm::mat4 InvMV = glm::inverse(glm::transpose(ViewMtx.ToGlmMat4()) * glm::transpose(ModelMtx.ToGlmMat4())); TexMtx = (ModelMtx * ViewMtx).Transpose().Inverse();
TexMtx = CMatrix4f::FromGlmMat4(InvMV);
PostMtx = CMatrix4f(0.5f, 0.0f, 0.0f, 0.5f, PostMtx = CMatrix4f(0.5f, 0.0f, 0.0f, 0.5f,
0.0f, 0.5f, 0.0f, 0.5f, 0.0f, 0.5f, 0.0f, 0.5f,
0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f,
@ -166,7 +163,7 @@ void CMaterialPass::SetAnimCurrent(FRenderOptions Options, u32 PassIndex)
case eModelMatrix: // Mode 6 case eModelMatrix: // Mode 6
{ {
// It looks ok, but I can't tell whether it's correct... // It looks ok, but I can't tell whether it's correct...
TexMtx = CMatrix4f::FromGlmMat4(glm::transpose(ModelMtx.ToGlmMat4())); TexMtx = ModelMtx.Transpose();
PostMtx = CMatrix4f(0.5f, 0.0f, 0.0f, TexMtx[0][3] * 0.50000001f, PostMtx = CMatrix4f(0.5f, 0.0f, 0.0f, TexMtx[0][3] * 0.50000001f,
0.0f, 0.5f, 0.0f, TexMtx[1][3] * 0.50000001f, 0.0f, 0.5f, 0.0f, TexMtx[1][3] * 0.50000001f,
0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f,
@ -180,9 +177,8 @@ void CMaterialPass::SetAnimCurrent(FRenderOptions Options, u32 PassIndex)
{ {
CMatrix4f View = CGraphics::sMVPBlock.ViewMatrix; CMatrix4f View = CGraphics::sMVPBlock.ViewMatrix;
glm::mat4 Mtx = glm::inverse(glm::transpose(ViewMtx.ToGlmMat4()) * glm::transpose(ModelMtx.ToGlmMat4())); TexMtx = (ModelMtx * ViewMtx).Transpose().Inverse();
Mtx[0][3] = Mtx[1][3] = Mtx[2][3] = 0.f; TexMtx[0][3] = TexMtx[1][3] = TexMtx[2][3] = 0.f;
TexMtx = CMatrix4f::FromGlmMat4(Mtx);
float XY = (View[3][0] + View[3][1]) * 0.025f * mAnimParams[1]; float XY = (View[3][0] + View[3][1]) * 0.025f * mAnimParams[1];
XY = (XY - (int) XY); XY = (XY - (int) XY);

View File

@ -86,7 +86,6 @@ LIBS += -L$$EXTERNALS_DIR/glew-2.0.0/lib/Release/x64 -lglew32s \
INCLUDEPATH += $$PWE_MAIN_INCLUDE \ INCLUDEPATH += $$PWE_MAIN_INCLUDE \
$$EXTERNALS_DIR/assimp/include \ $$EXTERNALS_DIR/assimp/include \
$$EXTERNALS_DIR/glew-2.0.0/include \ $$EXTERNALS_DIR/glew-2.0.0/include \
$$EXTERNALS_DIR/glm/glm \
$$EXTERNALS_DIR/lzo-2.09/include \ $$EXTERNALS_DIR/lzo-2.09/include \
$$EXTERNALS_DIR/nodtool/include \ $$EXTERNALS_DIR/nodtool/include \
$$EXTERNALS_DIR/nodtool/logvisor/include \ $$EXTERNALS_DIR/nodtool/logvisor/include \

View File

@ -138,21 +138,6 @@ float CMatrix4f::Determinant() const
return (A - B + C - D); return (A - B + C - D);
} }
glm::mat4 CMatrix4f::ToGlmMat4() const
{
glm::mat4 Out = glm::mat4(1);
memcpy(&Out[0][0], &m[0][0], sizeof(glm::mat4));
return Out;
}
// ************ STATIC ************
CMatrix4f CMatrix4f::FromGlmMat4(const glm::mat4& rkSrc)
{
CMatrix4f Out;
memcpy(&Out[0][0], &rkSrc[0][0], sizeof(CMatrix4f));
return Out;
}
// ************ OPERATORS ************ // ************ OPERATORS ************
inline float* CMatrix4f::operator[](long Index) inline float* CMatrix4f::operator[](long Index)
{ {

View File

@ -1,8 +1,6 @@
#ifndef CMATRIX4_H #ifndef CMATRIX4_H
#define CMATRIX4_H #define CMATRIX4_H
#include <glm.hpp>
class CQuaternion; class CQuaternion;
class CVector3f; class CVector3f;
class CVector4f; class CVector4f;
@ -30,12 +28,6 @@ public:
CMatrix4f Inverse() const; CMatrix4f Inverse() const;
float Determinant() const; float Determinant() const;
// Conversion
glm::mat4 ToGlmMat4() const;
// Static
static CMatrix4f FromGlmMat4(const glm::mat4& rkSrc);
// Operators // Operators
inline float* operator[](long Index); inline float* operator[](long Index);
inline const float* operator[](long Index) const; inline const float* operator[](long Index) const;

View File

@ -323,19 +323,6 @@ CTransform4f CTransform4f::ScaleMatrix(CVector3f Scale)
return Out; return Out;
} }
CTransform4f CTransform4f::FromGlmMat4(const glm::mat4& rkMtx)
{
CTransform4f Out;
for (int iRow = 0; iRow < 3; iRow++)
for (int iCol = 0; iCol < 4; iCol++)
Out[iRow][iCol] = rkMtx[iRow][iCol];
return Out;
}
static CTransform4f FromGlmMat4(const glm::mat4&)
{
}
// ************ CONSTANTS ************ // ************ CONSTANTS ************
const CTransform4f CTransform4f::skIdentity(1.0f, 0.0f, 0.0f, 0.0f, const CTransform4f CTransform4f::skIdentity(1.0f, 0.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f,

View File

@ -4,7 +4,6 @@
#include <FileIO/FileIO.h> #include <FileIO/FileIO.h>
#include <Common/Serialization/IArchive.h> #include <Common/Serialization/IArchive.h>
#include "CMatrix4f.h" #include "CMatrix4f.h"
#include <glm.hpp>
class CVector3f; class CVector3f;
class CVector4f; class CVector4f;
@ -48,7 +47,6 @@ public:
static CTransform4f TranslationMatrix(CVector3f Translation); static CTransform4f TranslationMatrix(CVector3f Translation);
static CTransform4f RotationMatrix(CQuaternion Rotation); static CTransform4f RotationMatrix(CQuaternion Rotation);
static CTransform4f ScaleMatrix(CVector3f Scale); static CTransform4f ScaleMatrix(CVector3f Scale);
static CTransform4f FromGlmMat4(const glm::mat4& rkMtx);
// Operators // Operators
float* operator[](long Index); float* operator[](long Index);

View File

@ -57,7 +57,6 @@ CONFIG (release, debug|release) {
# Include Paths # Include Paths
INCLUDEPATH += $$PWE_MAIN_INCLUDE \ INCLUDEPATH += $$PWE_MAIN_INCLUDE \
$$EXTERNALS_DIR/glm/glm \
$$EXTERNALS_DIR/lzo-2.09/include \ $$EXTERNALS_DIR/lzo-2.09/include \
$$EXTERNALS_DIR/tinyxml2/include \ $$EXTERNALS_DIR/tinyxml2/include \
$$EXTERNALS_DIR/zlib/include $$EXTERNALS_DIR/zlib/include

View File

@ -1,6 +1,5 @@
#include "MathUtil.h" #include "MathUtil.h"
#include "CMatrix4f.h" #include "CMatrix4f.h"
#include <gtc/matrix_transform.hpp>
namespace Math namespace Math
{ {
@ -367,13 +366,22 @@ std::pair<bool,float> RayTriangleIntersection(const CRay& rkRay,
CMatrix4f PerspectiveMatrix(float FOV, float Aspect, float Near, float Far) CMatrix4f PerspectiveMatrix(float FOV, float Aspect, float Near, float Far)
{ {
// todo: don't use glm float TanHalfFOV = tanf( DegreesToRadians(FOV) / 2.f );
return CMatrix4f::FromGlmMat4(glm::perspective(FOV, Aspect, Near, Far)).Transpose(); return CMatrix4f(
1.f / (Aspect * TanHalfFOV), 0, 0, 0,
0, 1.f / TanHalfFOV, 0, 0,
0, 0, -(Far+Near)/(Far-Near), (-2.f*Far*Near)/(Far-Near),
0, 0, -1, 0
);
} }
CMatrix4f OrthographicMatrix(float Left, float Right, float Bottom, float Top, float Near, float Far) CMatrix4f OrthographicMatrix(float Left, float Right, float Bottom, float Top, float Near, float Far)
{ {
return CMatrix4f::FromGlmMat4(glm::ortho(Left, Right, Bottom, Top, Near, Far)).Transpose(); return CMatrix4f (
2/(Right-Left), 0, 0, -(Right+Left)/(Right-Left),
0, 2/(Top-Bottom), 0, -(Top+Bottom)/(Top-Bottom),
0, 0, -2/(Far-Near), -(Far+Near)/(Far-Near),
0, 0, 0, 1);
} }
} // End namespace } // End namespace