#include <MovementPhysics/SwimPhysics/SwimPhysics.hpp>

SwimPhysics::SwimPhysics(Fluid &fluid) : m_fluid(fluid) {}

void SwimPhysics::updatePlayer(Player &player)
{
    // Calculate acceleration from controls.
    glm::vec3 acceleration(0.0f, 0.0f, 0.0f);
    glm::vec3 forward = player.getForwardVector();
    glm::vec3 right = player.getRightVector();

    if (player.controlFlags.contains(Player::ControlFlag::Forward))
    {
        acceleration += forward;
    }

    if (player.controlFlags.contains(Player::ControlFlag::Back))
    {
        acceleration -= forward;
    }

    if (player.controlFlags.contains(Player::ControlFlag::Right))
    {
        acceleration += right;
    }

    if (player.controlFlags.contains(Player::ControlFlag::Left))
    {
        acceleration -= right;
    }

    if (glm::length(acceleration) > 0.01f)
    {
        player.vel += wfvec3(glm::vec3(Player::accelerationSwimXY, Player::accelerationSwimXY, Player::accelerationSwimZ) *
            glm::normalize(acceleration));
    }

    if (player.controlFlags.contains(Player::ControlFlag::Jump))
    {
        player.vel.z += wfixed(Player::accelerationSwimZ);
    }
}

float SwimPhysics::getFriction()
{
    return m_fluid.density;
}

float SwimPhysics::getGravity()
{
    return gravity;
}