-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.cpp
More file actions
140 lines (108 loc) · 2.81 KB
/
Copy pathtest.cpp
File metadata and controls
140 lines (108 loc) · 2.81 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
#ifdef __APPLE__
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <sys/time.h>
#include <glm/glm.hpp>
//#include "terrain.h"
#include "rover.h"
//globals
static int g_Width = 600;
static int g_Height = 600;
static GLfloat g_nearPlane = 1;
static GLfloat g_farPlane = 1000;
int attribute_position, attribute_vertex;
float angle = 0.0;
float lx = 0.0, lz = -1.0;
float x = 100.0, z = 105.0;
//keyboard
void processNormalKeys(unsigned char key, int x, int y)
{
if (key == 27)
exit(0);
}
void processSpecialKeys(int key, int xx, int yy)
{
float fraction = 0.5;
switch (key)
{
case GLUT_KEY_LEFT:
angle -= 0.01;
lx = sin(angle);
lz = -cos(angle);
break;
case GLUT_KEY_RIGHT:
angle += 0.01f;
lx = sin(angle);
lz = -cos(angle);
break;
case GLUT_KEY_UP:
x += lx * fraction;
z += lz * fraction;
break;
case GLUT_KEY_DOWN:
x -= lx * fraction;
z -= lz * fraction;
break;
}
}
void renderScene()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
gluLookAt
(
x, 400.0, z,
x + lx, 1.0, z + lz,
0.0, 1.0, 0.0
);
/* //Draw Ground *later going to be terrain*
glBegin(GL_QUADS);
glVertex3f(-100.0, 0.0, -100);
glVertex3f(-100.0, 0.0, 100);
glVertex3f(100.0, 0.0, -100);
glVertex3f(100.0, 0.0, -100);
glEnd();
terrainLoadFromImage("heightmap.tga", 1);
terrainScale(-10, 30);
int myDisplayList = terrainCreateDL(0, 0, 0);
glCallList(myDisplayList);*/
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, roverPositions);
glDrawArrays(GL_TRIANGLES, 0, roverVertices);
glDisableClientState(GL_VERTEX_ARRAY);
glutSwapBuffers();
}
void changesize(GLint w, GLint h)
{
g_Width = w;
g_Height = h;
float ratio = 1.0 * w / h;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glViewport(0, 0, w, h);
gluPerspective(65, ratio, g_nearPlane, g_farPlane);
glMatrixMode(GL_MODELVIEW);
}
int main(int argc, char **argv)
{
//init GLUT and create window
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA);
glutInitWindowPosition(1, 1);
glutInitWindowSize(g_Width, g_Height);
glutCreateWindow("Simulation");
//register callbacks
glutDisplayFunc(renderScene);
glutReshapeFunc(changesize);
glutIdleFunc(renderScene);
glutKeyboardFunc(processNormalKeys);
glutSpecialFunc(processSpecialKeys);
//enter GLUT event processing cycle
glutMainLoop();
return 1;
}