tile2d
Loading...
Searching...
No Matches
Classes | Public Member Functions | Protected Member Functions | Friends | List of all members
TileBody< TileType > Class Template Reference

For use with a TileMap<>, allows collisions with other rigid bodies inside World<> More...

#include <tileMap.hpp>

Inheritance diagram for TileBody< TileType >:
Body WorldBody

Classes

class  SpatialIndex
 A spatial index where pos may point towards a chunk or tile. More...
 

Public Member Functions

 TileBody (TileMap< TileType > &tileMap, uint32_t id)
 Do not call directly, to construct a TileBody use createTileMap()
 
virtual void integrate (Float dt) override
 Integerates this body, meaning the linear velocity and angular velocity will be integrated into the position and rotation of this body.
 
virtual AABB< Float > getAABB () const override
 Returns the AABB of this body.
 
TileMap< TileType > & tileMap () const
 Returns the tile map attached to this rigid body.
 
std::array< vec2, 2 > normals () const
 Returns the normals of this body. Can be used for all tiles of this body.
 
vec2 getTileLocalPoint (const glm::i32vec2 &iPos) const
 Returns the local center of the tile located at iPos.
 
vec2 getTileWorldPoint (const glm::i32vec2 &iPos) const
 Returns the world center of the tile located at iPos.
 
TOBB getTileWorldOBB (const glm::i32vec2 &iPos) const
 Returns the world oriented bounding box of the tile located at iPos.
 
TOBB getTileWorldOBBOffset (const glm::i32vec2 &iPos, const vec2 &worldOffset) const
 Returns the world oriented bounding box of the tile located at iPos. with an added offset.
 
std::array< vec2, 4 > getTileWorldOBBOffsetVertices (const glm::i32vec2 &iPos, const vec2 &worldOffset) const
 Returns the world vertices of the tile located at iPos. with an added offset.
 
AABB< Float > getTileWorldAABB (const glm::i32vec2 &iPos) const
 Returns the world AABB of a tile located at iPos.
 
AABB< Float > getTileLocalAABB (const glm::i32vec2 &iPos) const
 Returns the local AABB of a tile located at iPos.
 
template<typename OutIt >
void queryChunks (const AABB< Float > &intersectBox, OutIt chunks) const
 Will get the list of chunks that intersect intersectBox, along with their AABBS.
 
template<typename OutIt >
void queryTiles (const AABB< Float > &intersectBox, OutIt tiles) const
 Will get the list of tiles that intersect intersectBox.
 
glm::i32vec2 getChunkCoords (const vec2 &localCoords) const
 Get the chunk that contains localCoords. Chunk may or may not exist.
 
glm::i32vec2 getChunkCoords (const glm::i32vec2 &tileCoords) const
 Get the chunk that contains tileCoords. Chunk may or may not exist.
 
glm::i32vec2 getTileCoords (const vec2 &localCoords) const
 Get the tile that contains localCoords. Tile may or may not exist.
 
AABB< Float > getChunkAABB (const glm::i32vec2 &chunk) const
 Get the AABB of the chunk located at chunk.
 
- Public Member Functions inherited from Body
 Body (uint32_t id, BodyType type)
 constructs a new WorldBody
 
virtual vec2 getWorldPoint (const vec2 &localPoint) const override
 Gets a local position thats within the local space of this body and transforms into the world space.
 
virtual vec2 getLocalPoint (const vec2 &worldPoint) const override
 Gets a world position thats space of this body and transforms into the local space of this body.
 
virtual vec2 getWorldPos () override
 Returns the world position of this body.
 
virtual void setStatic (bool static_) override
 Either make the body static or dynamic.
 
void addAngularVel (const Float &vel)
 Applies an angular velocity to this body.
 
const vec2 & com () const
 Returns the center of mass of this body.
 
const vec2 & centroid () const
 Returns the centroid of this body.
 
Float rotationalInertia () const
 Returns rotational inertia scalar of this body.
 
- Public Member Functions inherited from WorldBody
 WorldBody (uint32_t id, BodyType bodyType)
 constructs a new WorldBody
 
uint32_t id () const
 Returns the id assigned to this body the physics world.
 
BodyType bodyType () const
 Returns the bodyType of this body, see enum BodyType.
 
Transformtransform ()
 Returns the REFERENCE transform of this body.
 
