-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshapes.cpp
75 lines (71 loc) · 1.74 KB
/
shapes.cpp
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
#include <GL/glut.h>
#include <GL/glu.h>
#include<windows.h>
#include<math.h>
#include"shapes.h"
#define SETCOLOR(color) color.getRed(), color.getGreen(), color.getBlue()
#define PI 3.1415926535
void Shapes::rect(Color color)
{
glPushMatrix();
glColor3f(SETCOLOR(color));
glBegin(GL_POLYGON);
glVertex3f(0,0,-5.0);
glVertex3f(1,0,-5.0);
glVertex3f(1,1,-5.0);
glVertex3f(0,1,-5.0);
glEnd();
glPopMatrix();
}
void Shapes::rect(float x, float y, float w, float h,Color color)
{
glPushMatrix();
glColor3f(SETCOLOR(color));
glBegin(GL_POLYGON);
glVertex3f(x,y,-5.0);
glVertex3f(x+w,y,-5.0);
glVertex3f(x+w,x+h,-5.0);
glVertex3f(x,y+h,-5.0);
glEnd();
glPopMatrix();
}
void Shapes::circle(Color color)
{
glPushMatrix();
glColor3f(SETCOLOR(color));
glBegin(GL_POLYGON);
for(double i =0 ; i<2*PI;i+=PI/24)
glVertex3f(cos(i)*1,sin(i)*1,-5.0);
glEnd();
glPopMatrix();
}
void Shapes::triangle(Color color)
{
glPushMatrix();
glColor3f(SETCOLOR(color));
glBegin(GL_POLYGON);
glVertex3f(-1,0,-5.0);
glVertex3f(1,0,-5.0);
glVertex3f(.02,1,-5.0);
glVertex3f(0,1,-5.0);
glEnd();
glPopMatrix();
}
void Shapes::octagon(Color color)
{
float angle = 0.0;
float dAngle = PI/4.0;
float x,y;
glPushMatrix();
glColor3f(SETCOLOR(color));
glBegin(GL_POLYGON);
for(int i=0;i<8;i++)
{
double theta = i*2.0*PI/8.0;
x =cos(theta);
y = sin(theta);
glVertex3f(x,y,-5.0);
}
glEnd();
glPopMatrix();
}