Box2D Joint Toy
Ian Parberry's "Introduction to Game Physics"
Public Member Functions | Private Member Functions | Private Attributes | List of all members
CCar Class Reference

A car consisting of a body and two wheels. More...

#include <Car.h>

Inheritance diagram for CCar:
CCommon

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 Protected Attributes inherited from CCommon
static b2World * m_pPhysicsWorld = nullptr
 Pointer to Box2D Physics World.
 
static CRendererm_pRenderer = nullptr
 Pointer to the renderer.
 
static CObjectManagerm_pObjectManager = nullptr
 Pointer to the object manager.
 
static CWindmillm_pWindmill = nullptr
 Pointer to windmill.
 
static CGearm_pGear = nullptr
 Pointer to gear system.
 
static CNautilusGearm_pNautilusGear = nullptr
 Pointer to Nautilus gear system.
 
static CRackAndPinionm_pRackAndPinion = nullptr
 Pointer to rack-and-pinion.
 
static CCarm_pCar = nullptr
 Pointer to car.
 
static CRampm_pRamp = nullptr
 Pointer to ramp.
 
static CNewtonsCradlem_pNewtonsCradle = nullptr
 Pointer to Newton's Cradle.
 
static CPulleym_pPulley = nullptr
 Pointer to pulley system.
 
static eLevel m_eCurLevel = eLevel::Windmill
 Current level.
 

Detailed Description

A car consisting of a body and two wheels.

Constructor & Destructor Documentation

◆ CCar()

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.

Parameters
xX coordinate in Physics World units.
yY coordinate in Physics World units.

Member Function Documentation

◆ CreateBody()

b2Body * CCar::CreateBody ( float  x,
float  y 
)
private

Create the car body.

Create the car's body at a given point in Physics World.

Parameters
xX coordinate in Physics World units.
yY coordinate in Physics World units.
Returns
Pointer to the car body in Physics World.

◆ CreateWheel()

b2Body * CCar::CreateWheel ( float  x,
float  y 
)
private

Create a wheel.

Create a car wheel at a given point in Physics World.

Parameters
xX coordinate in Physics World units.
yY coordinate in Physics World units.
Returns
Pointer to the wheel's body in Physics World.

◆ move()

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.

◆ reverse()

void CCar::reverse ( )

Reverse the car.

Reverse the car by changing the sign of the motor speed on the revolute joint.