forked from carboned4/CeGue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRoadside.h
128 lines (110 loc) · 3.62 KB
/
Roadside.h
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
#ifndef ROADSIDE_H
#define ROADSIDE_H
#include "glut.h"
#include "SOIL.h"
#include "StaticObject.h"
class Roadside : public StaticObject {
public:
Roadside() :StaticObject(Box(-6.0,6.0,-0.5,0.2)){}
~Roadside(){}
int answerToColision(){ return 4; } // 4 = ground
int loadSelfTexture(){
textureID = SOIL_load_OGL_texture(
"Roadside.jpg",
SOIL_LOAD_AUTO,
SOIL_CREATE_NEW_ID,
SOIL_FLAG_MIPMAPS | SOIL_FLAG_INVERT_Y | SOIL_FLAG_NTSC_SAFE_RGB | SOIL_FLAG_COMPRESS_TO_DXT
);
if (0 == textureID)
{
printf("SOIL loading error: '%s'\n", SOIL_last_result());
}
printf("Texture loaded - Roadside\n");
return 1;
}
void draw(){
Vector3 vector = getPosition();
GLfloat mat_specular[] = { 0.0, 0.01, 0.0, 1.0 };
GLfloat mat_ambient[] = { 0.2, 0.5, 0.0, 1.0 };
GLfloat mat_diffuse[] = { 0.2, 0.5, 0.0, 1.0 };
GLfloat shininess = 10;
glPushMatrix();
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
glMaterialf(GL_FRONT, GL_SHININESS, shininess);
glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_ambient);
glTranslatef(vector.getX(), vector.getY(), vector.getZ());
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, textureID);
double tile_width = 0.25;
for (double y = -0.5 + tile_width / 2.0; y <= 0.5 - tile_width / 2.0; y += tile_width){
for (double x = -5.5 + tile_width / 2.0; x <= 5.5 - tile_width / 2.0; x += tile_width){
glPushMatrix();
glTranslatef(x, y, 0.0);
glColor3f(0.0, 0.5, 0.0);
glBegin(GL_QUADS);
glNormal3f(0.0, 0.0, 1.0);
glTexCoord2f(0.1, 0.1);
glVertex3f(-tile_width / 2.0, -tile_width / 2.0, 0.5);
glNormal3f(0.0, 0.0, 1.0);
glTexCoord2f(0.9, 0.1);
glVertex3f(tile_width / 2.0, -tile_width / 2.0, 0.5);
glNormal3f(0.0, 0.0, 1.0);
glTexCoord2f(0.9, 0.9);
glVertex3f(tile_width / 2.0, tile_width / 2.0, 0.5);
glNormal3f(0.0, 0.0, 1.0);
glTexCoord2f(0.1, 0.9);
glVertex3f(-tile_width / 2.0, tile_width / 2.0, 0.5);
glEnd();
glPopMatrix();
}
}
for (double z = -0.5 + tile_width / 2.0; z <= 0.5 - tile_width / 2.0; z += tile_width){
for (double x = -5.5 + tile_width/ 2.0; x <= 5.5 - tile_width / 2.0; x += tile_width){
glPushMatrix();
glTranslatef(x, 0.0, z);
glColor3f(0.0, 0.5, 0.0);
glBegin(GL_QUADS);
glNormal3f(0.0, -1.0, 1.0);
glTexCoord2f(0.1, 0.1);
glVertex3f(-tile_width / 2.0, -0.5, -tile_width / 2.0);
glNormal3f(0.0, -1.0, 1.0);
glTexCoord2f(0.9, 0.1);
glVertex3f(tile_width / 2.0, -0.5, -tile_width / 2.0);
glNormal3f(0.0, -1.0, 1.0);
glTexCoord2f(0.9, 0.9);
glVertex3f(tile_width / 2.0, -0.5, tile_width / 2.0);
glNormal3f(0.0, -1.0, 1.0);
glTexCoord2f(0.1, 0.9);
glVertex3f(-tile_width / 2.0, -0.5, tile_width / 2.0);
glEnd();
glPopMatrix();
}
}
for (double z = -0.5 + tile_width / 2.0; z <= 0.5 - tile_width / 2.0; z += tile_width){
for (double x = -5.5 + tile_width / 2.0; x <= 5.5 - tile_width / 2.0; x += tile_width){
glPushMatrix();
glTranslatef(x, 0.0, z);
glColor3f(0.0, 0.5, 0.0);
glBegin(GL_QUADS);
glNormal3f(0.0, 1.0, 1.0);
glTexCoord2f(0.1, 0.1);
glVertex3f(tile_width / 2.0, 0.5, -tile_width / 2.0);
glNormal3f(0.0, 1.0, 1.0);
glTexCoord2f(0.9, 0.1);
glVertex3f(-tile_width / 2.0, 0.5, -tile_width / 2.0);
glNormal3f(0.0, 1.0, 1.0);
glTexCoord2f(0.9, 0.9);
glVertex3f(-tile_width / 2.0, 0.5, tile_width / 2.0);
glNormal3f(0.0, 1.0, 1.0);
glTexCoord2f(0.1, 0.9);
glVertex3f(tile_width / 2.0, 0.5, tile_width / 2.0);
glEnd();
glPopMatrix();
}
}
glDisable(GL_TEXTURE_2D);
glPopMatrix();
}
};
#endif