The Shapes Library
Game Physics with Bespoke Code
Loading...
Searching...
No Matches
Shapes::CShape Class Reference

Shape. More...

#include <Shape.h>

Inheritance diagram for Shapes::CShape:
Collaboration diagram for Shapes::CShape:

Public Member Functions

 CShape (const CShapeDesc &)
 Constructor.
 
virtual ~CShape ()
 Destructor.
 
const eShape GetShapeType () const
 Get shape type.
 
const eMotion GetMotionType () const
 Get motion type.
 
const CAabb2DGetAABB () const
 Get AABB.
 
const bool GetSensor () const
 Is this shape a sensor?
 
const Vector2 & GetPos () const
 Get position.
 
void SetPos (const Vector2 &)
 Set position.
 
void SetAABBPoint (const Vector2 &)
 Set AABB point.
 
void AddAABBPoint (const Vector2 &)
 Add AABB point.
 
void SetCanCollide (bool=true)
 Turn collisions on or off.
 
const bool GetCanCollide () const
 Get whether shape can collide.
 
const bool GetRotating () const
 Get whether rotating.
 
void SetRotating (bool)
 Start or stop rotating.
 
const float GetOrientation () const
 Get orientation.
 
void SetOrientation (float)
 Set orientation.
 
const float GetRotSpeed () const
 Get rotation speed.
 
void SetRotSpeed (float)
 Set rotation speed.
 
const Vector2 & GetRotCenter () const
 Get rotation speed.
 
void SetRotCenter (const Vector2 &)
 Set center of rotation.
 
const float GetElasticity () const
 Get elasticity.
 
void * GetUserPtr () const
 Get user pointer.
 
void SetUserPtr (void *)
 Set user pointer.
 
virtual void Rotate (const Vector2 &, float)
 Rotate.
 
virtual void Reset ()
 Reset orientation.
 
virtual const bool CollisionDetected (CContactDesc &) const
 Collision detection.
 
virtual void move ()
 Translate.
 

Protected Attributes

eShape m_eShapeType = eShape::Unknown
 Type of shape.
 
eMotion m_eMotionType = eMotion::Static
 How shape moves.
 
float m_fElasticity = 1.0f
 Elasticity, aka restitution, bounciness.
 
bool m_bIsSensor = false
 Sensor only, no rebound on collision.
 
CAabb2D m_cAABB
 Axially aligned bounding box in World Space.
 
bool m_bCanCollide = true
 Can collide with other shapes.
 
float m_fOrientation = 0.0f
 Orientation angle.
 
void * m_pUser
 Spare pointer for user in case they might need one.
 
Vector2 m_vRotCenter
 Center of rotation.
 
float m_fRotSpeed = 0.0f
 Rotation speed.
 
bool m_bRotating = false
 Whether rotating.
 

Private Attributes

Vector2 m_vPos
 Position, access ONLY through get and set functions.
 
CAabb2D m_cObjSpaceAABB
 Axially aligned bounding box in object space.
 

Additional Inherited Members

- Static Protected Attributes inherited from Shapes::CShapeCommon
static float m_fGravity = 0.0f
 Gravitational constant.
 
static float m_fTimeStep = 0.0f
 Time step per animation frame (fictional).
 

Detailed Description

CShape is the base class for all shapes.

Constructor & Destructor Documentation

◆ CShape()

CShape::CShape ( const CShapeDesc & r)

Constructs a shape described by a shape descriptor. It is assumed that the shape is collidable.

Parameters
rShape descriptor.
Here is the call graph for this function:

◆ ~CShape()

CShape::~CShape ( )
virtual

This is needed because virtual functions. Otherwise you risk memory leaks. Apparently.

Member Function Documentation

◆ AddAABBPoint()

void CShape::AddAABBPoint ( const Vector2 & p)

Extend m_cObjSpaceAABB and m_cAABB to cover a new point.

Parameters
pA point in Object Space.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ CollisionDetected()

const bool CShape::CollisionDetected ( CContactDesc & c) const
virtual

Collision detection with a dynamic circle. This virtual function is a stub that will be overridden by the appropriate functions that do collision detection for various specific shapes.

Parameters
c[in, out] Contact descriptor for this collision.
Returns
true is there was a collision.

