Adding code x2

This commit is contained in:
2023-12-26 21:29:05 -06:00
parent d9bd070fd1
commit f90f1cf40b
25 changed files with 188 additions and 88 deletions

View File

@@ -0,0 +1 @@
#include <J3ML/LinearAlgebra/CoordinateFrame.h>

View File

@@ -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) {
}
}

View File

@@ -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() {}
}

View File

@@ -0,0 +1,3 @@
//
// Created by josh on 12/26/2023.
//

View File

@@ -0,0 +1,3 @@
//
// Created by josh on 12/26/2023.
//

View File

@@ -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
}

View File

@@ -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)
{