summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibGfx
diff options
context:
space:
mode:
authorJelle Raaijmakers <jelle@gmta.nl>2021-12-30 00:18:57 +0100
committerAndreas Kling <kling@serenityos.org>2021-12-30 14:24:29 +0100
commit57e1dc776558bc62067f9e027a00ba2f13229fad (patch)
tree12bb2c8fd189795a171b97ee6957dc891ba8be16 /Userland/Libraries/LibGfx
parent9bc8587c0d992699ad2360ef12c71a4175b79f47 (diff)
downloadserenity-57e1dc776558bc62067f9e027a00ba2f13229fad.zip
LibGfx: Add `Matrix3x3`
This defines `Matrix3x3`, `FloatMatrix3x3` and `DoubleMatrix3x3` mirroring `Matrix4x4`. Since we will need matrix multiplication with a `Vector3` for LibGL's normalization, we also add that `*` operator.
Diffstat (limited to 'Userland/Libraries/LibGfx')
-rw-r--r--Userland/Libraries/LibGfx/Matrix3x3.h33
1 files changed, 33 insertions, 0 deletions
diff --git a/Userland/Libraries/LibGfx/Matrix3x3.h b/Userland/Libraries/LibGfx/Matrix3x3.h
new file mode 100644
index 0000000000..2f97714b48
--- /dev/null
+++ b/Userland/Libraries/LibGfx/Matrix3x3.h
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2021, Jelle Raaijmakers <jelle@gmta.nl>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#pragma once
+
+#include <LibGfx/Matrix.h>
+#include <LibGfx/Vector3.h>
+
+namespace Gfx {
+
+template<typename T>
+using Matrix3x3 = Matrix<3, T>;
+
+template<typename T>
+constexpr static Vector3<T> operator*(Matrix3x3<T> const& m, Vector3<T> const& v)
+{
+ auto const& elements = m.elements();
+ return Vector3<T>(
+ v.x() * elements[0][0] + v.y() * elements[0][1] + v.z() * elements[0][2],
+ v.x() * elements[1][0] + v.y() * elements[1][1] + v.z() * elements[1][2],
+ v.x() * elements[2][0] + v.y() * elements[2][1] + v.z() * elements[2][2]);
+}
+
+typedef Matrix3x3<float> FloatMatrix3x3;
+typedef Matrix3x3<double> DoubleMatrix3x3;
+}
+
+using Gfx::DoubleMatrix3x3;
+using Gfx::FloatMatrix3x3;
+using Gfx::Matrix3x3;