#include "render/primitives.h"
#include "debugDraw.h"

void debugDraw::DrawCircle(const b2Vec2 &pos, float32 radius, const b2Color &color)
{
    render::primitives2d::round(vec2f(pos.x, pos.y), radius, rgba(color.r, color.b, color.g, 1), 0, 180);
}

void debugDraw::DrawSolidCircle(const b2Vec2 &pos, float32 radius, const b2Vec2 &axis, const b2Color &color)
{
    render::primitives2d::circle(vec2f(pos.x, pos.y), radius, rgba(color.r, color.b, color.g, .5), 0, 180);
}

void debugDraw::DrawPoint(const b2Vec2 &pos, float32 radius, const b2Color &color)
{
    render::primitives2d::circle(vec2f(pos.x, pos.y), radius, rgba(color.r, color.b, color.g, .5), 0, 180);
}

void debugDraw::DrawPolygon(const b2Vec2 *vertices, int32 count, const b2Color &color)
{
    int next;
    for (int i = 0; i < count; i++) {
        if ((next = i + 1) == count) {
            next = 0;
        }

        render::primitives2d::line(((vec2f *)vertices)[i], ((vec2f *)vertices)[next], rgba(color.r, color.b, color.g, 1.0));
    }
}

void debugDraw::DrawSolidPolygon(const b2Vec2 *vertices, int32 count, const b2Color &color)
{
    vec2f *data = new vec2f[count];
    for (int i = 0; i < count; i++) {
        data[i] = ((vec2f *)vertices)[i];
    }

    render::primitives2d::polygone(data, count, rgba(color.r, color.b, color.g, .5));
    delete[] data;
}

void debugDraw::DrawSegment(const b2Vec2 &p1, const b2Vec2 &p2, const b2Color &color)
{
    render::primitives2d::line(vec2f(p1.x, p1.y), vec2f(p2.x, p2.y), rgba(color.r, color.b, color.g, 1.0));
}

void debugDraw::DrawTransform(const b2Transform &xf)
{
    //puts("2");
}
