![]() |
Box2D Joint Toy
Ian Parberry's "Introduction to Game Physics"
|
A car consisting of a body and two wheels. More...
#include <Car.h>
Public Member Functions | |
CCar (float, float) | |
Constructor. More... | |
void | move () |
Reverse the car when it gets near the edges. More... | |
void | reverse () |
Reverse the car. More... | |
Private Member Functions | |
b2Body * | CreateBody (float, float) |
Create the car body. More... | |
b2Body * | CreateWheel (float, float) |
Create a wheel. More... | |
Private Attributes | |
b2Body * | m_pBody = nullptr |
Pointer to the car body. | |
b2WheelJoint * | m_pWheelJoint1 = nullptr |
Pointer to a wheel joint. | |
b2WheelJoint * | m_pWheelJoint2 = nullptr |
Pointer to a wheel joint. | |
Additional Inherited Members | |
![]() | |
static b2World * | m_pPhysicsWorld = nullptr |
Pointer to Box2D Physics World. | |
static CRenderer * | m_pRenderer = nullptr |
Pointer to the renderer. | |
static CObjectManager * | m_pObjectManager = nullptr |
Pointer to the object manager. | |
static CWindmill * | m_pWindmill = nullptr |
Pointer to windmill. | |
static CGear * | m_pGear = nullptr |
Pointer to gear system. | |
static CNautilusGear * | m_pNautilusGear = nullptr |
Pointer to Nautilus gear system. | |
static CRackAndPinion * | m_pRackAndPinion = nullptr |
Pointer to rack-and-pinion. | |
static CCar * | m_pCar = nullptr |
Pointer to car. | |
static CRamp * | m_pRamp = nullptr |
Pointer to ramp. | |
static CNewtonsCradle * | m_pNewtonsCradle = nullptr |
Pointer to Newton's Cradle. | |
static CPulley * | m_pPulley = nullptr |
Pointer to pulley system. | |
static eLevel | m_eCurLevel = eLevel::Windmill |
Current level. | |
A car consisting of a body and two wheels.
CCar::CCar | ( | float | x, |
float | y | ||
) |
Constructor.
Create physics bodies for the car body and wheels, and a wheel joint between each wheel and the car body.
x | X coordinate in Physics World units. |
y | Y coordinate in Physics World units. |
|
private |
Create the car body.
Create the car's body at a given point in Physics World.
x | X coordinate in Physics World units. |
y | Y coordinate in Physics World units. |
|
private |
Create a wheel.
Create a car wheel at a given point in Physics World.
x | X coordinate in Physics World units. |
y | Y coordinate in Physics World units. |
void CCar::move | ( | ) |
Reverse the car when it gets near the edges.
Ensure that the car reverses direction before hitting the left or right edge of the window. All other aspects of motion are, of course, handled by Box2D.
void CCar::reverse | ( | ) |
Reverse the car.
Reverse the car by changing the sign of the motor speed on the revolute joint.