![]() |
Ball and Spring Toy
Game Physics with Bespoke Code
|
The ragdoll. More...
#include <Ragdoll.h>


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 | |
| CPoint * | CreatePoint (eSprite, const Vector2 &) |
| Create point. | |
| CSpring * | CreateSpring (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 CObjectManager * | m_pObjectManager = nullptr |
| Pointer to the object manager. | |
| static eBody | m_eCurrentBody = (eBody)0 |
| Current body type. | |
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.
| CRagdoll::CRagdoll | ( | const Vector2 & | vCenter | ) |
Make a cross-braced stick figure with spring constraints.
| vCenter | Location of ragdoll center. |

| CRagdoll::~CRagdoll | ( | ) |
Virtual destructor required because CRagDoll is derived from CBody but is accessed using a CBody* pointer.
Create a spring joining two ragdoll points.
| e0 | Enumerated type of a point. |
| e1 | Enumerated type of a point. |
| fRest | Spring restitution. |


Create a stick joining two ragdoll points.
| e0 | Enumerated type of a point. |
| e1 | Enumerated type of a point. |


|
private |
Deliver an impulse to a point along a vector, given the vector's orientation angle and its magnitude.
| ePt | Enumerated type of a ragdoll point. |
| angle | Angle of impulse. |
| magnitude | Magnitude of impulse. |


|
private |
Reader function for the position of a ragdoll point.
| ePt | Enumerated type of a ragdoll point. |


|
private |
Reader function for the radius of the ball at a ragdoll point.
| ePt | Enumerated type of a ragdoll point. |


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


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


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


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


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


Set the position of a point in m_pPos relative to another point which is assumed to already be set in m_pPos.
| eTarget | Enumerated type of a point whose entry in m_pPos is to be set. |
| eFrom | Enumerated type of a point whose entry in m_pPos is already set. |
| x | Horizontal offset. |
| y | Vertical offset. |

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