17 float& operator[](std::size_t idx) {
return data[idx]; }
18 const float& operator[](std::size_t idx)
const {
return data[idx]; }
20 operator float*() {
return data; }
21 operator const float*()
const {
return data; }
23 Matrix4 operator*(
const Matrix4& other)
const {
24 return Matrix4::Multiply(*
this, other);
27 static Matrix4 Identity() {
29 m[0] = m[5] = m[10] = m[15] = 1.0f;
33 static Matrix4 Translate(
float x,
float y,
float z) {
34 Matrix4 m = Identity();
41 static Matrix4 Scale(
float sx,
float sy,
float sz) {
42 Matrix4 m = Identity();
49 static Matrix4 RotateZ(
float radians) {
50 float c = std::cos(radians);
51 float s = std::sin(radians);
52 Matrix4 m = Identity();
58 static Matrix4 Multiply(
const Matrix4& a,
const Matrix4& b) {
60 for(
int row = 0; row < 4; ++row) {
61 for(
int col = 0; col < 4; ++col) {
62 result[col + row * 4] =
63 a[0 + row * 4] * b[col + 0 * 4] +
64 a[1 + row * 4] * b[col + 1 * 4] +
65 a[2 + row * 4] * b[col + 2 * 4] +
66 a[3 + row * 4] * b[col + 3 * 4];
72 static Matrix4 Ortho(
float width,
float height) {
83 static Matrix4 OrthoTopLeft(
float width,
float height) {
86 m[5] = -2.0f / height;