Ball and Spring Toy
Game Physics with Bespoke Code
Loading...
Searching...
No Matches
CRagdoll Class Reference

The ragdoll. More...

#include <Ragdoll.h>

Inheritance diagram for CRagdoll:
Collaboration diagram for CRagdoll:

Public Member Functions

 CRagdoll (const Vector2 &)
 Constructor.
 
 ~CRagdoll ()
 Destructor.
 
void StandUp ()
 Attempt to stand up.
 
- Public Member Functions inherited from CBody
virtual ~CBody ()
 Destructor.
 
void DeliverImpulse (float)
 Deliver impulse to body.
 
void Teleport (const Vector2 &)
 Magically teleport body by this amount.
 
void Draw ()
 Draw body.
 

Private Member Functions

const bool isOnLeftSide () const
 Is on left side.
 
const bool isOnRightSide () const
 Is on right side.
 
const bool isTippingLeft () const
 Is tipping left.
 
const bool isTippingRight () const
 Is tipping right.
 
const bool isStanding () const
 Is standing.
 
void SetRelativePos (ePoint, ePoint, float, float)
 Set relative position.
 
void CreateStick (ePoint, ePoint)
 Create a stick.
 
void CreateSpring (ePoint, ePoint, float)
 Create a spring.
 
const Vector2 & GetPos (ePoint) const
 Get position of a point.
 
const float GetRadius (ePoint) const
 Get radius of ball at a point.
 
void DeliverImpulse (ePoint, float, float)
 Deliver impulse to point.
 

Private Attributes

float m_fDelay = 1.0f
 Delay between attempts to stand up.
 
Vector2 * m_pPos = nullptr
 Temporary array of point positions.
 
CPoint ** m_pPt = nullptr
 Temporary array of points.
 

Additional Inherited Members

- Protected Member Functions inherited from CBody
CPointCreatePoint (eSprite, const Vector2 &)
 Create point.
 
CSpringCreateSpring (eSprite, CPoint *, CPoint *, float=1.0f)
 Create spring.
 
- Protected Attributes inherited from CBody
std::vector< CPoint * > m_stdPt
 Vector of pointers to points in this body.
 
std::vector< CSpring * > m_stdSpr
 Vector of pointers to springs.
 
- Static Protected Attributes inherited from CCommon
static Sage::CSpriteRenderer * m_pRenderer = nullptr
 Pointer to the renderer.
 
static CObjectManagerm_pObjectManager = nullptr
 Pointer to the object manager.
 
static eBody m_eCurrentBody = (eBody)0
 Current body type.
 

Detailed Description

The ragdoll is a body that is approximately in the shape of a human body, with springs to make it stay in the right stance. It has a little rule-based AI to help it stay standing up.

Constructor & Destructor Documentation

◆ CRagdoll()

CRagdoll::CRagdoll ( const Vector2 & vCenter)

Make a cross-braced stick figure with spring constraints.

Parameters
vCenterLocation of ragdoll center.
Here is the call graph for this function:

◆ ~CRagdoll()

CRagdoll::~CRagdoll ( )

Virtual destructor required because CRagDoll is derived from CBody but is accessed using a CBody* pointer.

Member Function Documentation

◆ CreateSpring()

void CRagdoll::CreateSpring ( ePoint e0,
ePoint e1,
float fRest )
private

Create a spring joining two ragdoll points.

Parameters
e0Enumerated type of a point.
e1Enumerated type of a point.
fRestSpring restitution.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ CreateStick()

void CRagdoll::CreateStick ( ePoint e0,
ePoint e1 )
private

Create a stick joining two ragdoll points.

Parameters
e0Enumerated type of a point.
e1Enumerated type of a point.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ DeliverImpulse()

void CRagdoll::DeliverImpulse ( ePoint ePt,
float angle,
float magnitude )
private

Deliver an impulse to a point along a vector, given the vector's orientation angle and its magnitude.

Parameters
ePtEnumerated type of a ragdoll point.
angleAngle of impulse.
magnitudeMagnitude of impulse.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetPos()

const Vector2 & CRagdoll::GetPos ( ePoint ePt) const
private

Reader function for the position of a ragdoll point.

Parameters
ePtEnumerated type of a ragdoll point.
Returns
Position of the point in render space.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetRadius()

const float CRagdoll::GetRadius ( ePoint ePt) const
private

Reader function for the radius of the ball at a ragdoll point.

Parameters
ePtEnumerated type of a ragdoll point.
Returns
Radius of the point in render space.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ isOnLeftSide()

const bool CRagdoll::isOnLeftSide ( ) const
private

The ragdoll is on its left side if both its left hand and left elbow are one radius above the bottom of the window.

Returns
true if the ragdoll is on its left side.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ isOnRightSide()

const bool CRagdoll::isOnRightSide ( ) const
private

The ragdoll is on its right side if both its right hand and right elbow are one radius above the bottom of the window.

Returns
true if the ragdoll is on its right side.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ isStanding()

const bool CRagdoll::isStanding ( ) const
private

The ragdoll is standing upright if the vector from its gut to its sternum is approximately vertical and both feet are one radius above the bottom of the window.

Returns
true if the ragdoll is standing upright.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ isTippingLeft()

const bool CRagdoll::isTippingLeft ( ) const
private

The ragdoll is tipping left if its left foot is one radius above the ground and its right foot is at least 1.5 times and at most 3 times its radius above the bottom of the window.

Returns
true if the ragdoll is tipping left.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ isTippingRight()

const bool CRagdoll::isTippingRight ( ) const
private

The ragdoll is tipping right if its right foot is one radius above the ground and its left foot is at least 1.5 times and at most 3 times its radius above the bottom of the window.

Returns
true if the ragdoll is tipping right.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetRelativePos()

void CRagdoll::SetRelativePos ( ePoint eTarget,
ePoint eFrom,
float x,
float y )
private

Set the position of a point in m_pPos relative to another point which is assumed to already be set in m_pPos.

Parameters
eTargetEnumerated type of a point whose entry in m_pPos is to be set.
eFromEnumerated type of a point whose entry in m_pPos is already set.
xHorizontal offset.
yVertical offset.
Here is the caller graph for this function:

◆ StandUp()

void CRagdoll::StandUp ( )

Every 0.4-0.6 seconds (chosen pseudoandomly), the ragdoll attempts to stand upright at the center of the screen. If it is on its side, then it attempts to fling itself into the air and get upright. If one foot is on the ground, then it hops to attempt to right itself unless it is tipping over too much. If it is standing upright, then it attempts to shuffle over to near the middle of the window.

Here is the call graph for this function: