-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathWall.cpp
More file actions
200 lines (172 loc) · 4.87 KB
/
Wall.cpp
File metadata and controls
200 lines (172 loc) · 4.87 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
#include "Wall.h"
#include <cstdlib>
#include <math.h>
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
#include <stdio.h>
#include "strstream"
using std::strstreambuf;
using std::istrstream;
using std::ostrstream;
using std::strstream;
using std::fstream;
#define ESC 27
#define M_PI 3.1415926
using namespace std;
Wall::Wall(GLfloat xPos,GLfloat yPos,GLfloat zPos, char* type)
{
this->x=xPos;
this->y=yPos;
this->z=zPos;
this->height = 0.5f;
this->length = 1.0f;
this->width = 0.2f;
// cout<<xPos<<":"<<yPos<<":"<<zPos<<":"<<endl;
//ctor
this->type = type;
this->loadTexture();
}
Wall::~Wall()
{
//dtor
}
char* Wall::getType()
{
return this->type;
}
void Wall::drawCube()
{
GLfloat ambient[] = { 0.1, 0.1, 0.1, 1.0 };
GLfloat diffuse[] = { 0.0, 1.0, 1.0, 1.0 };
GLfloat specular[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat shininess[] = { 1.0 };
glMaterialfv(GL_FRONT, GL_AMBIENT, ambient);
glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuse);
glMaterialfv(GL_FRONT, GL_SPECULAR, specular);
glMaterialfv(GL_FRONT, GL_SHININESS, shininess);
glEnable( GL_TEXTURE_2D );
glBindTexture(GL_TEXTURE_2D, this->texture);
glBegin(GL_QUADS);
// Front Face
glNormal3f(0.0,0.0,1.0);
glTexCoord2f(0.0f, 0.0f);
glVertex3f(-1.00f, -1.00f, 1.00f);
glTexCoord2f(1.0f, 0.0f);
glVertex3f( 1.00f, -1.00f, 1.00f);
glTexCoord2f(1.0f, 1.0f);
glVertex3f(1.00f, 1.00f, 1.00f);
glTexCoord2f(0.0f, 1.0f);
glVertex3f(-1.00f, 1.00f, 1.00f);
// Back Face
glNormal3f(0.0,0.0,-1.0);
glTexCoord2f(1.0f, 0.0f);
glVertex3f(-1.00f, -1.00f, -1.00f);
glTexCoord2f(1.0f, 1.0f);
glVertex3f(-1.00f, 1.00f, -1.00f);
glTexCoord2f(0.0f, 1.0f);
glVertex3f( 1.00f, 1.00f, -1.00f);
glTexCoord2f(0.0f, 0.0f);
glVertex3f( 1.00f, -1.00f, -1.00f);
// Top Face
glNormal3f(0.0,1.0,0.0);
glTexCoord2f(0.0f, 0.0f);
glVertex3f(-1.00f, 1.00f, -1.00f);
glTexCoord2f(0.0f, 1.0f);
glVertex3f(-1.00f, 1.00f, 1.00f);
glTexCoord2f(1.0f, 1.0f);
glVertex3f( 1.00f, 1.00f, 1.00f);
glTexCoord2f(1.0f, 0.0f);
glVertex3f( 1.00f, 1.00f, -1.00f);
// Right face
glNormal3f(1.0,0.0,0.0);
glTexCoord2f(1.0f, 0.0f);
glVertex3f( 1.00f, -1.00f, -1.00f);
glTexCoord2f(1.0f, 1.0f);
glVertex3f( 1.00f, 1.00f, -1.00f);
glTexCoord2f(0.0f, 1.0f);
glVertex3f( 1.00f, 1.00f, 1.00f);
glTexCoord2f(0.0f, 0.0f);
glVertex3f( 1.00f, -1.00f, 1.00f);
// Left Face
glNormal3f(-1.0,0.0,0.0);
glTexCoord2f(0.0f, 0.0f);
glVertex3f(-1.00f, -1.00f, -1.00f);
glTexCoord2f(1.0f, 0.0f);
glVertex3f(-1.00f, -1.00f, 1.00f);
glTexCoord2f(1.0f, 1.0f);
glVertex3f(-1.00f, 1.00f, 1.00f);
glTexCoord2f(0.0f, 1.0f);
glVertex3f(-1.00f, 1.00f, -1.00f);
glEnd();
}
void Wall::draw()
{
glPushMatrix();
this->move();
glBindTexture(GL_TEXTURE_2D, this->texture);
if (this->type[0] == '1')
{
//East wall, relative to tile
//x+2<--->z+2
glPushMatrix();
glTranslatef(2.0,0.0,1.0);
glScalef(this->width,this->height,this->length); //Scale the cube
this->drawCube();
glPopMatrix();
}
if (this->type[1] == '1')
{
//North wall, relative to tile
//x<--->y
glPushMatrix();
glTranslatef(1.0,0.0,0.0);
glScalef(this->length,this->height,this->width); //Scale the cube
this->drawCube();
glPopMatrix();
}
if (this->type[2] == '1')
{
//West wall, relative to tile
//x<--->z
glPushMatrix();
glTranslatef(0.0,0.0,1.0);
glScalef(this->width,this->height,this->length);//Scale the cube
this->drawCube();
glPopMatrix();
}
if (this->type[3] == '1')
{
//South wall, relative to tile
//x+2.0<--->y+2.0
glPushMatrix();
glTranslatef(1.0f, 0.0f, 2.0f);
glScalef(this->length,this->height,this->width);//Scale the cube
this->drawCube();
glPopMatrix();
}
glPopMatrix();
}
int Wall::loadTexture()
{
// Load Bitmaps And Convert To Texture
texture = SOIL_load_OGL_texture
(
//"/home/angela/Documents/Comp371Project/data/metalwall.bmp",
"data/metalwall.bmp",
SOIL_LOAD_AUTO,
SOIL_CREATE_NEW_ID,
SOIL_FLAG_INVERT_Y
);
if(texture == 0)
{
printf( "SOIL loading error: '%s'\n", SOIL_last_result());
return false;
}
// Typical Texture Generation Using Data From The Bitmap
glBindTexture(GL_TEXTURE_2D, texture);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
return true; // Return Success
}