ToyMaker Game Engine 0.0.2
ToyMaker is a game engine developed and maintained by Zoheb Shujauddin.
Loading...
Searching...
No Matches
ToyMaker::ObjectBounds Struct Reference

A component defining the true bounds of a spatially queryable object situated somewhere in the world. More...

#include <types.hpp>

Classes

union  TrueVolume
 A union of supported volume structs. More...

Public Types

enum class  TrueVolumeType : uint8_t { BOX =0 , SPHERE , CAPSULE }
 The types of volumes supported by the engine.

Public Member Functions

void applyModelMatrix (const glm::mat4 &modelMatrix)
 Computes new mPosition and mOrientation offsets based on (presumably) the model transform of the underlying scene object.
glm::mat3 getRotationTransformLocal () const
 Gets the rotation matrix associated with this object's orientation offset.
glm::mat4 getRotationTransformOrigin () const
 Gets the rotation matrix associated with the underlying scene object's orientation.
glm::mat4 getTranslationTransformOrigin () const
 Gets the translation matrix associated with the underlying scene object's translation.
glm::vec3 getPositionWorld () const
 The final position of the origin of the object bounds in the world.
void setPositionWorld (const glm::vec3 &newPosition)
 Sets the new world position for the object while keeping its offset relative to its entity fixed.
void setPositionOffset (const glm::vec3 &newPosition)
 Sets the offset of the bounds origin to the scene node origin.
void setPositionOrigin (const glm::vec3 &newPosition)
 Sets the position of the scene node origin.
void recomputeWorldPositionOrientation ()
 Recomputes bounds world position based on origin and offsets.
glm::quat getOrientationWorld () const
 The final orientation of the object bounds in the world.
void setOrientationWorld (const glm::quat &newOrientation)
 Sets the new world orientation for the object while keeping its offset relative to its entity fixed.
void setOrientationOffset (const glm::quat &newOrientation)
 Sets orientation offset relative to the scene node's orientation.
void setOrientationOrigin (const glm::quat &newOrientation)
 Sets orientation of the scene node.
std::array< glm::vec3, 8 > getVolumeRelativeBoxCorners () const
 Gets the corners of the box just encapsulating this object's true volume, relative to the origin of the spatial query volume alone.
std::array< glm::vec3, 8 > getLocalOrientedBoxCorners () const
 Gets the corners of the box just encapsulating this object's true volume and sharing its position and orientation, relative to the origin of the underlying scene node at 0,0,0 (in short, in model space).
std::array< glm::vec3, 8 > getWorldOrientedBoxCorners () const
 Gets the corners of the box just encapsulating this object's true volume relative to the origin of the underlying scene node in world space.
std::array< AreaTriangle, 12 > getWorldOrientedBoxFaceTriangles () const
 Gets an array of triangles that make up the faces of the bounds-aligned box corners in world space.
std::pair< TrueVolumeType, TrueVolumegetVolume () const
 Returns the volume and its type associated with these bounds.
void setVolume (TrueVolumeType type, const TrueVolume &volume)
 Sets the volume for these bounds.
void setVolumeBox (const glm::vec3 &boxDimensions)
 Sets a box volume for this object.
void setVolumeCapsule (float radius, float height)
 Sets a capsule volume for this object.
void setVolumeSphere (float radius)
 Sets a sphere volume for this object.
glm::vec3 getSupportAlong (const glm::vec3 &axis) const
 Returns the point on this object's surface furthest along a given axis from the origin of this object.
std::pair< float, float > getProjectionAlong (const glm::vec3 &axis) const
 Returns this shape's projection along some unit vector.
bool isSensible () const
 Returns whether the underlying volume has sensible parameters (i.e., finite, non-degenerate, non-negative parameters).
bool isPositiveStrict () const
 Checks whether underlying bounds is non-trivial, as in each important parameter that represents the volume is greater than 0.
InteractionLayerMask getInteractionLayers () const
 Returns an integer representing which spatial queries and collisions this object will participate in.
void setInteractionLayers (InteractionLayerMask newLayers)
 Moves this object into a new group of interaction layers.
InteractionLayerMask getInteractionMask () const
 Returns an integer representing which layers this object will generate spatial queries and collisions for.
void setInteractionMask (InteractionLayerMask newMask)
 Changes which set of interaction layers this object can trigger events with.

Static Public Member Functions

static std::string getComponentTypeName ()
 Fetches the component type string associated with this class.
static ObjectBounds create (const VolumeBox &box, const glm::vec3 &positionOffset, const glm::quat &orientationOffset, InteractionLayerMask interactionLayers=0x1, InteractionLayerMask interactionMask=std::numeric_limits< InteractionLayerMask >::max())
 Creates bounds for an object in the shape of a box.
static ObjectBounds create (const VolumeCapsule &capsule, const glm::vec3 &positionOffset, const glm::quat &orientationOffset, InteractionLayerMask interactionLayers=0x1, InteractionLayerMask interactionMask=std::numeric_limits< InteractionLayerMask >::max())
 Creates bounds for an object in the shape of a capsule.
static ObjectBounds create (const VolumeSphere &sphere, const glm::vec3 &positionOffset, const glm::quat &orientationOffset, InteractionLayerMask interactionLayers=0x1, InteractionLayerMask interactionMask=std::numeric_limits< InteractionLayerMask >::max())
 Creates bounds for an object in the shape of a sphere.

Public Attributes

TrueVolumeType mType { TrueVolumeType::BOX }
 Value indicating the type of the volume represented by this object.
TrueVolume mTrueVolume {}
 The data defining the volume itself, independent of its position.
glm::vec3 mPositionWorld { 0.f }
 The world position of the bounds of this object in the current frame.
glm::vec3 mPositionOrigin { 0.f }
 The position, in the real world, of origin of the scene node this data is attached to.
glm::vec3 mPositionOffset { 0.f }
 The position of the origin of the spatial query volume relative to the origin of the node it is attached to.
glm::quat mOrientationWorld { glm::vec3 { 0.f } }
 The world orientation of the bounds of this object in the current frame.
glm::quat mOrientationOrigin { glm::vec3{ 0.f } }
 The orientation in the real world of the origin of the scene node this bounds component is attached to.
glm::quat mOrientationOffset { glm::vec3{ 0.f } }
 The transformation mapping forward as known by the underlying scene node, to forward as known by the spatial query volume.
InteractionLayerMask mInteractionLayers { 0x1 }
 Determines which spatial queries and collisions this object participates in.
InteractionLayerMask mInteractionMask { std::numeric_limits<InteractionLayerMask>::max() }
 Determines which spatial queries and collisions this object will generate.
bool mUpdatedFromTransform { true }
 Whether an update on the object's transform is allowed to modify object bounds properties.
bool mTransformUpdateRequired { false }
 Flag set when object position or orientation has been set through this component, indicating that the user facing Transform should be updated accordingly.
bool mVolumeSystemComputed { true }
 Flag set when these object bounds were set by the engine, through light bounds compute or model bounds compute.
bool mVolumeUpdateRequired { true }
 Flag set when this object's bounds must be recomputed by a related system.
bool mPhysicsRecomputeRequired { true }
 Flag set when this object's physics properties must be recomputed according to its new volume.

Detailed Description

A component defining the true bounds of a spatially queryable object situated somewhere in the world.

Also provides methods for retrieving related axis aligned and volume aligned box properties.

See also
ECSWorld::registerComponentTypes()

Member Function Documentation

◆ applyModelMatrix()

void ObjectBounds::applyModelMatrix ( const glm::mat4 & modelMatrix)

Computes new mPosition and mOrientation offsets based on (presumably) the model transform of the underlying scene object.

Parameters
modelMatrixThe transform specifying the new origin of the underlying scene object.

◆ create() [1/3]

ObjectBounds ObjectBounds::create ( const VolumeBox & box,
const glm::vec3 & positionOffset,
const glm::quat & orientationOffset,
InteractionLayerMask interactionLayers = 0x1,
InteractionLayerMask interactionMask = std::numeric_limits<InteractionLayerMask>::max() )
static

Creates bounds for an object in the shape of a box.

