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

Compound shape. More...

#include <Compound.h>

Collaboration diagram for Shapes::CCompoundShape:

Public Member Functions

 CCompoundShape (CShape *)
 Constructor.
 
 CCompoundShape ()
 Default constructor.
 
void AddShape (CShape *p)
 Add a shape.
 
void SetOrientation (float)
 Set orientation.
 
void SetRotSpeed (float)
 Set rotation speed.
 
void SetRotCenter (const Vector2 &)
 Set center of rotation.
 
const float GetOrientation () const
 Get orientation.
 
const float GetRotSpeed () const
 Get rotation speed.
 
const Vector2 GetRotCenter () const
 Get center of rotation.
 
const bool IsPartOf (CShape *)
 Test whether shape is in compound shape.
 
const CShapeGetCenterPoint () const
 Get center point.
 

Protected Attributes

std::vector< CShape * > m_stdShapes
 List of shapes.
 
CShapem_pCenterPoint = nullptr
 Point at center.
 

Detailed Description

A compound shape consists of a collection of shapes that ought to be grouped together for convenience.

Constructor & Destructor Documentation

◆ CCompoundShape()

CCompoundShape::CCompoundShape ( CShape * p)

Initialize a compound shape given its center. The center point is set to not collide with anything.

Parameters
pPointer to a point shape at the center.
Here is the call graph for this function:

Member Function Documentation

◆ AddShape()

void CCompoundShape::AddShape ( CShape * p)

Append a given shape to the shape list. There is no attempt to ensure that it's not already in there, so beware.

Parameters
pPointer to shape to be added.

◆ GetCenterPoint()

const CShape * CCompoundShape::GetCenterPoint ( ) const

Reader function for the center point.

Returns
The center point m_pCenterPoint.

◆ GetOrientation()

const float CCompoundShape::GetOrientation ( ) const

Reader function for the current orientation. This function assumes that all of the shapes in the shape list have the same orientation, so it just returns the orientation of the first shape (zero if there are no shapes yet).

Returns
Orientation.

◆ GetRotCenter()

const Vector2 CCompoundShape::GetRotCenter ( ) const

Reader function for the center of rotation. This function assumes that all of the shapes in the shape list have the same rotation speed, so it just returns the center of rotation of the first shape (or the zero vector if there are no shapes yet).

Returns
The position of the center of rotation.

◆ GetRotSpeed()

const float CCompoundShape::GetRotSpeed ( ) const

Reader function for the current rotation speed. This function assumes that all of the shapes in the shape list have the same rotation speed, so it just returns the rotation speed of the first shape (zero if there are no shapes yet).

Returns
Rotation speed.

◆ IsPartOf()

const bool CCompoundShape::IsPartOf ( CShape * pShape)

Test whether a shape is part of this compound shape. This function can be used during collision response when the compound shape has a sprite that changes on collision.

Parameters
pShapePointer to a shape.
Returns
true if the shape is part of this compound shape.

◆ SetOrientation()

void CCompoundShape::SetOrientation ( float a)

Set the orientation of all of the shapes in the shape list. Make sure you call this after all shapes have been added, since this orientation won't be applied to shapes added after this function is called.

Parameters
aAngle.

◆ SetRotCenter()

void CCompoundShape::SetRotCenter ( const Vector2 & p)

Set the center of rotation of all of the shapes in the shape list. Make sure you call this after all shapes have been added, since this rotation center won't be applied to shapes added after this function is called.

Parameters
pCenter of rotation.

◆ SetRotSpeed()

void CCompoundShape::SetRotSpeed ( float s)

Set the rotation speed of all of the shapes in the shape list. Make sure you call this after all shapes have been added, since this rotation speed won't be applied to shapes added after this function is called.

Parameters
sRotation speed in radians per millisecond.