Adding code x2
This commit is contained in:
@@ -4,11 +4,8 @@
|
||||
#include <cstdlib>
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
// TODO: Make GLM redundant, and remove it thereafter.
|
||||
|
||||
|
||||
// TODO: SIMD operations for fast math (parallelization!!)
|
||||
|
||||
namespace Math
|
||||
{
|
||||
const float Pi = M_PI;
|
||||
|
@@ -1,8 +1,10 @@
|
||||
//
|
||||
// Created by josh on 12/25/2023.
|
||||
//
|
||||
#pragma once
|
||||
|
||||
#ifndef J3ML_ANGLE2D_H
|
||||
#define J3ML_ANGLE2D_H
|
||||
#include <J3ML/LinearAlgebra.h>
|
||||
|
||||
#endif //J3ML_ANGLE2D_H
|
||||
namespace LinearAlgebra {
|
||||
class Angle2D {
|
||||
public:
|
||||
|
||||
};
|
||||
}
|
@@ -1,5 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <J3ML/LinearAlgebra.h>
|
||||
#include <J3ML/LinearAlgebra/Vector3.h>
|
||||
|
||||
namespace LinearAlgebra
|
||||
{
|
||||
|
@@ -1,5 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <J3ML/LinearAlgebra.h>
|
||||
|
||||
namespace LinearAlgebra
|
||||
{
|
||||
/// The CFrame is fundamentally 4 vectors (position, forward, right, up vector)
|
||||
|
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <J3ML/LinearAlgebra.h>
|
||||
#include <J3ML/LinearAlgebra/Vector2.h>
|
||||
|
||||
namespace LinearAlgebra {
|
||||
|
@@ -1,6 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <J3ML/LinearAlgebra.h>
|
||||
#include <J3ML/LinearAlgebra/Vector2.h>
|
||||
#include <J3ML/LinearAlgebra/Vector3.h>
|
||||
#include <J3ML/LinearAlgebra/Quaternion.h>
|
||||
|
||||
namespace LinearAlgebra {
|
||||
/// A 3-by-3 matrix for linear transformations of 3D geometry.
|
||||
|
@@ -1,5 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <J3ML/LinearAlgebra.h>
|
||||
|
||||
|
||||
|
||||
namespace LinearAlgebra {
|
||||
/// A 4-by-4 matrix for affine transformations and perspective projections of 3D geometry.
|
||||
|
@@ -1,15 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#include <J3ML/LinearAlgebra.h>
|
||||
|
||||
namespace LinearAlgebra
|
||||
{
|
||||
class Quaternion : public Vector4
|
||||
class Quaternion
|
||||
{
|
||||
public:
|
||||
Quaternion() {}
|
||||
Quaternion();
|
||||
Quaternion(const Quaternion& rhs) = default;
|
||||
explicit Quaternion(Matrix3x3& rotationMtrx) {}
|
||||
explicit Quaternion(Matrix4x4& rotationMtrx) {}
|
||||
explicit Quaternion(const Matrix3x3& rotationMtrx);
|
||||
explicit Quaternion(const Matrix4x4& rotationMtrx);
|
||||
// @note The input data is not normalized after construction, this has to be done manually.
|
||||
Quaternion(float x, float y, float z, float w);
|
||||
// Constructs this quaternion by specifying a rotation axis and the amount of rotation to be performed about that axis
|
||||
@@ -20,47 +21,23 @@ namespace LinearAlgebra
|
||||
Quaternion Inverse() const;
|
||||
//void Normalize();
|
||||
Quaternion Normalize() const;
|
||||
Vector3 GetWorldX() const { return Transform(1.f, 0.f, 0.f); }
|
||||
Vector3 GetWorldY() const { return Transform(0.f, 1.f, 0.f); }
|
||||
Vector3 GetWorldZ() const { return Transform(0.f, 0.f, 1.f); }
|
||||
Vector3 GetWorldX() const;
|
||||
Vector3 GetWorldY() const;
|
||||
Vector3 GetWorldZ() const;
|
||||
|
||||
Matrix3x3 ToMatrix3x3() const;
|
||||
|
||||
Vector3 Transform(const Vector3& vec) const
|
||||
{
|
||||
Matrix3x3 mat = this->ToMatrix3x3();
|
||||
return mat * vec;
|
||||
}
|
||||
Vector3 Transform(float X, float Y, float Z) const
|
||||
{
|
||||
return Transform(Vector3{X, Y, Z});
|
||||
}
|
||||
Vector3 Transform(const Vector3& vec) const;
|
||||
Vector3 Transform(float X, float Y, float Z) const;
|
||||
// Note: We only transform the x,y,z components of 4D vectors, w is left untouched
|
||||
Vector4 Transform(const Vector4& vec) const
|
||||
{
|
||||
return Vector4(Transform(vec.x, vec.y, vec.z), vec.w);
|
||||
}
|
||||
Vector4 Transform(float X, float Y, float Z, float W) const
|
||||
{
|
||||
return Transform(Vector4(X, Y, Z, W));
|
||||
}
|
||||
Vector4 Transform(const Vector4& vec) const;
|
||||
Vector4 Transform(float X, float Y, float Z, float W) const;
|
||||
|
||||
Quaternion GetInverse() const;
|
||||
Quaternion Lerp(const Quaternion& b, float t) const
|
||||
{
|
||||
float angle = this->dot(b);
|
||||
if (angle >= 0.f) // Make sure we rotate the shorter arc
|
||||
return (*this * (1.f - t) + b * t).Normalize();
|
||||
else
|
||||
return (*this * (t - 1.f) + b * t).Normalize();
|
||||
}
|
||||
Quaternion Lerp(const Quaternion& b, float t) const;
|
||||
Quaternion Slerp(const Quaternion& target) const;
|
||||
|
||||
void SetFromAxisAngle(const Vector3& axis, float angle)
|
||||
{
|
||||
float sinz, cosz;
|
||||
|
||||
}
|
||||
void SetFromAxisAngle(const Vector3& axis, float angle);
|
||||
|
||||
void SetFromAxisAngle(const Vector4& axis, float angle)
|
||||
{
|
||||
@@ -75,10 +52,7 @@ namespace LinearAlgebra
|
||||
// The rotation q2 is applied first before q1.
|
||||
Quaternion operator * (const Quaternion& rhs) const;
|
||||
|
||||
Quaternion operator * (float scalar) const
|
||||
{
|
||||
return Quaternion(x * scalar, y * scalar, z * scalar, w * scalar);
|
||||
}
|
||||
Quaternion operator * (float scalar) const;
|
||||
|
||||
// Transforms the given vector by this Quaternion.
|
||||
Vector3 operator * (const Vector3& rhs) const;
|
||||
@@ -87,7 +61,12 @@ namespace LinearAlgebra
|
||||
// Divides a quaternion by another. Divison "a / b" results in a quaternion that rotates the orientation b to coincide with orientation of
|
||||
Quaternion operator / (const Quaternion& rhs) const;
|
||||
Quaternion operator +(const Quaternion& rhs) const;
|
||||
Quaternion operator +() const { return *this; }
|
||||
Quaternion operator +() const;
|
||||
Quaternion operator -() const;
|
||||
public:
|
||||
float x = 0;
|
||||
float y = 0;
|
||||
float z = 0;
|
||||
float w = 0;
|
||||
};
|
||||
}
|
@@ -1,13 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
class Transform2D {
|
||||
protected:
|
||||
Matrix3x3 transformation;
|
||||
public:
|
||||
Transform2D Translate(const Vector2& offset) const;
|
||||
Transform2D Translate(float x, float y) const;
|
||||
Transform2D Scale(float scale); // Perform Uniform Scale
|
||||
Transform2D Scale(float x, float y); // Perform Nonunform Scale
|
||||
Transform2D Scale(const Vector2& scales); // Perform Nonuniform Scale
|
||||
Transform2D Rotate();
|
||||
};
|
||||
#include <J3ML/LinearAlgebra.h>
|
||||
#include <J3ML/LinearAlgebra/Matrix3x3.h>
|
||||
|
||||
namespace LinearAlgebra {
|
||||
class Transform2D {
|
||||
protected:
|
||||
Matrix3x3 transformation;
|
||||
public:
|
||||
Transform2D Translate(const Vector2& offset) const;
|
||||
Transform2D Translate(float x, float y) const;
|
||||
Transform2D Scale(float scale); // Perform Uniform Scale
|
||||
Transform2D Scale(float x, float y); // Perform Nonunform Scale
|
||||
Transform2D Scale(const Vector2& scales); // Perform Nonuniform Scale
|
||||
Transform2D Rotate();
|
||||
};
|
||||
}
|
||||
|
||||
|
@@ -1,7 +1,9 @@
|
||||
#include <cstddef>
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <J3ML/LinearAlgebra.h>
|
||||
#include <cstddef>
|
||||
|
||||
|
||||
namespace LinearAlgebra {
|
||||
|
||||
@@ -25,6 +27,7 @@ namespace LinearAlgebra {
|
||||
static const Vector2 Left;
|
||||
static const Vector2 Down;
|
||||
static const Vector2 Right;
|
||||
static const Vector2 NaN;
|
||||
|
||||
float operator[](std::size_t index);
|
||||
|
||||
@@ -126,8 +129,8 @@ namespace LinearAlgebra {
|
||||
float x = 0;
|
||||
float y = 0;
|
||||
#else
|
||||
const float x = 0;
|
||||
const float y = 0;
|
||||
float x = 0;
|
||||
float y = 0;
|
||||
#endif
|
||||
};
|
||||
}
|
@@ -132,9 +132,9 @@ public:
|
||||
float y = 0;
|
||||
float z = 0;
|
||||
#else
|
||||
const float x = 0;
|
||||
const float y = 0;
|
||||
const float z = 0;
|
||||
float x = 0;
|
||||
float y = 0;
|
||||
float z = 0;
|
||||
#endif
|
||||
};
|
||||
}
|
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <J3ML/LinearAlgebra/Vector3.h>
|
||||
#include <J3ML/LinearAlgebra.h>
|
||||
|
||||
|
||||
namespace LinearAlgebra {
|
||||
class Vector4 {
|
||||
@@ -13,9 +14,9 @@ namespace LinearAlgebra {
|
||||
Vector4(float X, float Y, float Z, float W);
|
||||
Vector4(const Vector4& copy) = default;
|
||||
Vector4(Vector4&& move) = default;
|
||||
|
||||
Vector4& operator=(const Vector4& rhs);
|
||||
|
||||
|
||||
float GetX() const;
|
||||
float GetY() const;
|
||||
float GetZ() const;
|
||||
@@ -89,10 +90,10 @@ namespace LinearAlgebra {
|
||||
float z = 0;
|
||||
float w = 0;
|
||||
#else
|
||||
const float x = 0;
|
||||
const float y = 0;
|
||||
const float z = 0;
|
||||
const float w = 0;
|
||||
float x = 0;
|
||||
float y = 0;
|
||||
float z = 0;
|
||||
float w = 0;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
1
src/J3ML/LinearAlgebra/CoordinateFrame.cpp
Normal file
1
src/J3ML/LinearAlgebra/CoordinateFrame.cpp
Normal file
@@ -0,0 +1 @@
|
||||
#include <J3ML/LinearAlgebra/CoordinateFrame.h>
|
@@ -1,4 +1,5 @@
|
||||
#include <J3ML/LinearAlgebra/Matrix3x3.h>
|
||||
#include <cmath>
|
||||
|
||||
namespace LinearAlgebra {
|
||||
|
||||
@@ -95,5 +96,9 @@ namespace LinearAlgebra {
|
||||
this->elems[2][2] = r3.z;
|
||||
}
|
||||
|
||||
Matrix3x3::Matrix3x3(const Quaternion &orientation) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@@ -1,8 +1,59 @@
|
||||
#include <J3ML/LinearAlgebra/Quaternion.h>
|
||||
|
||||
#include <J3ML/LinearAlgebra/Vector3.h>
|
||||
|
||||
|
||||
namespace LinearAlgebra {
|
||||
Quaternion Quaternion::operator-() const
|
||||
{
|
||||
return {-x, -y, -z, -w};
|
||||
}
|
||||
|
||||
Quaternion::Quaternion(const Matrix3x3 &rotationMtrx) {}
|
||||
|
||||
Quaternion::Quaternion(const Matrix4x4 &rotationMtrx) {}
|
||||
|
||||
Vector3 Quaternion::GetWorldX() const { return Transform(1.f, 0.f, 0.f); }
|
||||
|
||||
Vector3 Quaternion::GetWorldY() const { return Transform(0.f, 1.f, 0.f); }
|
||||
|
||||
Vector3 Quaternion::GetWorldZ() const { return Transform(0.f, 0.f, 1.f); }
|
||||
|
||||
Vector3 Quaternion::Transform(const Vector3 &vec) const {
|
||||
Matrix3x3 mat = this->ToMatrix3x3();
|
||||
return mat * vec;
|
||||
}
|
||||
|
||||
Vector3 Quaternion::Transform(float X, float Y, float Z) const {
|
||||
return Transform(Vector3{X, Y, Z});
|
||||
}
|
||||
|
||||
Vector4 Quaternion::Transform(const Vector4 &vec) const {
|
||||
return Vector4(Transform(vec.x, vec.y, vec.z), vec.w);
|
||||
}
|
||||
|
||||
Vector4 Quaternion::Transform(float X, float Y, float Z, float W) const {
|
||||
return Transform(Vector4(X, Y, Z, W));
|
||||
}
|
||||
|
||||
Quaternion Quaternion::Lerp(const Quaternion &b, float t) const {
|
||||
float angle = this->Dot(b);
|
||||
if (angle >= 0.f) // Make sure we rotate the shorter arc
|
||||
return (*this * (1.f - t) + b * t).Normalize();
|
||||
else
|
||||
return (*this * (t - 1.f) + b * t).Normalize();
|
||||
}
|
||||
|
||||
void Quaternion::SetFromAxisAngle(const Vector3 &axis, float angle) {
|
||||
float sinz, cosz;
|
||||
|
||||
}
|
||||
|
||||
Quaternion Quaternion::operator*(float scalar) const {
|
||||
return Quaternion(x * scalar, y * scalar, z * scalar, w * scalar);
|
||||
}
|
||||
|
||||
Quaternion Quaternion::operator+() const { return *this; }
|
||||
|
||||
Quaternion::Quaternion() {}
|
||||
}
|
3
src/J3ML/LinearAlgebra/Transform2D.cpp
Normal file
3
src/J3ML/LinearAlgebra/Transform2D.cpp
Normal file
@@ -0,0 +1,3 @@
|
||||
//
|
||||
// Created by josh on 12/26/2023.
|
||||
//
|
3
src/J3ML/LinearAlgebra/Transform3D.cpp
Normal file
3
src/J3ML/LinearAlgebra/Transform3D.cpp
Normal file
@@ -0,0 +1,3 @@
|
||||
//
|
||||
// Created by josh on 12/26/2023.
|
||||
//
|
@@ -1,11 +1,11 @@
|
||||
#include <J3ML/LinearAlgebra/Vector2.h>
|
||||
#include <cassert>
|
||||
#include <algorithm>
|
||||
#include <valarray>
|
||||
|
||||
namespace LinearAlgebra {
|
||||
|
||||
|
||||
|
||||
#pragma region vector2
|
||||
|
||||
Vector2::Vector2(): x(0), y(0)
|
||||
{}
|
||||
|
||||
@@ -158,6 +158,7 @@ const Vector2 Vector2::Up = {0, -1};
|
||||
const Vector2 Vector2::Down = {0, 1};
|
||||
const Vector2 Vector2::Left = {-1, 0};
|
||||
const Vector2 Vector2::Right = {1, 0};
|
||||
const Vector2 Vector2::NaN = {NAN, NAN};
|
||||
|
||||
float Vector2::GetX() const { return x; }
|
||||
|
||||
@@ -171,5 +172,5 @@ const Vector2 Vector2::Right = {1, 0};
|
||||
|
||||
float Vector2::Length(const Vector2 &of) { return of.Length(); }
|
||||
|
||||
#pragma endregion
|
||||
|
||||
}
|
@@ -1,6 +1,7 @@
|
||||
#include <J3ML/LinearAlgebra/Vector3.h>
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <cmath>
|
||||
|
||||
namespace LinearAlgebra {
|
||||
|
||||
@@ -55,18 +56,11 @@ namespace LinearAlgebra {
|
||||
|
||||
|
||||
|
||||
Vector3::Vector3(): x(0), y(0), z(0)
|
||||
{}
|
||||
Vector3::Vector3(): x(0), y(0), z(0) {}
|
||||
|
||||
Vector3::Vector3(float X, float Y, float Z): x(X), y(Y), z(Z)
|
||||
{}
|
||||
Vector3::Vector3(float X, float Y, float Z): x(X), y(Y), z(Z) {}
|
||||
|
||||
Vector3::Vector3(const Vector3& rhs)
|
||||
{
|
||||
this->x = rhs.x;
|
||||
this->y = rhs.y;
|
||||
this->z = rhs.z;
|
||||
}
|
||||
Vector3::Vector3(const Vector3& rhs) : x(rhs.x), y(rhs.y), z(rhs.z) {}
|
||||
|
||||
Vector3& Vector3::operator=(const Vector3& rhs)
|
||||
{
|
||||
|
3
tests/LinearAlgebra/EulerAngleTests.cpp
Normal file
3
tests/LinearAlgebra/EulerAngleTests.cpp
Normal file
@@ -0,0 +1,3 @@
|
||||
//
|
||||
// Created by josh on 12/26/2023.
|
||||
//
|
3
tests/LinearAlgebra/Matrix2x2Tests.cpp
Normal file
3
tests/LinearAlgebra/Matrix2x2Tests.cpp
Normal file
@@ -0,0 +1,3 @@
|
||||
//
|
||||
// Created by josh on 12/26/2023.
|
||||
//
|
3
tests/LinearAlgebra/QuaternionTests.cpp
Normal file
3
tests/LinearAlgebra/QuaternionTests.cpp
Normal file
@@ -0,0 +1,3 @@
|
||||
//
|
||||
// Created by josh on 12/26/2023.
|
||||
//
|
28
tests/LinearAlgebra/Vector2Tests.cpp
Normal file
28
tests/LinearAlgebra/Vector2Tests.cpp
Normal file
@@ -0,0 +1,28 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <J3ML/LinearAlgebra/Vector2.h>
|
||||
|
||||
|
||||
TEST(Vector2Test, V2_Constructor_Default) { }
|
||||
TEST(Vector2Test, V2_Addition) { }
|
||||
TEST(Vector2Test, V2_Subtraction) { }
|
||||
TEST(Vector2Test, V2_Multiplication) { }
|
||||
TEST(Vector2Test, V2_Division) { }
|
||||
TEST(Vector2Test, V2_Equality) { }
|
||||
TEST(Vector2Test, V2_Array_Operator_Indexing) { }
|
||||
|
||||
|
||||
TEST(Vector2Test, V2_Normalize)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
TEST(Vector2Test, V2_Dot)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
TEST(Vector2Test, V2_Min) { }
|
||||
TEST(Vector2Test, V2_Max) { }
|
||||
TEST(Vector2Test, V2_Distance) { }
|
||||
TEST(Vector2Test, V2_Length) { }
|
||||
TEST(Vector2Test, V2_Clamp) { }
|
3
tests/LinearAlgebra/Vector3Tests.cpp
Normal file
3
tests/LinearAlgebra/Vector3Tests.cpp
Normal file
@@ -0,0 +1,3 @@
|
||||
//
|
||||
// Created by josh on 12/26/2023.
|
||||
//
|
3
tests/LinearAlgebra/Vector4Tests.cpp
Normal file
3
tests/LinearAlgebra/Vector4Tests.cpp
Normal file
@@ -0,0 +1,3 @@
|
||||
//
|
||||
// Created by josh on 12/26/2023.
|
||||
//
|
Reference in New Issue
Block a user