#include "Mountains.hpp"
#include <logic/Logic.hpp>

Mountains::Mountains(const unsigned int n) : CylinderMesh(n) {
  const double h = 0.25;
  const Color c = Color(Color::White) /= 3;
  scale(
    1,
    h,
    1
  ).setColor(c);
  static Vector v;
  for (
    unsigned int i = 0;
    i < n;
    i++
  ) {
    v.set(
      1,
      h
    ).rotateY(Math::PImul2 * i / n);
    if (i % 2) {
      setColor(
        v,
        Color(c) /= 2
      );
    }
    setVector(
      v,
      (
        Vector(v).rotateY(
          Math::PI / 25 * Math::rand(-0.5)
        ) += Vector(
          0,
          0.25 * (
            sin(Math::PI * i / n) - 0.1 * (
              (i % 2 ? 1 : 0) + Math::rand()
            )
          )
        )
      ) += (
        Vector(
          v.x,
          0,
          v.z
        ) /= i % 2 ? 4 : 2
      )
    );
  }
  (
    setLight() *= Graphics::get()->R + FirstPerson::Logic::get()->getHero()->getRxz() * 3
  ).round();
}
