Box2D Render Library
Game Physics with a 2D Physics Engine
Loading...
Searching...
No Matches
CBox2DRenderer Class Reference

The Box2D renderer. More...

#include <Box2DRenderer.h>

Inheritance diagram for CBox2DRenderer:
Collaboration diagram for CBox2DRenderer:

Public Member Functions

 CBox2DRenderer (const UINT, const float)
 Constructor.
 
void Drawb2Body (b2Body *)
 Draw Box2D body.
 

Protected Member Functions

void Drawb2Shape (b2Shape *)
 Draw Box2D shape.
 
void Drawb2Polygon (b2PolygonShape *)
 Draw Box2D polygon shape.
 
void Drawb2Edge (b2EdgeShape *)
 Draw Box2D shape.
 
void Drawb2Circle (b2CircleShape *)
 Draw Box2D edge shape.
 
void Drawb2Chain (b2ChainShape *)
 Draw Box2D chain shape.
 

Private Member Functions

const float PW2RW (const float) const
 Physics World to Render World.
 
const Vector2 PW2RW (const b2Vec2 &) const
 Physics World to Render World.
 

Private Attributes

UINT m_nLineSprite = 0
 Line sprite.
 
Vector2 m_vPos
 Position in Render World.
 
float m_fRoll = 0.0f
 Roll angle.
 
float m_fPRS = 0.0f
 Physics World to Render World scale value.
 

Detailed Description

Adds to Sage::CSpriteRenderer the ability to draw Box2D shapes from a Box2D body.

Constructor & Destructor Documentation

◆ CBox2DRenderer()

CBox2DRenderer::CBox2DRenderer ( const UINT n,
const float fPRS )

The constructor. Initialize the renderer into Sage::eSpriteMode::Batched2D and record the index of the line sprite and the Physics World to Render World scale value.

Parameters
nindex of the line sprite.
fPRSPhysics World to Render World scale value.

Member Function Documentation

◆ Drawb2Body()

void CBox2DRenderer::Drawb2Body ( b2Body * pBody)

Draw a Box2D body using lines. Iterate through the fixtures attached to the body, calling Drawb2Shape() to draw the shape of each fixture.

Parameters
pBodyPointer to a Box2D body.
Here is the call graph for this function:

◆ Drawb2Chain()

void CBox2DRenderer::Drawb2Chain ( b2ChainShape * p)
protected

Draw a Box2D chain shape using lines. Assumes that eSprite::Line exists and has been loaded. This function is a stub that has not yet been implemented.

Parameters
pPointer to a Box2D chain shape.
Here is the caller graph for this function:

◆ Drawb2Circle()

void CBox2DRenderer::Drawb2Circle ( b2CircleShape * p)
protected

Draw a Box2D circle shape.

Parameters
pPointer to a Box2D circle shape.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Drawb2Edge()

void CBox2DRenderer::Drawb2Edge ( b2EdgeShape * p)
protected

Draw a Box2D edge shape as a line.

Parameters
pPointer to a Box2D edge shape.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Drawb2Polygon()

void CBox2DRenderer::Drawb2Polygon ( b2PolygonShape * p)
protected

Draw a Box2D polygon shape using lines. Iterate through the polygon points, drawing a line from each one to the one before it. The line from the first point to the last one is a special case.

Parameters
pPointer to a Box2D polygon shape.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Drawb2Shape()

void CBox2DRenderer::Drawb2Shape ( b2Shape * p)
protected

Draw a Box2D shape using lines. This is just a switch statement that calls one of Drawb2Circle(), Drawb2Edge(), Drawb2Polygon(), or Drawb2Chain() depending on the shape's type.

Parameters
pPointer to a Box2D shape.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ PW2RW() [1/2]

const Vector2 CBox2DRenderer::PW2RW ( const b2Vec2 & v) const
private

Convert a vector in Physics World to the corresponding vector in Render World by multiplying by m_fPRS, the Physics World to Render World scale value.

Parameters
vPhysics World vector.
Returns
Render World vector.

◆ PW2RW() [2/2]

const float CBox2DRenderer::PW2RW ( const float x) const
private

Convert a distance in Physics World to the corresponding distance in Render World by multiplying by m_fPRS, the Physics World to Render World scale value.

Parameters
xPhysics World distance.
Returns
Render World distance.
Here is the caller graph for this function: