Fixed windows errors
Some checks failed
Run ReCI Build Test / Explore-Gitea-Actions (push) Failing after 6m13s
Build Docs With Doxygen / Explore-Gitea-Actions (push) Successful in 24s

This commit is contained in:
2024-08-07 23:17:59 -04:00
parent b58582d7c4
commit 7bb94f9897
38 changed files with 128 additions and 140 deletions

View File

@@ -14,7 +14,6 @@
#include <J3ML/Geometry/Polyhedron.hpp>
#include <J3ML/Geometry/QuadTree.hpp>
#include <J3ML/Geometry/Ray.hpp>
#include <J3ML/Geometry/Shape.hpp>
#include <J3ML/Geometry/Sphere.hpp>
#include <J3ML/Geometry/Triangle.hpp>
#include <J3ML/Geometry/Triangle2D.hpp>

View File

@@ -14,12 +14,9 @@
#include <format>
#include <optional>
#include <J3ML/LinearAlgebra/Common.hpp>
#include <J3ML/Geometry/Common.hpp>
#include <J3ML/Geometry/Shape.hpp>
#include "Polygon.hpp"
#include "Sphere.hpp"
#include <J3ML/Geometry/Forward.hpp>
#include <J3ML/LinearAlgebra.hpp>
#include <J3ML/Algorithm/RNG.hpp>
@@ -44,7 +41,7 @@ namespace J3ML::Geometry
/// axes of the world space coordinate system. This makes computation involving AABB's very fast, since AABB's cannot
/// be arbitrarily oriented in the space with respect to each other.
/// If you need to represent a box in 3D space with arbitrary orientation, see the class OBB. */
class AABB : public Shape {
class AABB {
public:
/// Specifies the minimum extent of this AABB in the world space x, y and z axes.
Vector3 minPoint;

View File

@@ -12,14 +12,14 @@
#pragma once
#include <J3ML/LinearAlgebra/Vector2.hpp>
#include "Shape.hpp"
#include <J3ML/LinearAlgebra.hpp>
#include <J3ML/Geometry/Forward.hpp>
namespace J3ML::Geometry
{
using LinearAlgebra::Vector2;
// CaveGame AABB
class AABB2D : public Shape2D
class AABB2D
{
public:

View File

@@ -11,16 +11,15 @@
#pragma once
#include <J3ML/LinearAlgebra/Common.hpp>
#include <J3ML/Geometry/Common.hpp>
#include <J3ML/Geometry/Shape.hpp>
#include <J3ML/Geometry/Circle.hpp>
#include <J3ML/LinearAlgebra.hpp>
#include <J3ML/Geometry/Forward.hpp>
#include <J3ML/Geometry/LineSegment.hpp>
namespace J3ML::Geometry
{
/// A 3D cylinder with spherical ends.
class Capsule : public Shape
class Capsule
{
public:
/// Specifies the two inner points of this capsule

View File

@@ -11,8 +11,8 @@
#pragma once
#include <J3ML/Geometry/Forward.hpp>
#include <J3ML/LinearAlgebra.hpp>
#include <J3ML/Geometry/Common.hpp>
namespace J3ML
{

View File

@@ -4,25 +4,25 @@
// Forward declarations for classes that include each other
namespace J3ML::Geometry
{
class Shape;
class AABB2D;
class AABB;
class Capsule;
class Frustum;
class LineSegment;
class LineSegment2D;
class Line;
class OBB;
class OBB2D;
class Plane;
class Polygon;
class Polyhedron;
template<typename T> class QuadTree;
class Ray;
class Shape;
class Sphere;
class Circle;
class Triangle;
class Triangle2D;
class TriangleMesh;
template <int N> class PBVolume;
}

View File

@@ -3,9 +3,7 @@
//
#pragma once
#include <J3ML/Geometry/Common.hpp>
#include "Plane.hpp"
#include "Shape.hpp"
#include <J3ML/Geometry/Forward.hpp>
#include <J3ML/LinearAlgebra.hpp>
namespace J3ML::Geometry
@@ -78,7 +76,7 @@ namespace J3ML::Geometry
/// @see FrustumType
/// @see FrustumProjectiveSpace
/// @see FrustumHandedness
class Frustum : public Shape {
class Frustum {
public: // Members
/// Specifies whether this frustum is a perspective or an orthographic frustum.

View File

@@ -1,14 +1,11 @@
#pragma once
#include <J3ML/LinearAlgebra/Common.hpp>
#include <J3ML/Geometry/Common.hpp>
#include <J3ML/LinearAlgebra/Vector3.hpp>
#include <J3ML/LinearAlgebra.hpp>
#include <J3ML/Geometry/Forward.hpp>
namespace J3ML::Geometry
{
using LinearAlgebra::Vector3;
/// A line segment in 3D space is a finite line with a start and end point.
class LineSegment
{

View File

@@ -1,8 +1,7 @@
#pragma once
#include <J3ML/Geometry/Common.hpp>
#include <J3ML/Geometry/AABB.hpp>
#include <J3ML/Geometry/Polyhedron.hpp>
#include <J3ML/Geometry/Forward.hpp>
#include <J3ML/LinearAlgebra.hpp>
namespace J3ML::Geometry {
@@ -11,7 +10,7 @@ namespace J3ML::Geometry {
// with respect to the global world coordinate system. This allows OBBs to more tightly bound objects than AABBs do,
// which always align with the world space axes. This flexibility has the drawback that the geometry tests and operations
// involving OBBs are more costly, and representing an OBB in memory takes more space (15 floats vs 6 floats)
class OBB : public Shape
class OBB
{
public:
// The center position of this OBB

View File

@@ -11,13 +11,11 @@
#pragma once
#include <J3ML/Geometry/AABB.hpp>
#include <J3ML/Geometry/Polyhedron.hpp>
#include <J3ML/Geometry/Plane.hpp>
#include <J3ML/Geometry/Sphere.hpp>
#include "Sphere.hpp"
#include "Sphere.hpp"
namespace J3ML::Geometry
{

View File

@@ -1,12 +1,10 @@
#pragma once
#include <J3ML/LinearAlgebra/Vector3.hpp>
#include "Shape.hpp"
#include "Ray.hpp"
#include <J3ML/LinearAlgebra.hpp>
#include <J3ML/Geometry/Forward.hpp>
namespace J3ML::Geometry
{
using J3ML::LinearAlgebra::Vector3;
class Plane
{

View File

@@ -11,14 +11,13 @@
#pragma once
#include <J3ML/Geometry/Common.hpp>
#include <J3ML/Geometry/Forward.hpp>
#include <J3ML/LinearAlgebra.hpp>
#include <vector>
#include "Shape.hpp"
#include <J3ML/LinearAlgebra/Common.hpp>
namespace J3ML::Geometry {
class Polygon : public Shape
class Polygon
{
public:
std::vector<Vector3> vertices;

View File

@@ -1,14 +1,13 @@
#pragma once
#include <J3ML/Geometry/Common.hpp>
#include <J3ML/Geometry/Shape.hpp>
#include <J3ML/Geometry/Forward.hpp>
#include <vector>
#include <J3ML/LinearAlgebra/Vector3.hpp>
#include <J3ML/LinearAlgebra.hpp>
namespace J3ML::Geometry
{
using namespace J3ML::LinearAlgebra;
// Represents a three-dimensional closed geometric solid defined by flat polygonal faces.
class Polyhedron

View File

@@ -2,14 +2,13 @@
#include <vector>
#include <cstdint>
#include <J3ML/LinearAlgebra/Vector2.hpp>
#include <J3ML/LinearAlgebra.hpp>
#include <J3ML/Geometry/Forward.hpp>
#include <J3ML/Geometry/AABB2D.hpp>
namespace J3ML::Geometry {
using LinearAlgebra::Vector2;
template<typename T>
class QuadTree {
/// A fixed split rule for all QuadTrees: A QuadTree leaf node is only ever split if the leaf contains at least this many objects.
@@ -366,4 +365,4 @@ namespace J3ML::Geometry {
leaf->objects.pop_back();
}
}
}
}

View File

@@ -10,11 +10,12 @@
/// @edit 2024-07-06
#pragma once
#include <J3ML/LinearAlgebra/Vector3.hpp>
#include <format>
#include <J3ML/LinearAlgebra.hpp>
#include <vector>
#include "TriangleMesh.hpp"
#include "Frustum.hpp"
#include "OBB.hpp"
#include <ostream>
#include <iosfwd>
#include <J3ML/Geometry/Forward.hpp>
namespace J3ML::Geometry
{
@@ -29,8 +30,8 @@ namespace J3ML::Geometry
Vector3 Intersection;
Vector3 SurfaceNormal;
bool Hit;
Shape* Target;
static RaycastResult NoHit() { return {Vector3::NaN, Vector3::NaN, false, nullptr};}
//Shape* Target;
static RaycastResult NoHit() { return {Vector3::NaN, Vector3::NaN, false};}
};
/// A ray in 3D space is a line that starts from an origin point and extends to infinity in one direction
@@ -151,17 +152,12 @@ namespace J3ML::Geometry
// Returns a RaycastResult structure containing the first object the ray collides with,
// the surface intersection point,
// and the surface normal at the point of intersection.
RaycastResult Cast(std::vector<Shape> shapes, float maxDistance = 99999999);
// RaycastResult Cast(std::vector<Shape> shapes, float maxDistance = 99999999);
void ProjectToAxis(const Vector3 &direction, float &outMin, float &outMax) const;
[[nodiscard]] std::string ToString() const {
return std::format("Ray(origin:[{}], direction:[{}])", Origin.ToString(), Direction.ToString());
}
[[nodiscard]] std::string ToString() const;
};
inline std::ostream& operator << (std::ostream& o, const Ray& ray) {
o << ray.ToString();
return o;
}
}
std::ostream& operator << (std::ostream& o, const Ray& ray);
}

View File

@@ -1,27 +0,0 @@
#pragma once
namespace J3ML::Geometry
{
class GeometricPrimitive
{
public:
protected:
private:
};
class Shape
{
public:
virtual ~Shape() = default; //Polymorphic for dynamic_cast.
protected:
private:
};
class Shape2D
{
public:
virtual ~Shape2D() = default;
protected:
private:
};
}

View File

@@ -12,17 +12,12 @@
#pragma once
#include <J3ML/Geometry.hpp>
#include <J3ML/LinearAlgebra/Matrix3x3.hpp>
#include <J3ML/LinearAlgebra/Matrix4x4.hpp>
#include <J3ML/Geometry/LineSegment.hpp>
#include <J3ML/Geometry/TriangleMesh.hpp>
#include <J3ML/Geometry/Shape.hpp>
#include <J3ML/Geometry/Forward.hpp>
#include <J3ML/LinearAlgebra.hpp>
namespace J3ML::Geometry
{
using J3ML::LinearAlgebra::Matrix3x3;
using J3ML::LinearAlgebra::Matrix4x4;
// A mathematical representation of a 3-dimensional sphere
class Sphere
@@ -119,8 +114,8 @@ namespace J3ML::Geometry
[[nodiscard]] bool Contains(const Vector3& point, float epsilon) const;
[[nodiscard]] bool Contains(const LineSegment& lineseg) const;
TriangleMesh GenerateUVSphere() const {}
TriangleMesh GenerateIcososphere() const {}
TriangleMesh GenerateUVSphere() const;
TriangleMesh GenerateIcososphere() const;
void ProjectToAxis(const Vector3 &direction, float &outMin, float &outMax) const;
};

View File

@@ -1,7 +1,6 @@
#pragma once
#include "J3ML/LinearAlgebra/Vector3.hpp"
#include <J3ML/Geometry/Common.hpp>
#include <J3ML/Geometry/Forward.hpp>
#include <J3ML/LinearAlgebra.hpp>
#include <cfloat>

View File

@@ -1,12 +1,8 @@
#pragma once
#include <vector>
#include <J3ML/LinearAlgebra/Common.hpp>
#include <J3ML/Geometry/Common.hpp>
#include "J3ML/J3ML.hpp"
using namespace J3ML::LinearAlgebra;
#include <J3ML/LinearAlgebra.hpp>
#include <J3ML/Geometry/Forward.hpp>
namespace J3ML::Geometry
{

View File

@@ -14,8 +14,7 @@
#include <J3ML/LinearAlgebra/Common.hpp>
#include <J3ML/LinearAlgebra.hpp>
namespace J3ML::LinearAlgebra {
class Matrix2x2 {

View File

@@ -1,7 +1,7 @@
#pragma once
#include <J3ML/LinearAlgebra/Common.hpp>
#include <J3ML/LinearAlgebra/Forward.hpp>
#include <J3ML/Algorithm/RNG.hpp>
#include <algorithm>

View File

@@ -1,6 +1,6 @@
#pragma once
#include <J3ML/LinearAlgebra/Common.hpp>
#include <J3ML/LinearAlgebra/Forward.hpp>
#include <J3ML/Algorithm/RNG.hpp>
#include <cmath>

View File

@@ -3,7 +3,7 @@
#include <cstddef>
#include <cmath>
#include <J3ML/LinearAlgebra/Common.hpp>
#include <J3ML/LinearAlgebra/Forward.hpp>
namespace J3ML::LinearAlgebra {

View File

@@ -12,6 +12,7 @@
#include <J3ML/Geometry/TriangleMesh.hpp>
#include <J3ML/Geometry/Polyhedron.hpp>
#include <J3ML/Algorithm/RNG.hpp>
#include <J3ML/Geometry/OBB.hpp>
namespace J3ML::Geometry {
@@ -320,12 +321,12 @@ namespace J3ML::Geometry {
return result;
}
AABB::AABB(const Vector3 &min, const Vector3 &max) : Shape(), minPoint(min), maxPoint(max)
AABB::AABB(const Vector3 &min, const Vector3 &max) : minPoint(min), maxPoint(max)
{
}
AABB::AABB() : Shape() {}
AABB::AABB() {}
float Max(float a, float b)
{
@@ -528,6 +529,7 @@ namespace J3ML::Geometry {
}
}
}
return mesh;
}
std::optional<AABB> AABB::Intersection(const AABB& rhs) const {

View File

@@ -1,4 +1,4 @@
#include <J3ML/Geometry/Common.hpp>
#include <J3ML/Geometry/Forward.hpp>
namespace J3ML::Geometry {

View File

@@ -1,4 +1,3 @@
#include <J3ML/Geometry/Common.hpp>
#include <J3ML/Geometry/Frustum.hpp>
#include <cmath>
#include <J3ML/Geometry/AABB.hpp>
@@ -370,6 +369,10 @@ namespace J3ML::Geometry
Vector3 topSide = front + Math::Tan(verticalFov * 0.5f) * up;
Vector3 right = WorldRight();
Vector3 topSideNormal = ((handedness == FrustumHandedness::Right) ? Vector3::Cross(right, topSide) : Vector3::Cross(topSide, right)).Normalized();
return Plane(pos, topSideNormal);
} else
{
return Plane(NearPlanePos(0.f, 1.f), up);
}
}
@@ -378,6 +381,7 @@ namespace J3ML::Geometry
Vector3 bottomSide = front - Math::Tan(verticalFov * 0.5f) * up;
Vector3 left = -WorldRight();
Vector3 bottomSideNormal = ((handedness == FrustumHandedness::Right) ? Vector3::Cross(left, bottomSide) : Vector3::Cross(bottomSide, left)).Normalized();
return Plane(pos, bottomSideNormal);
} else {
return Plane(NearPlanePos(0.f, -1.f), -up);
}
@@ -391,6 +395,7 @@ namespace J3ML::Geometry
right.ScaleToLength(Math::Tan(horizontalFov * 0.5f));
Vector3 rightSide = front + right;
Vector3 rightSideNormal = ((handedness == FrustumHandedness::Right) ? Vector3::Cross(rightSide, up) : Vector3::Cross(up, rightSide)).Normalized();
return Plane(pos, rightSideNormal);
} else {
Vector3 right = WorldRight();
return Plane(NearPlanePos(1.f,0.f), right.Normalized());

View File

@@ -1,9 +1,9 @@
#include <J3ML/Geometry/LineSegment.hpp>
#include "J3ML/Geometry/Capsule.hpp"
#include <J3ML/Geometry/Line.hpp>
#include <J3ML/LinearAlgebra/Vector3.hpp>
#include <J3ML/LinearAlgebra/Matrix3x3.hpp>
#include <J3ML/LinearAlgebra.hpp>
#include <J3ML/Geometry/Plane.hpp>
#include <J3ML/Geometry/Ray.hpp>
namespace J3ML::Geometry {
@@ -272,4 +272,4 @@ namespace J3ML::Geometry {
LineSegment operator*(const Matrix4x4 &transform, const LineSegment &l) {
return LineSegment(transform.Mul(l.A), transform.Mul(l.B));
}
}
}

View File

@@ -1,8 +1,8 @@
#include <J3ML/Geometry/Shape.hpp>
#include <J3ML/Geometry/AABB.hpp>
#include <J3ML/Geometry/LineSegment.hpp>
#include <J3ML/Geometry/Polyhedron.hpp>
#include <J3ML/Geometry/OBB.hpp>
#include <J3ML/Geometry/Plane.hpp>
#include <J3ML/Geometry/Sphere.hpp>
namespace J3ML::Geometry {

View File

@@ -2,8 +2,13 @@
#include <J3ML/Geometry/AABB.hpp>
#include <J3ML/Geometry/OBB.hpp>
#include <J3ML/Geometry/Capsule.hpp>
#include <J3ML/Geometry/Frustum.hpp>
#include <J3ML/Geometry/Line.hpp>
#include <J3ML/Geometry/Polygon.hpp>
#include <J3ML/Geometry/Polyhedron.hpp>
#include <J3ML/Geometry/Ray.hpp>
#include <J3ML/Geometry/Sphere.hpp>
#include <J3ML/Geometry/Triangle.hpp>
namespace J3ML::Geometry
{
@@ -138,7 +143,7 @@ namespace J3ML::Geometry
Plane::Plane(const Vector3 &pos, const Vector3 &norm) : Position(pos), Normal(norm) {}
bool Plane::Intersects(J3ML::Geometry::Ray ray, float *dist) const {
bool Plane::Intersects(Ray ray, float *dist) const {
float t;
bool success = IntersectLinePlane(Normal, this->distance, ray.Origin, ray.Direction, t);
if (dist)

View File

@@ -8,6 +8,10 @@
#include <J3ML/Geometry/Capsule.hpp>
#include <set>
#include <cfloat>
#include <J3ML/Geometry/Frustum.hpp>
#include <J3ML/Geometry/OBB.hpp>
#include <J3ML/Geometry/Plane.hpp>
#include <J3ML/Geometry/Sphere.hpp>
namespace J3ML::Geometry
{

View File

@@ -1,6 +1,10 @@
#include <J3ML/Geometry/AABB.hpp>
#include <J3ML/Geometry/Line.hpp>
#include <J3ML/Geometry/LineSegment.hpp>
#include <J3ML/Geometry/Plane.hpp>
#include <J3ML/Geometry/Ray.hpp>
#include <J3ML/Geometry/Sphere.hpp>
#include <ostream>
namespace J3ML::Geometry
{
@@ -17,6 +21,17 @@ namespace J3ML::Geometry
outMin = -INFINITY;
}
std::string Ray::ToString() const
{
return std::format("Ray(origin:[{}], direction:[{}])", Origin.ToString(), Direction.ToString());
}
std::ostream& operator<<(std::ostream& o, const Ray& ray)
{
o << ray.ToString();
return o;
}
RaycastResult Ray::Cast(const Sphere &target, float maxDistance)
{
Vector3 p0 = this->Origin;
@@ -54,7 +69,6 @@ namespace J3ML::Geometry
intersection,
normal,
true,
(Shape *) &target
};
}
@@ -101,7 +115,6 @@ namespace J3ML::Geometry
intersection,
normal,
true,
(Shape*)&target
};
}
@@ -129,7 +142,6 @@ namespace J3ML::Geometry
intersection,
normal,
true,
(Shape*) &target
};
return RaycastResult::NoHit();

View File

@@ -1,4 +1,6 @@
#include <J3ML/Geometry/LineSegment.hpp>
#include <J3ML/Geometry/Sphere.hpp>
#include <J3ML/Geometry/TriangleMesh.hpp>
namespace J3ML::Geometry
{
@@ -7,6 +9,18 @@ namespace J3ML::Geometry
return Contains(lineseg.A) && Contains(lineseg.B);
}
TriangleMesh Sphere::GenerateUVSphere() const
{
// TODO: Implement this later
return TriangleMesh();
}
TriangleMesh Sphere::GenerateIcososphere() const
{
// TODO: Implement this later
return TriangleMesh();
}
void Sphere::ProjectToAxis(const Vector3 &direction, float &outMin, float &outMax) const
{
float d = Vector3::Dot(direction, Position);
@@ -43,11 +57,11 @@ namespace J3ML::Geometry
}
float Sphere::Volume() const {
return 4.f * M_PI * Cube(Radius) / 3.f;
return 4.f * Math::Pi * Cube(Radius) / 3.f;
}
float Sphere::SurfaceArea() const {
return 4.f * M_PI * Cube(Radius) / 3.f;
return 4.f * Math::Pi * Cube(Radius) / 3.f;
}
bool Sphere::IsFinite() const {
@@ -108,4 +122,4 @@ namespace J3ML::Geometry
}
}
}

View File

@@ -4,6 +4,7 @@
#include <J3ML/Geometry/LineSegment.hpp>
#include <J3ML/Geometry/Line.hpp>
#include <J3ML/Geometry/Capsule.hpp>
#include <J3ML/Geometry/Plane.hpp>
namespace J3ML::Geometry
{

View File

@@ -13,6 +13,8 @@
#include <strstream>
#include "J3ML/J3ML.hpp"
#include <sstream>
float PowUInt(float base, u32 exponent)
{

View File

@@ -72,14 +72,14 @@ namespace J3ML::LinearAlgebra {
if ((x*y*t + z*s) > 0.998) { // North pole singularity detected
pitch = 2 * std::atan2(x * std::sin(angle/2.f), std::cos(angle/2.f));
yaw = M_PI / 2.f;
yaw = Math::Pi / 2.f;
roll = 0;
return;
}
if ((x*y*t + z*s) < -0.998) { // South pole singularity detected
pitch = -2 * std::atan2(x * std::sin(angle/2.f), std::cos(angle/2.f));
yaw = -M_PI / 2.f;
yaw = -Math::Pi / 2.f;
roll = 0;
return;
}
@@ -129,14 +129,14 @@ namespace J3ML::LinearAlgebra {
double test = rhs.x * rhs.y + rhs.z * rhs.w;
if (test > 0.499) { // Singularity at north pole
pitch = 2 * std::atan2(rhs.x, rhs.w);
yaw = M_PI / 2.f;
yaw = Math::Pi / 2.f;
roll = 0;
return;
}
if (test < -0.499) { // Singularity at south pole
pitch = -2 * std::atan2(rhs.x, rhs.y);
yaw = - M_PI / 2.f;
yaw = - Math::Pi / 2.f;
roll = 0;
return;
}

View File

@@ -2,6 +2,9 @@
#include <algorithm>
#include <cassert>
#include <cmath>
#include <format>
#include <ostream>
#include <J3ML/Geometry/AABB.hpp>
#include <J3ML/Geometry/Sphere.hpp>
namespace J3ML::LinearAlgebra {
@@ -316,7 +319,7 @@ namespace J3ML::LinearAlgebra {
}
Angle2D Vector3::AngleBetween(const Vector3 &rhs) const {
const auto Pi_x_180 = 180.f / M_PI;
const auto Pi_x_180 = 180.f / Math::Pi;
auto dist = this->Distance(rhs);
float dx = -(asinf((rhs.y - this->y) / dist));
float dy = (atan2f(rhs.x - this->x,rhs.z - this->z));
@@ -532,7 +535,7 @@ namespace J3ML::LinearAlgebra {
return std::format("{},{},{}", x, y, z);
}
std::ostream & operator<<(std::ostream &o, const Vector3 &vector) {
std::ostream& operator<<(std::ostream &o, const Vector3 &vector) {
o << vector.ToString();
return o;
}

View File

@@ -1,6 +1,6 @@
#pragma once
#include <J3ML/Geometry/Common.hpp>
#include <J3ML/Geometry/Forward.hpp>
#include <jtest/jtest.hpp>
using J3ML::Geometry::Interval;