![]() |
Ball and Spring Toy
Ian Parberry's "Introduction to Game Physics"
|
The point. More...
#include <Point.h>
Public Member Functions | |
| CPoint (eSprite, const Vector2 &, float) | |
| Constructor. More... | |
| void | move () |
| Change position depending on time and velocity. More... | |
| void | draw (float) |
| Draw. More... | |
| void | DeliverImpulse (float, float) |
| Deliver an impulse. More... | |
| void | Adjust (const Vector2 &) |
| Adjust position from Gauss-Seidel relaxation. More... | |
| void | Teleport (const Vector2 &) |
| Magically teleport point by this amount. More... | |
| void | SetCollisionSound (eSound) |
| Override default collision sound. More... | |
| const Vector2 & | GetPos () const |
| Get position. More... | |
| float | GetRadius () const |
| Get radius. More... | |
Private Member Functions | |
| float | EdgeCollision () |
| Collision detection and response for edges of screen. More... | |
Private Attributes | |
| eSprite | m_eSpriteType = eSprite::Size |
| Sprite type. | |
| Vector2 | m_vPos |
| Current position. | |
| Vector2 | m_vOldPos |
| Previous position, needed for Verlet. | |
| float | m_fRadius = 0 |
| Radius of bounding circle. | |
| float | m_fAngle = 0 |
| Orientation angle. | |
| float | m_fXScale = 1 |
| Scale along x-axis. | |
| float | m_fYScale = 1 |
| Scale along y-axis. | |
| eSound | m_eCollisionSnd = eSound::Size |
| Collision sound. | |
Additional Inherited Members | |
Static Protected Attributes inherited from CCommon | |
| 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 point class is the representation of an abstract point moving through space using Verlet Integration.
| CPoint::CPoint | ( | eSprite | t, |
| const Vector2 & | p, | ||
| float | r | ||
| ) |
| t | Sprite type. |
| p | Initial position. |
| r | Radius. |
| void CPoint::Adjust | ( | const Vector2 & | v | ) |
All a point needs to do for Gauss-Seidel relaxation is to move when the spring tells it to.
| void CPoint::DeliverImpulse | ( | float | a, |
| float | m | ||
| ) |
Since we are using Verlet integration, an impulse is easily faked by moving the old position a distance proportional to the magnitude of the impulse in the direction of the vector's orientatio.
| a | Angle. |
| m | Magnitude. |
| void CPoint::draw | ( | float | a | ) |
| a | Orientation. |
|
private |
Checks for a collision, and does the necessary calculations for reflecting a point if it hits an edge.
| const Vector2 & CPoint::GetPos | ( | ) | const |
Reader function for position.
| float CPoint::GetRadius | ( | ) | const |
Reader function for radius.
| void CPoint::move | ( | ) |
Move the point using Verlet integration, perform collision detection and response with edges of window. Notice that there is no concept of time here.
| void CPoint::SetCollisionSound | ( | eSound | s | ) |
| s | New collision sound. |
| void CPoint::Teleport | ( | const Vector2 & | d | ) |
Teleport the point without changing its velocity. Well, actually points don't have a velocity under Verlet Integration, but you know what I mean. Just displace both the position and old position.
| d | Displacement. |