301 lines
12 KiB
C++
301 lines
12 KiB
C++
#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);*/
|