17 Mat4(
float m11,
float m12,
float m13,
float m14,
18 float m21,
float m22,
float m23,
float m24,
19 float m31,
float m32,
float m33,
float m34,
20 float m41,
float m42,
float m43,
float m44)
61 *
this = *
this * trans;
65 float radians = degrees * 3.14159265f / 180.0f;
66 float c = cosf(radians);
67 float s = sinf(radians);
111 static Mat4 Ortho(
float left,
float right,
float bottom,
float top,
float zNear,
float zFar)
114 2.0f / (right - left), 0, 0, -(right + left) / (right - left),
115 0, 2.0f / (top - bottom), 0, -(top + bottom) / (top - bottom),
116 0, 0, 1.0f / (zFar - zNear), -zNear / (zFar - zNear),
127 s.
x, s.
y, s.
z, -s.
dot(eye),
128 u.
x, u.
y, u.
z, -u.
dot(eye),
129 f.
x, f.
y, f.
z, -f.
dot(eye),
130 0.0f, 0.0f, 0.0f, 1.0f
144 static Mat4 Scale(
float scaleX,
float scaleY,
float scaleZ)
155 float angle = fovx * 3.14159265f / 180.0f;
156 float h = tanf(angle / 2.0f);
160 0, 0, zFar / (zFar - zNear), -zFar * zNear / (zFar - zNear),
166 float radians = degrees * 3.14159265f / 180.0f;
167 float c = cosf(radians);
168 float s = sinf(radians);
179 float radians = degrees * 3.14159265f / 180.0f;
180 float c = cosf(radians);
181 float s = sinf(radians);
193 m[0] * vec.
x +
m[1] * vec.
y +
m[2] * vec.
z +
m[3] * vec.
w,
194 m[4] * vec.
x +
m[5] * vec.
y +
m[6] * vec.
z +
m[7] * vec.
w,
195 m[8] * vec.
x +
m[9] * vec.
y +
m[10] * vec.
z +
m[11] * vec.
w,
196 m[12] * vec.
x +
m[13] * vec.
y +
m[14] * vec.
z +
m[15] * vec.
w
199 void scale(
float x,
float y,
float z)
212 for (
int i = 0; i < 4; ++i)
214 for (
int j = 0; j < 4; ++j)
216 result.
m[i * 4 + j] = 0.0f;
217 for (
int k = 0; k < 4; ++k)
219 result.
m[i * 4 + j] +=
m[i * 4 + k] * rhs.
m[k * 4 + j];
230 friend std::ostream&
operator<<(std::ostream& os,
const Mat4& mat);
234 os << std::fixed << std::setprecision(4);
235 os <<
"Matrix4x4:\n";
236 for (
int i = 0; i < 4; ++i)
239 for (
int j = 0; j < 4; ++j)
241 os << std::setw(10) << mat.
m[i * 4 + j];
242 if (j < 3) os <<
", ";
void rotateZ(float degrees)
friend std::ostream & operator<<(std::ostream &os, const Mat4 &mat)
static Mat4 CreateTranslation(float x, float y)
static Mat4 Perspective(float fovx, float aspect, float zNear, float zFar)
void translate(float x, float y, float z)
Mat4(float m11, float m12, float m13, float m14, float m21, float m22, float m23, float m24, float m31, float m32, float m33, float m34, float m41, float m42, float m43, float m44)
void rotateX(float degrees)
static Mat4 LookAt(const Vec3 &eye, const Vec3 ¢er, const Vec3 &up)
static Mat4 Scale(float scaleX, float scaleY)
static Mat4 Scale(float scaleX, float scaleY, float scaleZ)
void scale(float x, float y, float z)
void translate(float x, float y)
static Mat4 Translate(float x, float y, float z)
Mat4 & operator*=(const Mat4 &rhs)
static Mat4 Ortho(float left, float right, float bottom, float top, float zNear, float zFar)
Mat4 operator*(const Mat4 &rhs) const
Vec4 operator*(const Vec4 &vec) const
static Mat4 CreateScale(float scaleX, float scaleY)
void rotateY(float degrees)
static Mat4 Translate(float x, float y)
Vec3 normalize(const Vec3 &v)
std::ostream & operator<<(std::ostream &os, const Mat4 &mat)
float dot(const Vec3 &rhs) const
Vec3 cross(const Vec3 &other) const