Colliding Shapes
Ian Parberry's "Introduction to Game Physics"
Public Member Functions | Protected Attributes | Private Attributes | List of all members
CShape Class Reference

Shape. More...

#include <Shape.h>

Inheritance diagram for CShape:
CShapeCommon CCircle CLine CPoint CArc CDynamicCircle CKinematicCircle CLineSeg CKinematicPoint CKinematicArc CKinematicLineSeg

Public Member Functions

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

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 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. It contains shape type information and has a couple of handy constructors.

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.

◆ ~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.

◆ 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.

◆ GetMotionType()

const eMotion CShape::GetMotionType ( ) const

Reader function for the motion type.

Returns
Motion type.

◆ 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.

◆ GetRotating()

const bool CShape::GetRotating ( ) const

Reader function for rotation flag.

Returns
true if rotating.

◆ GetRotCenter()

const Vector2 & CShape::GetRotCenter ( ) const

Reader function for the center of rotation.

Returns
Center of rotation.

◆ GetRotSpeed()

const float CShape::GetRotSpeed ( ) const

Reader function for rotation speed.

Returns
Rotation speed.

◆ 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 CDynamicCircle.

◆ PreCollide()

bool CShape::PreCollide ( CContactDesc c)
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 CArc, CLineSeg, CCircle, and CPoint.

◆ 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 CKinematicArc, CKinematicLineSeg, CKinematicCircle, and 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 CKinematicArc, CKinematicLineSeg, CKinematicCircle, and CKinematicPoint.

◆ SetAABBPoint()

void CShape::SetAABBPoint ( const Vector2 &  p)

Set m_cObjSpaceAABB and m_cAABB to a single point.

Parameters
pA point in Object Space.

◆ 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.

◆ 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.

◆ 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.