ScummVM API documentation
matrix.h
1/* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 */
21
22#ifndef BLADERUNNER_MATRIX_H
23#define BLADERUNNER_MATRIX_H
24
25#include "bladerunner/vector.h"
26
27namespace BladeRunner {
28
29class Matrix3x2 {
30public:
31 float _m[2][3];
32
33 Matrix3x2();
34 Matrix3x2(float d[6]);
36 float m00, float m01, float m02,
37 float m10, float m11, float m12);
38
39 float &operator()(int r, int c) { assert(r >= 0 && r < 2); assert(c >= 0 && c < 3); return _m[r][c]; }
40 const float &operator()(int r, int c) const { assert(r >= 0 && r < 2); assert(c >= 0 && c < 3); return _m[r][c]; }
41};
42
43inline Matrix3x2 operator*(const Matrix3x2 &a, const Matrix3x2 &b) {
44 Matrix3x2 t;
45
46 t(0, 0) = a(0, 0) * b(0, 0) + a(0, 1) * b(1, 0);
47 t(0, 1) = a(0, 0) * b(0, 1) + a(0, 1) * b(1, 1);
48 t(0, 2) = a(0, 0) * b(0, 2) + a(0, 1) * b(1, 2) + a(0, 2);
49 t(1, 0) = a(1, 0) * b(0, 0) + a(1, 1) * b(1, 0);
50 t(1, 1) = a(1, 0) * b(0, 1) + a(1, 1) * b(1, 1);
51 t(1, 2) = a(1, 0) * b(0, 2) + a(1, 1) * b(1, 2) + a(1, 2);
52
53 return t;
54}
55
56inline Matrix3x2 operator+(const Matrix3x2 &a, Vector2 b) {
57 Matrix3x2 t(a);
58
59 t(0, 2) += b.x;
60 t(1, 2) += b.y;
61
62 return t;
63}
64
65inline Vector2 operator*(const Matrix3x2 &a, Vector2 b) {
66 Vector2 t;
67
68 t.x = a(0, 0) * b.x + a(0, 1) * b.y + a(0, 2);
69 t.y = a(1, 0) * b.x + a(1, 1) * b.y + a(1, 2);
70
71 return t;
72}
73
74class Matrix4x3 {
75public:
76 float _m[3][4];
77
78 Matrix4x3();
79 Matrix4x3(float d[12]);
81 float m00, float m01, float m02, float m03,
82 float m10, float m11, float m12, float m13,
83 float m20, float m21, float m22, float m23);
84
85 float &operator()(int r, int c) { assert(r >= 0 && r < 3); assert(c >= 0 && c < 4); return _m[r][c]; }
86 const float &operator()(int r, int c) const { assert(r >= 0 && r < 3); assert(c >= 0 && c < 4); return _m[r][c]; }
87
88 void unknown();
89};
90
91Matrix4x3 invertMatrix(const Matrix4x3 &m);
92Matrix4x3 rotationMatrixX(float angle);
93
94inline Matrix4x3 operator*(const Matrix4x3 &a, const Matrix4x3 &b) {
95 Matrix4x3 t;
96
97 for (int i = 0; i !=3; ++i) {
98 t(i, 0) = a(i, 0) * b(0, 0) + a(i, 1) * b(1, 0) + a(i, 2) * b(2, 0);
99 t(i, 1) = a(i, 0) * b(0, 1) + a(i, 1) * b(1, 1) + a(i, 2) * b(2, 1);
100 t(i, 2) = a(i, 0) * b(0, 2) + a(i, 1) * b(1, 2) + a(i, 2) * b(2, 2);
101 t(i, 3) = a(i, 0) * b(0, 3) + a(i, 1) * b(1, 3) + a(i, 2) * b(2, 3) + a(i, 3);
102 }
103
104 return t;
105}
106
107inline Vector3 operator*(const Matrix4x3 &m, const Vector3 &v) {
108 Vector3 r;
109
110 r.x = m(0, 0) * v.x + m(0, 1) * v.y + m(0, 2) * v.z + m(0, 3);
111 r.y = m(1, 0) * v.x + m(1, 1) * v.y + m(1, 2) * v.z + m(1, 3);
112 r.z = m(2, 0) * v.x + m(2, 1) * v.y + m(2, 2) * v.z + m(2, 3);
113
114 return r;
115}
116
117} // End of namespace BladeRunner
118
119#endif
Definition: matrix.h:29
Definition: matrix.h:74