aboutsummaryrefslogtreecommitdiff
path: root/engines/wintermute/math
diff options
context:
space:
mode:
authorEinar Johan Trøan Sømåen2012-06-02 02:21:01 +0200
committerEinar Johan Trøan Sømåen2012-06-02 13:09:34 +0200
commit221490a93df13fb6b17589c48c536c73ef6576b5 (patch)
treef477c4c8285928e1c49652bf7a4b0d9ee12ac918 /engines/wintermute/math
parente6729615ea471891be17d5681b63fe3492f127bd (diff)
downloadscummvm-rg350-221490a93df13fb6b17589c48c536c73ef6576b5.tar.gz
scummvm-rg350-221490a93df13fb6b17589c48c536c73ef6576b5.tar.bz2
scummvm-rg350-221490a93df13fb6b17589c48c536c73ef6576b5.zip
WINTERMUTE: Add subfolders for math, UI, tinyxml and Sys
Diffstat (limited to 'engines/wintermute/math')
-rw-r--r--engines/wintermute/math/MathUtil.cpp48
-rw-r--r--engines/wintermute/math/MathUtil.h42
-rw-r--r--engines/wintermute/math/Matrix4.cpp86
-rw-r--r--engines/wintermute/math/Matrix4.h59
-rw-r--r--engines/wintermute/math/Vector2.cpp55
-rw-r--r--engines/wintermute/math/Vector2.h75
6 files changed, 365 insertions, 0 deletions
diff --git a/engines/wintermute/math/MathUtil.cpp b/engines/wintermute/math/MathUtil.cpp
new file mode 100644
index 0000000000..d6b526f5b6
--- /dev/null
+++ b/engines/wintermute/math/MathUtil.cpp
@@ -0,0 +1,48 @@
+/* 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.
+ *
+ */
+
+/*
+ * This file is based on WME Lite.
+ * http://dead-code.org/redir.php?target=wmelite
+ * Copyright (c) 2011 Jan Nedoma
+ */
+
+#include "MathUtil.h"
+#include <cmath>
+
+namespace WinterMute {
+
+//////////////////////////////////////////////////////////////////////////
+float MathUtil::Round(float val) {
+ float result = floor(val);
+ if (val - result >= 0.5) result += 1.0;
+ return result;
+}
+
+//////////////////////////////////////////////////////////////////////////
+float MathUtil::RoundUp(float val) {
+ float result = floor(val);
+ if (val - result > 0) result += 1.0;
+ return result;
+}
+
+} // end of namespace WinterMute
diff --git a/engines/wintermute/math/MathUtil.h b/engines/wintermute/math/MathUtil.h
new file mode 100644
index 0000000000..bacf975d62
--- /dev/null
+++ b/engines/wintermute/math/MathUtil.h
@@ -0,0 +1,42 @@
+/* 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.
+ *
+ */
+
+/*
+ * This file is based on WME Lite.
+ * http://dead-code.org/redir.php?target=wmelite
+ * Copyright (c) 2011 Jan Nedoma
+ */
+
+#ifndef WINTERMUTE_MATHUTIL_H
+#define WINTERMUTE_MATHUTIL_H
+
+namespace WinterMute {
+
+class MathUtil {
+public:
+ static float Round(float val);
+ static float RoundUp(float val);
+};
+
+} // end of namespace WinterMute
+
+#endif // WINTERMUTE_MATHUTIL_H
diff --git a/engines/wintermute/math/Matrix4.cpp b/engines/wintermute/math/Matrix4.cpp
new file mode 100644
index 0000000000..d9d17b613b
--- /dev/null
+++ b/engines/wintermute/math/Matrix4.cpp
@@ -0,0 +1,86 @@
+/* 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.
+ *
+ */
+
+/*
+ * This file is based on WME Lite.
+ * http://dead-code.org/redir.php?target=wmelite
+ * Copyright (c) 2011 Jan Nedoma
+ */
+
+#include "engines/wintermute/math/Matrix4.h"
+#include "engines/wintermute/math/Vector2.h"
+#include <math.h>
+
+namespace WinterMute {
+
+//////////////////////////////////////////////////////////////////////////
+Matrix4::Matrix4() {
+ for (int i = 0; i < 4; i++) {
+ for (int j = 0; j < 4; j++) {
+ m[i][j] = 0.0f;
+ }
+ }
+}
+
+//////////////////////////////////////////////////////////////////////////
+Matrix4::~Matrix4() {
+}
+
+
+//////////////////////////////////////////////////////////////////////////
+void Matrix4::Identity() {
+ for (int i = 0; i < 4; i++) {
+ for (int j = 0; j < 4; j++) {
+ m[i][j] = 0.0f;
+ }
+ }
+ m[0][0] = 1.0f;
+ m[1][1] = 1.0f;
+ m[2][2] = 1.0f;
+ m[3][3] = 1.0f;
+
+}
+
+//////////////////////////////////////////////////////////////////////////
+void Matrix4::RotationZ(float angle) {
+ Identity();
+
+ m[0][0] = cos(angle);
+ m[1][1] = cos(angle);
+ m[0][1] = sin(angle);
+ m[1][0] = -sin(angle);
+}
+
+//////////////////////////////////////////////////////////////////////////
+void Matrix4::TransformVector2(Vector2 &vec) {
+ float norm;
+
+ norm = m[0][3] * vec.x + m[1][3] * vec.y + m[3][3];
+
+ float x = (m[0][0] * vec.x + m[1][0] * vec.y + m[3][0]) / norm;
+ float y = (m[0][1] * vec.x + m[1][1] * vec.y + m[3][1]) / norm;
+
+ vec.x = x;
+ vec.y = y;
+}
+
+} // end of namespace WinterMute
diff --git a/engines/wintermute/math/Matrix4.h b/engines/wintermute/math/Matrix4.h
new file mode 100644
index 0000000000..da5fd1393a
--- /dev/null
+++ b/engines/wintermute/math/Matrix4.h
@@ -0,0 +1,59 @@
+/* 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.
+ *
+ */
+
+/*
+ * This file is based on WME Lite.
+ * http://dead-code.org/redir.php?target=wmelite
+ * Copyright (c) 2011 Jan Nedoma
+ */
+
+#ifndef WINTERMUTE_MATRIX4_H
+#define WINTERMUTE_MATRIX4_H
+
+namespace WinterMute {
+
+class Vector2;
+
+class Matrix4 {
+public:
+ Matrix4();
+ ~Matrix4();
+
+ void Identity();
+ void RotationZ(float angle);
+ void TransformVector2(Vector2 &vec);
+
+ /* union {
+ struct {
+ float _11, _12, _13, _14;
+ float _21, _22, _23, _24;
+ float _31, _32, _33, _34;
+ float _41, _42, _43, _44;
+ };*/
+ float m[4][4];
+ //};
+
+};
+
+} // end of namespace WinterMute
+
+#endif // WINTERMUTE_MATRIX4_H
diff --git a/engines/wintermute/math/Vector2.cpp b/engines/wintermute/math/Vector2.cpp
new file mode 100644
index 0000000000..b2fa56dff4
--- /dev/null
+++ b/engines/wintermute/math/Vector2.cpp
@@ -0,0 +1,55 @@
+/* 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.
+ *
+ */
+
+/*
+ * This file is based on WME Lite.
+ * http://dead-code.org/redir.php?target=wmelite
+ * Copyright (c) 2011 Jan Nedoma
+ */
+
+#include "Vector2.h"
+#include <math.h>
+
+namespace WinterMute {
+
+//////////////////////////////////////////////////////////////////////////
+Vector2::Vector2() {
+ x = y = 0.0f;
+}
+
+//////////////////////////////////////////////////////////////////////////
+Vector2::Vector2(float x, float y) {
+ this->x = x;
+ this->y = y;
+}
+
+//////////////////////////////////////////////////////////////////////////
+Vector2::~Vector2() {
+}
+
+
+//////////////////////////////////////////////////////////////////////////
+float Vector2::Length() const {
+ return sqrt(x * x + y * y);
+}
+
+} // end of namespace WinterMute
diff --git a/engines/wintermute/math/Vector2.h b/engines/wintermute/math/Vector2.h
new file mode 100644
index 0000000000..aa3fe5aa86
--- /dev/null
+++ b/engines/wintermute/math/Vector2.h
@@ -0,0 +1,75 @@
+/* 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.
+ *
+ */
+
+/*
+ * This file is based on WME Lite.
+ * http://dead-code.org/redir.php?target=wmelite
+ * Copyright (c) 2011 Jan Nedoma
+ */
+
+#ifndef WINTERMUTE_VECTOR2_H
+#define WINTERMUTE_VECTOR2_H
+
+namespace WinterMute {
+
+class Vector2 {
+public:
+ Vector2();
+ Vector2(float x, float y);
+ ~Vector2();
+
+ float Length() const;
+
+ inline Vector2 &operator= (const Vector2 &other) {
+ x = other.x;
+ y = other.y;
+
+ return *this;
+ }
+
+ inline Vector2 operator+ (const Vector2 &other) const {
+ return Vector2(x + other.x, y + other.y);
+ }
+
+ inline Vector2 operator- (const Vector2 &other) const {
+ return Vector2(x - other.x, y - other.y);
+ }
+
+ inline Vector2 operator* (const float scalar) const {
+ return Vector2(x * scalar, y * scalar);
+ }
+
+ inline Vector2 &operator+= (const Vector2 &other) {
+ x += other.x;
+ y += other.y;
+
+ return *this;
+ }
+
+
+ float x;
+ float y;
+};
+
+} // end of namespace WinterMute
+
+#endif // WINTERMUTE_VECTOR2_H