![]() |
Ball and Spring Toy
Ian Parberry's "Introduction to Game Physics"
|
The ragdoll. More...
#include <Ragdoll.h>
Public Member Functions | |
CRagdoll (Vector2 v) | |
Constructor. More... | |
void | StandUp () |
Attempt to stand up. More... | |
![]() | |
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 | |
![]() | |
CPoint * | CreatePoint (eSprite, const Vector2 &) |
Create point. More... | |
CSpring * | CreateSpring (eSprite, CPoint *, CPoint *, float=1.0f) |
Create spring. More... | |
![]() | |
std::vector< CPoint * > | m_stdPt |
Vector of pointers to points in this body. | |
std::vector< CSpring * > | m_stdSpr |
Vector of pointers to springs. | |
![]() | |
static CRenderer * | 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 | ( | Vector2 | v | ) |
Make a cross-braced stick figure with spring constraints.
v | Location of ragdoll center. |
|
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.
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.