Implement Geometric Types
This commit is contained in:
@@ -20,12 +20,21 @@ namespace Geometry {
|
||||
class Triangle2D;
|
||||
class Polygon2D;
|
||||
|
||||
class Sphere;
|
||||
class LineSegment
|
||||
{
|
||||
Vector3 A;
|
||||
Vector3 B;
|
||||
};
|
||||
|
||||
struct IntersectionResult2D {};
|
||||
|
||||
bool Intersects2D(LineSegment2D seg, Rectangle rect);
|
||||
IntersectionResult2D GetIntersection2D(LineSegment2D seg, Rectangle rect);
|
||||
|
||||
|
||||
class OBB;
|
||||
|
||||
// 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
|
||||
@@ -34,38 +43,19 @@ namespace 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 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:
|
||||
@@ -75,28 +65,13 @@ namespace Geometry {
|
||||
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;
|
||||
}
|
Reference in New Issue
Block a user