-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathecran.cpp
More file actions
56 lines (41 loc) · 1.35 KB
/
Copy pathecran.cpp
File metadata and controls
56 lines (41 loc) · 1.35 KB
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
#include <iostream>
#include <ostream>
#include "point.hpp"
#include "scene.hpp"
#include "ecran.hpp"
using namespace std;
void Ecran::afficher(std::ostream &flux) const
{
flux << "Ecran: \n" << "posTL :"<< topLeft << " posTR :" <<
topRight << "posBL" << bottomLeft << "resolution : " << resolution << "\n\n" << std::endl;
}
Ecran::Ecran(){
}
Ecran::Ecran(const int res, const Point tl, const Point tr, const Point bl){
resolution = res;
topLeft = tl;
topRight = tr;
bottomLeft = bl;
// Calcul de la résolution verticale :
resolutionVerticale = (topLeft.getY() - bottomLeft.getY())*(res/(topRight.getX() - topLeft.getX()));
//creation dynamique d'un tableau 2D
pixels = new Couleur*[resolutionVerticale];
for(unsigned int i = 0; i < resolutionVerticale; ++i) pixels[i] = new Couleur[resolution];
}
void Ecran::deleteE(){
for(unsigned int i = 0; i < resolutionVerticale; ++i) delete[] pixels[i];
delete[] pixels;
}
Point Ecran::getPixel(const unsigned int i)
{
if(i>resolution*resolutionVerticale-1)
{
cout << "ce pixel n'existe pas" << endl;
}
float ligne = i/resolution;
float colonne = i%resolution;
Point vectUnitaireHorizontal = (topRight - topLeft)/resolution;
Point vectUnitaireVertical = (bottomLeft - topLeft)/resolutionVerticale;
Point p(topLeft + vectUnitaireVertical*ligne + vectUnitaireHorizontal*colonne);
return p;
}