Criada classe Mapa; scrolling
[Projeto-PCG.git] / geometry.cpp
blob589e9a52309108e2959caa7b853c17f1326102a0
1 #include "geometry.h"
2 #include "math.h"
3 #include <vector>
5 const double PI = 3.14159265358979323846;
7 Linha::Linha(double x1,double y1,double x2, double y2) {
8 vertices[0].x = x1;
9 vertices[0].y = y1;
10 vertices[1].x = x2;
11 vertices[1].y = y2;
14 Rect::Rect(double x1,double y1,double x2, double y2) {
15 vertices[0].x = x1;
16 vertices[0].y = y1;
17 vertices[1].x = x2;
18 vertices[1].y = y2;
19 normaliza();
22 void Rect::normaliza() {
23 double xmin,xmax,ymin,ymax;
24 xmin = std::min(vertices[0].x,vertices[1].x);
25 xmax = std::max(vertices[0].x,vertices[1].x);
26 ymin = std::min(vertices[0].y,vertices[1].y);
27 ymax = std::max(vertices[0].y,vertices[1].y);
28 vertices[0].x = xmin;
29 vertices[1].x = xmax;
30 vertices[0].y = ymin;
31 vertices[1].y = ymax;
34 void Linha::desenha() {
35 glColor3f(0,0,0);
36 glBegin(GL_LINES);
37 glVertex3f(vertices[0].x, vertices[0].y, 0.0f); // origin of the line
38 glVertex3f(vertices[1].x, vertices[1].y, 0.0f); // origin of the line
39 glEnd( );
42 void drawCircle(double radius, int lines)
44 double i2rad = PI/(lines/2.0);
45 glBegin(GL_LINE_LOOP);
46 for (int i=0; i < lines; i++) {
47 double degInRad = i*i2rad;
48 glVertex2f(cos(degInRad)*radius,sin(degInRad)*radius);
51 glEnd();