-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathellipse_02.cpp
More file actions
255 lines (220 loc) · 5.74 KB
/
ellipse_02.cpp
File metadata and controls
255 lines (220 loc) · 5.74 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
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
/*
* GLUT Shapes Demo
*
* Written by Nigel Stewart November 2003
*
* This program is test harness for the sphere, cone
* and torus shapes in GLUT.
*
* Spinning wireframe and smooth shaded shapes are
* displayed until the ESC or q key is pressed. The
* number of geometry stacks and slices can be adjusted
* using the + and - keys.
*/
#ifdef __APPLE__
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include<bits/stdc++.h>
using namespace std;
vector<int>vec;
static int slices = 16;
static int stacks = 16;
int x00 = 0, y00 = 0, flagup = 0, flying = 1, addy1 = 7, a = 80, b = 80,time1=0,time2=0,gtime=0,u=2, v=100, xmin = -320,ymin = -240,xmax = 319 ,ymax = 239, flag = 0, yprev = 0;
/* GLUT callback Handlers */
static void resize(int width, int height){
const float ar = (float) width / (float) height;
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-320, 319, -240, 239, -1, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity() ;
}
void mouse(int button, int state, int mousex, int mousey)
{
if(button==GLUT_LEFT_BUTTON && state==GLUT_DOWN)
{
int mx = mousex;
int my = mousey;
printf(" c1 %d %d\n",mx-320,-my+240);
glutPostRedisplay();
flag++;
if (flag == 1) {
x00 = mx-320;
y00 = -my+240;
if(y00 + b <= ymax)
ymax = y00 + b;
printf("%d %d %d\n",x00,y00,ymax);
}
}
// if (flag == 2)
// {
// findzone(0,0,50,-10);
// }
}
void draw4way(int xc, int yc, int x, int y){
glVertex2i(xc+x, yc+y);
glVertex2i(xc+x, yc-y);
glVertex2i(xc-x, yc+y);
glVertex2i(xc-x, yc-y);
}
void drawEllipseOb(int xc, int yc, int a, int b){
int x=0, y=b, d=(4*b*b)-(4*a*a*b)+(a*a);
draw4way(xc,yc,x,y);
while(a*a*(2*y - 1) > 2*b*b*(x+1)){
if(d<0){ //dE
x++;
d += 4*b*b*((2*x) + 3);
}
else{ // dSE
x++,y--;
d += 4*(b*b*((2*x)+3) + (a*a*(2-(2*y))));
}
draw4way(xc,yc,x,y);
}
while(y>0){
if(d<0){ //dSE
x++,y--;
d += 4*(b*b*((2*x)+2) + (a*a*(3-(2*y))));
}
else{
y--;
d += 4*a*a*(3 -(2*y));
}
draw4way(xc,yc,x,y);
}
}
static void display(void){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColor3d(1,1,1);
glBegin(GL_LINES);
glVertex2i(-320, 0);
glVertex2i(319, 0);
glVertex2i(0, -240);
glVertex2i(0, 239);
glEnd();
glBegin(GL_POINTS);
if(flag){
if(flying){
if(!flagup){
y00 = (ymax - b) - ((u*gtime*gtime)/20);
gtime++;
vec.push_back(y00);
}
else{
y00 = vec.back() + 5;
printf("%d\n",y00);
vec.pop_back();
// y00 = -160 + ((u*gtime*gtime)/200);
// gtime--;
}
//gtime ++;
//printf("gtime %d\n",gtime);
}
drawEllipseOb(x00,y00,a,b);
if(y00 + b > ymax){
// flying = 0;
// if(time1<20){
// addy1 = 241 - y00 - b + round(0.1*b);
// b -= round(0.1*b);
// time1 ++;
// // if(time1 == 19)
// // b=80,addy1 = -10,time1=0;
// }
// else if(time2<20){
// addy1 = 241 - y00 - round(b/0.9);
// b = round(b/0.9);
// time2 ++;
// if(time2==20)
// time1 = 0, time2 = 0, b = 80, flying = 1, flagup = 0, gtime = 1;
// }
time1 = 0, time2 = 0, b = 80, flying = 1, flagup = 0, gtime = 0;
//y00 += addy1 ;
// flagdown = 0;
// addy1 = -10;
}
else if(y00 - b < ymin){
//printf("%d\n", gtime);
flying = 0;
//printf(" %d %d %d %d\n", y00,time1,time2,b);
if(time1<10){
//addy1 = -241 - y00 + b - 8;
if(time1 == 0)
yprev = y00;
y00 -= 8;
b -= 8;
time1 ++;
// if(y00<ymin){
// y00 = ymin - 1, time1 = 10;
// printf("1 %d %d %d %d\n",y00,time1,time2,b);
// }
// if(time1 == 19)
// b=80,addy1 = -10,time1=0;
}
else if(y00<=yprev){
//addy1 = -241 - y00 + b + 8;
y00 += 8;
b += 8;
time2 ++;
if(b>80)
b = 80;
if(y00>yprev){
time1 = 0, time2 = 0, b = 80, flying = 1, flagup = 1,gtime=0;
//printf("1\n");
}
//printf("%d\n",y00);
// if(time2==11)
// time1 = 0, time2 = 0, b = 80, flying = 1, flagup = 1, gtime = 0;
}
//y00 += addy1 ;
}
}
glEnd();
glutSwapBuffers();
}
static void key(unsigned char key, int x, int y)
{
switch (key)
{
case 27 :
case 'q':
exit(0);
break;
case '+':
slices++;
stacks++;
break;
case '-':
if (slices>3 && stacks>3)
{
slices--;
stacks--;
}
break;
}
glutPostRedisplay();
}
static void idle(void)
{
glutPostRedisplay();
}
/* Program entry point */
int main(int argc, char *argv[]){
glutInit(&argc, argv);
glutInitWindowSize(640,480);
glutInitWindowPosition(10,10);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("Experiment 01");
glutReshapeFunc(resize);
glutDisplayFunc(display);
glutKeyboardFunc(key);
glutIdleFunc(idle);
glutMouseFunc(mouse);
glutMainLoop();
return EXIT_SUCCESS;
}