diff --git a/src/Core/Core.pro b/src/Core/Core.pro index 0d79c617..06aa4652 100644 --- a/src/Core/Core.pro +++ b/src/Core/Core.pro @@ -74,7 +74,6 @@ LIBS += -L$$EXTERNALS_DIR/glew-2.0.0/lib/Release/x64 -lglew32s \ INCLUDEPATH += $$PWE_MAIN_INCLUDE \ $$EXTERNALS_DIR/assimp/include \ $$EXTERNALS_DIR/glew-2.0.0/include \ - $$EXTERNALS_DIR/glm/glm \ $$EXTERNALS_DIR/lzo-2.09/include \ $$EXTERNALS_DIR/nodtool/include \ $$EXTERNALS_DIR/nodtool/logvisor/include \ diff --git a/src/Core/Render/CCamera.cpp b/src/Core/Render/CCamera.cpp index 048a7f8f..c1ecb4f1 100644 --- a/src/Core/Render/CCamera.cpp +++ b/src/Core/Render/CCamera.cpp @@ -2,7 +2,6 @@ #include "CGraphics.h" #include #include -#include CCamera::CCamera() : mMode(eFreeCamera) @@ -243,15 +242,17 @@ void CCamera::UpdateTransform() const void CCamera::UpdateView() const { - // todo: don't use glm UpdateTransform(); if (mViewDirty) { - glm::vec3 glmpos(mPosition.X, mPosition.Y, mPosition.Z); - glm::vec3 glmdir(mDirection.X, mDirection.Y, mDirection.Z); - glm::vec3 glmup(mUpVector.X, mUpVector.Y, mUpVector.Z); - mViewMatrix = CMatrix4f::FromGlmMat4(glm::lookAt(glmpos, glmpos + glmdir, glmup)).Transpose(); + mViewMatrix = CMatrix4f( + mRightVector.X, mRightVector.Y, mRightVector.Z, -mRightVector.Dot(mPosition), + mUpVector.X, mUpVector.Y, mUpVector.Z, -mUpVector.Dot(mPosition), + -mDirection.X, -mDirection.Y, -mDirection.Z, mDirection.Dot(mPosition), + 0.f, 0.f, 0.f, 1.f + ); + mViewDirty = false; } } diff --git a/src/Core/Render/CRenderer.cpp b/src/Core/Render/CRenderer.cpp index a3ba27b5..bcb4a696 100644 --- a/src/Core/Render/CRenderer.cpp +++ b/src/Core/Render/CRenderer.cpp @@ -11,7 +11,6 @@ #include #include #include -#include // ************ STATIC MEMBER INITIALIZATION ************ u32 CRenderer::sNumRenderers = 0; diff --git a/src/Core/Resource/CMaterialPass.cpp b/src/Core/Resource/CMaterialPass.cpp index 0a521119..7ea61bbf 100644 --- a/src/Core/Resource/CMaterialPass.cpp +++ b/src/Core/Resource/CMaterialPass.cpp @@ -101,9 +101,7 @@ void CMaterialPass::SetAnimCurrent(FRenderOptions Options, u32 PassIndex) case eInverseMV: // Mode 0 case eSimpleMode: // Mode 10 - maybe not correct? { - glm::mat4 InvMV = glm::inverse(glm::transpose(ViewMtx.ToGlmMat4()) * glm::transpose(ModelMtx.ToGlmMat4())); - InvMV[0][3] = InvMV[1][3] = InvMV[2][3] = 0.f; - TexMtx = CMatrix4f::FromGlmMat4(InvMV); + TexMtx = (ModelMtx * ViewMtx).Transpose().Inverse(); PostMtx = CMatrix4f(0.5f, 0.0f, 0.0f, 0.5f, 0.0f, 0.5f, 0.0f, 0.5f, 0.0f, 0.0f, 0.0f, 1.0f, @@ -113,8 +111,7 @@ void CMaterialPass::SetAnimCurrent(FRenderOptions Options, u32 PassIndex) case eInverseMVTranslated: // Mode 1 { - glm::mat4 InvMV = glm::inverse(glm::transpose(ViewMtx.ToGlmMat4()) * glm::transpose(ModelMtx.ToGlmMat4())); - TexMtx = CMatrix4f::FromGlmMat4(InvMV); + TexMtx = (ModelMtx * ViewMtx).Transpose().Inverse(); PostMtx = CMatrix4f(0.5f, 0.0f, 0.0f, 0.5f, 0.0f, 0.5f, 0.0f, 0.5f, 0.0f, 0.0f, 0.0f, 1.0f, @@ -166,7 +163,7 @@ void CMaterialPass::SetAnimCurrent(FRenderOptions Options, u32 PassIndex) case eModelMatrix: // Mode 6 { // 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, 0.0f, 0.5f, 0.0f, TexMtx[1][3] * 0.50000001f, 0.0f, 0.0f, 0.0f, 1.0f, @@ -180,9 +177,8 @@ void CMaterialPass::SetAnimCurrent(FRenderOptions Options, u32 PassIndex) { CMatrix4f View = CGraphics::sMVPBlock.ViewMatrix; - glm::mat4 Mtx = glm::inverse(glm::transpose(ViewMtx.ToGlmMat4()) * glm::transpose(ModelMtx.ToGlmMat4())); - Mtx[0][3] = Mtx[1][3] = Mtx[2][3] = 0.f; - TexMtx = CMatrix4f::FromGlmMat4(Mtx); + TexMtx = (ModelMtx * ViewMtx).Transpose().Inverse(); + TexMtx[0][3] = TexMtx[1][3] = TexMtx[2][3] = 0.f; float XY = (View[3][0] + View[3][1]) * 0.025f * mAnimParams[1]; XY = (XY - (int) XY); diff --git a/src/Editor/Editor.pro b/src/Editor/Editor.pro index dea5cb07..8acf7ccf 100644 --- a/src/Editor/Editor.pro +++ b/src/Editor/Editor.pro @@ -86,7 +86,6 @@ LIBS += -L$$EXTERNALS_DIR/glew-2.0.0/lib/Release/x64 -lglew32s \ INCLUDEPATH += $$PWE_MAIN_INCLUDE \ $$EXTERNALS_DIR/assimp/include \ $$EXTERNALS_DIR/glew-2.0.0/include \ - $$EXTERNALS_DIR/glm/glm \ $$EXTERNALS_DIR/lzo-2.09/include \ $$EXTERNALS_DIR/nodtool/include \ $$EXTERNALS_DIR/nodtool/logvisor/include \ diff --git a/src/Math/CMatrix4f.cpp b/src/Math/CMatrix4f.cpp index 7592637b..a819764d 100644 --- a/src/Math/CMatrix4f.cpp +++ b/src/Math/CMatrix4f.cpp @@ -138,21 +138,6 @@ float CMatrix4f::Determinant() const 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 ************ inline float* CMatrix4f::operator[](long Index) { diff --git a/src/Math/CMatrix4f.h b/src/Math/CMatrix4f.h index 12b4fae1..e31220a4 100644 --- a/src/Math/CMatrix4f.h +++ b/src/Math/CMatrix4f.h @@ -1,8 +1,6 @@ #ifndef CMATRIX4_H #define CMATRIX4_H -#include - class CQuaternion; class CVector3f; class CVector4f; @@ -30,12 +28,6 @@ public: CMatrix4f Inverse() const; float Determinant() const; - // Conversion - glm::mat4 ToGlmMat4() const; - - // Static - static CMatrix4f FromGlmMat4(const glm::mat4& rkSrc); - // Operators inline float* operator[](long Index); inline const float* operator[](long Index) const; diff --git a/src/Math/CTransform4f.cpp b/src/Math/CTransform4f.cpp index fc95af9e..dc70a5b0 100644 --- a/src/Math/CTransform4f.cpp +++ b/src/Math/CTransform4f.cpp @@ -323,19 +323,6 @@ CTransform4f CTransform4f::ScaleMatrix(CVector3f Scale) 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 ************ const CTransform4f CTransform4f::skIdentity(1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, diff --git a/src/Math/CTransform4f.h b/src/Math/CTransform4f.h index 04574d38..d006abba 100644 --- a/src/Math/CTransform4f.h +++ b/src/Math/CTransform4f.h @@ -4,7 +4,6 @@ #include #include #include "CMatrix4f.h" -#include class CVector3f; class CVector4f; @@ -48,7 +47,6 @@ public: static CTransform4f TranslationMatrix(CVector3f Translation); static CTransform4f RotationMatrix(CQuaternion Rotation); static CTransform4f ScaleMatrix(CVector3f Scale); - static CTransform4f FromGlmMat4(const glm::mat4& rkMtx); // Operators float* operator[](long Index); diff --git a/src/Math/Math.pro b/src/Math/Math.pro index d7308109..a942ff26 100644 --- a/src/Math/Math.pro +++ b/src/Math/Math.pro @@ -57,7 +57,6 @@ CONFIG (release, debug|release) { # Include Paths INCLUDEPATH += $$PWE_MAIN_INCLUDE \ - $$EXTERNALS_DIR/glm/glm \ $$EXTERNALS_DIR/lzo-2.09/include \ $$EXTERNALS_DIR/tinyxml2/include \ $$EXTERNALS_DIR/zlib/include diff --git a/src/Math/MathUtil.cpp b/src/Math/MathUtil.cpp index 3fedb876..9f3495c5 100644 --- a/src/Math/MathUtil.cpp +++ b/src/Math/MathUtil.cpp @@ -1,6 +1,5 @@ #include "MathUtil.h" #include "CMatrix4f.h" -#include namespace Math { @@ -367,13 +366,22 @@ std::pair RayTriangleIntersection(const CRay& rkRay, CMatrix4f PerspectiveMatrix(float FOV, float Aspect, float Near, float Far) { - // todo: don't use glm - return CMatrix4f::FromGlmMat4(glm::perspective(FOV, Aspect, Near, Far)).Transpose(); + float TanHalfFOV = tanf( DegreesToRadians(FOV) / 2.f ); + 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) { - 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