From b46f4554e8eada050b55ac560bc494933b5197b8 Mon Sep 17 00:00:00 2001 From: Dario Manesku Date: Sun, 27 Mar 2016 03:34:09 +0200 Subject: [PATCH 1/3] Added enums for Handness and NearFar. --- include/bx/fpumath.h | 84 +++++++++++++++++++++++++++----------------- 1 file changed, 51 insertions(+), 33 deletions(-) diff --git a/include/bx/fpumath.h b/include/bx/fpumath.h index 9bd4e6c..5fa3095 100644 --- a/include/bx/fpumath.h +++ b/include/bx/fpumath.h @@ -631,7 +631,16 @@ namespace bx mtxLookAtLh(_result, _eye, _at, _up); } - template + struct Handness + { + enum Enum + { + RightHanded = false, + LeftHanded = true, + }; + }; + + template inline void mtxProjXYWH(float* _result, float _x, float _y, float _width, float _height, float _near, float _far, bool _oglNdc = false) { const float diff = _far-_near; @@ -641,14 +650,14 @@ namespace bx memset(_result, 0, sizeof(float)*16); _result[ 0] = _width; _result[ 5] = _height; - _result[ 8] = LeftHanded ? -_x : _x; - _result[ 9] = LeftHanded ? -_y : _y; - _result[10] = LeftHanded ? aa : -aa; - _result[11] = LeftHanded ? 1.0f : -1.0f; + _result[ 8] = (Handness::LeftHanded == HandnessT) ? -_x : _x; + _result[ 9] = (Handness::LeftHanded == HandnessT) ? -_y : _y; + _result[10] = (Handness::LeftHanded == HandnessT) ? aa : -aa; + _result[11] = (Handness::LeftHanded == HandnessT) ? 1.0f : -1.0f; _result[14] = -bb; } - template + template inline void mtxProj_impl(float* _result, float _ut, float _dt, float _lt, float _rt, float _near, float _far, bool _oglNdc = false) { const float invDiffRl = 1.0f/(_rt - _lt); @@ -657,21 +666,21 @@ namespace bx const float height = 2.0f*_near * invDiffUd; const float xx = (_rt + _lt) * invDiffRl; const float yy = (_ut + _dt) * invDiffUd; - mtxProjXYWH(_result, xx, yy, width, height, _near, _far, _oglNdc); + mtxProjXYWH(_result, xx, yy, width, height, _near, _far, _oglNdc); } - template + template inline void mtxProj_impl(float* _result, const float _fov[4], float _near, float _far, bool _oglNdc = false) { - mtxProj_impl(_result, _fov[0], _fov[1], _fov[2], _fov[3], _near, _far, _oglNdc); + mtxProj_impl(_result, _fov[0], _fov[1], _fov[2], _fov[3], _near, _far, _oglNdc); } - template + template inline void mtxProj_impl(float* _result, float _fovy, float _aspect, float _near, float _far, bool _oglNdc = false) { const float height = 1.0f/tanf(toRad(_fovy)*0.5f); const float width = height * 1.0f/_aspect; - mtxProjXYWH(_result, 0.0f, 0.0f, width, height, _near, _far, _oglNdc); + mtxProjXYWH(_result, 0.0f, 0.0f, width, height, _near, _far, _oglNdc); } inline void mtxProj(float* _result, const float _fov[4], float _near, float _far, bool _oglNdc = false) @@ -704,12 +713,21 @@ namespace bx mtxProj_impl(_result, _fovy, _aspect, _near, _far, _oglNdc); } - template + struct NearFar + { + enum Enum + { + Default = false, + Reverse = true, + }; + }; + + template inline void mtxProjInfXYWH(float* _result, float _x, float _y, float _width, float _height, float _near, bool _oglNdc = false) { float aa; float bb; - if (Reverse) + if (NearFar::Reverse == NearFarT) { aa = _oglNdc ? -1.0f : 0.0f; bb = _oglNdc ? -2.0f*_near : -_near; @@ -723,14 +741,14 @@ namespace bx memset(_result, 0, sizeof(float)*16); _result[ 0] = _width; _result[ 5] = _height; - _result[ 8] = LeftHanded ? -_x : _x; - _result[ 9] = LeftHanded ? -_y : _y; - _result[10] = LeftHanded ? aa : -aa; - _result[11] = LeftHanded ? 1.0f : -1.0f; + _result[ 8] = (Handness::LeftHanded == HandnessT) ? -_x : _x; + _result[ 9] = (Handness::LeftHanded == HandnessT) ? -_y : _y; + _result[10] = (Handness::LeftHanded == HandnessT) ? aa : -aa; + _result[11] = (Handness::LeftHanded == HandnessT) ? 1.0f : -1.0f; _result[14] = -bb; } - template + template inline void mtxProjInf_impl(float* _result, float _ut, float _dt, float _lt, float _rt, float _near, bool _oglNdc = false) { const float invDiffRl = 1.0f/(_rt - _lt); @@ -739,30 +757,30 @@ namespace bx const float height = 2.0f*_near * invDiffUd; const float xx = (_rt + _lt) * invDiffRl; const float yy = (_ut + _dt) * invDiffUd; - mtxProjInfXYWH(_result, xx, yy, width, height, _near, _oglNdc); + mtxProjInfXYWH(_result, xx, yy, width, height, _near, _oglNdc); } - template + template inline void mtxProjInf_impl(float* _result, const float _fov[4], float _near, bool _oglNdc = false) { - mtxProjInf_impl(_result, _fov[0], _fov[1], _fov[2], _fov[3], _near, _oglNdc); + mtxProjInf_impl(_result, _fov[0], _fov[1], _fov[2], _fov[3], _near, _oglNdc); } - template + template inline void mtxProjInf_impl(float* _result, float _fovy, float _aspect, float _near, bool _oglNdc = false) { const float height = 1.0f/tanf(toRad(_fovy)*0.5f); const float width = height * 1.0f/_aspect; - mtxProjInfXYWH(_result, 0.0f, 0.0f, width, height, _near, _oglNdc); + mtxProjInfXYWH(_result, 0.0f, 0.0f, width, height, _near, _oglNdc); } - #define mtxProjInf mtxProjInf_impl - #define mtxProjInfLh mtxProjInf_impl - #define mtxProjInfRh mtxProjInf_impl - #define mtxProjRevInfLh mtxProjInf_impl - #define mtxProjRevInfRh mtxProjInf_impl + #define mtxProjInf mtxProjInf_impl + #define mtxProjInfLh mtxProjInf_impl + #define mtxProjInfRh mtxProjInf_impl + #define mtxProjRevInfLh mtxProjInf_impl + #define mtxProjRevInfRh mtxProjInf_impl - template + template inline void mtxOrtho_impl(float* _result, float _left, float _right, float _bottom, float _top, float _near, float _far, float _offset = 0.0f, bool _oglNdc = false) { const float aa = 2.0f/(_right - _left); @@ -775,16 +793,16 @@ namespace bx memset(_result, 0, sizeof(float)*16); _result[ 0] = aa; _result[ 5] = bb; - _result[10] = LeftHanded ? cc : -cc; + _result[10] = (Handness::LeftHanded == HandnessT) ? cc : -cc; _result[12] = dd + _offset; _result[13] = ee; _result[14] = ff; _result[15] = 1.0f; } - #define mtxOrtho mtxOrtho_impl - #define mtxOrthoLh mtxOrtho_impl - #define mtxOrthoRh mtxOrtho_impl + #define mtxOrtho mtxOrtho_impl + #define mtxOrthoLh mtxOrtho_impl + #define mtxOrthoRh mtxOrtho_impl inline void mtxRotateX(float* _result, float _ax) { From b264dec65109b66b8e878bd52ebfbe572a2e3075 Mon Sep 17 00:00:00 2001 From: Dario Manesku Date: Sun, 27 Mar 2016 03:42:08 +0200 Subject: [PATCH 2/3] Cleanup. --- include/bx/fpumath.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/include/bx/fpumath.h b/include/bx/fpumath.h index 5fa3095..356b02b 100644 --- a/include/bx/fpumath.h +++ b/include/bx/fpumath.h @@ -650,10 +650,10 @@ namespace bx memset(_result, 0, sizeof(float)*16); _result[ 0] = _width; _result[ 5] = _height; - _result[ 8] = (Handness::LeftHanded == HandnessT) ? -_x : _x; - _result[ 9] = (Handness::LeftHanded == HandnessT) ? -_y : _y; - _result[10] = (Handness::LeftHanded == HandnessT) ? aa : -aa; - _result[11] = (Handness::LeftHanded == HandnessT) ? 1.0f : -1.0f; + _result[ 8] = (Handness::RightHanded == HandnessT) ? _x : -_x; + _result[ 9] = (Handness::RightHanded == HandnessT) ? _y : -_y; + _result[10] = (Handness::RightHanded == HandnessT) ? -aa : aa; + _result[11] = (Handness::RightHanded == HandnessT) ? -1.0f : 1.0f; _result[14] = -bb; } @@ -741,10 +741,10 @@ namespace bx memset(_result, 0, sizeof(float)*16); _result[ 0] = _width; _result[ 5] = _height; - _result[ 8] = (Handness::LeftHanded == HandnessT) ? -_x : _x; - _result[ 9] = (Handness::LeftHanded == HandnessT) ? -_y : _y; - _result[10] = (Handness::LeftHanded == HandnessT) ? aa : -aa; - _result[11] = (Handness::LeftHanded == HandnessT) ? 1.0f : -1.0f; + _result[ 8] = (Handness::RightHanded == HandnessT) ? _x : -_x; + _result[ 9] = (Handness::RightHanded == HandnessT) ? _y : -_y; + _result[10] = (Handness::RightHanded == HandnessT) ? -aa : aa; + _result[11] = (Handness::RightHanded == HandnessT) ? -1.0f : 1.0f; _result[14] = -bb; } @@ -793,7 +793,7 @@ namespace bx memset(_result, 0, sizeof(float)*16); _result[ 0] = aa; _result[ 5] = bb; - _result[10] = (Handness::LeftHanded == HandnessT) ? cc : -cc; + _result[10] = (Handness::RightHanded == HandnessT) ? -cc : cc; _result[12] = dd + _offset; _result[13] = ee; _result[14] = ff; From f36c6d42c8c2f16a090079f4cf7b59f48c2c3834 Mon Sep 17 00:00:00 2001 From: Dario Manesku Date: Sun, 27 Mar 2016 03:44:54 +0200 Subject: [PATCH 3/3] Cleanup. --- include/bx/fpumath.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/include/bx/fpumath.h b/include/bx/fpumath.h index 356b02b..e88ad6a 100644 --- a/include/bx/fpumath.h +++ b/include/bx/fpumath.h @@ -685,32 +685,32 @@ namespace bx inline void mtxProj(float* _result, const float _fov[4], float _near, float _far, bool _oglNdc = false) { - mtxProj_impl(_result, _fov, _near, _far, _oglNdc); + mtxProj_impl(_result, _fov, _near, _far, _oglNdc); } inline void mtxProjLh(float* _result, const float _fov[4], float _near, float _far, bool _oglNdc = false) { - mtxProj_impl(_result, _fov, _near, _far, _oglNdc); + mtxProj_impl(_result, _fov, _near, _far, _oglNdc); } inline void mtxProjRh(float* _result, const float _fov[4], float _near, float _far, bool _oglNdc = false) { - mtxProj_impl(_result, _fov, _near, _far, _oglNdc); + mtxProj_impl(_result, _fov, _near, _far, _oglNdc); } inline void mtxProj(float* _result, float _fovy, float _aspect, float _near, float _far, bool _oglNdc = false) { - mtxProj_impl(_result, _fovy, _aspect, _near, _far, _oglNdc); + mtxProj_impl(_result, _fovy, _aspect, _near, _far, _oglNdc); } inline void mtxProjLh(float* _result, float _fovy, float _aspect, float _near, float _far, bool _oglNdc = false) { - mtxProj_impl(_result, _fovy, _aspect, _near, _far, _oglNdc); + mtxProj_impl(_result, _fovy, _aspect, _near, _far, _oglNdc); } inline void mtxProjRh(float* _result, float _fovy, float _aspect, float _near, float _far, bool _oglNdc = false) { - mtxProj_impl(_result, _fovy, _aspect, _near, _far, _oglNdc); + mtxProj_impl(_result, _fovy, _aspect, _near, _far, _oglNdc); } struct NearFar