Here my class
Code:
#include "CIndieLib_vc2008.h"
#include <Box2D/Box2D.h>
#include "d:\programmazione\ide-compilatori-librerie\box2d_v2.1.2\box2d\box2d\dynamics\b2worldcallbacks.h"
#pragma once
class DebugDraw :
public b2DebugDraw
{
public:
DebugDraw()
{
}
void SetIndielib(CIndieLib* ilib)
{
indielib = ilib;
}
~DebugDraw(void)
{
}
void DrawPolygon(const b2Vec2* vertices, int32 vertexCount, const b2Color& color)
{
if(!indielib) return;
//mpILib->Gfx_BeginScene();
for (int32 i = 0, j = 1; i < vertexCount; ++i, j++)
{
j = (j>=vertexCount)?0:j;
indielib->Render->BlitLine(static_cast<int>(mScale * vertices[i].x),
static_cast<int>(mOffsetY - mScale * vertices[i].y),
static_cast<int>(mScale * vertices[j].x),
static_cast<int>(mOffsetY - mScale * vertices[j].y),
255,
static_cast<byte>(color.r*255),
static_cast<byte>(color.g*255),
static_cast<byte>(color.b*255)
);
}
//mpILib->Gfx_EndScene();
}
void DrawSolidPolygon(const b2Vec2* vertices, int32 vertexCount, const b2Color& color)
{
if(!indielib) return;
//mpILib->Gfx_BeginScene();
for (int32 i = 0, j = 1; i < vertexCount; ++i, j++)
{
j = (j>=vertexCount)?0:j;
indielib->Render->BlitLine(static_cast<int>(mScale * vertices[i].x),
static_cast<int>(mOffsetY - mScale * vertices[i].y),
static_cast<int>(mScale * vertices[j].x),
static_cast<int>(mOffsetY - mScale * vertices[j].y),
200,
static_cast<byte>(color.r*255),
static_cast<byte>(color.g*255),
static_cast<byte>(color.b*255)
);
}
}
void DrawCircle(const b2Vec2& center, float32 radius, const b2Color& color)
{
if(!indielib) return;
int NUMPOINTS = 24+(int)radius/20;
std::vector<b2Vec2> vertices;
int i;//,j;
float X;
float Y;
float Theta;
float WedgeAngle; //Size of angle between two points on the circle (single wedge)
//Precompute WedgeAngle
WedgeAngle = static_cast<float>(((2*PI) / NUMPOINTS));
//Set up vertices for a circle
//Used <= in the for statement to ensure last point meets first point (closed circle)
for(i=0; i<=NUMPOINTS; i++)
{
//Calculate theta for this vertex
Theta = i * WedgeAngle;
//Compute X and Y locations
X = static_cast<float>((center.x + radius * cos(Theta)));
Y = static_cast<float>((center.y - radius * sin(Theta)));
vertices.push_back(b2Vec2(X, Y));
}
//mpILib->Gfx_BeginScene();
for (int32 k = 0, j = 1; k < (signed)vertices.size(); ++k, ++j)
{
j = (j>=(signed)vertices.size())?0:j;
indielib->Render->BlitLine(static_cast<int>(mScale * vertices[k].x),
static_cast<int>(mOffsetY - mScale * vertices[k].y),
static_cast<int>(mScale * vertices[j].x),
static_cast<int>(mOffsetY - mScale * vertices[j].y),
255,
static_cast<byte>(color.r*255),
static_cast<byte>(color.g*255),
static_cast<byte>(color.b*255)
);
}
}
void DrawSolidCircle(const b2Vec2& center, float32 radius, const b2Vec2&, const b2Color& color)
{
if(!indielib) return;
int NUMPOINTS = 24+(int)radius/20;
std::vector<b2Vec2> vertices;
int i;//,j;
float X;
float Y;
float Theta;
float WedgeAngle; //Size of angle between two points on the circle (single wedge)
//Precompute WedgeAngle
WedgeAngle = static_cast<float>(((2*PI) / NUMPOINTS));
//Set up vertices for a circle
//Used <= in the for statement to ensure last point meets first point (closed circle)
for(i=0; i<=NUMPOINTS; i++)
{
//Calculate theta for this vertex
Theta = i * WedgeAngle;
//Compute X and Y locations
X = static_cast<float>((center.x + radius * cos(Theta)));
Y = static_cast<float>((center.y - radius * sin(Theta)));
vertices.push_back(b2Vec2(X, Y));//Circle[i] = mpILibVector(X, Y);
}
//mpILib->Gfx_BeginScene();
for (int32 k = 0, j = 1; k < (signed)vertices.size(); ++k, ++j)
{
j = (j>=(signed)vertices.size())?0:j;
indielib->Render->BlitLine(static_cast<int>(mScale * vertices[k].x),
static_cast<int>(mOffsetY - mScale * vertices[k].y),
static_cast<int>(mScale * vertices[j].x),
static_cast<int>(mOffsetY - mScale * vertices[j].y),
200,
static_cast<byte>(color.r*255),
static_cast<byte>(color.g*255),
static_cast<byte>(color.b*255)
);
}
}
void DrawSegment(const b2Vec2& p1, const b2Vec2& p2, const b2Color& color)
{
if(!indielib) return;
//mpILib->Gfx_BeginScene();
indielib->Render->BlitLine(static_cast<int>(mScale * p1.x),
static_cast<int>(mOffsetY - mScale * p1.y),
static_cast<int>(mScale * p2.x),
static_cast<int>(mOffsetY- mScale * p2.y),
255,
static_cast<byte>(color.r*255),
static_cast<byte>(color.g*255),
static_cast<byte>(color.b*255)
);
}
void DrawTransform(const b2Transform& xf)
{
if(!indielib) return;
b2Vec2 p1 = xf.position, p2;
const float32 k_axisScale = 0.4f;
//mpILib->Gfx_BeginScene();
p2 = p1 + k_axisScale * xf.R.col1;
indielib->Render->BlitLine(static_cast<int>(mScale * p1.x),
static_cast<int>(mOffsetY - mScale * p1.y),
static_cast<int>(mScale * p2.x),
static_cast<int>(mOffsetY - mScale * p2.y),
255,
255,
0,
0);
p2 = p1 + k_axisScale * xf.R.col2;
indielib->Render->BlitLine(static_cast<int>(mScale * p1.x),
static_cast<int>(mOffsetY - mScale * p1.y),
static_cast<int>(mScale * p2.x),
static_cast<int>(mOffsetY - mScale * p2.y),
255,
0,
255,
0);
}
private:
CIndieLib* indielib;
float mScale; //Scaling factor to draw primitives
float mOffsetY; //Offset to draw y axis in correct direction, as IndieLib coords of pixels start at 0 in upper position.
};