Parameters
boxThe data defining the volume itself, independent of its placement.
positionOffsetThe offset of the center of the box, relative to the owning entity's position per its Transform.
orientationOffsetThe quaternion specifying the angle offset for these bounds
interactionLayersWhich set of interaction layers this object belongs to
interactionMaskWhich set of interaction layers this object triggers interactions with
Returns
ObjectBounds The constructed object bounds.
Todo
Oriention offset should just be a quaternion. Multiple quaternions may produce the same forward vector while still altering the up and right vectors.

◆ create() [2/3]

ObjectBounds ObjectBounds::create ( const VolumeCapsule & capsule,
const glm::vec3 & positionOffset,
const glm::quat & orientationOffset,
InteractionLayerMask interactionLayers = 0x1,
InteractionLayerMask interactionMask = std::numeric_limits<InteractionLayerMask>::max() )
static

Creates bounds for an object in the shape of a capsule.

Parameters
capsuleThe data defining the volume itself.
positionOffsetThe offset of the center of the capsule, relative to the owning entity's position per its Transform.
orientationOffsetThe quaternion specifying the angle offset for these bounds
interactionLayersWhich set of interaction layers this object belongs to
interactionMaskWhich set of interaction layers this object triggers interactions with
Returns
ObjectBounds The constructed object bounds.
Todo
Oriention offset should just be a quaternion. Multiple quaternions may produce the same forward vector while still altering the up and right vectors.

◆ create() [3/3]

ObjectBounds ObjectBounds::create ( const VolumeSphere & sphere,
const glm::vec3 & positionOffset,
const glm::quat & orientationOffset,
InteractionLayerMask interactionLayers = 0x1,
InteractionLayerMask interactionMask = std::numeric_limits<InteractionLayerMask>::max() )
static

Creates bounds for an object in the shape of a sphere.

Parameters
sphereThe data defining the volume itself.
positionOffsetThe offset of the center of the sphere, relative to the owning entity's position per its Transform.
orientationOffsetThe quaternion specifying the angle offset for these bounds
interactionLayersWhich set of interaction layers this object belongs to
interactionMaskWhich set of interaction layers this object triggers interactions with
Returns
ObjectBounds The constructed object bounds.
Todo
Oriention offset should just be a quaternion. Multiple quaternions may produce the same forward vector while still altering the up and right vectors.

◆ getComponentTypeName()

std::string ToyMaker::ObjectBounds::getComponentTypeName ( )
inlinestatic

Fetches the component type string associated with this class.

Returns
std::string The component type string of this class.

◆ getLocalOrientedBoxCorners()

std::array< glm::vec3, 8 > ObjectBounds::getLocalOrientedBoxCorners ( ) const

Gets the corners of the box just encapsulating this object's true volume and sharing its position and orientation, relative to the origin of the underlying scene node at 0,0,0 (in short, in model space).

Returns
std::array<glm::vec3, 8> An array of coordinates of bounds-aligned box corners in model space.

◆ getOrientationWorld()

glm::quat ObjectBounds::getOrientationWorld ( ) const

The final orientation of the object bounds in the world.

Orientation here refers to global orientation, where w=1,xyz=0 corresponds to the object facing down the -Z axis

Returns
glm::quat The orientation of this node's object bounds.

◆ getPositionWorld()

glm::vec3 ObjectBounds::getPositionWorld ( ) const

The final position of the origin of the object bounds in the world.

Returns
glm::vec3 The origin of this node's object bounds.

◆ getProjectionAlong()

std::pair< float, float > ObjectBounds::getProjectionAlong ( const glm::vec3 & axis) const

Returns this shape's projection along some unit vector.

Returns
std::pair<float, float> The minimum and maximum points of this shape on the vector

◆ getRotationTransformLocal()

glm::mat3 ToyMaker::ObjectBounds::getRotationTransformLocal ( ) const
inline

Gets the rotation matrix associated with this object's orientation offset.

Returns
glm::mat3 This object's orientation offset's rotation matrix representation.

◆ getRotationTransformOrigin()

glm::mat4 ToyMaker::ObjectBounds::getRotationTransformOrigin ( ) const
inline

Gets the rotation matrix associated with the underlying scene object's orientation.

Returns
glm::mat3 The orientation of the underlying scene object's origin.

◆ getSupportAlong()

