#include <Redacted3D/types/entity/moby.h>
#include <Redacted3D/engine/engine.h>
using namespace J3ML;

void Moby::hMove(Vector3 a, float vel) {
    position.z -= (vel*engine->frameDelta) * a.x;
    position.x += (vel*engine->frameDelta) * a.z;
}

void Moby::vMove(float vel) {
        position.y += (vel*engine->frameDelta);
}

//Returns the position we'd be at *if* we did a movement.
Vector3 Moby::simulateHMove(Vector3 a, float vel) {
    Vector3 p;
    p.z -= (vel*engine->frameDelta) * a.x;
    p.x += (vel*engine->frameDelta) * a.z;
    return p;
}

Vector3 Moby::fAngle()
{
    Vector3 a;
    a.x = -(cos(Math::Radians(this->angle.y)) * cos(Math::Radians(this->angle.x)));
    a.y = -sin(Math::Radians(this->angle.x));
    a.z = -(sin(Math::Radians(this->angle.y)) * cos(Math::Radians(this->angle.x)));
    return a;
}

Vector3 Moby::bAngle()
{
    return -fAngle();
}

Vector3 Moby::rAngle()
{
    Vector3 f = fAngle();
    Vector3 a;
    a.x = f.x * upVector.z - f.z * upVector.y;
    a.y = f.z * upVector.x - f.x * upVector.z;
    a.z = f.x * upVector.y - f.y * upVector.x;
    return a;
}

Vector3 Moby::lAngle()
{
    Vector3 f = fAngle();
    Vector3 a;
    a.x = -(f.y * upVector.z - f.z * upVector.y);
    a.y = (f.z * upVector.x - f.x * upVector.z);
    a.z = -(f.x * upVector.y - f.y * upVector.x);
    return a;
}

Vector3 Moby::simulateVMove(Vector3 position, float speed) {
    return {position.x, position.y += (speed*engine->frameDelta), position.z};
}
