Saga
Saga Game Engine
Loading...
Searching...
No Matches
Geometry

Classes

struct  Saga::Geometry::Triangle
 Represents a 3D triangle, equipped with some utility functions. More...
 

Functions

std::optional< float > Saga::Geometry::rayBoxCollision (glm::vec3 rayOrigin, glm::vec3 rayDir, glm::vec3 cornerBotLeft, glm::vec3 cornerTopRight)
 Find the intersection time t between a ray and a box.
 
glm::vec2 Saga::Geometry::detectCircleCollision (const glm::vec2 &aPos, const float &aRadius, const glm::vec2 &bPos, const float &bRadius)
 Detect if two circles overlap. If they do, output the minimum translation vector from the first circle for both to not be colliding.
 
std::optional< std::tuple< float, float > > Saga::Geometry::rayUnitCircleAtOriginIntersection (const glm::vec2 &origin, const glm::vec2 &rayDirection)
 Find the entrance and exit times t between a unit circle at the origin and a ray.
 
glm::vec3 Saga::Geometry::detectAACylinderCylinderCollision (float height0, float radius0, glm::vec3 pos0, float height1, float radius1, glm::vec3 pos1)
 Find the minimum translation vector for two axis-aligned cylinders. If the two cylinders are not penetrating, then return the zero vector.
 
std::optional< std::tuple< float, glm::vec3 > > Saga::Geometry::movingCylinderCylinderIntersection (float height0, float radius0, glm::vec3 pos0, float height1, float radius1, glm::vec3 pos1, glm::vec3 dir)
 Find the earliest time between intersection of two cylinders, one of which is moving. It must be the case that the two cylinders are not penetrating at the start.
 
std::optional< float > Saga::Geometry::rayEllipsoidIntersection (const glm::vec3 &rayOrigin, const glm::vec3 &rayDirection, const glm::vec3 &position, const glm::vec3 &radius)
 Find the intersection time t between a ray and an axis-aligned ellipsoid.
 
std::optional< float > Saga::Geometry::rayUnitSphereAtOriginIntersection (const glm::vec3 &origin, const glm::vec3 &rayDirection)
 Find the intersection time t between a unit sphere at the origin and a ray.
 
std::optional< float > Saga::Geometry::unitSphereTriangleCollision (const glm::vec3 &pos, const glm::vec3 &dir, const glm::vec3 &a, const glm::vec3 &b, const glm::vec3 &c)
 Find the intersection time t between a moving unit sphere with a triangle.
 
std::optional< float > Saga::Geometry::movingEllipsoidEllipsoidIntersection (const glm::vec3 &ellipsoidPos0, const glm::vec3 &ellipsoidDir0, const glm::vec3 &ellipsoidRadius0, const glm::vec3 &ellipsoidPos1, const glm::vec3 &ellipsoidRadius1)
 Find the intersection between two moving axis-aligned ellipsoids.
 
std::optional< float > Saga::Geometry::ellipsoidTriangleCollision (const glm::vec3 &ellipsoidPos, const glm::vec3 &ellipsoidDir, const glm::vec3 &ellipsoidRadius, const glm::vec3 &a, const glm::vec3 &b, const glm::vec3 &c)
 Find the intersection time t between a moving ellipsoid and a triangle.
 
std::optional< float > Saga::Geometry::unitSphereEdgeCollision (const glm::vec3 &pos, const glm::vec3 &dir, const glm::vec3 &c, const glm::vec3 &d)
 Find collision between a moving unit sphere and an edge (line segment) in 3D.
 
float Saga::Geometry::detectLineSegmentCollision (const float &alo, const float &ahi, const float &blo, const float &bhi)
 Detect collision (and return minimum translation vector) of two line segments.
 
std::optional< float > Saga::Geometry::rayTriangleIntersection (const glm::vec3 &origin, const glm::vec3 &rayDirection, Triangle triangle)
 Find the intersection time t where a ray and triangle intersects. Does not detect intersections to the back side of the triangle.
 
glm::vec3 Saga::Geometry::getClosestPoint (const glm::vec3 pointPos, Triangle triangle)
 Find the closest point between a point and a triangle.
 

Detailed Description

Function Documentation

◆ detectAACylinderCylinderCollision()

glm::vec3 Saga::Geometry::detectAACylinderCylinderCollision ( float  height0,
float  radius0,
glm::vec3  pos0,
float  height1,
float  radius1,
glm::vec3  pos1 
)

Find the minimum translation vector for two axis-aligned cylinders. If the two cylinders are not penetrating, then return the zero vector.

