summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibGfx/Matrix4x4.h
diff options
context:
space:
mode:
authorStephan Unverwerth <s.unverwerth@gmx.de>2021-04-18 16:25:25 +0200
committerAndreas Kling <kling@serenityos.org>2021-05-08 10:13:22 +0200
commit09f850728a728b1fd211ec30153dc51bcc83725e (patch)
tree0ff9d19b2405efff4b526139888f4eab54f1f5b0 /Userland/Libraries/LibGfx/Matrix4x4.h
parent0c5d61ae8834763a4d56fe047df0cca137b254dc (diff)
downloadserenity-09f850728a728b1fd211ec30153dc51bcc83725e.zip
LibGfx: Add some missing operators to Vector3 Vector4 and Matrix4x4
Diffstat (limited to 'Userland/Libraries/LibGfx/Matrix4x4.h')
-rw-r--r--Userland/Libraries/LibGfx/Matrix4x4.h19
1 files changed, 19 insertions, 0 deletions
diff --git a/Userland/Libraries/LibGfx/Matrix4x4.h b/Userland/Libraries/LibGfx/Matrix4x4.h
index 16f927d3ce..c1ebdfaaa5 100644
--- a/Userland/Libraries/LibGfx/Matrix4x4.h
+++ b/Userland/Libraries/LibGfx/Matrix4x4.h
@@ -8,6 +8,7 @@
#include <LibGfx/Matrix.h>
#include <LibGfx/Vector3.h>
+#include <LibGfx/Vector4.h>
#include <math.h>
namespace Gfx {
@@ -46,6 +47,15 @@ public:
return product;
}
+ Vector4<T> operator*(const Vector4<T>& v) const
+ {
+ return Vector4<T>(
+ v.x() * m_elements[0][0] + v.y() * m_elements[1][0] + v.z() * m_elements[2][0] + v.w() * m_elements[3][0],
+ v.x() * m_elements[0][1] + v.y() * m_elements[1][1] + v.z() * m_elements[2][1] + v.w() * m_elements[3][1],
+ v.x() * m_elements[0][2] + v.y() * m_elements[1][2] + v.z() * m_elements[2][2] + v.w() * m_elements[3][2],
+ v.x() * m_elements[0][3] + v.y() * m_elements[1][3] + v.z() * m_elements[2][3] + v.w() * m_elements[3][3]);
+ }
+
Vector3<T> transform_point(const Vector3<T>& p) const
{
return Vector3<T>(
@@ -54,6 +64,15 @@ public:
p.x() * m_elements[0][2] + p.y() * m_elements[1][2] + p.z() * m_elements[2][2] + m_elements[3][2]);
}
+ static Matrix4x4 identity()
+ {
+ return Matrix4x4(
+ 1, 0, 0, 0,
+ 0, 1, 0, 0,
+ 0, 0, 1, 0,
+ 0, 0, 0, 1);
+ }
+
static Matrix4x4 translate(const Vector3<T>& p)
{
return Matrix4x4(