#ifndef MATH_BASIS_H_
#define MATH_BASIS_H_

#include "./mat4.h"
#include "./quat.h"

namespace math
{

  struct BASIS 
  {
    QUAT rot;
    VEC3 pos;
    float  w;

    BASIS() {}
    BASIS(const QUAT &rot, const VEC3 &pos) : rot(rot), pos(pos), w(1.0f) {}
    BASIS(const MAT4 &matrix) : rot(matrix.getRot()), pos(matrix.getPos()), w(1.0f) {}

    void identity() {
      rot = QUAT(0, 0, 0, 1);
      pos = VEC3(0, 0, 0);
      w  = 1.0f;
    }

    BASIS operator * (const BASIS &basis) const {
      return BASIS(rot * basis.rot, pos + rot * basis.pos);
    }

    VEC3 operator * (const VEC3 &v) const {
      return rot * v + pos;
    }

    BASIS inverse() const {
      QUAT q = rot.conjugate();
      return BASIS(q, -(q * pos));
    }

    void translate(const VEC3 &v) {
      pos += rot * v;
    }
    
    void rotate(const QUAT &q) {
      rot = rot * q;
    }

    BASIS lerp(const BASIS &basis, float t) {
      BASIS b;
      b.rot = rot.lerp(basis.rot, t);
      b.pos = pos.lerp(basis.pos, t);
      return b;
    }
  };

}
#endif
