aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorThomas Fach-Pedersen2014-06-05 22:57:33 +0200
committerEugene Sandulenko2016-09-29 22:33:36 +0200
commit789bb7a2810a1bee537229862037e1f11396e2e6 (patch)
tree2653f55b471cd79fd8ac548ac3b8b89d2b9ef582 /engines
parent303aba7dd109a3a6dfde34fd0191b53a5d6d7f67 (diff)
downloadscummvm-rg350-789bb7a2810a1bee537229862037e1f11396e2e6.tar.gz
scummvm-rg350-789bb7a2810a1bee537229862037e1f11396e2e6.tar.bz2
scummvm-rg350-789bb7a2810a1bee537229862037e1f11396e2e6.zip
BLADERUNNER: Add Vector and Matrix classes
Diffstat (limited to 'engines')
-rw-r--r--engines/bladerunner/matrix.cpp169
-rw-r--r--engines/bladerunner/matrix.h133
-rw-r--r--engines/bladerunner/module.mk1
-rw-r--r--engines/bladerunner/vector.h128
4 files changed, 431 insertions, 0 deletions
diff --git a/engines/bladerunner/matrix.cpp b/engines/bladerunner/matrix.cpp
new file mode 100644
index 0000000000..a55271ed39
--- /dev/null
+++ b/engines/bladerunner/matrix.cpp
@@ -0,0 +1,169 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "bladerunner/matrix.h"
+
+#include "common/scummsys.h"
+
+namespace BladeRunner {
+
+Matrix3x2::Matrix3x2()
+{
+ for (int r = 0; r != 2; ++r)
+ for (int c = 0; c != 3; ++c)
+ _m[r][c] = (r == c) ? 1.0f : 0.0f;
+}
+
+Matrix3x2::Matrix3x2(float d[6])
+{
+ for (int r = 0; r != 2; ++r)
+ for (int c = 0; c != 3; ++c)
+ _m[r][c] = d[r*3+c];
+}
+
+Matrix3x2::Matrix3x2(
+ float m00, float m01, float m02,
+ float m10, float m11, float m12)
+{
+ _m[0][0] = m00;
+ _m[0][1] = m01;
+ _m[0][2] = m02;
+ _m[1][0] = m10;
+ _m[1][1] = m11;
+ _m[1][2] = m12;
+}
+
+Matrix4x3::Matrix4x3()
+{
+ for (int r = 0; r != 3; ++r)
+ for (int c = 0; c != 4; ++c)
+ _m[r][c] = (r == c) ? 1.0f : 0.0f;
+}
+
+Matrix4x3::Matrix4x3(float d[12])
+{
+ for (int r = 0; r != 3; ++r)
+ for (int c = 0; c != 4; ++c)
+ _m[r][c] = d[r*4+c];
+}
+
+Matrix4x3::Matrix4x3(
+ float m00, float m01, float m02, float m03,
+ float m10, float m11, float m12, float m13,
+ float m20, float m21, float m22, float m23)
+{
+ _m[0][0] = m00;
+ _m[0][1] = m01;
+ _m[0][2] = m02;
+ _m[0][3] = m03;
+ _m[1][0] = m10;
+ _m[1][1] = m11;
+ _m[1][2] = m12;
+ _m[1][3] = m13;
+ _m[2][0] = m20;
+ _m[2][1] = m21;
+ _m[2][2] = m22;
+ _m[2][3] = m23;
+}
+
+Matrix4x3 rotationMatrixX(float angle)
+{
+ float ca = cos(angle);
+ float sa = sin(angle);
+
+ return Matrix4x3( 1.0f, 0.0f, 0.0f, 0.0f,
+ 0.0f, ca, sa, 0.0f,
+ 0.0f, -sa, ca, 0.0f );
+}
+
+static inline
+void swapRows(double *r1, double *r2)
+{
+ for (int c = 0; c != 8; ++c)
+ {
+ double t = r1[c];
+ r1[c] = r2[c];
+ r2[c] = t;
+ }
+}
+
+static inline
+void subtractRow(double *r1, double factor, double *r2)
+{
+ for (int c = 0; c != 8; ++c)
+ r1[c] -= factor * r2[c];
+}
+
+static inline
+void divideRow(double *r1, double d)
+{
+ for (int c = 0; c != 8; ++c)
+ r1[c] /= d;
+}
+
+Matrix4x3 invertMatrix(const Matrix4x3 &m)
+{
+ double w[3][8];
+
+ for (int r = 0; r != 3; ++r) {
+ for (int c = 0; c != 4; ++c) {
+ w[r][c] = m(r, c);
+ w[r][c+4] = (r == c) ? 1.0 : 0.0;
+ }
+ }
+
+ if (w[0][0] == 0.0) {
+ if (w[1][0] != 0.0)
+ swapRows(w[0], w[1]);
+ else
+ swapRows(w[0], w[2]);
+ }
+ divideRow(w[0], w[0][0]);
+ subtractRow(w[1], w[1][0], w[0]);
+ subtractRow(w[2], w[2][0], w[0]);
+
+ if (w[1][1] == 0.0)
+ swapRows(w[1], w[2]);
+
+ divideRow(w[1], w[1][1]);
+ subtractRow(w[0], w[0][1], w[1]);
+ subtractRow(w[2], w[2][1], w[1]);
+
+ divideRow(w[2], w[2][2]);
+ subtractRow(w[0], w[0][2], w[2]);
+ subtractRow(w[1], w[1][2], w[2]);
+
+ for (int r = 0; r != 3; ++r) {
+ w[r][7] = -w[r][3];
+ w[r][3] = 0.0;
+ }
+
+ Matrix4x3 result;
+
+ for (int r = 0; r != 3; ++r)
+ for (int c = 0; c != 4; ++c)
+ result(r, c) = float(w[r][c+4]);
+
+ return result;
+}
+
+} // End of namespace BladeRunner
diff --git a/engines/bladerunner/matrix.h b/engines/bladerunner/matrix.h
new file mode 100644
index 0000000000..64c30701b1
--- /dev/null
+++ b/engines/bladerunner/matrix.h
@@ -0,0 +1,133 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef BLADERUNNER_MATRIX_H
+#define BLADERUNNER_MATRIX_H
+
+#include "bladerunner/vector.h"
+
+namespace BladeRunner {
+
+class Matrix3x2
+{
+public:
+ float _m[2][3];
+
+ Matrix3x2();
+ Matrix3x2(float d[6]);
+ Matrix3x2(
+ float m00, float m01, float m02,
+ float m10, float m11, float m12);
+
+ float &operator()(int r, int c) { assert(r >= 0 && r < 2); assert(c >= 0 && c < 3); return _m[r][c]; }
+ const float &operator()(int r, int c) const { assert(r >= 0 && r < 2); assert(c >= 0 && c < 3); return _m[r][c]; }
+};
+
+inline
+Matrix3x2 operator*(const Matrix3x2 &a, const Matrix3x2 &b)
+{
+ Matrix3x2 t;
+
+ t(0,0) = a(0,0)*b(0,0) + a(0,1)*b(1,0);
+ t(0,1) = a(0,0)*b(0,1) + a(0,1)*b(1,1);
+ t(0,2) = a(0,0)*b(0,2) + a(0,1)*b(1,2) + a(0,2);
+ t(1,0) = a(1,0)*b(0,0) + a(1,1)*b(1,0);
+ t(1,1) = a(1,0)*b(0,1) + a(1,1)*b(1,1);
+ t(1,2) = a(1,0)*b(0,2) + a(1,1)*b(1,2) + a(1,2);
+
+ return t;
+}
+
+inline
+Matrix3x2 operator+(const Matrix3x2 &a, Vector2 b)
+{
+ Matrix3x2 t(a);
+
+ t(0,2) += b.x;
+ t(1,2) += b.y;
+
+ return t;
+}
+
+inline
+Vector2 operator*(const Matrix3x2 &a, Vector2 b)
+{
+ Vector2 t;
+
+ t.x = a(0,0) * b.x + a(0,1) * b.y + a(0,2);
+ t.y = a(1,0) * b.x + a(1,1) * b.y + a(1,2);
+
+ return t;
+}
+
+class Matrix4x3
+{
+public:
+ float _m[3][4];
+
+ Matrix4x3();
+ Matrix4x3(float d[12]);
+ Matrix4x3(
+ float m00, float m01, float m02, float m03,
+ float m10, float m11, float m12, float m13,
+ float m20, float m21, float m22, float m23);
+
+ float &operator()(int r, int c) { assert(r >= 0 && r < 3); assert(c >= 0 && c < 4); return _m[r][c]; }
+ const float &operator()(int r, int c) const { assert(r >= 0 && r < 3); assert(c >= 0 && c < 4); return _m[r][c]; }
+
+};
+
+Matrix4x3 invertMatrix(const Matrix4x3 &m);
+Matrix4x3 rotationMatrixX(float angle);
+
+inline
+Matrix4x3 operator*(const Matrix4x3 &a, const Matrix4x3 &b)
+{
+ Matrix4x3 t;
+
+ for (int i = 0; i !=3; ++i)
+ {
+ // printf("t(%d,0) = %7.2f*%7.2f + %7.2f*%7.2f + %7.2f*%7.2f\n", i, a(i,0), b(0,0), a(i,0), b(1,0), a(i,0), b(2,0));
+ t(i,0) = a(i,0)*b(0,0) + a(i,1)*b(1,0) + a(i,2)*b(2,0);
+ t(i,1) = a(i,0)*b(0,1) + a(i,1)*b(1,1) + a(i,2)*b(2,1);
+ t(i,2) = a(i,0)*b(0,2) + a(i,1)*b(1,2) + a(i,2)*b(2,2);
+ t(i,3) = a(i,0)*b(0,3) + a(i,1)*b(1,3) + a(i,2)*b(2,3) + a(i,3);
+ }
+
+ return t;
+}
+
+inline
+Vector3 operator*(const Matrix4x3 &m, const Vector3 &v)
+{
+ Vector3 r;
+
+ r.x = m(0, 0) * v.x + m(0, 1) * v.y + m(0, 2) * v.z + m(0, 3);
+ r.y = m(1, 0) * v.x + m(1, 1) * v.y + m(1, 2) * v.z + m(1, 3);
+ r.z = m(2, 0) * v.x + m(2, 1) * v.y + m(2, 2) * v.z + m(2, 3);
+
+ return r;
+}
+
+} // End of namespace BladeRunner
+
+#endif
diff --git a/engines/bladerunner/module.mk b/engines/bladerunner/module.mk
index 752543b684..3d014483cf 100644
--- a/engines/bladerunner/module.mk
+++ b/engines/bladerunner/module.mk
@@ -10,6 +10,7 @@ MODULE_OBJS = \
detection.o \
gameinfo.o \
image.o \
+ matrix.o \
outtake.o \
scene.o \
script/rc01.o \
diff --git a/engines/bladerunner/vector.h b/engines/bladerunner/vector.h
new file mode 100644
index 0000000000..3b85da40d7
--- /dev/null
+++ b/engines/bladerunner/vector.h
@@ -0,0 +1,128 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef BLADERUNNER_VECTOR_H
+#define BLADERUNNER_VECTOR_H
+
+#include "common/types.h"
+
+namespace BladeRunner {
+
+class Vector2
+{
+public:
+ float x;
+ float y;
+
+ Vector2()
+ : x(0.0), y(0.0)
+ {}
+
+ Vector2(float ax, float ay)
+ : x(ax), y(ay)
+ {}
+};
+
+class Vector3
+{
+public:
+ float x;
+ float y;
+ float z;
+
+ Vector3()
+ : x(0.0), y(0.0), z(0.0)
+ {}
+
+ Vector3(float ax, float ay, float az)
+ : x(ax), y(ay), z(az)
+ {}
+};
+
+inline
+Vector3 operator+(Vector3 a, Vector3 b)
+{
+ return Vector3(a.x + b.x, a.y + b.y, a.z + b.z);
+}
+
+inline
+Vector3 operator-(Vector3 a, Vector3 b)
+{
+ return Vector3(a.x - b.x, a.y - b.y, a.z - b.z);
+}
+
+inline
+Vector3 operator*(float f, Vector3 v)
+{
+ return Vector3(f * v.x, f * v.y, f * v.z);
+}
+
+class Vector4
+{
+public:
+ float x;
+ float y;
+ float z;
+ float w;
+
+ Vector4()
+ : x(0.0), y(0.0), z(0.0), w(0.0)
+ {}
+
+ Vector4(float ax, float ay, float az, float aw)
+ : x(ax), y(ay), z(az), w(aw)
+ {}
+};
+
+inline
+Vector4 operator+(Vector4 a, Vector4 b)
+{
+ return Vector4(a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w);
+}
+
+inline
+Vector4 operator-(Vector4 a, Vector4 b)
+{
+ return Vector4(a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w);
+}
+
+inline
+Vector4 operator*(float f, Vector4 v)
+{
+ return Vector4(f * v.x, f * v.y, f * v.z, f * v.w);
+}
+
+inline
+Vector4 operator*(Vector4 v, float f)
+{
+ return Vector4(f * v.x, f * v.y, f * v.z, f * v.w);
+}
+
+inline
+Vector4 operator/(Vector4 a, Vector4 b)
+{
+ return Vector4(a.x / b.x, a.y / b.y, a.z / b.z, a.w / b.w);
+}
+
+} // End of namespace BladeRunner
+
+#endif