-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcircle.cpp
149 lines (128 loc) · 3.28 KB
/
circle.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#include "circle.h"
#include <math.h>
#include <stdio.h>
#include <ctime>
#define PI 3.1415926535897932384626433832795
Circle::Circle(){};
Circle::Circle(float cx,float cy,float radius, float color[3]){
this->cx = cx;
this->cy = cy;
this->color[0] = color[0];
this->color[1] = color[1];
this->color[2] = color[2];
this->radius1 = radius;
this->radius2 = radius;
}
Circle::Circle(float cx,float cy,float radius1, float radius2, float color[3]){
this->cx = cx;
this->cy = cy;
this->color[0] = color[0];
this->color[1] = color[1];
this->color[2] = color[2];
this->radius1 = radius1;
this->radius2 = radius2;
}
void Circle::setRadius(float radius){
this->radius1 = radius1;
}
void Circle::setColors(float* colors){
this->color[0] = colors[0];
this->color[1] = colors[1];
this->color[2] = colors[2];
printf("%.2f,%.2f,%.2f\n",colors[0],colors[1],colors[2]);
}
void Circle::drawCircle(int type){
//All triangles fan out starting with this point
if(type){
glColor3d(this->color[0],this->color[1],this->color[2]);
glBegin(GL_TRIANGLE_FAN);
}
else{
glColor3d(0,0,0);
glLineWidth(3);
glBegin(GL_LINE_LOOP);
}
//glVertex3f(cx/600,cy/600,0.0);
//printf("centro: (%f,%f)\n",cx,cy);
int nSides = 100;
float x,y;
int nVertex = nSides + 2;
for (int i = 0; i < nVertex; i++ )
{
x = radius1*cos(i*2.0*PI/nSides);
y = radius2*sin(i*2.0*PI/nSides);
glVertex3f(x,y,0.0);
}
glEnd();
}
void Circle::draw(int type){
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glTranslatef(cx,1000-cy,0);
drawCircle(type);
glPopMatrix();
/*
//All triangles fan out starting with this point
glMatrixMode(GL_MODELVIEW);
glColor3d(this->color[0],this->color[1],this->color[2]);
glPushMatrix();
//cy = 1000-cy;
glTranslatef(cx,1000-cy,0);
glBegin(GL_POLYGON);
//glVertex3f(cx/600,cy/600,0.0);
//printf("centro: (%f,%f)\n",cx,cy);
int nSides = 100;
float x,y;
int nVertex = nSides + 2;
for (int i = 0; i < nVertex; i++ )
{
x = radius*cos(i*2.0*PI/nSides);
y = radius*sin(i*2.0*PI/nSides);
//y = 1000-y;
glVertex3f(x,y,0.0);
}
//printf("cx = %f, cy = %f\n",cx,1000-cy);
glEnd();
glPopMatrix();
//glFlush();
*/
}
void Circle::setc(float x, float y) {
this->cx = x;
this->cy = y;
}
float Circle::getRadius(){
return (this->radius1);
}
float Circle::getcX() {
return this->cx;
}
float Circle::getcY() {
return this->cy;
}
void Circle::moveX(float ds){
this->cx += ds;
}
void Circle::moveY(float ds){
this->cy += ds;
}
void Circle::jump(){
this->radius1 += 0.2;
}
int Circle::colisao(Circle* cir){
float dist = sqrt(pow(this->cx-cir->cx,2)+pow(this->cy-cir->cy,2));
printf("pow(this->cx-cir->cx,2) = %f\n",pow(this->cx-cir->cx,2));
if(pow(dist,2)<pow(this->radius1+cir->radius1,2)){
return 1;
}
else{
//printf("%f\n",pow(dist,2)<pow(this->radius+cir->radius,2));
return 0;
}
}
int Circle::inside(Circle* cir){
float dist = sqrt(pow(this->cx-cir->cx,2)+pow(this->cy-cir->cy,2));
if(dist<cir->radius1-this->radius1)
return 1;
return 0;
}