TP2: finished project.

This commit is contained in:
Yohan Boujon 2021-12-18 14:59:41 +01:00
parent dcbf9e8d06
commit f722f86f2a
11 changed files with 824 additions and 8 deletions

View file

@ -1,7 +1,7 @@
#ifndef __BMP__
#define __BMP__
#ifndef BMP_H_INCLUDED
#define BMP_H_INCLUDED
///////////////////////////////////////////////////////////
// header inclus dans tous les fichiers sources
// header inclus dans tous les fichiers sources
// G. Péoux, 2009
///////////////////////////////////////////////////////////
#include <fstream>
@ -11,7 +11,7 @@
using namespace std;
////////////////////////////////////
//Redefinition des types d'entiers//
//Redefinition des tsetpixelypes d'entiers//
////////////////////////////////////
typedef unsigned char BYTE;
typedef unsigned long int ULONG;
@ -47,7 +47,7 @@ class Bmp {
//affecte la couleur 'color' au pixel de coordonnees (X,Y)
void setpixel(SHORT X,SHORT Y,ULONG color);
//retourne la couleur d'un pixel
ULONG getpixel(SHORT X,SHORT Y);
ULONG getpixel(SHORT X,SHORT Y);
//trace une ligne à partir de deux points
void line(SHORT,SHORT,SHORT,SHORT,ULONG color);
//Ecriture de l'image dans un fichier
@ -61,4 +61,4 @@ class Bmp {
void convert(BYTE *, ULONG );
void convert(BYTE *, USHORT);
};
#endif
#endif

106
tp2/cercle.cpp Normal file
View file

@ -0,0 +1,106 @@
#include "cercle.h"
cercle :: cercle(point& pixel, int r):point(pixel),m_rayon(r)
{}
void cercle :: afficher(Bmp& imageTemp)
{
point pointCentre(getCoordX(),getCoordY(),getColor());
point pointTemp(m_rayon+getCoordX(),getCoordY(),VERT);
point pointSet(m_rayon+getCoordX(),getCoordY(),VERT);
for(float teta(0) ; teta<360 ; teta=teta+0.1)
{
pointSet.geoRotation(pointCentre,teta);
imageTemp.setpixel(getCoordX(),getCoordY(),getColor());
pointSet = pointTemp;
};
imageTemp.setpixel(pointTemp.getCoordX(),pointTemp.getCoordY(),NOIR);
}
void cercle :: afficherDecal(Bmp& imageTemp)
{
point pointCentre(getCoordX(),getCoordY(),getColor());
point pointSet(m_rayon+getCoordX(),getCoordY(),getColor());
for(float teta(0) ; teta<360 ; teta=teta+0.1)
{
pointSet.geoRotation(pointCentre,teta);
imageTemp.setpixel(pointSet.getCoordX(),pointSet.getCoordY(),pointSet.getColor());
};
}
void cercle :: afficherBeta(Bmp& imageTemp)
{
int x;
for(double y=(getCoordY()-m_rayon) ; y<(getCoordY()+m_rayon) ; y+=0.01)
{
x=sqrt((m_rayon*m_rayon)-(y-getCoordY())*(y-getCoordY()))+(getCoordX());
if(x>=0 && y>=0)
{
imageTemp.setpixel(x,y,getColor());
};
x=-sqrt((m_rayon*m_rayon)-(y-getCoordY())*(y-getCoordY()))+(getCoordX());
if(x>=0 && y>=0)
{
imageTemp.setpixel(x,y,getColor());
};
};
}
void cercle :: afficherPlein(Bmp& imageTemp)
{
point pointTemp,pointSet;
point pointCentre(getCoordX(),getCoordY(),getColor());
//ULONG couleurChangeante = VERT;
for(int rayonTemp(1) ; rayonTemp<m_rayon ; rayonTemp++)
{
pointTemp.redefine(rayonTemp+getCoordX(),getCoordY(),VERT);
pointSet.redefine(rayonTemp+getCoordX(),getCoordY(),VERT);
for(float teta(0) ; teta<360 ; teta=teta+0.1)
{
pointSet.geoRotation(pointCentre,teta);
imageTemp.setpixel(pointSet.getCoordX(),pointSet.getCoordY(),getColor());
//couleurChangeante++;
pointSet = pointTemp;
};
}
/*float maxTeta = exp(10/(rayonTemp));*/
}
/*void cercle :: geoTranslation(SHORT x)
{
point::geoTranslation(x);
}*/
/*void cercle :: geoTranslation(SHORT x,SHORT y)
{
point::geoTranslation(x,y);
}*/
void cercle :: geoHomothetie(point& centre, float k)
{
point::geoHomothetie(centre,k);
m_rayon=k*m_rayon;
}
/*void cercle :: geoRotation(point& centre, double degree)
{
point::geoRotation(centre,degree);
}*/
/*
int y(0),i(0);
string nomImage("img_"),extensionImage(".bmp"),finalImage;
y++;
if(y>2500)
{
string yString = to_string(i);
finalImage=nomImage+yString+extensionImage;
int n (finalImage.length());
char char_array[n + 1];
strcpy(char_array, finalImage.c_str());
imageTemp.write(char_array);
i++;
y=0;
}
*/

24
tp2/cercle.h Normal file
View file

@ -0,0 +1,24 @@
#ifndef CERCLE_H_INCLUDED
#define CERCLE_H_INCLUDED
#include "point.h"
class cercle: public point
{
private:
int m_rayon;
public:
cercle(point& pixel, int r);
void afficher(Bmp& imageTemp);
void afficherDecal(Bmp& imageTemp);
void afficherBeta(Bmp& imageTemp);
void afficherPlein(Bmp& imageTemp);
//void geoTranslation(SHORT x);
//void geoTranslation(SHORT x,SHORT y);
void geoHomothetie(point& centre, float k);
//void geoRotation(point& centre, double degree);
};
#endif // CERCLE_H_INCLUDED

301
tp2/facette.cpp Normal file
View file

@ -0,0 +1,301 @@
#include "facette.h"
using namespace std;
void rotateClass(double& rotation,SHORT& centreX, SHORT& centreY, point& pointA, point& pointB, point& pointC, point& pointD);
void afficheTotal(point& pointA,point& pointB,point& pointC,point& pointD,Bmp& Image);
void TourneEtRetourne(double rotation,short centreX, short centreY, point& pointA, point& pointB, point& pointC, point& pointD, Bmp& image);
point getPointDroite(point& pointA,point& pointB,point& pointC,point& pointD);
point getPointGauche(point& pointA,point& pointB,point& pointC,point& pointD,point& pointDroite);
point getPointBas(point& pointA,point& pointB,point& pointC,point& pointD,point& pointDroite,point& pointGauche);
point getPointHaut(point& pointA,point& pointB,point& pointC,point& pointD,point& pointDroite,point& pointGauche,point& pointBas);
facette :: facette(point& paramA,int taille):m_rotation(0)
{
m_pointA = paramA;
point pointB(paramA.getCoordX()+taille,paramA.getCoordY(),paramA.getColor());
point pointC(paramA.getCoordX()+taille,paramA.getCoordY()+taille,paramA.getColor());
point pointD(paramA.getCoordX(),paramA.getCoordY()+taille,paramA.getColor());
m_pointB = pointB;
m_pointC = pointC;
m_pointD = pointD;
int i(0);
while((m_pointB.getCoordX()-i)-(m_pointA.getCoordX()+i) >= 0)
{
m_centreX = m_pointA.getCoordX()+i;
m_centreY = m_pointA.getCoordY()+i;
i++;
}
}
facette :: facette(point& paramA,point& paramB,point& paramC,point& paramD):m_rotation(0)
{
m_pointA = paramA;
m_pointB = paramB;
m_pointC = paramC;
m_pointD = paramD;
int i(0);
while((m_pointB.getCoordX()-i)-(m_pointA.getCoordX()+i) >= 0)
{
m_centreX = m_pointA.getCoordX()+i;
m_centreY = m_pointA.getCoordY()+i;
i++;
}
}
void facette :: afficher(Bmp& imageTemp)
{
afficheTotal(m_pointA,m_pointB,m_pointC,m_pointD,imageTemp);
}
void facette :: afficherPlein(Bmp& imageTemp)
{
double antiRotation=-m_rotation;
rotateClass(antiRotation,m_centreX,m_centreY,m_pointA,m_pointB,m_pointC,m_pointD);
short pointAX(m_pointA.getCoordX()),pointAY(m_pointA.getCoordY()),pointBX(m_pointB.getCoordX()),pointBY(m_pointB.getCoordY()),pointCX(m_pointC.getCoordX()),
pointCY(m_pointC.getCoordY()),pointDX(m_pointD.getCoordX()),pointDY(m_pointD.getCoordY()),pointXMax(m_pointC.getCoordX()),pointYMax(m_pointC.getCoordY());
rotateClass(m_rotation,m_centreX,m_centreY,m_pointA,m_pointB,m_pointC,m_pointD);
afficheTotal(m_pointA,m_pointB,m_pointC,m_pointD,imageTemp);
while((pointAX <= pointXMax-2) && (pointAY <= pointYMax-2))
{
pointAX++;
pointAY++;
pointBX--;
pointBY++;
pointCX--;
pointCY--;
pointDX++;
pointDY--;
m_pointA.redefine(pointAX,pointAY,m_pointA.getColor());
m_pointB.redefine(pointBX,pointBY,m_pointA.getColor());
m_pointC.redefine(pointCX,pointCY,m_pointA.getColor());
m_pointD.redefine(pointDX,pointDY,m_pointA.getColor());
TourneEtRetourne(m_rotation,m_centreX,m_centreY,m_pointA,m_pointB,m_pointC,m_pointD,imageTemp);
};
pointAX=m_centreX,pointAY=m_centreY,pointBX=m_centreX,pointBY=m_centreY,pointCX=m_centreX,pointCY=m_centreY,pointDX=m_centreX,pointDY=m_centreY;
while((pointCX <= pointXMax) && (pointCY <= pointYMax))
{
pointAX--;
pointAY--;
pointBX++;
pointBY--;
pointCX++;
pointCY++;
pointDX--;
pointDY++;
m_pointA.redefine(pointAX,pointAY,m_pointA.getColor());
m_pointB.redefine(pointBX,pointBY,m_pointA.getColor());
m_pointC.redefine(pointCX,pointCY,m_pointA.getColor());
m_pointD.redefine(pointDX,pointDY,m_pointA.getColor());
TourneEtRetourne(m_rotation,m_centreX,m_centreY,m_pointA,m_pointB,m_pointC,m_pointD,imageTemp);
};
}
void facette :: afficherPleinNew(Bmp& imageTemp)
{
int i;
bool aucunTrait=false;
afficheTotal(m_pointA,m_pointB,m_pointC,m_pointD,imageTemp);
point pointDroite(getPointDroite(m_pointA,m_pointB,m_pointC,m_pointD).getCoordX(),getPointDroite(m_pointA,m_pointB,m_pointC,m_pointD).getCoordY(),getPointDroite(m_pointA,m_pointB,m_pointC,m_pointD).getColor());
point pointGauche(getPointGauche(m_pointA,m_pointB,m_pointC,m_pointD,pointDroite).getCoordX(),getPointGauche(m_pointA,m_pointB,m_pointC,m_pointD,pointDroite).getCoordY(),getPointGauche(m_pointA,m_pointB,m_pointC,m_pointD,pointDroite).getColor());
point pointBas(getPointBas(m_pointA,m_pointB,m_pointC,m_pointD,pointDroite,pointGauche).getCoordX(),getPointBas(m_pointA,m_pointB,m_pointC,m_pointD,pointDroite,pointGauche).getCoordY(),getPointBas(m_pointA,m_pointB,m_pointC,m_pointD,pointDroite,pointGauche).getColor());
point pointHaut(getPointHaut(m_pointA,m_pointB,m_pointC,m_pointD,pointDroite,pointGauche,pointBas).getCoordX(),getPointHaut(m_pointA,m_pointB,m_pointC,m_pointD,pointDroite,pointGauche,pointBas).getCoordY(),getPointHaut(m_pointA,m_pointB,m_pointC,m_pointD,pointDroite,pointGauche,pointBas).getColor());
cout << m_pointA.getCoordX() << " " << m_pointA.getCoordY() << endl;
cout << m_pointB.getCoordX() << " " << m_pointB.getCoordY() << endl;
cout << m_pointC.getCoordX() << " " << m_pointC.getCoordY() << endl;
cout << m_pointD.getCoordX() << " " << m_pointD.getCoordY() << endl << endl;
cout << "Point Droite : " << pointDroite.getCoordX() << " " << pointDroite.getCoordY() << endl;
cout << "Point Gauche : " << pointGauche.getCoordX() << " " << pointGauche.getCoordY() << endl << endl;
cout << "Point Haut : " << pointHaut.getCoordX() << " " << pointHaut.getCoordY() << endl;
cout << "Point Bas : " << pointBas.getCoordX() << " " << pointBas.getCoordY() << endl << endl;
SHORT pointYTemp=pointBas.getCoordY(), pointXTemp=pointBas.getCoordX(),Ytemp,xTempCenter;
float a = (float)(pointBas.getCoordY()-pointHaut.getCoordY())/(float)(pointBas.getCoordX()-pointHaut.getCoordX());
float b = (float)pointHaut.getCoordY()-(a*(float)pointHaut.getCoordX());
float xTemp = pointBas.getCoordX();
cout << "a : " << a << " = (" << pointBas.getCoordY() << " - " << pointHaut.getCoordY() << ") / (" << pointBas.getCoordX() << " - " << pointHaut.getCoordX() << ")" << endl;
cout << "b : " << b << " = " << pointHaut.getCoordY() << "- (" << a << " * " << pointHaut.getCoordX() << ")" << endl;
cout << a << "x +" << b << endl << endl;
cout << a*xTemp+b << " = " << pointBas.getCoordY() << endl;
do
{
Ytemp=(SHORT)((a*xTemp+b));
xTempCenter = (SHORT)xTemp;
do{
xTempCenter++;
if(xTempCenter > 509)
{
aucunTrait = true;
}
}while((imageTemp.getpixel(xTempCenter+1,Ytemp) == NOIR) && (aucunTrait == false));
if(aucunTrait == false)
{
imageTemp.line((SHORT)xTemp,Ytemp,xTempCenter,Ytemp,pointHaut.getColor());
}
aucunTrait=false;
do{
xTempCenter--;
if(xTempCenter < 0)
{
aucunTrait = true;
}
}while((imageTemp.getpixel(xTempCenter-1,Ytemp) == NOIR) && (aucunTrait == false));
if(aucunTrait == false)
{
imageTemp.line((SHORT)xTemp,Ytemp,xTempCenter,Ytemp,pointHaut.getColor());
}
aucunTrait=false;
/*while((imageTemp.getpixel(xTempCenter,Ytemp) == NOIR) && (xTempCenter<511))
{
//cout << "xTempCenter : " << xTempCenter << ", " << Ytemp << endl;
//cout << "xTempCenter Pixel : " << imageTemp.getpixel(xTempCenter,Ytemp) << endl;
xTempCenter++;
imageTemp.setpixel(xTempCenter,Ytemp,pointHaut.getColor());
};
imageTemp.setpixel(SHORT(xTemp),Ytemp,ROUGE);
afficheTotal(m_pointA,m_pointB,m_pointC,m_pointD,imageTemp);
xTempCenter = (SHORT)xTemp;
while(imageTemp.getpixel(xTempCenter,Ytemp) == NOIR && (xTempCenter>0))
{
imageTemp.setpixel(xTempCenter,Ytemp,pointHaut.getColor());
xTempCenter--;
};*/
if(a < 0)
{
xTemp=xTemp - 0.001;
}
else{
xTemp=xTemp + 0.001;
}
}
while(Ytemp < pointHaut.getCoordY());
cout << a*xTemp+b << " = " << pointHaut.getCoordY() << endl;
}
void facette :: rotateFacette(double rotation)
{
m_rotation=m_rotation+rotation;
rotateClass(rotation,m_centreX,m_centreY,m_pointA,m_pointB,m_pointC,m_pointD);
}
void rotateClass(double& rotation,SHORT& centreX, SHORT& centreY, point& pointA, point& pointB, point& pointC, point& pointD)
{
point pointCentre(centreX,centreY,NOIR);
pointA.geoRotation(pointCentre,rotation);
pointB.geoRotation(pointCentre,rotation);
pointC.geoRotation(pointCentre,rotation);
pointD.geoRotation(pointCentre,rotation);
}
void afficheTotal(point& pointA,point& pointB,point& pointC,point& pointD,Bmp& Image)
{
Image.line(pointA.getCoordX(),pointA.getCoordY(),pointB.getCoordX(),pointB.getCoordY(),pointA.getColor());
Image.line(pointB.getCoordX(),pointB.getCoordY(),pointC.getCoordX(),pointC.getCoordY(),pointA.getColor());
Image.line(pointC.getCoordX(),pointC.getCoordY(),pointD.getCoordX(),pointD.getCoordY(),pointA.getColor());
Image.line(pointD.getCoordX(),pointD.getCoordY(),pointA.getCoordX(),pointA.getCoordY(),pointA.getColor());
}
void TourneEtRetourne(double rotation,short centreX, short centreY, point& pointA, point& pointB, point& pointC, point& pointD, Bmp& image)
{
double antiRotation=-rotation;
double retourne = 90;
rotateClass(rotation,centreX,centreY,pointA,pointB,pointC,pointD);
for(short i(0); i<3; i++)
{
retourne = 90*i;
rotateClass(retourne,centreX,centreY,pointA,pointB,pointC,pointD);
afficheTotal(pointA,pointB,pointC,pointD,image);
};
rotateClass(antiRotation,centreX,centreY,pointA,pointB,pointC,pointD);
}
point getPointDroite(point& pointA,point& pointB,point& pointC,point& pointD)
{
int iMax(3),i;
point tabPoi[4]= {pointA,pointB,pointC,pointD};
short maxX=tabPoi[3].getCoordX();
for(i=3; i>=0 ; i--)
{
if(tabPoi[i].getCoordX() > maxX)
{
maxX = tabPoi[i].getCoordX();
iMax = i;
}
}
return tabPoi[iMax];
};
point getPointGauche(point& pointA,point& pointB,point& pointC,point& pointD,point& pointDroite)
{
int iMin(3),i;
point tabPoi[4]= {pointA,pointB,pointC,pointD};
short minX=tabPoi[3].getCoordX();
for(i=3; i>=0 ; i--)
{
if((tabPoi[i].getCoordX() < minX) && (tabPoi[i] != pointDroite))
{
minX = tabPoi[i].getCoordX();
iMin = i;
}
}
return tabPoi[iMin];
};
point getPointBas(point& pointA,point& pointB,point& pointC,point& pointD,point& pointDroite,point& pointGauche)
{
int iMin(0),i;
point tabPoi[4]= {pointA,pointB,pointC,pointD};
short minY=tabPoi[0].getCoordY();
for(i=0; i<=3 ; i++)
{
if(tabPoi[i].getCoordY() < minY)
{
minY = tabPoi[i].getCoordY();
iMin = i;
}
}
return tabPoi[iMin];
};
point getPointHaut(point& pointA,point& pointB,point& pointC,point& pointD,point& pointDroite,point& pointGauche,point& pointBas)
{
int iMax(0),i;
point tabPoi[4]= {pointA,pointB,pointC,pointD};
short maxY=tabPoi[0].getCoordY();
for(i=0; i<=3 ; i++)
{
if((tabPoi[i].getCoordY() > maxY) && (tabPoi[i].getCoordX() != pointBas.getCoordX()))
{
maxY = tabPoi[i].getCoordY();
iMax = i;
}
}
return tabPoi[iMax];
};
/* int y(0);
string nomImage("img_"),extensionImage(".bmp"),finalImage;
string yString = to_string(y);
finalImage=nomImage+yString+extensionImage;
int n (finalImage.length());
char char_array[n + 1];
strcpy(char_array, finalImage.c_str());
imageTemp.write(char_array);*/

27
tp2/facette.h Normal file
View file

@ -0,0 +1,27 @@
#ifndef FACETTE_H_INCLUDED
#define FACETTE_H_INCLUDED
#include "point.h"
class facette{
private:
point m_pointA;
point m_pointB;
point m_pointC;
point m_pointD;
SHORT m_centreX;
SHORT m_centreY;
double m_rotation;
public:
facette(point& paramA,int taille);
facette(point& paramA,point& paramB,point& paramC,point& paramD);
void afficher(Bmp& imageTemp);
void afficherPlein(Bmp& imageTemp);
void afficherPleinNew(Bmp& imageTemp);
void rotateFacette(double rotation);
};
#endif // FACETTE_H_INCLUDED

View file

@ -1,11 +1,95 @@
#include <iostream>
#include "bmp.h"
#include "point.h"
#include "cercle.h"
#include "segment.h"
#include "facette.h"
using namespace std;
int main()
{
Bmp image(512,512,NOIR);
image.write("test.bmp");
Bmp image(512,512,NOIR),image2(512,512,NOIR);
point point2(150,150,VERT);
facette carre1(point2,200);
carre1.rotateFacette(100);
carre1.afficherPleinNew(image);
image.write("carre_pleinTest.bmp");
return 0;
}
/* string nomImage("img_"),extensionImage(".bmp"),finalImage;
for(int i(0); i<361 ; i++)
{
Bmp image(512,512,NOIR);
point secondPoint(150,150,VERT), premierPoint(384,256,VERT), troisiemePoint(300,100,VERT), quatriemePoint(500,128,VERT);
facette carre2(secondPoint,200),carre1(premierPoint,secondPoint,troisiemePoint,quatriemePoint);
carre2.rotateFacette(i);
carre2.afficher(image);
string iString = to_string(i);
finalImage=nomImage+iString+extensionImage;
int n (finalImage.length());
char char_array[n + 1];
strcpy(char_array, finalImage.c_str());
image.write(char_array);
} */
/*
Bmp image(512,512,NOIR),image2(512,512,NOIR),image3(512,512,NOIR),image4(512,512,NOIR),image5(512,512,NOIR);
point point1(256,256,ROSE),point2(150,150,ROUGE),point3(150,150,VERT);
cercle cercle1(point1,200);
facette carre1(point2,200),carre2(point3,200);
cercle1.afficherPlein(image);
image.write("cercle1.bmp");
carre1.rotateFacette(45);
carre1.afficherPlein(image2);
image2.write("carre1.bmp");
carre2.afficherPlein(image3);
image3.write("carre2.bmp");
carre2.afficher(image4);
image4.write("carre3.bmp");
carre1.rotateFacette(45);
carre1.afficher(image5);
image5.write("carre4.bmp");
*/
/*
Bmp image(512,512,NOIR),image2(512,512,NOIR);
point point2(150,150,VERT);
facette carre1(point2,200);
carre1.rotateFacette(45);
carre1.afficherPleinNew(image);
image.write("carre_pleinTest.bmp");
*/
/*
string nomImage("img_"),extensionImage(".bmp"),finalImage;
for(int i(0); i<361 ; i++)
{
Bmp image(512,512,NOIR);
point secondPoint(150,150,VERT);
facette carre2(secondPoint,200);
carre2.rotateFacette(i);
string iString = to_string(i);
finalImage=nomImage+iString+extensionImage;
cout << endl << finalImage << " :" << endl;
carre2.afficherPleinNew(image);
int n (finalImage.length());
char char_array[n + 1];
strcpy(char_array, finalImage.c_str());
image.write(char_array);
}
*/

121
tp2/point.cpp Normal file
View file

@ -0,0 +1,121 @@
#include "point.h"
point :: point(void):m_x(0),m_y(0),m_couleur(ROUGE)
{}
point :: point(SHORT x, SHORT y, ULONG couleur) :m_x(x),m_y(y),m_couleur(couleur)
{}
point :: point(point& copiePoint) :m_x(copiePoint.getCoordX()),m_y(copiePoint.getCoordY()),m_couleur(copiePoint.getColor())
{}
SHORT point :: getCoordX(void)
{
return m_x;
}
SHORT point :: getCoordY(void)
{
return m_y;
}
ULONG point :: getColor(void)
{
return m_couleur;
}
void point :: geoTranslation(SHORT x)
{
x=m_x+x;
if(x >= 0)
{
m_x=x;
}
else
{
cout << "geoTranslation : valeur retournee negative" << endl;
};
}
void point :: geoTranslation(SHORT x, SHORT y)
{
x=m_x+x;
y=m_y+y;
if((x >= 0) && (y >= 0))
{
m_x=x;
m_y=y;
}
else
{
cout << "geoTranslation : valeur retournee negative" << endl;
};
}
void point :: geoHomothetie(point& centre, float k)
{
SHORT x=k*(m_x-centre.getCoordX());
SHORT y=k*(m_y-centre.getCoordY());
if((x >= 0) && (y >= 0))
{
m_x=x;
m_y=y;
}
else
{
cout << "geoHomothetie : valeur retournee negative" << endl;
};
}
void point :: geoRotation(point& centre, double degree)
{
double rad = degree*(PI/180);
SHORT x = ((m_x-centre.getCoordX()) * cos(rad)) + ((centre.getCoordY()-m_y) * sin(rad)) + centre.getCoordX();
SHORT y = ((m_y-centre.getCoordY()) * cos(rad)) + ((m_x-centre.getCoordX()) * sin(rad)) + centre.getCoordY();
if((x >= 0) && (y >= 0))
{
m_x=x;
m_y=y;
}
else
{
cout << "geoRotation : valeur retournee negative" << endl;
};
}
void point :: geoRotation(point& centre, double degree, bool isTrig)
{
if(isTrig==true)
{
degree = -degree;
}
double rad = degree*(PI/180);
SHORT x = ((m_x-centre.getCoordX()) * cos(rad)) + ((centre.getCoordY()-m_y) * sin(rad)) + centre.getCoordX();
SHORT y = ((m_y-centre.getCoordY()) * cos(rad)) + ((m_x-centre.getCoordX()) * sin(rad)) + centre.getCoordY();
if((x >= 0) && (y >= 0))
{
m_x=x;
m_y=y;
}
else
{
cout << "geoRotation : valeur retournee negative" << endl;
};
}
void point :: afficher(Bmp& imageTemp)
{
imageTemp.setpixel(m_x,m_y,m_couleur);
}
void point :: redefine(short x, short y, ULONG color)
{
m_x=x;
m_y=y;
m_couleur=color;
}
bool point::operator!=(const point& b) const
{
return ((b.m_x != m_x) || (b.m_y != m_y) || (b.m_couleur != m_couleur));
}

35
tp2/point.h Normal file
View file

@ -0,0 +1,35 @@
#ifndef POINT_H_INCLUDED
#define POINT_H_INCLUDED
#include "bmp.h"
#include <cstring>
#define PI 3.1415926535897932384626
class point
{
private:
SHORT m_x;
SHORT m_y;
ULONG m_couleur;
public:
point(void);
point(SHORT x, SHORT y, ULONG couleur);
point(point& copiePoint);
void geoTranslation(SHORT x);
void geoTranslation(SHORT x, SHORT y);
void geoHomothetie(point& centre, float k);
void geoRotation(point& centre, double degree);
void geoRotation(point& centre, double degree, bool isTrig);
void afficher(Bmp& imageTemp);
SHORT getCoordX(void);
SHORT getCoordY(void);
ULONG getColor(void);
point getPoint(void);
void redefine(short x, short y, ULONG color);
bool operator!=(const point& b) const;
};
#endif // POINT_H_INCLUDED

43
tp2/segment.cpp Normal file
View file

@ -0,0 +1,43 @@
#include "segment.h"
segment :: segment(void):m_pointA(0,0,VERT),m_pointB(0,0,VERT)
{}
segment :: segment(point paramA, point paramB):m_pointA(paramA),m_pointB(paramB)
{}
segment :: segment(segment& copie)
{
m_pointA = copie.getPointA();
m_pointB = copie.getPointB();
}
point segment :: getPointA(void)
{
return m_pointA;
}
point segment :: getPointB(void)
{
return m_pointB;
}
void segment :: rotateSegment(double rotation)
{
m_pointA.geoRotation(m_pointB,rotation);
}
void segment :: homothetieSegment(float k)
{
m_pointA.geoHomothetie(m_pointB,k);
}
void segment :: translationSegment(SHORT x, SHORT y)
{
m_pointA.geoTranslation(x,y);
}
void segment :: afficher(Bmp& imageTemp)
{
imageTemp.line(m_pointA.getCoordX(),m_pointA.getCoordY(),m_pointB.getCoordX(),m_pointB.getCoordY(),m_pointA.getColor());
}

25
tp2/segment.h Normal file
View file

@ -0,0 +1,25 @@
#ifndef SEGMENT_H_INCLUDED
#define SEGMENT_H_INCLUDED
#include "point.h"
class segment{
private :
point m_pointA;
point m_pointB;
public :
segment(void);
segment(point paramA, point paramB);
segment(segment& copie);
point getPointA(void);
point getPointB(void);
void rotateSegment(double rotation);
void homothetieSegment(float k);
void translationSegment(SHORT x, SHORT y);
void afficher(Bmp& imageTemp);
};
#endif // SEGMENT_H_INCLUDED

50
tp2/tp2_exo1.cbp Normal file
View file

@ -0,0 +1,50 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
<FileVersion major="1" minor="6" />
<Project>
<Option title="tp2_exo1" />
<Option pch_mode="2" />
<Option compiler="gcc" />
<Build>
<Target title="Debug">
<Option output="bin/Debug/tp2_exo1" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Debug/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-g" />
</Compiler>
</Target>
<Target title="Release">
<Option output="bin/Release/tp2_exo1" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Release/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-O2" />
</Compiler>
<Linker>
<Add option="-s" />
</Linker>
</Target>
</Build>
<Compiler>
<Add option="-Wall" />
<Add option="-fexceptions" />
</Compiler>
<Unit filename="bmp.cpp" />
<Unit filename="bmp.h" />
<Unit filename="cercle.cpp" />
<Unit filename="cercle.h" />
<Unit filename="facette.cpp" />
<Unit filename="facette.h" />
<Unit filename="main.cpp" />
<Unit filename="point.cpp" />
<Unit filename="point.h" />
<Unit filename="segment.cpp" />
<Unit filename="segment.h" />
<Extensions>
<lib_finder disable_auto="1" />
</Extensions>
</Project>
</CodeBlocks_project_file>