ToyMaker Game Engine 0.0.2
ToyMaker is a game engine developed and maintained by Zoheb Shujauddin.
Loading...
Searching...
No Matches
Spatial Queries

Files

file  ToyMaker_Main/include/toymaker/engine/spatial_query/math.hpp
 Geometrical, mathematical functions and related structs used to answer some simple questions about shapes situated somewhere in the world.
file  ToyMaker_Main/include/toymaker/engine/spatial_query/octree.hpp
 Data structures, functions, and methods relating to the hierarchical organization and representation of spatial data.
file  ToyMaker_Main/include/toymaker/engine/spatial_query/sweep_prune.hpp
 Acceleration structure for finding pairs of objects whose AABBs are intersecting.
file  ToyMaker_Main/include/toymaker/engine/spatial_query/system.hpp
 The file containing classes related to the spatial query system, which uses simplified geometrical data and spatial indexing data structures to answer spatial queries generated by other parts of the program.
file  ToyMaker_Main/include/toymaker/engine/spatial_query/types.hpp
 Classes and structs representing data related to the engine's spatial query system (the precursor to a full-fledged physics system).

Classes

class  ToyMaker::OctreeNode
 A single node of an octree, representing a single octant of the 8 that make up its parent region. More...
class  ToyMaker::Octree
 A data structure used for speeding up spatial queries about 3-dimensional objects in the scene. More...
class  ToyMaker::CollisionPair
 Names two distinct entities participating in a collision, with their entity IDs sorted in ascending order. More...
class  ToyMaker::SweepPrune
 A class designed around finding which pairs of AABBs may be intersecting (so as to limit the number of full collision checks that need be performed). More...
class  ToyMaker::SpatialQuerySystem
 The spatial query system, an ECS System that tracks and updates spatial query data for objects in the scene, and which exposes spatial query methods. More...
class  ToyMaker::SpatialQuerySystem::LightBoundsComputeSystem
 A subsystem of the spatial query system responsible for tracking light volumes and recomputing their ObjectBounds accordingly. More...
struct  ToyMaker::VolumeBase_
 The base class of all spatial query volumes. More...
struct  ToyMaker::Volume< TDerived >
struct  ToyMaker::VolumeBox
 Holds the parameters describing the spatial query volume of a simple three-dimensionsal box. More...
struct  ToyMaker::VolumeCapsule
 Holds the parameters describing the spatial query volume of a simple three-dimensionsal capsule (or pill, or whatever you like). More...
struct  ToyMaker::VolumeSphere
 Holds parameters describing a spherical spatial query volume. More...
struct  ToyMaker::AreaTriangle
 A set of 3 points located in the world forming a (hopefully sensible) triangle. More...
struct  ToyMaker::AreaCircle
 A set of numbers representing a single circle situated somewhere in the world. More...
struct  ToyMaker::Ray
 A set of numbers describing a ray with its source at some finite point in the world, projected in a direction for some positive length. More...
struct  ToyMaker::Plane
 A set of numbers describing a plane situated somewhere in the world. More...
struct  ToyMaker::ObjectBounds
 A component defining the true bounds of a spatially queryable object situated somewhere in the world. More...
class  ToyMaker::AxisAlignedBounds
 An object containing a coarse simplified representation, AABB, of spatially queryable objects. More...

Typedefs

using ToyMaker::BoxCorner = uint8_t
 Type used to represent the name of the corner of a box.
using ToyMaker::InteractionLayerMask = uint16_t
 Bit field where each bit represents an interaction layer – a physics/spatial layer that can trigger or receive events from objects in other related layers.

Enumerations

enum  ToyMaker::BoxCornerSpecifier : BoxCorner { RIGHT =0x1 , TOP =0x2 , FRONT =0x4 }
 Enum values correspond to bits on a BoxCorner which help specify which side of the box on each axis is being indicated.

Functions

glm::mat3 ToyMaker::computeBarycentricSolver (const AreaTriangle &triangle)
 Computes a Barycentric solver matrix based on an input triangle.
std::pair< bool, glm::vec3 > ToyMaker::computeIntersection (const Ray &ray, const Plane &plane)
 Returns a bool-vector pair, with bool indicating whether a point of intersection was found, and the vector containing the point of intersection.
std::pair< bool, glm::vec3 > ToyMaker::computeIntersection (const Ray &ray, const AreaTriangle &triangle)
 Returns a bool-vector pair, with bool indicating whether a point of intersection was found, and the vector containing the point of intersection.
std::pair< uint8_t, std::pair< glm::vec3, glm::vec3 > > ToyMaker::computeIntersections (const Ray &ray, const AxisAlignedBounds &axisAlignedBounds)
 Returns an unsigned int and vector-pair pair, with unsigned indicating whether any and how many points of intersection were found with the AABB, and the vector containing the points of intersection.
