From e054000b0ae2d4a834d859118cfffa47b9397b12 Mon Sep 17 00:00:00 2001 From: Dario Manesku Date: Fri, 26 Feb 2016 14:34:59 +0100 Subject: [PATCH 1/4] Fixed *Rh() and *Lh() mtx functions. --- include/bx/fpumath.h | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/include/bx/fpumath.h b/include/bx/fpumath.h index b45bde0..2f41d45 100644 --- a/include/bx/fpumath.h +++ b/include/bx/fpumath.h @@ -607,7 +607,7 @@ namespace bx inline void mtxLookAtLh(float* __restrict _result, const float* __restrict _eye, const float* __restrict _at, const float* __restrict _up = NULL) { float tmp[4]; - vec3Sub(tmp, _eye, _at); + vec3Sub(tmp, _at, _eye); float view[4]; vec3Norm(view, tmp); @@ -618,7 +618,7 @@ namespace bx inline void mtxLookAtRh(float* __restrict _result, const float* __restrict _eye, const float* __restrict _at, const float* __restrict _up = NULL) { float tmp[4]; - vec3Sub(tmp, _at, _eye); + vec3Sub(tmp, _eye, _at); float view[4]; vec3Norm(view, tmp); @@ -640,10 +640,10 @@ namespace bx memset(_result, 0, sizeof(float)*16); _result[ 0] = _width; _result[ 5] = _height; - _result[ 8] = -_x; - _result[ 9] = _y; - _result[10] = aa; - _result[11] = 1.0f; + _result[ 8] = _x; + _result[ 9] = _y; + _result[10] = -aa; + _result[11] = -1.0f; _result[14] = -bb; } @@ -677,10 +677,10 @@ namespace bx memset(_result, 0, sizeof(float)*16); _result[ 0] = _width; _result[ 5] = _height; - _result[ 8] = _x; + _result[ 8] = -_x; _result[ 9] = -_y; - _result[10] = -aa; - _result[11] = -1.0f; + _result[10] = aa; + _result[11] = 1.0f; _result[14] = -bb; } @@ -732,7 +732,7 @@ namespace bx memset(_result, 0, sizeof(float)*16); _result[ 0] = aa; _result[ 5] = bb; - _result[10] = -cc; + _result[10] = cc; _result[12] = dd + _offset; _result[13] = ee; _result[14] = ff; @@ -751,7 +751,7 @@ namespace bx memset(_result, 0, sizeof(float)*16); _result[ 0] = aa; _result[ 5] = bb; - _result[10] = cc; + _result[10] = -cc; _result[12] = dd + _offset; _result[13] = ee; _result[14] = ff; From d599a8419fa973cc71af70c112874290210ef0e3 Mon Sep 17 00:00:00 2001 From: Dario Manesku Date: Fri, 26 Feb 2016 14:44:36 +0100 Subject: [PATCH 2/4] Use *Lh() matrices as default to match winding in bgfx examples. --- include/bx/fpumath.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/bx/fpumath.h b/include/bx/fpumath.h index 2f41d45..f2762f5 100644 --- a/include/bx/fpumath.h +++ b/include/bx/fpumath.h @@ -628,7 +628,7 @@ namespace bx inline void mtxLookAt(float* __restrict _result, const float* __restrict _eye, const float* __restrict _at, const float* __restrict _up = NULL) { - mtxLookAtRh(_result, _eye, _at, _up); + mtxLookAtLh(_result, _eye, _at, _up); } inline void mtxProjRhXYWH(float* _result, float _x, float _y, float _width, float _height, float _near, float _far, bool _oglNdc = false) @@ -707,17 +707,17 @@ namespace bx inline void mtxProj(float* _result, float _ut, float _dt, float _lt, float _rt, float _near, float _far, bool _oglNdc = false) { - mtxProjRh(_result, _ut, _dt, _lt, _rt, _near, _far, _oglNdc); + mtxProjLh(_result, _ut, _dt, _lt, _rt, _near, _far, _oglNdc); } inline void mtxProj(float* _result, const float _fov[4], float _near, float _far, bool _oglNdc = false) { - mtxProjRh(_result, _fov, _near, _far, _oglNdc); + mtxProjLh(_result, _fov, _near, _far, _oglNdc); } inline void mtxProj(float* _result, float _fovy, float _aspect, float _near, float _far, bool _oglNdc = false) { - mtxProjRh(_result, _fovy, _aspect, _near, _far, _oglNdc); + mtxProjLh(_result, _fovy, _aspect, _near, _far, _oglNdc); } inline void mtxOrthoLh(float* _result, float _left, float _right, float _bottom, float _top, float _near, float _far, float _offset = 0.0f, bool _oglNdc = false) From 4b2b96641b4008582c93f804938b88b5b6de59ea Mon Sep 17 00:00:00 2001 From: Dario Manesku Date: Fri, 26 Feb 2016 16:21:17 +0100 Subject: [PATCH 3/4] Fixing off center proj mtx. --- include/bx/fpumath.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/include/bx/fpumath.h b/include/bx/fpumath.h index f2762f5..76465f5 100644 --- a/include/bx/fpumath.h +++ b/include/bx/fpumath.h @@ -649,10 +649,10 @@ namespace bx inline void mtxProjRh(float* _result, float _ut, float _dt, float _lt, float _rt, float _near, float _far, bool _oglNdc = false) { - const float width = 2.0f / (_lt + _rt); - const float height = 2.0f / (_ut + _dt); - const float xx = (_lt - _rt) * width * 0.5f; - const float yy = (_ut - _dt) * height * 0.5f; + const float width = 2.0f / (_rt - _lt); + const float height = 2.0f / (_ut - _dt); + const float xx = (_lt + _rt) * width * 0.5f; + const float yy = (_ut + _dt) * height * 0.5f; mtxProjRhXYWH(_result, xx, yy, width, height, _near, _far, _oglNdc); } @@ -686,10 +686,10 @@ namespace bx inline void mtxProjLh(float* _result, float _ut, float _dt, float _lt, float _rt, float _near, float _far, bool _oglNdc = false) { - const float width = 2.0f / (_lt + _rt); - const float height = 2.0f / (_ut + _dt); - const float xx = (_lt - _rt) * width * 0.5f; - const float yy = (_ut - _dt) * height * 0.5f; + const float width = 2.0f / (_rt - _lt); + const float height = 2.0f / (_ut - _dt); + const float xx = (_lt + _rt) * width * 0.5f; + const float yy = (_ut + _dt) * height * 0.5f; mtxProjLhXYWH(_result, xx, yy, width, height, _near, _far, _oglNdc); } From 3c3e8deb17fe7320425aefff715c610f4c303a98 Mon Sep 17 00:00:00 2001 From: Dario Manesku Date: Fri, 26 Feb 2016 16:46:33 +0100 Subject: [PATCH 4/4] Amend for the previous commit. --- include/bx/fpumath.h | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/include/bx/fpumath.h b/include/bx/fpumath.h index 76465f5..ea2d13d 100644 --- a/include/bx/fpumath.h +++ b/include/bx/fpumath.h @@ -649,10 +649,12 @@ namespace bx inline void mtxProjRh(float* _result, float _ut, float _dt, float _lt, float _rt, float _near, float _far, bool _oglNdc = false) { - const float width = 2.0f / (_rt - _lt); - const float height = 2.0f / (_ut - _dt); - const float xx = (_lt + _rt) * width * 0.5f; - const float yy = (_ut + _dt) * height * 0.5f; + const float invDiffRl = 1.0f/(_rt - _lt); + const float invDiffUd = 1.0f/(_ut - _dt); + const float width = 2.0f*_near * invDiffRl; + const float height = 2.0f*_near * invDiffUd; + const float xx = (_rt + _lt) * invDiffRl; + const float yy = (_ut + _dt) * invDiffUd; mtxProjRhXYWH(_result, xx, yy, width, height, _near, _far, _oglNdc); } @@ -686,10 +688,12 @@ namespace bx inline void mtxProjLh(float* _result, float _ut, float _dt, float _lt, float _rt, float _near, float _far, bool _oglNdc = false) { - const float width = 2.0f / (_rt - _lt); - const float height = 2.0f / (_ut - _dt); - const float xx = (_lt + _rt) * width * 0.5f; - const float yy = (_ut + _dt) * height * 0.5f; + const float invDiffRl = 1.0f/(_rt - _lt); + const float invDiffUd = 1.0f/(_ut - _dt); + const float width = 2.0f*_near * invDiffRl; + const float height = 2.0f*_near * invDiffUd; + const float xx = (_rt + _lt) * invDiffRl; + const float yy = (_ut + _dt) * invDiffUd; mtxProjLhXYWH(_result, xx, yy, width, height, _near, _far, _oglNdc); }