From f419bd2c4fa2bf8df5df29100eae6fbca1d2578a Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Sun, 25 Mar 2018 20:35:37 -0700 Subject: Added functions for Ortho projection matrix --- Common/interface/BasicMath.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'Common/interface') diff --git a/Common/interface/BasicMath.h b/Common/interface/BasicMath.h index eae2dc8a..de42c49e 100644 --- a/Common/interface/BasicMath.h +++ b/Common/interface/BasicMath.h @@ -1180,6 +1180,22 @@ inline float4x4 Projection(float fov, float aspectRatio, float zNear, float zFar return mOut; } +inline float4x4 OrthoOffCenter(float left, float right, float bottom, float top, float zNear, float zFar, bool bIsDirectX) // Left-handed ortho projection +{ + float _22 = (bIsDirectX ? 1.f : 2.f) / (zFar - zNear); + float _32 = (bIsDirectX ? zNear : zNear + zFar) / (zNear - zFar); + return float4x4 ( + 2.f / (right - left), 0.f, 0.f, 0.f, + 0.f, 2.f/(top - bottom), 0.f, 0.f, + 0.f, 0.f, _22, 0.f, + (left + right)/(left - right), (top + bottom) / (bottom - top), _32, 1.f + ); +} + +inline float4x4 Ortho(float width, float height, float zNear, float zFar, bool bIsDirectX) // Left-handed ortho projection +{ + return OrthoOffCenter(-width * 0.5f, +width * 0.5f, -height * 0.5f, +height * 0.5f, zNear, zFar, bIsDirectX); +} struct Quaternion { -- cgit v1.2.3