std::pair< uint8_t, std::pair< glm::vec3, glm::vec3 > > ToyMaker::computeIntersections (const Ray &ray, const ObjectBounds &objectbounds)
 Returns an unsigned int and vector pair pair, with int indicating whether and how many points of intersection were found, and the vector containing the points of intersection.
bool ToyMaker::overlaps (const glm::vec3 &point, const ObjectBounds &bounds)
 Returns a bool value indicating whether point is contained by bounds.
bool ToyMaker::overlaps (const ObjectBounds &bounds, const glm::vec3 &point)
 Returns a bool value indicating whether point is contained by bounds.
bool ToyMaker::overlaps (const Ray &ray, const ObjectBounds &bounds)
 Returns a bool value indicating whether the ray passes through the object volume.
bool ToyMaker::overlaps (const ObjectBounds &bounds, const Ray &ray)
 Returns a bool value indicating whether the ray passes through the object volume.
bool ToyMaker::overlaps (const glm::vec3 &point, const AxisAlignedBounds &bounds)
 Returns whether point is contained by bounds.
bool ToyMaker::overlaps (const AxisAlignedBounds &bounds, const glm::vec3 &point)
 Returns whether point is contained by bounds.
bool ToyMaker::overlaps (const Ray &ray, const AxisAlignedBounds &bounds)
 Returns whether ray overlaps with bounds.
bool ToyMaker::overlaps (const AxisAlignedBounds &bounds, const Ray &ray)
 Returns whether ray overlaps with bounds.
bool ToyMaker::overlaps (const AxisAlignedBounds &one, const AxisAlignedBounds &two)
 Returns whether one overlaps two.
bool ToyMaker::overlaps (const ObjectBounds &one, const ObjectBounds &two)
 Returns whether one overlaps two.
bool ToyMaker::overlaps (const AxisAlignedBounds &one, const ObjectBounds &two)
 Returns whether one overlaps two.
bool ToyMaker::overlaps (const ObjectBounds &one, const AxisAlignedBounds &two)
 Returns whether one overlaps two.
Collision ToyMaker::checkCollisionSphereSphere (const ObjectBounds &one, const ObjectBounds &two)
 Specialization of checkCollision() where both objects being tested are spheres.
bool ToyMaker::contains (const glm::vec3 &point, const ObjectBounds &bounds)
 Returns whether point is contained by bounds.
bool ToyMaker::contains (const glm::vec3 &point, const AxisAlignedBounds &bounds)
 Returns whether point is contained by bounds.
bool ToyMaker::contains (const Ray &ray, const AxisAlignedBounds &bounds)
 Returns whether ray is contained by bounds.
bool ToyMaker::contains (const Ray &ray, const ObjectBounds &bounds)
 Returns whether ray is contained by bounds.
bool ToyMaker::contains (const AxisAlignedBounds &one, const AxisAlignedBounds &two)
 Returns whether one is contained by two.
bool ToyMaker::contains (const ObjectBounds &one, const AxisAlignedBounds &two)
 Returns whether one is contained by two.
template<typename T, typename U>
glm::vec3 ToyMaker::minkowskiDifference (const T &one, const U &two, const glm::vec3 &along)
 Closely associated with GJK; finds the Minkowski difference between two shapes situated somewhere in the world.
template<typename T, typename U>
std::tuple< glm::vec3, glm::vec3, glm::vec3 > ToyMaker::minkowskiDifferenceFull (const T &one, const U &two, const glm::vec3 &along)
 Closely associated with GJK; finds the Minkowski difference between two shapes situated somewhere in the world.
std::array< AreaTriangle, 12 > ToyMaker::computeBoxFaceTriangles (const std::array< glm::vec3, 8 > &boxCorners)
 Generates a list of triangles making up the surface of a box situated somewhere in the world, given the coordinates of its corners.
bool ToyMaker::ObjectBounds::isPositiveStrict () const
 Checks whether underlying bounds is non-trivial, as in each important parameter that represents the volume is greater than 0.
InteractionLayerMask ToyMaker::ObjectBounds::getInteractionLayers () const
 Returns an integer representing which spatial queries and collisions this object will participate in.
void ToyMaker::ObjectBounds::setInteractionLayers (InteractionLayerMask newLayers)
 Moves this object into a new group of interaction layers.
InteractionLayerMask ToyMaker::ObjectBounds::getInteractionMask () const
 Returns an integer representing which layers this object will generate spatial queries and collisions for.
void ToyMaker::ObjectBounds::setInteractionMask (InteractionLayerMask newMask)
 Changes which set of interaction layers this object can trigger events with.
InteractionLayerMask ToyMaker::AxisAlignedBounds::getInteractionLayers () const
 Returns an integer representing which spatial queries and collisions this object will participate in.
