-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpolygon_manager.h
More file actions
91 lines (73 loc) · 1.84 KB
/
polygon_manager.h
File metadata and controls
91 lines (73 loc) · 1.84 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
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
#ifndef POLYGON_MANAGER_H_
#define POLYGON_MANAGER_H_
#include <string>
#include <vector>
#include <iostream>
#include "point.h"
#include "color.h"
#include "config.h"
#include "polygon.h"
#include "clipping_window.h"
using namespace std;
class PolygonManager {
public:
PolygonManager() {
create_new_poly = true;
}
void add_point( int x, int y ) {
if ( create_new_poly ) {
if ( polygons.size() >= MAX_POLYGONS ) {
cerr << "Max number of polygons added (" << MAX_POLYGONS << ")"
<< endl;
return;
}
create_new_poly = false;
Polygon p;
polygons.push_back( p );
}
polygons.back().add_point( x, y );
}
void add_final_point( int x, int y ) {
if ( polygons.back().size() < 2 ) {
cerr << "Polygon requires at least three points "
<< "to be considered a polygon!" << endl;
return;
}
if ( create_new_poly ) {
cerr << "Right-click already pressed. Left click "
<< "to add a new polygon." << endl;
return;
}
create_new_poly = true;
polygons.back().add_final_point( x, y );
}
void draw_verticies( float (&framebuffer)[HEIGHT][WIDTH][3] ) {
for ( int i = 0; i < polygons.size(); ++i ) {
polygons[i].draw_verticies( framebuffer );
}
}
void draw_fill( float (&framebuffer)[HEIGHT][WIDTH][3],
ClippingWindow &cw ) {
// fill the buffer
for ( int y = 0; y < HEIGHT; ++y ) {
for ( int i = 0; i < polygons.size(); ++i ) {
polygons[i].draw_fill( y, framebuffer, cw );
}
}
// cleanup any leftover elements in the edge list
for ( int i = 0; i < polygons.size(); ++i ) {
polygons[i].clear_active_edge_list();
}
}
friend ostream& operator<<( ostream& os, const PolygonManager& pm ) {
os << "Polygons:" << endl;
for ( auto &polygon : pm.polygons ) {
os << "=> " << polygon << endl;
}
return os;
}
private:
bool create_new_poly;
vector<Polygon> polygons;
};
#endif