/* Mathematiques de l'informatique graphique    */
/* Coordonnees homogenes en 3D                  */
/*                                              */
/* Mars 2021                                    */

#include <stdio.h>

#include "CH3D.h"

#include "TG3D.h"
#include "Pos3D.h"
#include "Dir3D.h"

/* Construit la position origine                */

CH3D::CH3D(void) : x(0.0F),y(0.0F),z(0.0F),w(1.0F) {
}

/* Construit la CH3D (xp,yp,zp,wp)              */

CH3D::CH3D(float xp, float yp, float zp, float wp) : x(xp),y(yp),z(zp),w(wp) {
}

/* Construit un clone de la CH3D ch             */

CH3D::CH3D(CH3D *ch) : x(ch->x),y(ch->y),z(ch->z),w(ch->w) {
}

/* Destructeur                                  */

CH3D::~CH3D(void) {
}

/* Methode de transformation de this            */
/* par la transformation geometrique mat        */
/* et de retour du resultat obtenu              */

CH3D CH3D::mult(const TG3D& tg) {
  CH3D res;
  res.x = this->x * tg.mat[0][0] + this->y * tg.mat[0][1] + this->z * tg.mat[0][2] + this->w * tg.mat[0][3];
  res.y = this->x * tg.mat[1][0] + this->y * tg.mat[1][1] + this->z * tg.mat[1][2] + this->w * tg.mat[1][3];
  res.z = this->x * tg.mat[2][0] + this->y * tg.mat[2][1] + this->z * tg.mat[2][2] + this->w * tg.mat[2][3];
  res.w = this->x * tg.mat[3][0] + this->y * tg.mat[3][1] + this->z * tg.mat[3][2] + this->w * tg.mat[3][3];
  return res;
}

/* Methode d'affichage texte                    */

void CH3D::print(void) {
  printf("%10.4f %10.4f %10.4f %10.4f",x,y,z,w);
}

/* Cast CH3D vers Pos3D                          */

CH3D::operator Pos3D() {
  Pos3D output(x,y,z);
  return output;
}

/* Cast CH3D vers Dir3D                          */

CH3D::operator Dir3D() {
  Dir3D output(x,y,z);
  return output;
}