[Scummvm-git-logs] scummvm master -> 3d84e3eb75dabce6d04537cd132c0a1637e227a3
aquadran
aquadran at gmail.com
Sun Mar 28 22:04:52 UTC 2021
This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
3d84e3eb75 MATH: Extend matrix operators. Added getXYZ() for vector4.
Commit: 3d84e3eb75dabce6d04537cd132c0a1637e227a3
https://github.com/scummvm/scummvm/commit/3d84e3eb75dabce6d04537cd132c0a1637e227a3
Author: PaweÅ KoÅodziejski (aquadran at gmail.com)
Date: 2021-03-29T00:04:46+02:00
Commit Message:
MATH: Extend matrix operators. Added getXYZ() for vector4.
Changed paths:
math/matrix.h
math/vector4d.cpp
math/vector4d.h
diff --git a/math/matrix.h b/math/matrix.h
index 6813858d8a..eb53d5ccbe 100644
--- a/math/matrix.h
+++ b/math/matrix.h
@@ -131,13 +131,17 @@ public:
static Matrix<rows, cols> sum(const Matrix<rows, cols> &m1, const Matrix<rows, cols> &m2);
static Matrix<rows, cols> difference(const Matrix<rows, cols> &m1, const Matrix<rows, cols> &m2);
static Matrix<rows, cols> product(const Matrix<rows, cols> &m1, float factor);
+ static Matrix<rows, cols> product(const Matrix<rows, cols> &m1, const Matrix<rows, cols> &m2);
static Matrix<rows, cols> quotient(const Matrix<rows, cols> &m1, float factor);
+ static Matrix<rows, cols> quotient(const Matrix<rows, cols> &m1, const Matrix<rows, cols> &m2);
Matrix<rows, cols> &operator=(const Matrix<rows, cols> &m);
Matrix<rows, cols> &operator+=(const Matrix<rows, cols> &m);
Matrix<rows, cols> &operator-=(const Matrix<rows, cols> &m);
Matrix<rows, cols> &operator*=(float factor);
+ Matrix<rows, cols> &operator*=(const Matrix<rows, cols> &m);
Matrix<rows, cols> &operator/=(float factor);
+ Matrix<rows, cols> &operator/=(const Matrix<rows, cols> &m);
protected:
MatrixBase();
@@ -312,6 +316,15 @@ Matrix<r, c> MatrixBase<r, c>::product(const Matrix<r, c> &m1, float factor) {
return result;
}
+template <int r, int c>
+Matrix<r, c> MatrixBase<r, c>::product(const Matrix<r, c> &m1, const Matrix<r, c> &m2) {
+ Matrix<r, c> result;
+ for (int i = 0; i < r * c; ++i) {
+ result._values[i] = m1._values[i] * m2._values[i];
+ }
+ return result;
+}
+
template <int r, int c>
Matrix<r, c> MatrixBase<r, c>::quotient(const Matrix<r, c> &m1, float factor) {
Matrix<r, c> result;
@@ -321,6 +334,14 @@ Matrix<r, c> MatrixBase<r, c>::quotient(const Matrix<r, c> &m1, float factor) {
return result;
}
+template <int r, int c>
+Matrix<r, c> MatrixBase<r, c>::quotient(const Matrix<r, c> &m1, const Matrix<r, c> &m2) {
+ Matrix<r, c> result;
+ for (int i = 0; i < r * c; ++i) {
+ result._values[i] = m1._values[i] / m2._values[i];
+ }
+ return result;
+}
@@ -427,11 +448,21 @@ inline Matrix<r, c> operator-(const Matrix<r, c> &m1, const Matrix<r, c> &m2) {
return Matrix<r, c>::difference(m1, m2);
}
+template <int r, int c>
+inline Matrix<r, c> operator*(const Matrix<r, c> &m1, const Matrix<r, c> &m2) {
+ return Matrix<r, c>::product(m1, m2);
+}
+
template <int r, int c>
inline Matrix<r, c> operator*(const Matrix<r, c> &m1, float factor) {
return Matrix<r, c>::product(m1, factor);
}
+template <int r, int c>
+inline Matrix<r, c> operator/(const Matrix<r, c> &m1, const Matrix<r, c> &m2) {
+ return Matrix<r, c>::quotient(m1, m2);
+}
+
template <int r, int c>
inline Matrix<r, c> operator/(const Matrix<r, c> &m1, float factor) {
return Matrix<r, c>::quotient(m1, factor);
diff --git a/math/vector4d.cpp b/math/vector4d.cpp
index 0bc9a47550..10357fd8a3 100644
--- a/math/vector4d.cpp
+++ b/math/vector4d.cpp
@@ -21,6 +21,7 @@
*/
#include "common/streamdebug.h"
+#include "math/vector3d.h"
#include "math/vector4d.h"
namespace Math {
@@ -50,4 +51,9 @@ void Vector4d::set(float lx, float ly, float lz, float lw) {
x() = lx; y() = ly; z() = lz; w() = lw;
}
+Vector3d Vector4d::getXYZ() const {
+ Vector3d v(value(0), value(1), value(2));
+ return v;
+}
+
} // end of namespace Math
diff --git a/math/vector4d.h b/math/vector4d.h
index e369cf0d74..677f5586ee 100644
--- a/math/vector4d.h
+++ b/math/vector4d.h
@@ -27,6 +27,7 @@
#include "common/endian.h"
#include "math/vector.h"
+#include "math/vector3d.h"
#include "math/angle.h"
namespace Math {
@@ -51,7 +52,7 @@ public:
Matrix(const float *data);
void set(float lx, float ly, float lz, float lw);
-
+ Vector3d getXYZ() const;
};
} // end of namespace Math
More information about the Scummvm-git-logs
mailing list