From e7eb912eaa30adb162938334a5313a9a94e92ecb Mon Sep 17 00:00:00 2001 From: Ian Curtis Date: Tue, 22 Mar 2016 13:47:28 +0000 Subject: [PATCH] add maths functions --- Src/Graphics/New3D/New3D.cpp | 15 +++++++++++++++ Src/Graphics/New3D/New3D.h | 1 + 2 files changed, 16 insertions(+) diff --git a/Src/Graphics/New3D/New3D.cpp b/Src/Graphics/New3D/New3D.cpp index 78fe11f..50aa49c 100644 --- a/Src/Graphics/New3D/New3D.cpp +++ b/Src/Graphics/New3D/New3D.cpp @@ -1017,4 +1017,19 @@ bool CNew3D::ClockWiseWinding() } } +float CNew3D::Determinant3x3(const float m[16]) { + + /* + | A B C | + M = | D E F | + | G H I | + + then the determinant is calculated as follows: + + det M = A * (EI - HF) - B * (DI - GF) + C * (DH - GE) + */ + + return m[0] * ((m[5] * m[10]) - (m[6] * m[9])) - m[4] * ((m[1] * m[10]) - (m[2] * m[9])) + m[8] * ((m[1] * m[6]) - (m[2] * m[5])); +} + } // New3D diff --git a/Src/Graphics/New3D/New3D.h b/Src/Graphics/New3D/New3D.h index ae4fea4..68100f5 100644 --- a/Src/Graphics/New3D/New3D.h +++ b/Src/Graphics/New3D/New3D.h @@ -172,6 +172,7 @@ private: enum class AlphaType{ none, poly, texture }; void RenderScene(int priority, bool alpha); bool ClockWiseWinding(); // calculate winding with current matrix + float Determinant3x3(const float m[16]); /* * Data