/* 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 print(char *message1,CH3D *ch,char *message2) {
  printf("%s",message1);
  ch->print();
  printf("%s",message2);
}

static void print(char *message1,TG3D *tg,char *message2) {
  printf("%s",message1);
  tg->print();
  printf("%s",message2);
}

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");
  print("tr1 : translation de vecteur (1.8,-3.4,6.7)\n",&tr1,"\n");
  print("tr2 : translation de vecteur (-4.5,0.1,3.2)\n",tr2,"\n");
  print("tr3 : translation identite\n",&tr3,"\n");
  print("tr4 : translation clone de tr2\n",&tr4,"\n");

  Dir3D axe1(-1.3F,2.3F,3.7F);
  Rt3D rt1(45.0F,axe1);
  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");
  print("rt1 : rotation de 45.0 degres autour de l'axe (-1.3,2.3,3.7) passant par O\n",&rt1,"\n");
  print("rt2 : rotation de 30.0 degres autour de l'axe (2.1,-0.7,1.8) passant par O\n",rt2,"\n");
  print("rt3 : rotation identite\n",&rt3,"\n");
  print("rt4 : rotation clone de rt2\n",&rt4,"\n");
  print("rt5 : rotation de 30.0 degres autour de l'axe Ox\n",rt5,"\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");
  print("sc1 : zoom de rapports (0.3,1.3,0.7)\n",&sc1,"\n");
  print("sc2 : zoom de rapports (0.2,0.9,1.7)\n",sc2,"\n");
  print("sc3 : zoom identite\n",&sc3,"\n");
  print("sc4 : zoom de clone de sc2\n",&sc4,"\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);

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

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

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

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

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

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

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

  getchar();

  return(0);
}

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