Implement Geometric Class Definitions (round 2)

This commit is contained in:
2024-01-26 00:14:28 -05:00
parent 4152b0d2aa
commit 256fe730cd
11 changed files with 139 additions and 11 deletions

View File

@@ -53,7 +53,8 @@ add_library(J3ML SHARED ${J3ML_SRC}
src/J3ML/Geometry/Capsule.cpp
src/J3ML/Geometry/TriangleMesh.cpp
src/J3ML/Geometry/QuadTree.cpp
src/J3ML/Geometry/LineSegment.cpp)
src/J3ML/Geometry/LineSegment.cpp
include/J3ML/Geometry/AABB2D.h)
set_target_properties(J3ML PROPERTIES LINKER_LANGUAGE CXX)
install(TARGETS ${PROJECT_NAME} DESTINATION lib/${PROJECT_NAME})

View File

@@ -0,0 +1,10 @@
#pragma once
namespace Geometry
{
// CaveGame AABB
class AABB2D
{
};
}

View File

@@ -7,6 +7,23 @@
namespace Geometry
{
enum class FrustumType
{
Invalid,
/// Set the Frustum type to this value to define the orthographic projection formula. In orthographic projection,
/// 3D images are projected onto a 2D plane essentially by flattening the object along one direction (the plane normal).
/// The size of the projected images appear the same independent of their distance to the camera, and distant objects will
/// not appear smaller. The shape of the Frustum is identical to an oriented bounding box (OBB).
Orthographic,
/// Set the Frustum type to this value to use the perspective projection formula. With perspective projection, the 2D
/// image is formed by projecting 3D points towards a single point (the eye point/tip) of the Frustum, and computing the
/// point of intersection of the line of the projection and the near plane of the Frustum.
/// This corresponds to the optics in the real-world, and objects become smaller as they move to the distance.
/// The shape of the Frustum is a rectangular pyramid capped from the tip.
Perspective
};
class Frustum {
public:
Plane TopFace;

View File

@@ -1,5 +1,7 @@
#pragma once
#include <J3ML/LinearAlgebra/Vector3.h>
namespace Geometry
{
class LineSegment

View File

@@ -1,8 +1,45 @@
//
// Created by dawsh on 1/25/24.
//
#pragma once
#ifndef J3ML_OBB_H
#define J3ML_OBB_H
#include "AABB.h"
#endif //J3ML_OBB_H
namespace Geometry {
class OBB
{
public:
// The center position of this OBB
Vector3 pos;
// Stores half-sizes to x, y, and z directions in the local space of this OBB.
Vector3 r;
// Specifies normalized direc tion vectors for the local axes
Vector3 axis[3];
OBB() {}
OBB(const Vector3& pos, const Vector3& radii, const Vector3& axis0, const Vector3& axis1, const Vector3& axis2);
OBB(const AABB& aabb);
inline static int NumFaces() { return 6; }
inline static int NumEdges() { return 12; }
inline static int NumVertices() { return 8; }
Polyhedron ToPolyhedron() const;
AABB MinimalEnclosingAABB() const;
Sphere MinimalEnclosingSphere() const;
Sphere MaximalContainedSphere() const;
Vector3 Size() const;
Vector3 HalfSize() const;
Vector3 Diagonal() const;
Vector3 HalfDiagonal() const;
bool IsFinite() const;
bool IsDegenerate() const;
Vector3 CenterPoint() const;
Vector3 Centroid() const;
Vector3 AnyPointFast() const;
float Volume();
float SurfaceArea();
LineSegment Edge(int edgeIndex) const;
Vector3 CornerPoint(int cornerIndex) const;
};
}

View File

@@ -1,9 +1,48 @@
#pragma once
#include <vector>
#include <cstdint>
#include <J3ML/LinearAlgebra/Vector2.h>
namespace Geometry
{
template <typename T>
class QuadTree
{
public:
struct Node
{
Node *parent;
uint32_t childIndex;
std::vector<T> objects;
Vector2 center;
Vector2 radius;
bool IsLeaf() const { return childIndex == 0xFFFFFFFF;}
uint32_t TopLeftChildIndex() const { return childIndex;}
uint32_t TopRightChildIndex() const { return childIndex+1;}
uint32_t BottomLeftChildIndex() const { return childIndex+2;}
uint32_t BottomRightChildIndex() const { return childIndex+3;}
/// This assumes that the QuadTree contains unique objects and never duplicates
void Remove(const T &object)
{
for (size_t i = 0; i < objects.size(); ++i){
if (objects[i] == object) {
AssociateQuadTreeNode(object, 0); // Mark in the object that it has been removed from the QuadTree.
std::swap(objects[i], objects.back());
objects.pop_back();
return;
}
}
}
AABB2D ComputeAABB()
{}
};
};
}

View File

@@ -2,5 +2,8 @@
namespace Geometry
{
class Triangle
{
};
}

View File

@@ -1,8 +1,17 @@
//
// Created by josh on 12/25/2023.
//
#include <cstdint>
#ifndef J3ML_J3ML_H
#define J3ML_J3ML_H
namespace J3ML
{
using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
#endif //J3ML_J3ML_H
using s8 = int8_t;
using s16 = int16_t;
using s32 = int32_t;
using s64 = int64_t;
}

View File

@@ -1,5 +1,6 @@
#include <iostream>
#include <J3ML/Geometry.h>
#include <J3ML/J3ML.h>
int main(int argc, char** argv)
{

View File

@@ -1 +1,5 @@
#include <J3ML/Geometry/AABB.h>
#include <J3ML/Geometry/AABB.h>
namespace Geometry {
}

View File

@@ -1 +1,6 @@
#include <J3ML/Geometry/QuadTree.h>
namespace Geometry
{
}