Parameters
height0height of the first cylinder.
radius0radius of the first cylinder.
pos0position of the first cylinder.
height1height of the second cylinder.
radius1radius of the second cylinder.
pos1position of the second cylinder.
Returns
glm::vec3 The minimum translation vector.
Here is the call graph for this function:

◆ detectCircleCollision()

glm::vec2 Saga::Geometry::detectCircleCollision ( const glm::vec2 &  aPos,
const float &  aRadius,
const glm::vec2 &  bPos,
const float &  bRadius 
)

Detect if two circles overlap. If they do, output the minimum translation vector from the first circle for both to not be colliding.

Parameters
aPoscenter of the first circle.
aRadiusradius of the first circle.
bPoscenter of the second circle.
bRadiusradius of the second circle.
Returns
glm::vec2 zero if non overlapping. The minimum translation vector with respect to the first circle otherwise.

◆ detectLineSegmentCollision()

float Saga::Geometry::detectLineSegmentCollision ( const float &  alo,
const float &  ahi,
const float &  blo,
const float &  bhi 
)

Detect collision (and return minimum translation vector) of two line segments.

Parameters
alostarting point of the first line segment.
ahiending point of the first line segment. Must be at least the starting point.
blostarting point of the second line segment.
bhiending point of the second line segment. Must be at least the starting point.
Returns
float minimum distance the first line segment has to move for both to not be intersecting

◆ ellipsoidTriangleCollision()

std::optional< float > Saga::Geometry::ellipsoidTriangleCollision ( const glm::vec3 &  ellipsoidPos,
const glm::vec3 &  ellipsoidDir,
const glm::vec3 &  ellipsoidRadius,
const glm::vec3 &  a,
const glm::vec3 &  b,
const glm::vec3 &  c 
)

Find the intersection time t between a moving ellipsoid and a triangle.

Parameters
ellipsoidPosposition of the ellipsoid.
ellipsoidDirdirection of the ellipsoid.
ellipsoidRadiusradius of the ellipsoid.
atriangle first point in counter-clockwise order.
btriangle second point in counter-clockwise order.
ctriangle third point in counter-clockwise order.
Returns
float t in [0,1] such that ellipsoidPos + t * ellipsoidDir is the first time the ellipsoid intersects with the triangle.
float t in [0,1] such that ellipsoidPos * t * ellipsoidDir is the time the ellipsoid exits the triangle, should it already intersect at ellipsoidPos.
nothing if t does not exists, or is not in range, or the ellipsoid is not moving.
Here is the call graph for this function:

◆ getClosestPoint()

glm::vec3 Saga::Geometry::getClosestPoint ( const glm::vec3  pointPos,
Triangle  triangle 
)

Find the closest point between a point and a triangle.

Parameters
pointPosposition of the point in cartesian coordinate.
trianglethe triangle.
Returns
glm::vec3 a point inside the triangle whose euclidean distance is cloest to the pointPos.
Here is the call graph for this function:

◆ movingCylinderCylinderIntersection()

std::optional< std::tuple< float, glm::vec3 > > Saga::Geometry::movingCylinderCylinderIntersection ( float  height0,
float  radius0,
glm::vec3  pos0,
float  height1,
float  radius1,
glm::vec3  pos1,
glm::vec3  dir 
)

Find the earliest time between intersection of two cylinders, one of which is moving. It must be the case that the two cylinders are not penetrating at the start.

Parameters
height0height of the first cylinder.
radius0radius of the first cylinder.
pos0position of the first cylinder.
height1height of the second cylinder.
radius1radius of the second cylinder.
pos1position of the second cylinder.
dirthe direction of the first cylinder.
Returns
float t in (0,1] such that pos0 + t * dir is the first time that the two cylinders intersect.
glm::vec3 normal the normal direction of the contact.
nothing if the two cylinders are already penetrating, or if t does not exist in the range (0,1]. @warn does not work on degenerate cylinders. Will return nothing.
Here is the call graph for this function:

◆ movingEllipsoidEllipsoidIntersection()

std::optional< float > Saga::Geometry::movingEllipsoidEllipsoidIntersection ( const glm::vec3 &  ellipsoidPos0,
const glm::vec3 &  ellipsoidDir0,
const glm::vec3 &  ellipsoidRadius0,
const glm::vec3 &  ellipsoidPos1,
const glm::vec3 &  ellipsoidRadius1 
)

Find the intersection between two moving axis-aligned ellipsoids.

Parameters
ellipsoidPos0position of the first ellipsoid.
ellipsoidDir0direction that the first ellipsoid is moving.
ellipsoidRadius0radius of the first ellipsoid.
ellipsoidPos1position of the second ellipsoid.
ellipsoidRadius1radius of the second ellipsoid.
Here is the call graph for this function:

◆ rayBoxCollision()

