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

///Moves the moby horizontally only.
void Moby::hMove(Direction a, float vel) {
    position.z -= (vel*engine->frameDelta) * a.x;
    position.x += (vel*engine->frameDelta) * a.z;
}

///Moves the moby vertically only.
void Moby::vMove(float vel) {
        position.y += (vel*engine->frameDelta);
}

///Moves the moby in a given Direction Vector with a given speed.
void Moby::move(Direction a, float speed) {
    position.x += a.z * (speed * engine->frameDelta);
    position.z -= a.x * (speed * engine->frameDelta);
    position.y += a.y * (speed * engine->frameDelta);
}

///Moves the moby in the direction it's facing without having to pass it in.
void Moby::move(float speed) {
    Direction a = getAngleDirection();
    position.x += a.z * (speed * engine->frameDelta);
    position.z -= a.x * (speed * engine->frameDelta);
    position.y += a.y * (speed * engine->frameDelta);
}

///Moves the moby in the direction of it's velocity without having to pass it in.
void Moby::vAngleMove(float speed) {
    Direction a = getVelocityAngleDirection();
    position.x += a.z * (speed * engine->frameDelta);
    position.z -= a.x * (speed * engine->frameDelta);
    position.y += a.y * (speed * engine->frameDelta);
}

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

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

Direction Moby::fAngle() {
    return getAngleDirection();
}

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

Direction Moby::rAngle() {
    return Vector3::Cross(fAngle(), engine->world->upVector);
}

Direction Moby::lAngle() {
    return -rAngle();
}

float Moby::getVelocity() {
    return velocity;
}

void Moby::setVelocity(float vel) {
    velocity = vel;
}

Direction Moby::getVelocityAngleDirection() {
    Direction a = Vector3::Direction(velAngle);
    ///X and Z are reversed in the Re3D scene.
    a.x = -a.x;
    a.z = -a.z;
    return a;
}

Vector3 Moby::getVelocityAngle() {
    return velAngle;
}

void Moby::setVelocityAngle(const Vector3 &a) {
    velAngle = a;
}

void Moby::setVelocityAngle(float pitch, float yaw, float roll) {
    velAngle = {pitch, yaw, roll};
}