Skip to content

Commit 5273b9a

Browse files
committed
修正矩阵乘法为行主序,列向量
1 parent cba9585 commit 5273b9a

1 file changed

Lines changed: 17 additions & 14 deletions

File tree

src/Context/Matrix.h

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,17 @@ namespace FCT
4747
}
4848
void translate(float x, float y)
4949
{
50-
m[8] += x;
51-
m[9] += y;
50+
m[3] += x;
51+
m[7] += y;
5252
}
5353
void translate(float x, float y, float z)
5454
{
55-
Mat4 trans;
56-
trans.m[12] = x;
57-
trans.m[13] = y;
58-
trans.m[14] = z;
55+
Mat4 trans = {
56+
1, 0, 0, x,
57+
0, 1, 0, y,
58+
0, 0, 1, z,
59+
0, 0, 0, 1
60+
};
5961
*this = *this * trans;
6062
}
6163
void rotateX(float degrees)
@@ -74,8 +76,8 @@ namespace FCT
7476
static Mat4 CreateTranslation(float x, float y)
7577
{
7678
Mat4 ret;
77-
ret.m[8] += x;
78-
ret.m[9] += y;
79+
ret.m[3] += x;
80+
ret.m[7] += y;
7981
return ret;
8082
}
8183
static Mat4 CreateScale(float scaleX, float scaleY)
@@ -94,17 +96,18 @@ namespace FCT
9496
ret.m[9] += y;
9597
return ret;
9698
}
97-
static Mat4 Translate(float x, float y,float z)
99+
static Mat4 Translate(float x, float y, float z)
98100
{
99101
Mat4 ret = {
100-
1, 0, 0, 0,
101-
0, 1, 0, 0,
102-
0, 0, 1, 0,
103-
x, y, z, 1};
104-
102+
1, 0, 0, x,
103+
0, 1, 0, y,
104+
0, 0, 1, z,
105+
0, 0, 0, 1
106+
};
105107
return ret;
106108
}
107109

110+
108111
static Mat4 Ortho(float left, float right, float bottom, float top, float zNear, float zFar)
109112
{
110113
Mat4 result;

0 commit comments

Comments
 (0)