-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPolygon.cpp
More file actions
executable file
·95 lines (83 loc) · 2.56 KB
/
Polygon.cpp
File metadata and controls
executable file
·95 lines (83 loc) · 2.56 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
92
93
94
95
//
// Polygon.cpp
// Prog01Version1
//
//
// Hope for being able to do different polygons.
//
// Created by Michael Sayers on 9/22/2023
// Modified from Class Code Examples from CS406 Jean-Yves Hervé
//
#include <cmath>
#include <vector>
#include <utility>
#include <iostream>
#include "glPlatform.h"
#include "Polygon.h"
using namespace std;
using namespace earshooter;
//Basic sequence of vertices to create a polygon.
Polygon::Polygon(float centerX, float centerY, float angle, float scaleX, float scaleY,std::vector<std::pair<float,float>> vertexVector,
float red, float green, float blue)
: GraphicObject(centerX, centerY, angle),
Object(centerX,centerY,angle),
_scaleX(scaleX),
_scaleY(scaleY),
_vertexVector(vertexVector),
_red(red),
_green(green),
_blue(blue)
{
}
//Implementiation of different shapes like lines.
// Polygon::Polygon(float centerX, float centerY, float angle, float scaleX, float scaleY,std::vector<std::pair<float,float>> vertexVector,
// float red, float green, float blue, int type, float thickness)
// : GraphicObject(centerX, centerY, angle),
// _red(red),
// _green(green),
// _blue(blue),
// _vertexVector(vertexVector),
// _type(type),
// _thickness(thickness),
// _modification(sqrt(pow(thickness,2)/2))
// {
// }
Polygon::~Polygon()
{
}
void Polygon::draw() const
{
// save the current coordinate system (origin, axes, scale)
glPushMatrix();
// move to the center of the disk
glTranslatef(getX(), getY(), 0.f);
// apply rotation
glRotatef(getAngle(), 0.f, 0.f, 1.f);
// apply the scale
// glScalef(getScaleX(), getScaleY(), 1.f);
glScalef(_scaleX, _scaleY, 1.f);
glColor3f(_red, _green, _blue);
glBegin(GL_POLYGON);
for (int k=0; k<_vertexVector.size(); k++)
glVertex2f(_vertexVector[k].first,
_vertexVector[k].second);
glEnd();
// restore the original coordinate system (origin, axes, scale)
glPopMatrix();
}
// Next thing to work on expanding a line to a polygon.
// void Polygon::coordinateDraw() const
// {
// for (int j=0; j<((_vertexVector.size())-1); j++) {
// //Math to consider the four corners of the box.
// std::vector<std::pair<float,float>> tempVector;
// tempVector.push_back({_vertexVector[j].first-_})
// glBegin(GL_POLYGON);
// for (int k=0; k<4; k++)
// glVertex2f(tempVector[k].first,
// tempVector[k].second);
// glEnd();
// };
// // restore the original coordinate system (origin, axes, scale)
// glPopMatrix();
// }