#include "House.hpp"

House::Mesh::Roof::Roof(const double height) {
  (
    (
      rotateY(Math::PIdiv2).rotateZ(- Math::PI / 6).translate(
        0.5,
        0,
        - 0.5
      ).setVector(
        0,
        1,
        0.5,
        0,
        height,
        0.5
      ).setVector(
        0,
        1,
        - 0.5,
        0,
        height,
        - 0.5
      ).translate(-height) *= 105
    ).round() *= 0.01
  ).setColor(
    Color(Color::Magenta) *= 0.75
  );
  Mesh* m = clone();
  *this += m->rotateY(Math::PI);
  delete m;
  setLight();
}

House::Mesh::Mesh(
  const double height,
  const double roofHeight
) : BoxMesh(false) {
  scale(
    1,
    height,
    1
  ).translate(- height);
  {
    ::Mesh* m = new TriangleMesh();
    *this += m->setVector(
      0,
      1,
      0,
      0.5,
      roofHeight,
      0
    );
    *this += m->rotateY(Math::PI).translate(
      1,
      0,
      1
    );
    delete m;
  }
  const double r = (height + roofHeight) / 2;
  translate(
    - 0.5,
    r - roofHeight,
    - 0.5
  ).setLight();
  {
    ::Mesh* m = new Roof(roofHeight);
    *this += m->translate(r);
    delete m;
  }
}

const Mesh& House::getMesh() const {
  return mesh;
}

const bool House::isStatic() const {
  return true;
}

House::House(
  const double height,
  const double roofHeight
) : mesh(
  height,
  roofHeight
) {
}
