salut salut salut la communauté developpez.com

j'ai une petite questions pour les programmeurs que vous êtes. J'ai une matrice et je voudrais pouvoir la faire tourner (rotationner ).
Seulement, quand l'image (que représente la matrice) tourne, l'image se déforme . Peut-être que vous réussirez à m'aider.
Voilà le code de ma fonction rotation (qui se trouve en faite dans un fichier qui est destiné à être généré en .dll) :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
void Image::Rotation(int angle)
{
	//les variables suivantes contiennent la largeur et la hauteur de la matrice
	int w,h;
	//je test si l'angle passé en parametre vaut 270
	if(angle==270)
	{
		// j'associe les valeurs des champs "height" et "width" (de la classe Image) aux variables w et h
		w=height;
		h=width;
		//je crée un vector 2D nommee mat qui aura h comme hauteur et des vector de largeur w en ligne)
		vector<vector<Pixel>> mat(h, vector<Pixel> (w));
		for (int i=0 ; i<h; i++)
		{
			for (int j=0 ; j<w; j++)
			{
				int ii=j;
				int jj=w-1-i;
				mat[i][j].setColor('R',matriceImg[ii][jj].getColor('R'));
				mat[i][j].setColor('V',matriceImg[ii][jj].getColor('V'));
				mat[i][j].setColor('B',matriceImg[ii][jj].getColor('B'));
			}
		}
		//mon image devient l'image resultant de la rotation
		matriceImg=mat;
	}
	else if(angle==180)
	{
		w=width;
		h=height;
		vector<vector<Pixel>> mat(h, vector<Pixel> (w));
		for (int i=0 ; i<h; i++)
		{
			for (int j=0 ; j<w; j++)
			{
				int ii=h-1-i;
				int jj=w-1-j;
				mat[i][j].setColor('R',matriceImg[ii][jj].getColor('R'));
				mat[i][j].setColor('V',matriceImg[ii][jj].getColor('V'));
				mat[i][j].setColor('B',matriceImg[ii][jj].getColor('B'));
			}
		}
		matriceImg=mat;
	}
	else if(angle==90)
	{
		w=height;
		h=width;
		vector<vector<Pixel>> mat(h, vector<Pixel> (w));
		for (int i=0 ; i<h; i++)
		{
			for (int j=0 ; j<w; j++)
			{
				int ii=h-1-j;
				int jj=i;
				mat[i][j].setColor('R',matriceImg[ii][jj].getColor('R'));
				mat[i][j].setColor('V',matriceImg[ii][jj].getColor('V'));
				mat[i][j].setColor('B',matriceImg[ii][jj].getColor('B'));
			}
		}
		matriceImg=mat;
	}
	//dans le cas d'un angle quelconque
	else
	{
		w=height;
		h=width;
		vector<vector<Pixel>> mat(h, vector<Pixel> (w));
 
		// Coordonnées pour le centre de rotation
		int icentre=h/2;
		int jcentre=w/2;
 
		for (int i=0 ; i<h; i++)
		{
			for (int j=0 ; j<w; j++)
			{
				int ii=((i-icentre)*cos(angle*PI/180))-((j-jcentre)*sin(angle*PI/180))+icentre;
				int jj=((i-icentre)*cos(angle*PI/180))+((j-jcentre)*sin(angle*PI/180))+jcentre;
				if(ii>=0 && ii<h && jj>=0 && jj<w) // Controler que les coordonnées ne sont pas en dehors de la matrice
				{
					mat[i][j].setColor('R',matriceImg[ii][jj].getColor('R'));
					mat[i][j].setColor('V',matriceImg[ii][jj].getColor('V'));
					mat[i][j].setColor('B',matriceImg[ii][jj].getColor('B'));
				}
				else
				{
					mat[i][j].setColor(255);
				}
			}
		}
		matriceImg=mat;
	}
 
	width=w;
	height=h;
}
merci d'avance