#include <freeCam.h>
#include <JGL/Colors.h>

void FreeCam::pre_render() {
    if (engine->window->isKeyDown(Keys::W))
        move(getAngleDirection(), 4);

    if (engine->window->isKeyDown(Keys::S))
        move(bAngle(), 4);

    if (engine->window->isKeyDown(Keys::A))
        move(lAngle(), 4);

    if (engine->window->isKeyDown(Keys::D))
        move(rAngle(), 4);

    if (engine->window->isKeyDown(Keys::Space))
        vMove(4);

    if (engine->window->isKeyDown(Keys::LeftShift))
        vMove(-4);

    if (engine->window->isKeyDown(Keys::LeftArrow))
        setAngle(getAngle().x, getAngle().y - 75.0f * engine->frameDelta, getAngle().z);

    if (engine->window->isKeyDown(Keys::RightArrow))
        setAngle(getAngle().x, getAngle().y + 75.0f * engine->frameDelta, getAngle().z);

    if (engine->window->isKeyDown(Keys::UpArrow))
        setAngle(getAngle().x - 75.0f * engine->frameDelta, getAngle().y, getAngle().z);

    if (engine->window->isKeyDown(Keys::DownArrow))
        setAngle(getAngle().x + 75.0f * engine->frameDelta, getAngle().y, getAngle().z);
    
    if (engine->window->isKeyDown(Keys::Q))
        setAngle(getAngle().x, getAngle().y, getAngle().z - 75.0f * engine->frameDelta);

    if (engine->window->isKeyDown(Keys::E))
        setAngle(getAngle().x, getAngle().y, getAngle().z + 75.0f * engine->frameDelta);
}

Vector3 textAngle = {0,0,0};
void FreeCam::jglRenderPass() {
    textAngle.x = textAngle.x - (96.f * engine->frameDelta);
    using namespace JGL;
    J3D::Begin();
        J3D::DrawString(JGL::Colors::Red, "Text", {0, -2, 0}, textAngle, 4.f, 32, Fonts::Jupiteroid);
    J3D::End();

    J2D::Begin();
        J2D::FillRect({255,0,0,128}, {0, 72}, {100, 100});
        J2D::FillCircle(JGL::Colors::White, {16, 128}, 12, 16);

        J2D::DrawString(JGL::Colors::White, "Framerate: " + std::to_string((int) engine->framerate()), 0, -16, 1, 16, Fonts::Jupiteroid);
        J2D::DrawString(JGL::Colors::White, "Framecount: " + std::to_string(engine->frameCount), 0, -33, 1,16, Fonts::Jupiteroid);
        J2D::DrawString(JGL::Colors::White, "Position: " + std::to_string(position.x) + " " + std::to_string(position.y) + " " + std::to_string(position.z), 0, -50, 1,16, Fonts::Jupiteroid);
        J2D::DrawString(JGL::Colors::White, "ViewAngle: " + std::to_string(getAngle().x) + " " + std::to_string(getAngle().y) + " " + std::to_string(getAngle().z), 0, -67, 1,16, Fonts::Jupiteroid);
    J2D::End();
}
