From ce8b16aacf2bade21a6d0a03f21d1deff78bc6e8 Mon Sep 17 00:00:00 2001 From: Tomas Jakobsson Date: Thu, 8 Aug 2019 21:49:48 +0200 Subject: [PATCH] Add Transform4x4f::orthoProjection --- es-core/src/math/Transform4x4f.cpp | 39 ++++++++++++++++++++++++++++++ es-core/src/math/Transform4x4f.h | 17 +++++++------ 2 files changed, 48 insertions(+), 8 deletions(-) diff --git a/es-core/src/math/Transform4x4f.cpp b/es-core/src/math/Transform4x4f.cpp index 4944c0845..f8ed5621b 100644 --- a/es-core/src/math/Transform4x4f.cpp +++ b/es-core/src/math/Transform4x4f.cpp @@ -49,6 +49,45 @@ const Vector3f Transform4x4f::operator*(const Vector3f& _other) const } // operator* +Transform4x4f& Transform4x4f::orthoProjection(float _left, float _right, float _bottom, float _top, float _near, float _far) +{ + float* tm = (float*)this; + const float o[6] = { 2 / (_right - _left), + 2 / (_top - _bottom), + -2 / (_far - _near), + -(_right + _left) / (_right - _left), + -(_top + _bottom) / (_top - _bottom), + -(_far + _near) / (_far - _near) }; + const float temp[12] = { tm[ 0] * o[0], + tm[ 1] * o[0], + tm[ 2] * o[0], + tm[ 4] * o[1], + tm[ 5] * o[1], + tm[ 6] * o[1], + tm[ 8] * o[2], + tm[ 9] * o[2], + tm[10] * o[2], + tm[ 0] * o[3] + tm[ 4] * o[4] + tm[ 8] * o[5] + tm[12], + tm[ 1] * o[3] + tm[ 5] * o[4] + tm[ 9] * o[5] + tm[13], + tm[ 2] * o[3] + tm[ 6] * o[4] + tm[10] * o[5] + tm[14] }; + + tm[ 0] = temp[ 0]; + tm[ 1] = temp[ 1]; + tm[ 2] = temp[ 2]; + tm[ 4] = temp[ 3]; + tm[ 5] = temp[ 4]; + tm[ 6] = temp[ 5]; + tm[ 8] = temp[ 6]; + tm[ 9] = temp[ 7]; + tm[10] = temp[ 8]; + tm[12] = temp[ 9]; + tm[13] = temp[10]; + tm[14] = temp[11]; + + return *this; + +} // orthoProjection + Transform4x4f& Transform4x4f::invert(const Transform4x4f& _other) { float* tm = (float*)this; diff --git a/es-core/src/math/Transform4x4f.h b/es-core/src/math/Transform4x4f.h index b1646a692..0f70a94ba 100644 --- a/es-core/src/math/Transform4x4f.h +++ b/es-core/src/math/Transform4x4f.h @@ -25,14 +25,15 @@ public: inline const Vector4f& r2() const { return mR2; } inline const Vector4f& r3() const { return mR3; } - Transform4x4f& invert (const Transform4x4f& _other); - Transform4x4f& scale (const Vector3f& _scale); - Transform4x4f& rotate (const float _angle, const Vector3f& _axis); - Transform4x4f& rotateX (const float _angle); - Transform4x4f& rotateY (const float _angle); - Transform4x4f& rotateZ (const float _angle); - Transform4x4f& translate(const Vector3f& _translation); - Transform4x4f& round (); + Transform4x4f& orthoProjection(float _left, float _right, float _bottom, float _top, float _near, float _far); + Transform4x4f& invert (const Transform4x4f& _other); + Transform4x4f& scale (const Vector3f& _scale); + Transform4x4f& rotate (const float _angle, const Vector3f& _axis); + Transform4x4f& rotateX (const float _angle); + Transform4x4f& rotateY (const float _angle); + Transform4x4f& rotateZ (const float _angle); + Transform4x4f& translate (const Vector3f& _translation); + Transform4x4f& round (); inline Vector3f& translation() { return mR3.v3(); } inline const Vector3f& translation() const { return mR3.v3(); }