const Transformtransform () const
 Returns the CONST REFERENCE transform of this body.
 
void moveBy (const vec2 &amount)
 Moves the body by amount.
 
void rotateBy (Float amount)
 Rotates the body by amount.
 
void setPos (const vec2 &pos)
 Sets the position of this body to pos.
 
void setRot (Float rot)
 Sets the rotation of this body to rot.
 
bool isStatic () const
 Returns if the body is static, meaning it cannot be moved by forces or other bodies.
 
void addLinearVel (const vec2 &vel)
 applies a linear velocity to this body
 
Float mass () const
 Returns the mass of this body.
 
Float inverseMass () const
 Returns the inverse mass of this body.
 
AABB< Float > getAABB (const Transform &spaceTransform, const vec2 &localOffset={ Float(0.5f), Float(0.5f) }) const
 
AABB< Float > getAABB (const AABB< Float > &localAABB, const Transform &spaceTransform, const vec2 &localOffset={ Float(0.5f), Float(0.5f) }) const
 

Protected Member Functions

void insertIntoChunk (const glm::i32vec2 &tile)
 
AABB< Float > getLocalAABB () const
 
vec2 getTileLocalPointNoDim (const glm::i32vec2 &iPos) const
 
void calculateRotationalInertia ()
 
void calculateRotationalInertiaAndAABB ()
 
void addTile (const glm::i32vec2 &iPos)
 
void removeTile (const glm::i32vec2 &iPos)
 
void beginBulkInsert ()
 
void endBulkInsert ()
 
void beginBulkErase ()
 
void endBulkErase ()
 

Friends

class TileMap< TileType >
 

Additional Inherited Members

- Public Types inherited from WorldBody
enum  FlagIndexes { NEEDS_REINSERT = 0 , IS_STATIC = 1 }
 
- Protected Attributes inherited from Body
Float m_inverseI = 0
 
vec2 m_centroid = { 0.0f, 0.0f }
 
vec2 m_com = { 0.0f, 0.0f }
 
Float m_I = 0.0f
 
vec2 m_unweightedCom = { 0.0f, 0.0f }
 
vec2 m_unweightedCentroid = { 0.0f, 0.0f }
 
vec2 m_force = { 0.0f, 0.0f }
 
Float m_angularVelocity = 0.0f
 
Float m_torque = 0.0f
 
- Protected Attributes inherited from WorldBody
Transform m_transform
 
Float m_mass = 0.0f
 
Float m_inverseMass = 0
 
vec2 m_linearVelocity = { 0.0f, 0.0f }
 
std::bitset< 4 > m_flags
 
BodyType m_bodyType = BodyType::Invalid
 

Detailed Description

template<typename TileType>
class TileBody< TileType >

For use with a TileMap<>, allows collisions with other rigid bodies inside World<>

Member Function Documentation

◆ getAABB()

template<typename TileType >
virtual AABB< Float > TileBody< TileType >::getAABB ( ) const
inlineoverridevirtual

Returns the AABB of this body.

Returns
The AABB of this body

Implements WorldBody.

◆ getChunkAABB()

template<typename TileType >
AABB< Float > TileBody< TileType >::getChunkAABB ( const glm::i32vec2 & chunk) const
inline

Get the AABB of the chunk located at chunk.

Parameters
chunkThe chunk position
Returns
The chunk AABB

◆ getChunkCoords() [1/2]

template<typename TileType >
glm::i32vec2 TileBody< TileType >::getChunkCoords ( const glm::i32vec2 & tileCoords) const
inline

Get the chunk that contains tileCoords. Chunk may or may not exist.

Parameters
tileCoordsA tile position
Returns
The chunk position

◆ getChunkCoords() [2/2]

template<typename TileType >
glm::i32vec2 TileBody< TileType >::getChunkCoords ( const vec2 & localCoords) const
inline

Get the chunk that contains localCoords. Chunk may or may not exist.

Parameters
localCoordsA local position
Returns
The chunk position

◆ getTileCoords()

template<typename TileType >
glm::i32vec2 TileBody< TileType >::getTileCoords ( const vec2 & localCoords) const
inline

Get the tile that contains localCoords. Tile may or may not exist.

Parameters
localCoordsA local position
Returns
The tile position

◆ getTileLocalAABB()

