Code: Select all
SDL_Point worldToPixel(b2Vec2 worldLocation)
{
SDL_Point p;
p.x = worldLocation.x * SCALE - camera.x;
p.y = worldLocation.y * SCALE - camera.y;
return p;
}
Code: Select all
void DrawPolygon(const b2Vec2* vertices, int32 vertexCount, const b2Color& color)
{
// RUBEScene* scene = getCurrentScene();
SDL_Renderer* renderer = getRenderer();
Sint16 xs[8];
Sint16 ys[8];
int32 i;
for (i = 0; i < vertexCount; ++i) {
// SDL_Point p = scene->worldToPixel( vertices[i] );
SDL_Point p = worldToPixel(vertices[i]);
xs[i] = p.x;
ys[i] = p.y;
}
polygonRGBA(renderer, xs, ys, vertexCount, (uint8)(color.r*255), (uint8)(color.g * 255), (uint8)(color.b * 255), SDL_ALPHA_OPAQUE);
}
How get const b2Vec2* vertices and int32 vertexCount ??
Example for draw circle for body (bb16_r):
object made from json file.
b2Body *bb16_r;
bb16_r = (b2Body*)jsonR.getBodyByName("service_wheel");
Code: Select all
void DrawCircle(const b2Vec2& center, float32 radius, const b2Color& color)
{
SDL_Renderer* renderer = getRenderer();
const float32 k_segments = 16.0f;
const float32 k_increment = 2.0f * b2_pi / k_segments;
float32 theta = 0.0f;
Sint16 xs[16];
Sint16 ys[16];
int32 i;
for (i = 0; i < k_segments; ++i) {
b2Vec2 v = center + radius * b2Vec2(cosf(theta), sinf(theta));
SDL_Point p = scene->worldToPixel( v );
xs[i] = p.x;
ys[i] = p.y;
theta += k_increment;
}
polygonRGBA(renderer, xs, ys, (int)k_segments, (uint8)(color.r * 255), (uint8)(color.g * 255), (uint8)(color.b * 255), SDL_ALPHA_OPAQUE);
}
Code: Select all
DrawCircle(bb16_r->GetPosition(), bb16_r->GetFixtureList()->GetShape()->m_radius, { 255, 0, 0, 0 });