Reimplemented in Shapes::CArc, Shapes::CCircle, Shapes::CLineSeg, and Shapes::CPoint.

◆ GetAABB()

const CAabb2D & CShape::GetAABB ( ) const

Reader function for the axially aligned bounding box.

Returns
Axially aligned bounding box.

◆ GetCanCollide()

const bool CShape::GetCanCollide ( ) const

Reader function for the collidable flag.

Returns
true if shape can collide.

◆ GetElasticity()

const float CShape::GetElasticity ( ) const

Reader function for the elasticity.

Returns
Elasticity.
Here is the caller graph for this function:

◆ GetMotionType()

const eMotion CShape::GetMotionType ( ) const

Reader function for the motion type.

Returns
Motion type.
Here is the caller graph for this function:

◆ GetOrientation()

const float CShape::GetOrientation ( ) const

Reader function for orientation.

Returns
Orientation.

◆ GetPos()

const Vector2 & CShape::GetPos ( ) const

Reader function for the position.

Returns
Position.
Here is the caller graph for this function:

◆ GetRotating()

const bool CShape::GetRotating ( ) const

Reader function for rotation flag.

Returns
true if rotating.
Here is the caller graph for this function:

◆ GetRotCenter()

const Vector2 & CShape::GetRotCenter ( ) const

Reader function for the center of rotation.

Returns
Center of rotation.
Here is the caller graph for this function:

◆ GetRotSpeed()

const float CShape::GetRotSpeed ( ) const

Reader function for rotation speed.

Returns
Rotation speed.
Here is the caller graph for this function:

◆ GetSensor()

const bool CShape::GetSensor ( ) const

Reader function for the sensor setting.

Returns
true if this shape is a sensor.

◆ GetShapeType()

const eShape CShape::GetShapeType ( ) const

Reader function for the shape type.

Returns
Shape type.

◆ GetUserPtr()

void * CShape::GetUserPtr ( ) const

Reader function for the user pointer.

Returns
User pointer.

◆ move()

void CShape::move ( )
virtual

Virtual move function. This is for shapes that move, obviously not static ones. Kinematic shapes are handled here. Dynamic shapes get handled by a virtual function in CDynamicCircle.

Reimplemented in Shapes::CDynamicCircle.

Here is the call graph for this function:

◆ Reset()

void CShape::Reset ( )
virtual

Reset to original orientation. This virtual function is a stub only. It will be overridden by the appropriate functions that perform a reset for various specific kinematic shapes.

Reimplemented in Shapes::CKinematicArc, Shapes::CKinematicCircle, Shapes::CKinematicLineSeg, and Shapes::CKinematicPoint.

◆ Rotate()

void CShape::Rotate ( const Vector2 & v,
float a )
virtual

Rotate to a given orientation This virtual function is a stub only. It will be overridden by the appropriate functions that perform a rotation for various specific kinematic shapes.

Parameters
vCenter of rotation.
aAngle increment from original orientation.

Reimplemented in Shapes::CKinematicArc, Shapes::CKinematicCircle, Shapes::CKinematicLineSeg, and Shapes::CKinematicPoint.

Here is the caller graph for this function:

◆ SetAABBPoint()

void CShape::SetAABBPoint ( const Vector2 & p)

Set m_cObjSpaceAABB and m_cAABB to a single point.

Parameters
pA point in Object Space.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetCanCollide()

void CShape::SetCanCollide ( bool b = true)

This function should be used to enable or disable collisions at run-time.

Parameters
btrue if collisions are enabled, false if disabled.
Here is the caller graph for this function:

◆ SetOrientation()

void CShape::SetOrientation ( float a)
Parameters
aAngle.

◆ SetPos()

void CShape::SetPos ( const Vector2 & p)

Writer function for the position. This both changes the shape's position and translates its AABB.

Parameters
pNew position.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetRotating()

void CShape::SetRotating ( bool b)
Parameters
btrue to start rotating, false to stop rotating.

◆ SetRotCenter()

void CShape::SetRotCenter ( const Vector2 & p)
Parameters
pCenter of rotation.

◆ SetRotSpeed()

void CShape::SetRotSpeed ( float s)
Parameters
sRotation speed.

◆ SetUserPtr()

void CShape::SetUserPtr ( void * p)

Writer function for the user pointer.

Parameters
pUser pointer.