template<typename TileType >
AABB< Float > TileBody< TileType >::getTileLocalAABB ( const glm::i32vec2 & iPos) const
inline

Returns the local AABB of a tile located at iPos.

Parameters
iPosThe tile position of the tile to get the local AABB of
Returns
The local AABB of a tile located at iPos

◆ getTileLocalPoint()

template<typename TileType >
vec2 TileBody< TileType >::getTileLocalPoint ( const glm::i32vec2 & iPos) const
inline

Returns the local center of the tile located at iPos.

Parameters
iPosThe tile position of the tile to get the local center of
Returns
The local center of the tile located at iPos.

◆ getTileWorldAABB()

template<typename TileType >
AABB< Float > TileBody< TileType >::getTileWorldAABB ( const glm::i32vec2 & iPos) const
inline

Returns the world AABB of a tile located at iPos.

Parameters
iPosThe tile position of the tile to get the world AABB of
Returns
The world AABB of a tile located at iPos

◆ getTileWorldOBB()

template<typename TileType >
TOBB TileBody< TileType >::getTileWorldOBB ( const glm::i32vec2 & iPos) const
inline

Returns the world oriented bounding box of the tile located at iPos.

Parameters
iPosThe tile position of the tile to get the world oriented bounding box of
Returns
The world oriented bounding box of the tile located at iPos.

◆ getTileWorldOBBOffset()

template<typename TileType >
TOBB TileBody< TileType >::getTileWorldOBBOffset ( const glm::i32vec2 & iPos,
const vec2 & worldOffset ) const
inline

Returns the world oriented bounding box of the tile located at iPos. with an added offset.

Parameters
iPosThe tile position of the tile to get the world oriented bounding box of
worldOffsetThe world offset to add to the position of TOBB
Returns
The world oriented bounding box of the tile located at iPos.

◆ getTileWorldOBBOffsetVertices()

template<typename TileType >
std::array< vec2, 4 > TileBody< TileType >::getTileWorldOBBOffsetVertices ( const glm::i32vec2 & iPos,
const vec2 & worldOffset ) const
inline

Returns the world vertices of the tile located at iPos. with an added offset.

Parameters
iPosThe tile position of the tile to get the world vertices of
worldOffsetThe world offset to add to the position of the world vertices
Returns
The world vertices of the tile located at iPos.

◆ getTileWorldPoint()

template<typename TileType >
vec2 TileBody< TileType >::getTileWorldPoint ( const glm::i32vec2 & iPos) const
inline

Returns the world center of the tile located at iPos.

Parameters
iPosThe tile position of the tile to get the world center of
Returns
The world center of the tile located at iPos.

◆ integrate()

template<typename TileType >
virtual void TileBody< TileType >::integrate ( Float dt)
inlineoverridevirtual

Integerates this body, meaning the linear velocity and angular velocity will be integrated into the position and rotation of this body.

Parameters
dtThe amount to integrate by; delta time

Reimplemented from Body.

◆ normals()

template<typename TileType >
std::array< vec2, 2 > TileBody< TileType >::normals ( ) const
inline

Returns the normals of this body. Can be used for all tiles of this body.

Returns
The normals of this body

◆ queryChunks()

template<typename TileType >
template<typename OutIt >
void TileBody< TileType >::queryChunks ( const AABB< Float > & intersectBox,
OutIt chunks ) const
inline

Will get the list of chunks that intersect intersectBox, along with their AABBS.

Parameters
intersectBoxAn AABB that will be used to recieve a list of chunks that intersect it
chunksAn inserter object used to recieve the list of chunks intersectBox
Template Parameters
OutItThe type of the inserter object, See chunks

◆ queryTiles()

template<typename TileType >
template<typename OutIt >
void TileBody< TileType >::queryTiles ( const AABB< Float > & intersectBox,
OutIt tiles ) const
inline

Will get the list of tiles that intersect intersectBox.

Parameters
intersectBoxAn AABB that will be used to recieve a list of tiles that intersect it
tilesAn inserter object used to recieve the list of tiles that intersect intersectBox
Template Parameters
OutItThe type of the inserter object, See tiles

◆ tileMap()

template<typename TileType >
TileMap< TileType > & TileBody< TileType >::tileMap ( ) const
inline

Returns the tile map attached to this rigid body.

Returns
The tile map attached to this rigid body

The documentation for this class was generated from the following file: