mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 11:57:35 +00:00
LibGfx: Add some missing operators to Vector3 Vector4 and Matrix4x4
This commit is contained in:
parent
0c5d61ae88
commit
09f850728a
3 changed files with 53 additions and 0 deletions
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
#include <LibGfx/Matrix.h>
|
#include <LibGfx/Matrix.h>
|
||||||
#include <LibGfx/Vector3.h>
|
#include <LibGfx/Vector3.h>
|
||||||
|
#include <LibGfx/Vector4.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
namespace Gfx {
|
namespace Gfx {
|
||||||
|
@ -46,6 +47,15 @@ public:
|
||||||
return product;
|
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
|
Vector3<T> transform_point(const Vector3<T>& p) const
|
||||||
{
|
{
|
||||||
return Vector3<T>(
|
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]);
|
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)
|
static Matrix4x4 translate(const Vector3<T>& p)
|
||||||
{
|
{
|
||||||
return Matrix4x4(
|
return Matrix4x4(
|
||||||
|
|
|
@ -28,6 +28,22 @@ public:
|
||||||
void set_y(T value) { m_y = value; }
|
void set_y(T value) { m_y = value; }
|
||||||
void set_z(T value) { m_z = value; }
|
void set_z(T value) { m_z = value; }
|
||||||
|
|
||||||
|
Vector3& operator+=(const Vector3& other)
|
||||||
|
{
|
||||||
|
m_x += other.m_x;
|
||||||
|
m_y += other.m_y;
|
||||||
|
m_z += other.m_z;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector3& operator-=(const Vector3& other)
|
||||||
|
{
|
||||||
|
m_x -= other.m_x;
|
||||||
|
m_y -= other.m_y;
|
||||||
|
m_z -= other.m_z;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
Vector3 operator+(const Vector3& other) const
|
Vector3 operator+(const Vector3& other) const
|
||||||
{
|
{
|
||||||
return Vector3(m_x + other.m_x, m_y + other.m_y, m_z + other.m_z);
|
return Vector3(m_x + other.m_x, m_y + other.m_y, m_z + other.m_z);
|
||||||
|
|
|
@ -31,6 +31,24 @@ public:
|
||||||
void set_z(T value) { m_z = value; }
|
void set_z(T value) { m_z = value; }
|
||||||
void set_w(T value) { m_w = value; }
|
void set_w(T value) { m_w = value; }
|
||||||
|
|
||||||
|
Vector4& operator+=(const Vector4& other)
|
||||||
|
{
|
||||||
|
m_x += other.m_x;
|
||||||
|
m_y += other.m_y;
|
||||||
|
m_z += other.m_z;
|
||||||
|
m_w += other.m_w;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector4& operator-=(const Vector4& other)
|
||||||
|
{
|
||||||
|
m_x -= other.m_x;
|
||||||
|
m_y -= other.m_y;
|
||||||
|
m_z -= other.m_z;
|
||||||
|
m_w -= other.m_w;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
Vector4 operator+(const Vector4& other) const
|
Vector4 operator+(const Vector4& other) const
|
||||||
{
|
{
|
||||||
return Vector4(m_x + other.m_x, m_y + other.m_y, m_z + other.m_z, m_w + other.m_w);
|
return Vector4(m_x + other.m_x, m_y + other.m_y, m_z + other.m_z, m_w + other.m_w);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue