summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/bx/include/bx/fpumath.h
diff options
context:
space:
mode:
Diffstat (limited to '3rdparty/bx/include/bx/fpumath.h')
-rw-r--r--3rdparty/bx/include/bx/fpumath.h72
1 files changed, 50 insertions, 22 deletions
diff --git a/3rdparty/bx/include/bx/fpumath.h b/3rdparty/bx/include/bx/fpumath.h
index be125aa69eb..0dd274feb24 100644
--- a/3rdparty/bx/include/bx/fpumath.h
+++ b/3rdparty/bx/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);
@@ -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)
@@ -640,19 +640,21 @@ 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;
}
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 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);
}
@@ -677,19 +679,21 @@ 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;
}
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 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);
}
@@ -707,20 +711,20 @@ 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 mtxOrtho(float* _result, float _left, float _right, float _bottom, float _top, float _near, float _far, float _offset = 0.0f, bool _oglNdc = false)
+ inline void mtxOrthoLh(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);
const float bb = 2.0f/(_top - _bottom);
@@ -739,6 +743,30 @@ namespace bx
_result[15] = 1.0f;
}
+ inline void mtxOrthoRh(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);
+ const float bb = 2.0f/(_top - _bottom);
+ const float cc = (_oglNdc ? 2.0f : 1.0f) / (_far - _near);
+ const float dd = (_left + _right)/(_left - _right);
+ const float ee = (_top + _bottom)/(_bottom - _top);
+ const float ff = _oglNdc ? (_near + _far)/(_near - _far) : _near/(_near - _far);
+
+ memset(_result, 0, sizeof(float)*16);
+ _result[ 0] = aa;
+ _result[ 5] = bb;
+ _result[10] = -cc;
+ _result[12] = dd + _offset;
+ _result[13] = ee;
+ _result[14] = ff;
+ _result[15] = 1.0f;
+ }
+
+ inline void mtxOrtho(float* _result, float _left, float _right, float _bottom, float _top, float _near, float _far, float _offset = 0.0f, bool _oglNdc = false)
+ {
+ return mtxOrthoLh(_result, _left, _right, _bottom, _top, _near, _far, _offset, _oglNdc);
+ }
+
inline void mtxRotateX(float* _result, float _ax)
{
const float sx = fsin(_ax);