-
Notifications
You must be signed in to change notification settings - Fork 83
/
OpenGL-Free-Fall-Animation.cpp
71 lines (60 loc) · 1.17 KB
/
OpenGL-Free-Fall-Animation.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
#include <iostream>
#include <cmath>
#include <gl/glut.h>
void init() {
glClearColor(1.0, 1.0, 1.0, 0.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glPointSize(4.0);
glColor3f(0.0f, 0.0f, 0.0f);
gluOrtho2D(0.0, 640.0, 0.0, 480.0);
}
typedef struct {
double x;
double y;
} Point;
Point p1 = {320.0, 480.0};
Point p2 = {340.0, 480.0};
double time1 = 0.0;
double time2 = 0.0;
void calc() {
time1 += 0.1;
time2 += 0.1;
p1.y = (-0.5*9.8)*(time1*time1)+0+480;
p2.y = (-0.5*1.6)*(time2*time2)+0+480;
if(p1.y < 0.0) {
p1.y = 480;
time1 = 0;
}
if(p2.y < 0.0) {
p2.y = 480;
time2 = 0;
}
}
void display() {
calc();
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_POINTS);
glColor3f(0.0f, 0.0f, 1.0f);
glVertex2d(p1.x, p1.y);
glColor3f(0.0f, 1.0f, 0.0f);
glVertex2d(p2.x, p2.y);
glEnd();
glFlush();
}
void Timer(int value) {
glutTimerFunc(1000 / 60, Timer, value);
glutPostRedisplay();
}
int main(int argc, char** argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowPosition(200, 200);
glutInitWindowSize(640, 480);
glutCreateWindow("OpenGL");
init();
Timer(0);
glutDisplayFunc(display);
glutMainLoop();
return 0;
}