Skip to content
Permalink
Browse files

Common: Add additional Matrix/Vec functions.

  • Loading branch information
jordan-woyak committed Nov 6, 2019
1 parent d8c62b5 commit 1e028025e506e4bff1f8063c2b55e5356a05a330
Showing with 23 additions and 0 deletions.
  1. +17 −0 Source/Core/Common/Matrix.cpp
  2. +6 −0 Source/Core/Common/Matrix.h
@@ -84,6 +84,23 @@ Matrix33 Matrix33::RotateZ(float rad)
return mtx;
}

Matrix33 Matrix33::Rotate(float rad, const Vec3& axis)
{
const float s = std::sin(rad);
const float c = std::cos(rad);
Matrix33 mtx;
mtx.data[0] = axis.x * axis.x * (1 - c) + c;
mtx.data[1] = axis.x * axis.y * (1 - c) - axis.z * s;
mtx.data[2] = axis.x * axis.z * (1 - c) + axis.y * s;
mtx.data[3] = axis.y * axis.x * (1 - c) + axis.z * s;
mtx.data[4] = axis.y * axis.y * (1 - c) + c;
mtx.data[5] = axis.y * axis.z * (1 - c) - axis.x * s;
mtx.data[6] = axis.z * axis.x * (1 - c) - axis.y * s;
mtx.data[7] = axis.z * axis.y * (1 - c) + axis.x * s;
mtx.data[8] = axis.z * axis.z * (1 - c) + c;
return mtx;
}

Matrix33 Matrix33::Scale(const Vec3& vec)
{
Matrix33 mtx = {};
@@ -20,6 +20,10 @@ union TVec3
TVec3() = default;
TVec3(T _x, T _y, T _z) : data{_x, _y, _z} {}

TVec3 Cross(const TVec3& rhs) const
{
return {(y * rhs.z) - (rhs.y * z), (z * rhs.x) - (rhs.z * x), (x * rhs.y) - (rhs.x * y)};
}
T Dot(const TVec3& other) const { return x * other.x + y * other.y + z * other.z; }
T LengthSquared() const { return Dot(*this); }
T Length() const { return std::sqrt(LengthSquared()); }
@@ -275,6 +279,8 @@ class Matrix33
static Matrix33 RotateY(float rad);
static Matrix33 RotateZ(float rad);

static Matrix33 Rotate(float rad, const Vec3& axis);

static Matrix33 Scale(const Vec3& vec);

// set result = a x b

0 comments on commit 1e02802

Please sign in to comment.
You can’t perform that action at this time.