1
0
forked from josh/j3ml

Implement Geometric Types

This commit is contained in:
2024-01-25 14:01:19 -05:00
parent d012af1214
commit 5cd5a44963
20 changed files with 234 additions and 40 deletions

View File

@@ -0,0 +1,62 @@
#pragma once
#include <J3ML/LinearAlgebra/Vector3.h>
#include "Plane.h"
#include "Sphere.h"
using namespace LinearAlgebra;
namespace Geometry
{
class AABB
{
static AABB FromCenterAndSize(const Vector3 FromSize);
float MinX();
// Returns the smallest sphere that contains this AABB.
// This function computes the minimal volume sphere that contains all the points inside this AABB
Sphere MinimalEnclosingSphere() const;
// Returns the largest sphere that can fit inside this AABB
// This function computes the largest sphere that can fit inside this AABB.
Sphere MaximalContainedSphere() const;
Vector3 GetCentroid() const;
// Quickly returns an arbitrary point inside this AABB
Vector3 AnyPointFast() const;
Vector3 PointInside(float x, float y, float z) const;
// Returns an edge of this AABB
LineSegment Edge(int edgeIndex) const;
Vector3 CornerPoint(int cornerIndex);
Vector3 ExtremePoint(const Vector3& direction) const;
Vector3 ExtremePoint(const Vector3& direction, float projectionDistance);
Vector3 PointOnEdge(int edgeIndex, float u) const;
Vector3 FaceCenterPoint(int faceIndex) const;
Vector3 FacePoint(int faceIndex, float u, float v) const;
Vector3 FaceNormal(int faceIndex) const;
Plane FacePlane(int faceIndex);
static AABB MinimalEnclosingAABB(const Vector3* pointArray, int numPoints);
Vector3 GetSize();
Vector3 GetVolume();
float GetVolumeCubed();
float GetSurfaceArea();
Vector3 GetRandomPointInside();
Vector3 GetRandomPointOnSurface();
Vector3 GetRandomPointOnEdge();
Vector3 GetRandomCornerPoint();
AABB Translated(const Vector3& offset) const;
AABB TransformAABB(const Matrix3x3& transform);
AABB TransformAABB(const Matrix4x4& transform);
AABB TransformAABB(const Quaternion& transform);
OBB Transform(const Matrix3x3& transform);
OBB Transform(const Matrix4x4& transform);
OBB Transform(const Quaternion& transform);
bool Contains(const Vector3& point) const;
bool Contains(const LineSegment& lineSegment) const;
bool Contains(const AABB& aabb) const;
bool Contains(const OBB& obb) const;
bool Contains(const Sphere& sphere) const;
bool C
};
}

View File

@@ -0,0 +1,8 @@
//
// Created by dawsh on 1/25/24.
//
#ifndef J3ML_CAPSULE_H
#define J3ML_CAPSULE_H
#endif //J3ML_CAPSULE_H

View File

@@ -0,0 +1,38 @@
//
// Created by dawsh on 1/25/24.
//
#pragma once
#include "Plane.h"
namespace Geometry
{
class Frustum {
public:
Plane TopFace;
Plane BottomFace;
Plane RightFace;
Plane LeftFace;
Plane FarFace;
Plane NearFace;
static Frustum CreateFrustumFromCamera(const Camera& cam, float aspect, float fovY, float zNear, float zFar);
};
Frustum Frustum::CreateFrustumFromCamera(const Camera &cam, float aspect, float fovY, float zNear, float zFar) {
Frustum frustum;
const float halfVSide = zFar * tanf(fovY * 0.5f);
const float halfHSide = halfVSide * aspect;
const Vector3 frontMultFar = cam.Front * zFar;
frustum.NearFace = Plane{cam.Position + cam.Front * zNear, cam.Front};
frustum.FarFace = Plane{cam.Position + frontMultFar, -cam.Front};
frustum.RightFace = Plane{cam.Position, Vector3::Cross(frontMultFar - cam.Right * halfHSide, cam.Up)};
frustum.LeftFace = Plane{cam.Position, Vector3::Cross(cam.Up, frontMultFar+cam.Right*halfHSide)};
frustum.TopFace = Plane{cam.Position, Vector3::Cross(cam.Right, frontMultFar - cam.Up * halfVSide)};
frustum.BottomFace = Plane{cam.Position, Vector3::Cross(frontMultFar + cam.Up * halfVSide, cam.Right)};
return frustum;
}
}

View File

@@ -0,0 +1,8 @@
//
// Created by dawsh on 1/25/24.
//
#ifndef J3ML_LINESEGMENT_H
#define J3ML_LINESEGMENT_H
#endif //J3ML_LINESEGMENT_H

View File

@@ -0,0 +1,8 @@
//
// Created by dawsh on 1/25/24.
//
#ifndef J3ML_OBB_H
#define J3ML_OBB_H
#endif //J3ML_OBB_H

View File

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

View File

@@ -0,0 +1,8 @@
//
// Created by dawsh on 1/25/24.
//
#ifndef J3ML_POLYGON_H
#define J3ML_POLYGON_H
#endif //J3ML_POLYGON_H

View File

@@ -0,0 +1,8 @@
//
// Created by dawsh on 1/25/24.
//
#ifndef J3ML_QUADTREE_H
#define J3ML_QUADTREE_H
#endif //J3ML_QUADTREE_H

View File

@@ -0,0 +1,8 @@
//
// Created by dawsh on 1/25/24.
//
#ifndef J3ML_RAY_H
#define J3ML_RAY_H
#endif //J3ML_RAY_H

View File

@@ -0,0 +1,9 @@
#pragma once
namespace Geometry
{
class Sphere
{
};
}

View File

@@ -0,0 +1,8 @@
//
// Created by dawsh on 1/25/24.
//
#ifndef J3ML_TRIANGLE_H
#define J3ML_TRIANGLE_H
#endif //J3ML_TRIANGLE_H

View File

@@ -0,0 +1,8 @@
//
// Created by dawsh on 1/25/24.
//
#ifndef J3ML_TRIANGLE2D_H
#define J3ML_TRIANGLE2D_H
#endif //J3ML_TRIANGLE2D_H

View File

@@ -0,0 +1,8 @@
//
// Created by dawsh on 1/25/24.
//
#ifndef J3ML_TRIANGLEMESH_H
#define J3ML_TRIANGLEMESH_H
#endif //J3ML_TRIANGLEMESH_H