#include "Fire.hpp"
#include "Logic.hpp"
#include <sound/Sound.hpp>

Object& Fire::setActive(const bool active) {
  if (active) {
    Sound::fire();
  }
  rotation = 0;
  return MeshObject::setActive(active);
}

Object& Fire::simulate(const Time dt) {
  matrix.setZRotation(rotation -= Math::PI * 3 * dt);
  return MeshObject::simulate(dt);
}

const bool Fire::isTransparent() const {
  return true;
}

Object& Fire::onCollision(Object* object) {
  return setActive(false);
}

Fire::ConeMesh::ConeMesh(const Color& color) : ::ConeMesh(
  4,
  1,
  true
) {
  setVector(
    Vector::Zero,
    Vector(Vector::Y) /= 2
  ).setColor(color).setLight(
    Color(color) /= 4
  ).rotateX(Math::PIdiv2).centralize().round(2) *= 0.25;
}

const Fire::ConeMesh Fire::coneMesh = Fire::ConeMesh();

Fire::LineMesh::LineMesh(const Color& color) {
  setColor(color).setColor(
    Vector::Zero,
    Color::Black
  ).rotateY(Math::PIdiv2).centralize().round() *= 0.125;
}

const Fire::LineMesh Fire::lineMesh = Fire::LineMesh();

const Mesh& Fire::getMesh() const {
  return coneMesh;
}