glm::vec3 ObjectBounds::getSupportAlong ( const glm::vec3 & axis) const

Returns the point on this object's surface furthest along a given axis from the origin of this object.

Strongly related to the Gilbert-Johnson-Keerthi (GJK) algorithm for detecting intersections of convex shapes.

See also
Simplex

◆ getTranslationTransformOrigin()

glm::mat4 ToyMaker::ObjectBounds::getTranslationTransformOrigin ( ) const
inline

Gets the translation matrix associated with the underlying scene object's translation.

Returns
glm::mat4 The translation matrix of the underlying scene object's origin

◆ getVolumeRelativeBoxCorners()

std::array< glm::vec3, 8 > ObjectBounds::getVolumeRelativeBoxCorners ( ) const

Gets the corners of the box just encapsulating this object's true volume, relative to the origin of the spatial query volume alone.

Returns
std::array<glm::vec3, 8> An array of coordinates representing the corners of the box just containing the spatial query volume.

◆ getWorldOrientedBoxCorners()

std::array< glm::vec3, 8 > ObjectBounds::getWorldOrientedBoxCorners ( ) const

Gets the corners of the box just encapsulating this object's true volume relative to the origin of the underlying scene node in world space.

Returns
std::array<glm::vec3, 8> An array of coordinates of bounds-aligned box corners in world space.

◆ getWorldOrientedBoxFaceTriangles()

std::array< AreaTriangle, 12 > ToyMaker::ObjectBounds::getWorldOrientedBoxFaceTriangles ( ) const
inline

Gets an array of triangles that make up the faces of the bounds-aligned box corners in world space.

Returns
std::array<AreaTriangle, 12> An array of triangles for the faces of the bounds-aligned box.
See also
getWorldOrientedBoxCorners()

◆ setOrientationOffset()

void ObjectBounds::setOrientationOffset ( const glm::quat & newOrientation)

Sets orientation offset relative to the scene node's orientation.

Does not keep bounds orientation stable.

◆ setOrientationOrigin()

void ObjectBounds::setOrientationOrigin ( const glm::quat & newOrientation)

Sets orientation of the scene node.

Does not keep bounds orientation stable.

◆ setOrientationWorld()

void ObjectBounds::setOrientationWorld ( const glm::quat & newOrientation)

Sets the new world orientation for the object while keeping its offset relative to its entity fixed.

Orientation here refers to global orientation, where w=1,xyz=0 corresponds to the object facing down the -Z axis

Keeps bounds orientation stable, while updating origin orientation.

◆ setPositionOffset()

void ObjectBounds::setPositionOffset ( const glm::vec3 & newPosition)

Sets the offset of the bounds origin to the scene node origin.

Does not keep bounds position stable while updating position offset.

◆ setPositionOrigin()

void ObjectBounds::setPositionOrigin ( const glm::vec3 & newPosition)

Sets the position of the scene node origin.

Does not keep bounds position stable while updating position offset.

◆ setPositionWorld()

void ObjectBounds::setPositionWorld ( const glm::vec3 & newPosition)

Sets the new world position for the object while keeping its offset relative to its entity fixed.

Parameters
newPositionThe new position this object should appear in

Keeps bounds position stable while updating origin orientation.

Member Data Documentation

◆ mVolumeSystemComputed

bool ToyMaker::ObjectBounds::mVolumeSystemComputed { true }

Flag set when these object bounds were set by the engine, through light bounds compute or model bounds compute.

This is set to false when bounds are set by the scene description or by a user-side aspect.

See also
SpatialQuerySystem::StaticModelBoundsComputeSystem
SpatialQuerySystem::LightBoundsComputeSystem

◆ mVolumeUpdateRequired

bool ToyMaker::ObjectBounds::mVolumeUpdateRequired { true }

Flag set when this object's bounds must be recomputed by a related system.

See also
SpatialQuerySystem::StaticModelBoundsComputeSystem
SpatialQuerySystem::LightBoundsComputeSystem

The documentation for this struct was generated from the following files:
  • ToyMaker_Main/include/toymaker/engine/spatial_query/types.hpp
  • ToyMaker_Main/src/spatial_query/types.cpp