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 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (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, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 * 21 */ 22 23 #ifndef BLADERUNNER_MATRIX_H 24 #define BLADERUNNER_MATRIX_H 25 26 #include "bladerunner/vector.h" 27 28 namespace BladeRunner { 29 30 class Matrix3x2 { 31 public: 32 float _m[2][3]; 33 34 Matrix3x2(); 35 Matrix3x2(float d[6]); 36 Matrix3x2( 37 float m00, float m01, float m02, 38 float m10, float m11, float m12); 39 operator()40 float &operator()(int r, int c) { assert(r >= 0 && r < 2); assert(c >= 0 && c < 3); return _m[r][c]; } operator()41 const float &operator()(int r, int c) const { assert(r >= 0 && r < 2); assert(c >= 0 && c < 3); return _m[r][c]; } 42 }; 43 44 inline Matrix3x2 operator*(const Matrix3x2 &a, const Matrix3x2 &b) { 45 Matrix3x2 t; 46 47 t(0, 0) = a(0, 0) * b(0, 0) + a(0, 1) * b(1, 0); 48 t(0, 1) = a(0, 0) * b(0, 1) + a(0, 1) * b(1, 1); 49 t(0, 2) = a(0, 0) * b(0, 2) + a(0, 1) * b(1, 2) + a(0, 2); 50 t(1, 0) = a(1, 0) * b(0, 0) + a(1, 1) * b(1, 0); 51 t(1, 1) = a(1, 0) * b(0, 1) + a(1, 1) * b(1, 1); 52 t(1, 2) = a(1, 0) * b(0, 2) + a(1, 1) * b(1, 2) + a(1, 2); 53 54 return t; 55 } 56 57 inline Matrix3x2 operator+(const Matrix3x2 &a, Vector2 b) { 58 Matrix3x2 t(a); 59 60 t(0, 2) += b.x; 61 t(1, 2) += b.y; 62 63 return t; 64 } 65 66 inline Vector2 operator*(const Matrix3x2 &a, Vector2 b) { 67 Vector2 t; 68 69 t.x = a(0, 0) * b.x + a(0, 1) * b.y + a(0, 2); 70 t.y = a(1, 0) * b.x + a(1, 1) * b.y + a(1, 2); 71 72 return t; 73 } 74 75 class Matrix4x3 { 76 public: 77 float _m[3][4]; 78 79 Matrix4x3(); 80 Matrix4x3(float d[12]); 81 Matrix4x3( 82 float m00, float m01, float m02, float m03, 83 float m10, float m11, float m12, float m13, 84 float m20, float m21, float m22, float m23); 85 operator()86 float &operator()(int r, int c) { assert(r >= 0 && r < 3); assert(c >= 0 && c < 4); return _m[r][c]; } operator()87 const float &operator()(int r, int c) const { assert(r >= 0 && r < 3); assert(c >= 0 && c < 4); return _m[r][c]; } 88 89 void unknown(); 90 }; 91 92 Matrix4x3 invertMatrix(const Matrix4x3 &m); 93 Matrix4x3 rotationMatrixX(float angle); 94 95 inline Matrix4x3 operator*(const Matrix4x3 &a, const Matrix4x3 &b) { 96 Matrix4x3 t; 97 98 for (int i = 0; i !=3; ++i) { 99 t(i, 0) = a(i, 0) * b(0, 0) + a(i, 1) * b(1, 0) + a(i, 2) * b(2, 0); 100 t(i, 1) = a(i, 0) * b(0, 1) + a(i, 1) * b(1, 1) + a(i, 2) * b(2, 1); 101 t(i, 2) = a(i, 0) * b(0, 2) + a(i, 1) * b(1, 2) + a(i, 2) * b(2, 2); 102 t(i, 3) = a(i, 0) * b(0, 3) + a(i, 1) * b(1, 3) + a(i, 2) * b(2, 3) + a(i, 3); 103 } 104 105 return t; 106 } 107 108 inline Vector3 operator*(const Matrix4x3 &m, const Vector3 &v) { 109 Vector3 r; 110 111 r.x = m(0, 0) * v.x + m(0, 1) * v.y + m(0, 2) * v.z + m(0, 3); 112 r.y = m(1, 0) * v.x + m(1, 1) * v.y + m(1, 2) * v.z + m(1, 3); 113 r.z = m(2, 0) * v.x + m(2, 1) * v.y + m(2, 2) * v.z + m(2, 3); 114 115 return r; 116 } 117 118 } // End of namespace BladeRunner 119 120 #endif 121