Ball and Spring Toy
Ian Parberry's "Introduction to Game Physics"
Public Member Functions | Private Member Functions | Private Attributes | List of all members
CRagdoll Class Reference

The ragdoll. More...

#include <Ragdoll.h>

Inheritance diagram for CRagdoll:
CBody CCommon

Public Member Functions

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

Private Member Functions

const bool isOnLeftSide () const
 Is on left side. More...
 
const bool isOnRightSide () const
 Is on right side. More...
 
const bool isTippingLeft () const
 Is tipping left. More...
 
const bool isTippingRight () const
 Is tipping right. More...
 
const bool isStanding () const
 Is standing. More...
 

Private Attributes

float m_fDelay = 1.0f
 Delay between attempts to stand up.
 

Additional Inherited Members

- Protected Member Functions inherited from CBody
CPointCreatePoint (eSprite, const Vector2 &)
 Create point. More...
 
CSpringCreateSpring (eSprite, CPoint *, CPoint *, float=1.0f)
 Create spring. More...
 
- 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 CRendererm_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 ( Vector2  v)

Make a cross-braced stick figure with spring constraints.

Parameters
vLocation of ragdoll center.
Returns
Pointer to the ragdoll's head.

Member Function Documentation

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

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

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

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

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

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