Set up shapes for dynamic cast
Some checks failed
Run ReCI Build Test / Explore-Gitea-Actions (push) Failing after 1m29s
Build Docs With Doxygen / Explore-Gitea-Actions (push) Successful in 22s

This commit is contained in:
2024-08-20 21:37:14 -04:00
parent fe654611eb
commit 47993084ff
19 changed files with 52 additions and 31 deletions

View File

@@ -14,7 +14,7 @@
#include <format>
#include <optional>
#include <J3ML/Geometry/Shape.hpp>
#include <J3ML/Geometry/Forward.hpp>
#include <J3ML/LinearAlgebra.hpp>
#include <J3ML/Algorithm/RNG.hpp>
@@ -41,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 {
class AABB : public Shape {
public:
/// Specifies the minimum extent of this AABB in the world space x, y and z axes.
Vector3 minPoint;

View File

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

View File

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

View File

@@ -11,6 +11,7 @@
#pragma once
#include <J3ML/Geometry/Shape.hpp>
#include <J3ML/Geometry/Forward.hpp>
#include <J3ML/LinearAlgebra.hpp>
@@ -19,7 +20,7 @@ namespace J3ML
/// A two-dimensional circle in 3D space.
/// This class represents both a hollow circle (only edge) and a solid circle (disc).
class Circle
class Circle : public Shape
{
public:
/// The center position of this circle.

View File

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

View File

@@ -1,19 +1,20 @@
#pragma once
#include "LineSegment.hpp"
#include <J3ML/Geometry/Shape.hpp>
#include <J3ML/Geometry/LineSegment.hpp>
namespace J3ML::Geometry
{
class Line
class Line : public Shape
{
public:
Vector3 Position; /// Specifies the origin of this line.
Vector3 Direction; /// The normalized direction vector of this ray.
public:
static void
ClosestPointLineLine(const Vector3 &v0, const Vector3 &v10, const Vector3 &v2, const Vector3 &v32, float &d,
float &d2);
Line(const Vector3& position, const Vector3& direction) : Position(position), Direction(direction) {}
static void ClosestPointLineLine(const Vector3 &v0, const Vector3 &v10, const Vector3 &v2, const Vector3 &v32, float &d, float &d2);
Vector3 ClosestPoint(const J3ML::Geometry::LineSegment &other, float &d, float &d2) const;

View File

@@ -1,13 +1,14 @@
#pragma once
#include <J3ML/LinearAlgebra.hpp>
#include <J3ML/Geometry/Shape.hpp>
#include <J3ML/Geometry/Forward.hpp>
namespace J3ML::Geometry
{
/// A line segment in 3D space is a finite line with a start and end point.
class LineSegment
class LineSegment : public Shape2D
{
public:
Vector3 A; /// The starting point of this line segment.

View File

@@ -1,5 +1,6 @@
#pragma once
#include <J3ML/Geometry/Shape.hpp>
#include <J3ML/Geometry/Forward.hpp>
#include <J3ML/LinearAlgebra.hpp>
@@ -10,7 +11,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
class OBB : public Shape
{
public:
// The center position of this OBB

View File

@@ -1,4 +1,6 @@
#pragma once
#include <J3ML/Geometry/Shape.hpp>
#include <J3ML/LinearAlgebra.hpp>
#include <J3ML/Geometry/Forward.hpp>
@@ -6,7 +8,7 @@
namespace J3ML::Geometry
{
class Plane
class Plane : public Shape
{
public:
Vector3 Position;

View File

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

View File

@@ -1,8 +1,8 @@
#pragma once
#include <J3ML/Geometry/Forward.hpp>
#include <vector>
#include <J3ML/Geometry/Shape.hpp>
#include <J3ML/Geometry/Forward.hpp>
#include <J3ML/LinearAlgebra.hpp>
@@ -10,7 +10,7 @@ namespace J3ML::Geometry
{
// Represents a three-dimensional closed geometric solid defined by flat polygonal faces.
class Polyhedron
class Polyhedron : public Shape
{
public:
// Stores a list of indices of a single face of a Polygon

View File

@@ -15,6 +15,7 @@
#include <vector>
#include <ostream>
#include <iosfwd>
#include <J3ML/Geometry/Shape.hpp>
#include <J3ML/Geometry/Forward.hpp>
namespace J3ML::Geometry
@@ -35,7 +36,7 @@ namespace J3ML::Geometry
};
/// A ray in 3D space is a line that starts from an origin point and extends to infinity in one direction
class Ray
class Ray : public Shape
{
public: // Properties
// The position of this ray.

View File

@@ -0,0 +1,8 @@
#pragma once
class Shape {
public:
virtual ~Shape() = default;
};
class Shape2D : public Shape{};

View File

@@ -11,7 +11,7 @@
#pragma once
#include <J3ML/Geometry/Shape.hpp>
#include <J3ML/Geometry/Forward.hpp>
#include <J3ML/LinearAlgebra.hpp>
@@ -20,7 +20,7 @@ namespace J3ML::Geometry
{
// A mathematical representation of a 3-dimensional sphere
class Sphere
class Sphere : public Shape
{
public: // Properties
Vector3 Position; // The center point of this sphere.

View File

@@ -1,12 +1,13 @@
#pragma once
#include <J3ML/Geometry/Shape.hpp>
#include <J3ML/Geometry/Forward.hpp>
#include <J3ML/LinearAlgebra.hpp>
#include <cfloat>
namespace J3ML::Geometry
{
class Triangle
class Triangle : public Shape
{
public:
Vector3 V0;
@@ -136,6 +137,7 @@ namespace J3ML::Geometry
Vector3 Vertex(int i) const;
LineSegment Edge(int i) const;
Triangle(const Vector3& v0, const Vector3& v1, const Vector3& v2) : V0(v0), V1(v1), V2(v2) {}
};

View File

@@ -1,5 +1,6 @@
#pragma once
#include <J3ML/Geometry/Shape.hpp>
#include <J3ML/LinearAlgebra/Forward.hpp>
#include <J3ML/LinearAlgebra/Vector2.hpp>
#include <J3ML/Geometry/Forward.hpp>
@@ -14,7 +15,7 @@ namespace J3ML::Geometry
/** @note The order in which the vertices are stored in this data structure is important.
The triangles (a,b,c) and (a,c,b) are otherwise equivalent, but their plane normals point to the opposite directions.
@see PlaneCCW(), PlaneCW() */
class Triangle2D {
class Triangle2D : public Shape2D {
public:
Vector2 A; /// The first Triangle endpoint.

View File

@@ -2,12 +2,13 @@
#include <vector>
#include <J3ML/LinearAlgebra.hpp>
#include <J3ML/Geometry/Shape.hpp>
#include <J3ML/Geometry/Forward.hpp>
namespace J3ML::Geometry
{
class TriangleMesh
class TriangleMesh : public Shape
{
public:
/// Default constructor for a triangle mesh.

View File

@@ -1,6 +1,5 @@
#pragma once
#include "J3ML/J3ML.hpp"
#include <J3ML/J3ML.hpp>
namespace J3ML::LinearAlgebra {

View File

@@ -45,10 +45,9 @@ namespace J3ML::Geometry
}
Triangle Triangle::Translated(const Vector3& translation) const {
return {
V0 + translation,
V1 + translation,
V2 + translation
return {V0 + translation,
V1 + translation,
V2 + translation
};
}