1
0
forked from josh/j3ml

Implement J3ML Namespace

This commit is contained in:
2024-02-02 13:53:23 -05:00
parent d37b685df9
commit 9a5f12e505
45 changed files with 108 additions and 99 deletions

View File

@@ -3,9 +3,9 @@
#pragma once
namespace Geometry {
using Vector2 = LinearAlgebra::Vector2;
using Vector3 = LinearAlgebra::Vector3;
namespace J3ML::Geometry {
using Vector2 = J3ML::LinearAlgebra::Vector2;
using Vector3 = J3ML::LinearAlgebra::Vector3;
class LineSegment2D
{

View File

@@ -22,7 +22,7 @@
namespace Geometry
namespace J3ML::Geometry
{
using namespace LinearAlgebra;

View File

@@ -2,7 +2,7 @@
#include <J3ML/LinearAlgebra/Vector2.h>
namespace Geometry
namespace J3ML::Geometry
{
using LinearAlgebra::Vector2;
// CaveGame AABB

View File

@@ -3,7 +3,7 @@
#include "LineSegment.h"
#include <J3ML/LinearAlgebra/Vector3.h>
namespace Geometry
namespace J3ML::Geometry
{
using namespace LinearAlgebra;
class Capsule

View File

@@ -6,9 +6,11 @@
#include "Plane.h"
#include <J3ML/LinearAlgebra/CoordinateFrame.h>
namespace Geometry
namespace J3ML::Geometry
{
using J3ML::LinearAlgebra::CoordinateFrame;
enum class FrustumType
{
Invalid,

View File

@@ -2,7 +2,7 @@
#include <J3ML/LinearAlgebra/Vector3.h>
namespace Geometry
namespace J3ML::Geometry
{
using LinearAlgebra::Vector3;
class LineSegment

View File

@@ -5,7 +5,7 @@
#include <J3ML/Geometry/LineSegment.h>
#include <J3ML/Geometry/Polyhedron.h>
namespace Geometry {
namespace J3ML::Geometry {
class OBB
{
public:

View File

@@ -1,13 +1,18 @@
#pragma once
#include <J3ML/LinearAlgebra/Vector3.h>
using namespace LinearAlgebra;
class Plane
namespace J3ML::Geometry
{
public:
using J3ML::LinearAlgebra::Vector3;
class Plane
{
public:
Vector3 Position;
Vector3 Normal;
float distance = 0.f;
};
};
}

View File

@@ -1,6 +1,6 @@
#pragma once
namespace Geometry {
namespace J3ML::Geometry {
class Polygon {
};

View File

@@ -1,6 +1,6 @@
#pragma once
namespace Geometry
namespace J3ML::Geometry
{
class Polyhedron {

View File

@@ -5,7 +5,7 @@
#include <J3ML/LinearAlgebra/Vector2.h>
#include "AABB2D.h"
namespace Geometry {
namespace J3ML::Geometry {
using LinearAlgebra::Vector2;

View File

@@ -6,7 +6,7 @@
#include <J3ML/LinearAlgebra/Vector3.h>
namespace Geometry
namespace J3ML::Geometry
{
using LinearAlgebra::Vector3;
class Ray

View File

@@ -2,7 +2,7 @@
#include "J3ML/Geometry.h"
namespace Geometry
namespace J3ML::Geometry
{
class Sphere
{

View File

@@ -1,6 +1,6 @@
#pragma once
namespace Geometry
namespace J3ML::Geometry
{
class Triangle
{

View File

@@ -1,8 +1,10 @@
//
// Created by dawsh on 1/25/24.
//
#pragma once
#ifndef J3ML_TRIANGLE2D_H
#define J3ML_TRIANGLE2D_H
#endif //J3ML_TRIANGLE2D_H
namespace J3ML::Geometry
{
class Shape2D {};
class Triangle2D {
public:
};
}

View File

@@ -1,6 +1,6 @@
#pragma once
namespace Geometry
namespace J3ML::Geometry
{
class TriangleMesh
{

View File

@@ -6,7 +6,7 @@
#include <functional>
namespace Math
namespace J3ML::Math
{
const float Pi = M_PI;
inline float Radians(float degrees) { return degrees * (Pi/180.f); }
@@ -29,7 +29,7 @@ namespace Math
// Dawsh Linear Algebra Library - Everything you need for 3D math
namespace LinearAlgebra {
namespace J3ML::LinearAlgebra {
class Vector2; // A type representing a position in a 2-dimensional coordinate space.
class Vector3; // A type representing a position in a 3-dimensional coordinate space.
class Vector4; // A type representing a position in a 4-dimensional coordinate space.

View File

@@ -2,7 +2,7 @@
#include <J3ML/LinearAlgebra.h>
namespace LinearAlgebra {
namespace J3ML::LinearAlgebra {
class Angle2D {
public:
float x;

View File

@@ -3,7 +3,7 @@
#include <J3ML/LinearAlgebra.h>
#include <J3ML/LinearAlgebra/Vector3.h>
namespace LinearAlgebra
namespace J3ML::LinearAlgebra
{
/// Transitional datatype, not useful for internal representation of rotation

View File

@@ -3,7 +3,7 @@
#include <J3ML/LinearAlgebra.h>
#include <J3ML/LinearAlgebra/Vector3.h>
namespace LinearAlgebra
namespace J3ML::LinearAlgebra
{
/// The CFrame is fundamentally 4 vectors (position, forward, right, up vector)
class CoordinateFrame

View File

@@ -2,7 +2,7 @@
#include <J3ML/LinearAlgebra.h>
#include <J3ML/LinearAlgebra/Vector3.h>
namespace LinearAlgebra {
namespace J3ML::LinearAlgebra {
// Essential Reading:
// http://www.essentialmath.com/GDC2012/GDC2012_JMV_Rotations.pdf

View File

@@ -3,7 +3,7 @@
#include <J3ML/LinearAlgebra.h>
#include <J3ML/LinearAlgebra/Vector2.h>
namespace LinearAlgebra {
namespace J3ML::LinearAlgebra {
class Matrix2x2 {
public:
enum { Rows = 3 };

View File

@@ -5,7 +5,7 @@
#include <J3ML/LinearAlgebra/Vector3.h>
#include <J3ML/LinearAlgebra/Quaternion.h>
namespace LinearAlgebra {
namespace J3ML::LinearAlgebra {
/// A 3-by-3 matrix for linear transformations of 3D geometry.
/* This can represent any kind of linear transformations of 3D geometry, which include
* rotation, scale, shear, mirroring, and orthographic projection.

View File

@@ -3,7 +3,7 @@
#include <J3ML/LinearAlgebra.h>
#include <J3ML/LinearAlgebra/Quaternion.h>
namespace LinearAlgebra {
namespace J3ML::LinearAlgebra {
/// A 4-by-4 matrix for affine transformations and perspective projections of 3D geometry.
/* This matrix can represent the most generic form of transformations for 3D objects,

View File

@@ -6,7 +6,7 @@
#include <J3ML/LinearAlgebra/AxisAngle.h>
#include <J3ML/LinearAlgebra/Matrix3x3.h>
namespace LinearAlgebra
namespace J3ML::LinearAlgebra
{
class Quaternion : public Vector4 {
public:

View File

@@ -3,7 +3,7 @@
#include <J3ML/LinearAlgebra.h>
#include <J3ML/LinearAlgebra/Matrix3x3.h>
namespace LinearAlgebra {
namespace J3ML::LinearAlgebra {
class Transform2D {
protected:
Matrix3x3 transformation;

View File

@@ -3,7 +3,7 @@
#include <J3ML/LinearAlgebra.h>
#include <cstddef>
namespace LinearAlgebra {
namespace J3ML::LinearAlgebra {
using namespace J3ML;

View File

@@ -6,7 +6,7 @@
#include <J3ML/LinearAlgebra/Angle2D.h>
namespace LinearAlgebra {
namespace J3ML::LinearAlgebra {
// A 3D (x, y, z) ordered pair.
class Vector3 {

View File

@@ -3,7 +3,7 @@
#include <J3ML/LinearAlgebra.h>
namespace LinearAlgebra {
namespace J3ML::LinearAlgebra {
class Vector4 {
public:
// Default Constructor

View File

@@ -1,6 +1,6 @@
#include <J3ML/Geometry/Capsule.h>
namespace Geometry
namespace J3ML::Geometry
{
Capsule::Capsule() : l() {}

View File

@@ -1,6 +1,6 @@
#include <J3ML/Geometry/Frustum.h>
namespace Geometry
namespace J3ML::Geometry
{
Frustum Frustum::CreateFrustumFromCamera(const CoordinateFrame &cam, float aspect, float fovY, float zNear, float zFar) {
Frustum frustum;

View File

@@ -1,6 +1,6 @@
#include <J3ML/Geometry/LineSegment.h>
namespace Geometry {
namespace J3ML::Geometry {
LineSegment::LineSegment(const Vector3 &a, const Vector3 &b) : A(a), B(b)
{

View File

@@ -1,6 +1,6 @@
#include <J3ML/LinearAlgebra/AxisAngle.h>
#include <J3ML/LinearAlgebra/Quaternion.h>
namespace LinearAlgebra {
namespace J3ML::LinearAlgebra {
AxisAngle::AxisAngle() : axis(Vector3::Zero) {}

View File

@@ -3,27 +3,26 @@
#include <algorithm>
#pragma region EulerAngle
namespace LinearAlgebra {
EulerAngle::EulerAngle(float pitch, float yaw, float roll): pitch(pitch), yaw(yaw), roll(roll)
{}
namespace J3ML::LinearAlgebra {
EulerAngle::EulerAngle(float pitch, float yaw, float roll): pitch(pitch), yaw(yaw), roll(roll)
{}
float EulerAngle::GetPitch(float pitch_limit) const
{ return std::clamp( std::remainderf(pitch,360.f), -pitch_limit, pitch_limit); }
float EulerAngle::GetPitch(float pitch_limit) const
{ return std::clamp( std::remainderf(pitch,360.f), -pitch_limit, pitch_limit); }
float EulerAngle::GetYaw(float yaw_limit) const
{ return std::clamp(std::remainderf(yaw, 360.f), -yaw_limit, yaw_limit); }
float EulerAngle::GetYaw(float yaw_limit) const
{ return std::clamp(std::remainderf(yaw, 360.f), -yaw_limit, yaw_limit); }
float EulerAngle::GetRoll(float pitch_limit) const
{ return std::clamp( std::remainderf(pitch,360.f), -pitch_limit, pitch_limit); }
float EulerAngle::GetRoll(float pitch_limit) const
{ return std::clamp( std::remainderf(pitch,360.f), -pitch_limit, pitch_limit); }
bool EulerAngle::operator==(const EulerAngle& a) const
{
bool EulerAngle::operator==(const EulerAngle& a) const
{
return (pitch == a.pitch) && (yaw == a.yaw) && (roll == a.roll);
}
}
void EulerAngle::clamp()
{
void EulerAngle::clamp()
{
if (this->pitch > 89.0f)
this->pitch = 89.0f;
if (this->pitch <= -89.0f)
@@ -37,16 +36,16 @@ void EulerAngle::clamp()
this->roll = 0.0;
if (this->roll <= -360.0f)
this->roll = 0.0;
}
}
EulerAngle EulerAngle::movementAngle() const
{
EulerAngle EulerAngle::movementAngle() const
{
EulerAngle a;
a.pitch = (cos(Math::Radians(yaw)) * cos(Math::Radians(pitch)));
a.yaw = -sin(Math::Radians(pitch));
a.roll = (sin(Math::Radians(yaw)) * cos(Math::Radians(pitch)));
return a;
}
}
EulerAngle::EulerAngle() : pitch(0), yaw(0), roll(0) {}
}

View File

@@ -1,6 +1,6 @@
#include <J3ML/LinearAlgebra/Matrix2x2.h>
namespace LinearAlgebra {
namespace J3ML::LinearAlgebra {
Vector2 Matrix2x2::GetRow(int index) const {
float x = this->elems[index][0];

View File

@@ -1,7 +1,7 @@
#include <J3ML/LinearAlgebra/Matrix3x3.h>
#include <cmath>
namespace LinearAlgebra {
namespace J3ML::LinearAlgebra {
const Matrix3x3 Matrix3x3::Zero = Matrix3x3(0, 0, 0, 0, 0, 0, 0, 0, 0);
const Matrix3x3 Matrix3x3::Identity = Matrix3x3(1, 0, 0, 0, 1, 0, 0, 0, 1);

View File

@@ -1,7 +1,7 @@
#include <J3ML/LinearAlgebra/Matrix4x4.h>
#include <J3ML/LinearAlgebra/Vector4.h>
namespace LinearAlgebra {
namespace J3ML::LinearAlgebra {
const Matrix4x4 Matrix4x4::Zero = Matrix4x4(0);
const Matrix4x4 Matrix4x4::Identity = Matrix4x4({1,0,0,0}, {0,1,0,0}, {0,0,1,0}, {0,0,0,1});
const Matrix4x4 Matrix4x4::NaN = Matrix4x4(NAN);

View File

@@ -4,7 +4,7 @@
#include <J3ML/LinearAlgebra/Matrix4x4.h>
#include <J3ML/LinearAlgebra/Quaternion.h>
namespace LinearAlgebra {
namespace J3ML::LinearAlgebra {
Quaternion Quaternion::operator-() const
{
return {-x, -y, -z, -w};

View File

@@ -1,6 +1,6 @@
#include <J3ML/LinearAlgebra/Transform2D.h>
namespace LinearAlgebra {
namespace J3ML::LinearAlgebra {
const Transform2D Transform2D::Identity = Transform2D({0, 0}, {1, 1}, {0,0}, {0,0}, 0);
const Transform2D Transform2D::FlipX = Transform2D({0, 0}, {-1, 1}, {0,0}, {0,0}, 0);

View File

@@ -4,7 +4,7 @@
#include <valarray>
#include <iostream>
namespace LinearAlgebra {
namespace J3ML::LinearAlgebra {
Vector2::Vector2(): x(0), y(0)
{}

View File

@@ -3,9 +3,9 @@
#include <cassert>
#include <cmath>
namespace LinearAlgebra {
namespace J3ML::LinearAlgebra {
#pragma region vector3
const Vector3 Vector3::Zero = {0,0,0};
const Vector3 Vector3::Up = {0, -1, 0};
@@ -308,5 +308,5 @@ namespace LinearAlgebra {
return {x, y, z};
}
#pragma endregion
}

View File

@@ -7,7 +7,7 @@
#include <cmath>
#include <algorithm>
namespace LinearAlgebra {
namespace J3ML::LinearAlgebra {
const Vector4 Vector4::Zero = {0,0,0,0};
const Vector4 Vector4::NaN = {NAN, NAN, NAN, NAN};

View File

@@ -1,7 +1,7 @@
#include <gtest/gtest.h>
#include <J3ML/LinearAlgebra/Vector2.h>
using Vector2 = LinearAlgebra::Vector2;
using J3ML::LinearAlgebra::Vector2;
TEST(Vector2Test, V2_Constructor_Default)
{

View File

@@ -1,7 +1,7 @@
#include <gtest/gtest.h>
#include <J3ML/LinearAlgebra/Vector3.h>
using Vector3 = LinearAlgebra::Vector3;
using J3ML::LinearAlgebra::Vector3;
void EXPECT_V3_EQ(const Vector3& lhs, const Vector3& rhs)
{
@@ -185,11 +185,12 @@ TEST(Vector3Test, V3_Lerp)
EXPECT_V3_EQ(Start.Lerp(Finish, Percent), ExpectedResult);
}
TEST(Vector3Test, V3_AngleBetween) {
using J3ML::LinearAlgebra::Angle2D;
Vector3 A{ .5f, .5f, .5f};
Vector3 B {.25f, .75f, .25f};
A = A.Normalize();
B = B.Normalize();
LinearAlgebra::Angle2D ExpectedResult {-0.69791365, -2.3561945};
Angle2D ExpectedResult {-0.69791365, -2.3561945};
std::cout << A.AngleBetween(B).x << ", " << A.AngleBetween(B).y << "";
auto angle = A.AngleBetween(B);
EXPECT_FLOAT_EQ(angle.x, ExpectedResult.x);

View File

@@ -1,7 +1,7 @@
#include <gtest/gtest.h>
#include <J3ML/LinearAlgebra/Vector4.h>
using Vector4 = LinearAlgebra::Vector4;
using Vector4 = J3ML::LinearAlgebra::Vector4;
void EXPECT_V4_EQ(const Vector4& lhs, const Vector4& rhs)