/* Mathematiques de l'Infographie               */
/* Test des classes TG3D, Tr3D, Rt3D et Sc3D    */
/*                                              */
/* Auteur: Nicolas JANEY                        */
/* nicolas.janey@univ-fcomte.fr                 */
/* Mars 2020                                    */

#if defined(WIN32) || defined(WIN64)
  #define _CRTDBG_MAP_ALLOC
  #if defined(_DEBUG)
    #define _AFXDLL
    #include <afx.h>
  #endif
#endif
#include <stdlib.h>
#if defined(WIN32) || defined(WIN64)
  #include <crtdbg.h>
#endif

#include <stdio.h>

#include "Pos3D.h"
#include "Dir3D.h"
#include "Tr3D.h"
#include "Rt3D.h"
#include "Sc3D.h"

//////////////////////////////////////////////////

static void afficher(char *message,CH3D *ch) {
  printf("%s",message);
  ch->print();
  printf("\n");
}

int main(void) {

#if defined(WIN32) || defined(WIN64)
  #if defined(_DEBUG)
    _CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
    //_crtBreakAlloc = 120;
  #endif
#endif

  Tr3D tr1(1.8F,-3.4F,6.7F);
  Tr3D *tr2 = new Tr3D(-4.5F,0.1F,3.2F);
  Tr3D tr3;
  Tr3D tr4(tr2);

  printf("Translations\n\n");
  tr1.print("tr1 : translation de vecteur (1.8,-3.4,6.7)\n","\n");
  tr2->print("tr2 : translation de vecteur (-4.5,0.1,3.2)\n","\n");
  tr3.print("tr3 : translation identite\n","\n");
  tr4.print("tr4 : translation clone de tr2\n","\n");

  Rt3D rt1(45.0F,-1.3F,2.3F,3.7F);
  Dir3D axe2(2.1F,-0.7F,1.8F);
  Rt3D *rt2 = new Rt3D(30.0F,&axe2);
  Rt3D rt3;
  Rt3D rt4(rt2);
  Dir3D axe5(1.0F,0.0F,0.0F);
  Rt3D *rt5 = new Rt3D(30.0,&axe5);

  printf("Rotations\n\n");
  rt1.print("rt1 : rotation de 45.0 degres autour de l'axe (-1.3,2.3,3.7) passant par O\n","\n");
  rt2->print("rt2 : rotation de 30.0 degres autour de l'axe (2.1,-0.7,1.8) passant par O\n","\n");
  rt3.print("rt3 : rotation identite\n","\n");
  rt4.print("rt4 : rotation clone de rt2\n","\n");
  rt5->print("rt5 : rotation de 30.0 degres autour de l'axe Ox\n","\n");

  Sc3D sc1(0.3F,1.3F,0.7F);
  Sc3D *sc2 = new Sc3D(0.2F,0.9F,1.7F);
  Sc3D sc3;
  Sc3D sc4(sc2);

  printf("Zooms\n\n");
  sc1.print("sc1 : zoom de rapports (0.3,1.3,0.7)\n","\n");
  sc2->print("sc2 : zoom de rapports (0.2,0.9,1.7)\n","\n");
  sc3.print("sc3 : zoom identite\n","\n");
  sc4.print("sc4 : zoom de clone de sc2\n","\n");

  Pos3D p1(2.0F,3.0F,4.0F);
  Pos3D *p2 = new Pos3D(-1.1F,-0.2F,-2.3F);
  Dir3D d1(2.0F,3.0F,4.0F);
  Dir3D *d2 = new Dir3D(-1.1F,-0.2F,-2.3F);

  tr1.print("tr1 : translation de vecteur (1.8,-3.4,6.7)\n","\n");
  tr2->print("tr2 : translation de vecteur (-4.5,0.1,3.2)\n","\n");
  rt1.print("rt1 : rotation de 45.0 degres autour de l'axe (-1.3,2.3,3.7) passant par O\n","\n");
  rt2->print("rt2 : rotation de 30.0 degres autour de l'axe (2.1,-0.7,1.8) passant par O\n","\n");

  printf("Transformations de positions 3D\n\n");
  { p1.print("p1                               : ","\n");
    Pos3D p(&p1,&tr1);
    p.print("p cree par translation tr1 de p1 : ","\n");
    p.transformation(tr2);
    p.print("p modifie par translation tr2    : ","\n");
    printf("\n"); }

  { p2->print("p2                               : ","\n");
    Pos3D p(p2,&rt1);
    p.print("p cree par rotation rt1 de p2    : ","\n");
    p.transformation(rt2);
    p.print("p modifie par rotation rt2       : ","\n");
    printf("\n"); }

  printf("Transformations de directions 3D\n\n");
  { d1.print("d1                               : ","\n");
    Dir3D d(&d1,&tr1);
    d.print("d cree par translation tr1 de d1 : ","\n");
    d.transformation(tr2);
    d.print("d modifie par translation tr2    : ","\n");
    printf("\n"); }

  { d2->print("d2                               : ","\n");
    Dir3D d(d2,&rt1);
    d.print("d cree par rotation rt1 de d1    : ","\n");
    d.transformation(rt2);
    d.print("d modifie par rotation rt2       : ","\n");
    printf("\n"); }

  printf("Compositions de transformations geometriques\n\n");
  TG3D tg1(&tr1,&rt1);
  tg1.print("Composition de tr1 et rt1\n","\n");
  TG3D tg2(&rt1,&tr1);
  tg2.print("Composition de rt1 et tr1\n","\n");
  printf("\n");

  delete(sc2);
  delete(rt5);
  delete(rt2);
  delete(tr2);
  delete(p2);
  delete(d2);

  getchar();

  return(0);
}

//////////////////////////////////////////////////
