-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest.cpp
More file actions
82 lines (65 loc) · 1.69 KB
/
Copy pathtest.cpp
File metadata and controls
82 lines (65 loc) · 1.69 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
#include <iostream>
#include <stdlib.h>
#include <math.h>
#include <GL/gl.h>
#include <GL/glut.h>
//Initializes 3D rendering
void initRendering() {
glEnable(GL_DEPTH_TEST);
}
//Called when the window is resized
void handleResize(int w, int h) {
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0, (double)w / (double)h, 1.0, 200.0);
}
float _angle = 0.0;
float _cameraAngle = 0.0;
float _ang_tri = 0.0;
float car_move = 0.0;
float _move_o1 = 0.0;
//Draws the 3D scene
void drawScene() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW); //Switch to the drawing perspective
glLoadIdentity(); //Reset the drawing perspective
//glRotatef(-4.5, 1.0, 1.0, 0.0); //Rotate the camera
glTranslatef(0.0, 0.0, -7.0); //Move forward 5 units
glPushMatrix();
glColor3f(1.0, 0.0, 0.0);
glTranslatef(_move_o1, 0.0, 0.0);
glRotatef(-90, 1.0, 0.0, 0.0);
glRotatef(_angle, 0.0, 0.0, 1.0);
glutWireTorus(0.2, 0.3, 20, 20);
glPopMatrix();
glutSwapBuffers();
}
void update(int value) {
_angle += 2.0f;
if (_angle > 360) {
_angle -= 360;
}
_move_o1 += 0.04f;
if(_move_o1 > 5.0){
_move_o1 = -3.2;
}
glutPostRedisplay();
glutTimerFunc(20, update, 0);
}
int main(int argc, char** argv) {
//Initialize GLUT
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(800, 800);
glutInitWindowPosition(200,100);
//Create the window
glutCreateWindow("Cone");
initRendering();
//Set handler functions
glutDisplayFunc(drawScene);
glutReshapeFunc(handleResize);
glutTimerFunc(10, update, 0); //Add a timer
glutMainLoop();
return 0;
}