/* Mathematiques de l'informatique graphique    */
/* Rotation 3D en coordonnees homogenes         */
/*                                              */
/* Auteur: Nicolas JANEY                        */
/* nicolas.janey@univ-fcomte.fr                 */
/* Mars 2020                                    */

#include <stdlib.h>
#include <stdio.h>
#include <math.h>

#include "TG3D.h"
#include "Rt3D.h"
#include "Dir3D.h"

#ifndef M_PI
#define M_PI 3.14159265358979323846264338327950288
#endif

/* Construit la rotation identite               */

Rt3D::Rt3D(void):TG3D() {
}

/* Construit la rotation d'angle alpha degres   */
/* autour de l'axe de direction dir passant     */
/* par l'origine                                */

Rt3D::Rt3D(float angle,Dir3D &dir):TG3D() {
  Dir3D dirNorm = dir.normalize();
  double a = angle*(M_PI/180.0);
  float sn =(float) sin(a);
  float cs =(float) cos(a);
  mat[0][0] = dirNorm.x*dirNorm.x+cs*(1.0F-dirNorm.x*dirNorm.x);
  mat[0][1] = dirNorm.x*dirNorm.y*(1.0F-cs)-sn*dirNorm.z;
  mat[0][2] = dirNorm.x*dirNorm.z*(1.0F-cs)+sn*dirNorm.y;
  mat[1][0] = dirNorm.x*dirNorm.y*(1.0F-cs)+sn*dirNorm.z;
  mat[1][1] = dirNorm.y*dirNorm.y+cs*(1.0F-dirNorm.y*dirNorm.y);
  mat[1][2] = dirNorm.y*dirNorm.z*(1.0F-cs)-sn*dirNorm.x;
  mat[2][0] = dirNorm.x*dirNorm.z*(1.0F-cs)-sn*dirNorm.y;
  mat[2][1] = dirNorm.y*dirNorm.z*(1.0F-cs)+sn*dirNorm.x;
  mat[2][2] = dirNorm.z*dirNorm.z+cs*(1.0F-dirNorm.z*dirNorm.z);
}

/* Construit le clone de la rotation rt         */

Rt3D::Rt3D(Rt3D *rt):TG3D(rt) {
}

/* Destructeur                                  */

Rt3D::~Rt3D(void) {
}