std::optional< float > Saga::Geometry::rayBoxCollision ( glm::vec3  rayOrigin,
glm::vec3  rayDir,
glm::vec3  cornerBotLeft,
glm::vec3  cornerTopRight 
)

Find the intersection time t between a ray and a box.

Parameters
rayOriginorigin of the ray.
rayDirdirection of the ray
cornerbotLeftbottom left corner of the box.
cornerTopRIghtupper right corner of the box.
Returns
either the time t in [0,1] where rayOrigin + rayDir * t is intersecting the box, or nothing. If the ray starts inside the box, this return 0.

◆ rayEllipsoidIntersection()

std::optional< float > Saga::Geometry::rayEllipsoidIntersection ( const glm::vec3 &  rayOrigin,
const glm::vec3 &  rayDirection,
const glm::vec3 &  position,
const glm::vec3 &  radius 
)

Find the intersection time t between a ray and an axis-aligned ellipsoid.

Parameters
originorigin of the ray.
rayDirectiondirection of the ray.
positionposition of the ellipsoid.
radiusradius of the ellipsoid.
Returns
std::optional<float> t in the range [0,1] such that origin + t * rayDirection is the intersection between the ray and the ellipsoid.
nothing if no such t exists.
0 if ray starts out intersecting the the ellipsoid.
Here is the call graph for this function:

◆ rayTriangleIntersection()

std::optional< float > Saga::Geometry::rayTriangleIntersection ( const glm::vec3 &  origin,
const glm::vec3 &  rayDirection,
Triangle  triangle 
)

Find the intersection time t where a ray and triangle intersects. Does not detect intersections to the back side of the triangle.

Parameters
originorigin of the ray.
rayDirectiondirection of the ray.
trianglethe triangle.
Returns
float t in [0,1] such that origin + t * rayDirection is the intersection point between the ray and the triangle.
nothing if t does not exist, or is not in range, or is grazing (parallel to the triangle).
0 if ray starts out intersecting the triangle.

◆ rayUnitCircleAtOriginIntersection()

std::optional< std::tuple< float, float > > Saga::Geometry::rayUnitCircleAtOriginIntersection ( const glm::vec2 &  origin,
const glm::vec2 &  rayDirection 
)

Find the entrance and exit times t between a unit circle at the origin and a ray.

Parameters
originorigin of the ray.
rayDirectiondirection of the ray.
Returns
tlo <= thi such that origin + tlo * rayDirection is the intersection between the ray and the unit circle, and the same applies to thi.
nothing if no intersection exists.
Here is the call graph for this function:

◆ rayUnitSphereAtOriginIntersection()

std::optional< float > Saga::Geometry::rayUnitSphereAtOriginIntersection ( const glm::vec3 &  origin,
const glm::vec3 &  rayDirection 
)

Find the intersection time t between a unit sphere at the origin and a ray.

Parameters
originorigin of the ray.
rayDirectiondirection of the ray.
Returns
float t in the range [0,1] such that origin + t * rayDirection is the intersection between the ray and the unit sphere.
0 if ray origin already intersect the unit sphere.
nothing if no intersection exists.
Here is the call graph for this function:

◆ unitSphereEdgeCollision()

std::optional< float > Saga::Geometry::unitSphereEdgeCollision ( const glm::vec3 &  pos,
const glm::vec3 &  dir,
const glm::vec3 &  c,
const glm::vec3 &  d 
)

Find collision between a moving unit sphere and an edge (line segment) in 3D.

Parameters
posposition of the sphere.
dirdirection the sphere is moving in.
can endpoint of the line segment.
danother endpoint of the line segment.
Returns
float t in [0,1] such that pos + dir * t is when the sphere collide with the line segment.
float t in [0,1] such that pos + dir * t is when the sphere exits the line segment, if the sphere already collides at pos.
nothing if no such point exists, or none exists in the given range.
Here is the call graph for this function:

◆ unitSphereTriangleCollision()

std::optional< float > Saga::Geometry::unitSphereTriangleCollision ( const glm::vec3 &  pos,
const glm::vec3 &  dir,
const glm::vec3 &  a,
const glm::vec3 &  b,
const glm::vec3 &  c 
)

Find the intersection time t between a moving unit sphere with a triangle.

Parameters
posposition of the unit sphere.
dirdirection of the unit sphere.
atriangle first point in counter-clockwise order.
btriangle second point in counter-clockwise order.
ctriangle third point in counter-clockwise order.
Returns
float positive t such that pos + t * dir is the first time the unit sphere intersects with the triangle. If they already intersects, then this would be the time they exits. -1 if no such time exists. t is in the range [0,1] otherwise
Here is the call graph for this function: