2005-04-18 15:27:00 +00:00
|
|
|
#include <GL/gl.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include <zoom/render.h>
|
|
|
|
#include <zoom/player.h>
|
|
|
|
#include <zoom/level.h>
|
2006-10-20 12:57:05 +00:00
|
|
|
#include <zoom/texture.h>
|
2005-04-22 19:51:02 +00:00
|
|
|
#include <neofx/math.h>
|
2005-04-18 15:27:00 +00:00
|
|
|
|
|
|
|
extern PLAYER player;
|
|
|
|
extern LEVEL level;
|
|
|
|
extern GLuint sphere;
|
2006-10-20 12:57:05 +00:00
|
|
|
extern LIGHT light;
|
|
|
|
|
|
|
|
void RenderWall(WALL w, GLuint *textures) {
|
|
|
|
int i;
|
|
|
|
float d, s, t;
|
|
|
|
VECTOR v, v1, v2;
|
|
|
|
VERTEX p;
|
|
|
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D, textures[w.texture]);
|
|
|
|
|
|
|
|
d = VectorDot(w.normal, VectorSub(w.vertices[0], light.pos));
|
|
|
|
|
|
|
|
if(d >= 0) {
|
|
|
|
glActiveTexture(GL_TEXTURE0);
|
|
|
|
glDisable(GL_TEXTURE_2D);
|
|
|
|
|
|
|
|
glBegin(GL_TRIANGLES);
|
|
|
|
|
|
|
|
for(i = 0; i < 3; i++) {
|
|
|
|
glMultiTexCoord2fv(GL_TEXTURE1, (GLfloat*)&w.texcoords[i]);
|
|
|
|
glVertex3fv((GLfloat*)&w.vertices[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
glEnd();
|
|
|
|
|
|
|
|
glEnable(GL_TEXTURE_2D);
|
|
|
|
glActiveTexture(GL_TEXTURE1);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
p = VectorAdd(light.pos, VectorMul(w.normal, d));
|
|
|
|
|
|
|
|
v1 = VectorNormalize(VectorSub(w.vertices[0], w.vertices[1]));
|
|
|
|
v2 = VectorCross(v1, w.normal);
|
|
|
|
|
|
|
|
glBegin(GL_TRIANGLES);
|
|
|
|
|
|
|
|
glNormal3fv((GLfloat*)&w.normal);
|
|
|
|
|
|
|
|
for(i = 0; i < 3; i++) {
|
|
|
|
v = VectorSub(w.vertices[i], p);
|
|
|
|
s = VectorDot(v, v1)*0.005 / d + 0.5;
|
|
|
|
t = VectorDot(v, v2)*0.005 / d + 0.5;
|
|
|
|
glMultiTexCoord2f(GL_TEXTURE0, s, t);
|
|
|
|
glMultiTexCoord2fv(GL_TEXTURE1, (GLfloat*)&w.texcoords[i]);
|
|
|
|
glVertex3fv((GLfloat*)&w.vertices[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
glEnd();
|
|
|
|
}
|
2005-04-18 15:27:00 +00:00
|
|
|
|
|
|
|
void Render() {
|
2006-10-20 12:57:05 +00:00
|
|
|
//GLfloat light_position[] = { 0.0, 0.0, 0.0, 1.0 };
|
|
|
|
//GLfloat light_emission[] = {1.0, 1.0, 1.0, 1.0};
|
2005-04-18 15:27:00 +00:00
|
|
|
GLfloat std_emission[] = {0.0, 0.0, 0.0, 1.0};
|
|
|
|
MATRIX rotate = {
|
|
|
|
player.rotycos, 0.0, -player.rotysin, 0.0,
|
|
|
|
0.0, 1.0, 0.0, 0.0,
|
|
|
|
player.rotysin, 0.0, player.rotycos, 0.0,
|
|
|
|
0.0, 0.0, 0.0, 1.0
|
|
|
|
};
|
2006-10-20 12:57:05 +00:00
|
|
|
COLOR color_light = {1.0, 1.0, 1.0};
|
|
|
|
COLOR color_ambient = {0.1, 0.1, 0.1};
|
2005-04-18 15:27:00 +00:00
|
|
|
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
|
|
|
glLoadIdentity();
|
|
|
|
|
|
|
|
glRotatef(player.rotx, 1.0, 0.0, 0.0);
|
|
|
|
glMultMatrixf(rotate.f);
|
|
|
|
|
|
|
|
|
|
|
|
glTranslatef(-player.pos.x, -player.pos.y, -player.pos.z);
|
|
|
|
|
2006-10-20 12:57:05 +00:00
|
|
|
//glLightfv(GL_LIGHT0, GL_POSITION, light_position);
|
2005-04-18 15:27:00 +00:00
|
|
|
glPushMatrix();
|
|
|
|
glDisable(GL_TEXTURE_2D);
|
2006-10-20 12:57:05 +00:00
|
|
|
glColor3fv((GLfloat*)&color_light);
|
|
|
|
//glMaterialfv(GL_FRONT, GL_EMISSION, light_emission);
|
|
|
|
glTranslatef(light.pos.x, light.pos.y, light.pos.z);
|
2005-04-18 15:27:00 +00:00
|
|
|
glScalef(0.1, 0.1, 0.1);
|
|
|
|
glCallList(sphere);
|
2006-10-20 12:57:05 +00:00
|
|
|
//glMaterialfv(GL_FRONT, GL_EMISSION, std_emission);
|
2005-04-18 15:27:00 +00:00
|
|
|
glEnable(GL_TEXTURE_2D);
|
|
|
|
glPopMatrix();
|
|
|
|
|
2006-10-20 12:57:05 +00:00
|
|
|
glColor3fv((GLfloat*)&color_ambient);
|
|
|
|
|
2005-04-18 15:27:00 +00:00
|
|
|
DrawRoom(&level, player.room);
|
|
|
|
|
|
|
|
glFlush();
|
|
|
|
}
|