cubos::core::geom namespace

Geometry module.

Classes

struct AABB
Represents an axis-aligned bounding box.
struct Box
Represents a box shape.
struct Capsule
Represents a capsule or sphere shape.
struct Intersection
Contains info regarding an intersection between shapes.
struct Plane
Represents a plane. Assumes equation: normal.x + normal.y + normal.z + d = 0.

Functions

auto intersects(const Box& box1, const glm::mat4& localToWorld1, const Box& box2, const glm::mat4& localToWorld2, Intersection& intersect) -> CUBOS_CORE_API bool
Computes the intersection between two box shapes.
auto sutherlandHodgmanClipping(const std::vector<glm::vec3>& inputPolygon, int numClipPlanes, const cubos::core::geom::Plane* clipPlanes, bool removeNotClipToPlane) -> CUBOS_CORE_API std::vector<glm::vec3>
Performs the Sutherland-Hodgman Clipping algorithm.
auto planeEdgeIntersection(const cubos::core::geom::Plane& plane, const glm::vec3& start, const glm::vec3& end, glm::vec3& outPoint) -> CUBOS_CORE_API bool
Compute the intersection between a plane and an edge.
auto pointInPlane(const glm::vec3& point, const cubos::core::geom::Plane& plane) -> CUBOS_CORE_API bool
Computes if a point is in the area limited by the plane.
auto getMaxVertexInAxis(int numVertices, const glm::vec3 vertices[], const glm::vec3& localAxis) -> CUBOS_CORE_API int
Computes the vertex furthest along the axis.
auto getIncidentReferencePolygon(const cubos::core::geom::Box& shape, const glm::vec3& normal, std::vector<glm::vec3>& outPoints, glm::vec3& outNormal, std::vector<cubos::core::geom::Plane>& outAdjacentPlanes, const glm::mat4& localToWorld, float scale) -> CUBOS_CORE_API void
Computes the candidate face of the polygon to be reference, as well as it's normal and adjacent planes.
auto getClosestPointEdge(const glm::vec3& point, glm::vec3 start, glm::vec3 end) -> CUBOS_CORE_API glm::vec3
Computes the closest point on the line (edge) to point.
auto getClosestPointPolygon(const glm::vec3& point, const std::vector<glm::vec3>& polygon) -> CUBOS_CORE_API glm::vec3
Iterates through all edges in polygon and computes closest position on the edges of the polygon to point.
auto getCameraFrustumCorners(const glm::mat4& view, const glm::mat4& proj, float zNear, float zFar, std::vector<glm::vec4>& corners) -> CUBOS_CORE_API void
Gets a camera's frustum corners in world space.

Function documentation

CUBOS_CORE_API bool cubos::core::geom::intersects(const Box& box1, const glm::mat4& localToWorld1, const Box& box2, const glm::mat4& localToWorld2, Intersection& intersect)

Computes the intersection between two box shapes.

Parameters
box1 Box shape of the first entity.
localToWorld1 Local to world matrix of the first entity.
box2 Box shape of the second entity.
localToWorld2 Local to world matrix of the second entity.
intersect

CUBOS_CORE_API std::vector<glm::vec3> cubos::core::geom::sutherlandHodgmanClipping(const std::vector<glm::vec3>& inputPolygon, int numClipPlanes, const cubos::core::geom::Plane* clipPlanes, bool removeNotClipToPlane)

Performs the Sutherland-Hodgman Clipping algorithm.

Parameters
inputPolygon The polygon to perform the clipping on.
numClipPlanes Number of cliping planes.
clipPlanes Clipping planes
removeNotClipToPlane Whether to remove the points if they're outside the plane.
Returns The polygon resulting from the clipping.

CUBOS_CORE_API bool cubos::core::geom::planeEdgeIntersection(const cubos::core::geom::Plane& plane, const glm::vec3& start, const glm::vec3& end, glm::vec3& outPoint)

Compute the intersection between a plane and an edge.

Parameters
plane The plane.
start The start point of the edge.
end The end point of the edge.
outPoint The position of the intersection.
Returns True if there's intersection, false otherwise.

CUBOS_CORE_API bool cubos::core::geom::pointInPlane(const glm::vec3& point, const cubos::core::geom::Plane& plane)

Computes if a point is in the area limited by the plane.

Parameters
point The position of the point in world coordinates.
plane The plane to use.
Returns True is the point is on the plane or closer, false otherwise.

CUBOS_CORE_API int cubos::core::geom::getMaxVertexInAxis(int numVertices, const glm::vec3 vertices[], const glm::vec3& localAxis)

Computes the vertex furthest along the axis.

Parameters
numVertices
vertices Array of vertices.
localAxis The direction of the axis in local coordinates.
Returns The index of the vertex.

CUBOS_CORE_API void cubos::core::geom::getIncidentReferencePolygon(const cubos::core::geom::Box& shape, const glm::vec3& normal, std::vector<glm::vec3>& outPoints, glm::vec3& outNormal, std::vector<cubos::core::geom::Plane>& outAdjacentPlanes, const glm::mat4& localToWorld, float scale)

Computes the candidate face of the polygon to be reference, as well as it's normal and adjacent planes.

Parameters
shape Collider shape.
normal The reference normal in world coordinates.
outPoints The points of the resulting face.
outNormal The resulting normal.
outAdjacentPlanes The resulting adjacent planes (4).
localToWorld The localToWorld matrix of the body.
scale The scale of the body.

TODO: since this is a box shape, we know how many points and adjacent planes exist beforehand

CUBOS_CORE_API glm::vec3 cubos::core::geom::getClosestPointEdge(const glm::vec3& point, glm::vec3 start, glm::vec3 end)

Computes the closest point on the line (edge) to point.

Parameters
point Position of the point.
start Starting position of the edge.
end End position of the edge.
Returns Closest position on edge to the point.

CUBOS_CORE_API glm::vec3 cubos::core::geom::getClosestPointPolygon(const glm::vec3& point, const std::vector<glm::vec3>& polygon)

Iterates through all edges in polygon and computes closest position on the edges of the polygon to point.

Parameters
point Position of the point.
polygon List of points that compose the shape (edges are defined as a line-loop list of vertices).
Returns Closest point that resides on any of the given edges of the polygon.

CUBOS_CORE_API void cubos::core::geom::getCameraFrustumCorners(const glm::mat4& view, const glm::mat4& proj, float zNear, float zFar, std::vector<glm::vec4>& corners)

Gets a camera's frustum corners in world space.

Parameters
view Matrix that transforms world space to the camera's view space.
proj Matrix that transforms the camera's view space to its clip space.
zNear Near clipping plane.
zFar Far clipping plane.
corners Output vector where the corners will be stored.