aboutsummaryrefslogtreecommitdiff
path: root/src/libjin/math
diff options
context:
space:
mode:
Diffstat (limited to 'src/libjin/math')
-rw-r--r--src/libjin/math/matrix.cpp17
-rw-r--r--src/libjin/math/matrix.h6
2 files changed, 23 insertions, 0 deletions
diff --git a/src/libjin/math/matrix.cpp b/src/libjin/math/matrix.cpp
index 39042f0..a80f37a 100644
--- a/src/libjin/math/matrix.cpp
+++ b/src/libjin/math/matrix.cpp
@@ -8,6 +8,8 @@ namespace jin
namespace math
{
+ const Matrix Matrix::Identity;
+
// | e0 e4 e8 e12 |
// | e1 e5 e9 e13 |
// | e2 e6 e10 e14 |
@@ -22,6 +24,21 @@ namespace math
{
}
+ void Matrix::setOrtho(float l, float r, float b, float t, float n, float f)
+ {
+ float w = r - l;
+ float h = t - b;
+ float z = f - n;
+ setIdentity();
+ e[0] = 2 / w;
+ e[5] = 2 / h;
+ e[10] = -2 / z;
+ e[12] = -(r + l) / w;
+ e[13] = -(t + b) / h;
+ e[14] = -(f + n) / z;
+ e[15] = 1;
+ }
+
// | e0 e4 e8 e12 |
// | e1 e5 e9 e13 |
// | e2 e6 e10 e14 |
diff --git a/src/libjin/math/matrix.h b/src/libjin/math/matrix.h
index b9a55d4..52fc9c8 100644
--- a/src/libjin/math/matrix.h
+++ b/src/libjin/math/matrix.h
@@ -16,6 +16,8 @@ namespace math
* This class is the basis for all transformations in LOVE. Althought not
* really needed for 2D, it contains 4x4 elements to be compatible with
* OpenGL without conversions.
+ * Ҫתõľ
+ * https://blog.csdn.net/candycat1992/article/details/8830894
**/
class Matrix
{
@@ -31,6 +33,8 @@ namespace math
public:
+ static const Matrix Identity;
+
/**
* Creates a new identity matrix.
**/
@@ -41,6 +45,8 @@ namespace math
**/
~Matrix();
+ void setOrtho(float _left, float _right, float _bottom, float _top, float _near, float _far);
+
/**
* Multiplies this Matrix with another Matrix, changing neither.
* @param m The Matrix to multiply with this Matrix.