108 lines
3.0 KiB
C++
108 lines
3.0 KiB
C++
#include <J3ML/LinearAlgebra/Vector3.h>
|
|
|
|
#pragma once
|
|
|
|
namespace Geometry {
|
|
using Vector2 = LinearAlgebra::Vector2;
|
|
using Vector3 = LinearAlgebra::Vector3;
|
|
|
|
class LineSegment2D
|
|
{
|
|
Vector2 A;
|
|
Vector2 B;
|
|
};
|
|
|
|
class Rectangle; //AABB2D;
|
|
class OBB2D;
|
|
class Line2D;
|
|
class Ray2D;
|
|
class Triangle2D;
|
|
class Polygon2D;
|
|
|
|
struct IntersectionResult2D {
|
|
|
|
};
|
|
|
|
bool Intersects2D(LineSegment2D seg, Rectangle rect);
|
|
IntersectionResult2D GetIntersection2D(LineSegment2D seg, Rectangle rect);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// A 3D axis-aligned bounding box
|
|
// This data structure can be used to represent coarse bounds of objects, in situations where detailed triangle-level
|
|
// computations can be avoided. In physics systems, bounding boxes are used as an efficient early-out test for geometry
|
|
// intersection queries.
|
|
// the 'Axis-aligned' part in the name means that the local axes of this bounding box are restricted to align with the
|
|
// 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 Capsule;
|
|
class Line;
|
|
class LineSegment
|
|
{
|
|
Vector3 A;
|
|
Vector3 B;
|
|
};
|
|
class Ray
|
|
{
|
|
Vector3 Origin;
|
|
Vector3 Direction;
|
|
};
|
|
|
|
class OBB;
|
|
class Plane
|
|
{
|
|
public:
|
|
Vector3 Position;
|
|
Vector3 Normal;
|
|
float distance = 0.f;
|
|
|
|
};
|
|
class Frustum {
|
|
public:
|
|
Plane TopFace;
|
|
Plane BottomFace;
|
|
Plane RightFace;
|
|
Plane LeftFace;
|
|
Plane FarFace;
|
|
Plane NearFace;
|
|
};
|
|
|
|
class Camera {
|
|
public:
|
|
Vector3 Position;
|
|
Vector3 Front;
|
|
Vector3 Right;
|
|
Vector3 Up;
|
|
};
|
|
|
|
static 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;
|
|
}
|
|
|
|
class Polygon;
|
|
class Polyhedron;
|
|
class QuadTree;
|
|
class OctTree;
|
|
class Sphere;
|
|
class Triangle;
|
|
class TriangleMesh;
|
|
} |