void ToyMaker::AxisAlignedBounds::setInteractionLayers (InteractionLayerMask newLayers)
 Sets interaction layer mask for this object.
 ToyMaker::NLOHMANN_JSON_SERIALIZE_ENUM (ObjectBounds::TrueVolumeType, { {ObjectBounds::TrueVolumeType::BOX, "box"}, {ObjectBounds::TrueVolumeType::SPHERE, "sphere"}, {ObjectBounds::TrueVolumeType::CAPSULE, "capsule"}, }) inline void to_json(nlohmann
void ToyMaker::from_json (const nlohmann::json &json, ObjectBounds &objectBounds)
void ToyMaker::to_json (nlohmann::json &json, const AxisAlignedBounds &axisAlignedBounds)
void ToyMaker::from_json (const nlohmann::json &json, AxisAlignedBounds &objectBounds)
std::pair< glm::vec3, glm::vec3 > ToyMaker::getTangents (const glm::vec3 &vector)
 Returns a pair of normalized tangents to an input vector.

Detailed Description

Function Documentation

◆ checkCollisionSphereSphere()

Collision ToyMaker::checkCollisionSphereSphere ( const ObjectBounds & one,
const ObjectBounds & two )

Specialization of checkCollision() where both objects being tested are spheres.

This is useful because we can get collision information in a single iteration and avoid the expensive gjk test.

◆ computeBarycentricSolver()

glm::mat3 ToyMaker::computeBarycentricSolver ( const AreaTriangle & triangle)

Computes a Barycentric solver matrix based on an input triangle.

Warning
Error if triangle with colinear points provided.

◆ computeBoxFaceTriangles()

std::array< AreaTriangle, 12 > ToyMaker::computeBoxFaceTriangles ( const std::array< glm::vec3, 8 > & boxCorners)

Generates a list of triangles making up the surface of a box situated somewhere in the world, given the coordinates of its corners.

Parameters
boxCornersAn array containing coordinates for the corners of a box located somewhere in the world.
Returns
std::array<AreaTriangle, 12> The triangles representing the faces of the box.

◆ computeIntersection() [1/2]

std::pair< bool, glm::vec3 > ToyMaker::computeIntersection ( const Ray & ray,
const AreaTriangle & triangle )

Returns a bool-vector pair, with bool indicating whether a point of intersection was found, and the vector containing the point of intersection.

Warning
Error if invalid ray or triangle specified (triangle with no area, or ray with no direction)

◆ computeIntersection() [2/2]

std::pair< bool, glm::vec3 > ToyMaker::computeIntersection ( const Ray & ray,
const Plane & plane )

Returns a bool-vector pair, with bool indicating whether a point of intersection was found, and the vector containing the point of intersection.

Warning
Error if invalid ray or plane specified (plane with no normal, or ray with no direction)

◆ computeIntersections() [1/2]

std::pair< uint8_t, std::pair< glm::vec3, glm::vec3 > > ToyMaker::computeIntersections ( const Ray & ray,
const AxisAlignedBounds & axisAlignedBounds )

Returns an unsigned int and vector-pair pair, with unsigned indicating whether any and how many points of intersection were found with the AABB, and the vector containing the points of intersection.

(if the ray "glances off" the volume, it does not count as an intersection per my implementation)

Warning
Error if invalid ray or AABB specified, which includes an AABB with negative or zero volume.

◆ computeIntersections() [2/2]

std::pair< uint8_t, std::pair< glm::vec3, glm::vec3 > > ToyMaker::computeIntersections ( const Ray & ray,
const ObjectBounds & objectbounds )

Returns an unsigned int and vector pair pair, with int indicating whether and how many points of intersection were found, and the vector containing the points of intersection.

Object bounds only supports convex shapes, and so one can expect that if a point of intersection exists, then there will be a second to go with it. (provided the ray is long enough) (and also unless the ray "glances off" the volume, which counts as no intersection per my implementation)

◆ getTangents()

std::pair< glm::vec3, glm::vec3 > ToyMaker::getTangents ( const glm::vec3 & vector)

Returns a pair of normalized tangents to an input vector.

See Erin Catto's blog post for the method used here to derive consistent tangents to a vector efficiently.

◆ minkowskiDifference()

template<typename T, typename U>
glm::vec3 ToyMaker::minkowskiDifference ( const T & one,
const U & two,
const glm::vec3 & along )
inline

Closely associated with GJK; finds the Minkowski difference between two shapes situated somewhere in the world.

See also
gjkOverlaps

◆ minkowskiDifferenceFull()

template<typename T, typename U>
std::tuple< glm::vec3, glm::vec3, glm::vec3 > ToyMaker::minkowskiDifferenceFull ( const T & one,
const U & two,
const glm::vec3 & along )
inline

Closely associated with GJK; finds the Minkowski difference between two shapes situated somewhere in the world.

See also
gjkOverlaps
Returns
std::tuple<glm::vec3, glm::vec3, glm::vec3> 0. Minkowski difference; 1. SupportA; 2. SupportB