summaryrefslogtreecommitdiffstats
path: root/level.c
diff options
context:
space:
mode:
authorneoraider <devnull@localhost>2006-10-20 14:57:05 +0200
committerneoraider <devnull@localhost>2006-10-20 14:57:05 +0200
commit79801b6b794a5fb50a3a013354323a48de37c050 (patch)
tree3e97322cb1ea3aa6206b6f420a9c67ceca3d9c81 /level.c
parent05f9b1d15c237e89176cc2b207454f0f30073d57 (diff)
downloadlibzoom-79801b6b794a5fb50a3a013354323a48de37c050.tar
libzoom-79801b6b794a5fb50a3a013354323a48de37c050.zip
Physik-Engine angefangen.
Lightmaps implementiert.
Diffstat (limited to 'level.c')
-rw-r--r--level.c192
1 files changed, 92 insertions, 100 deletions
diff --git a/level.c b/level.c
index ccee0bc..f8c1fda 100644
--- a/level.c
+++ b/level.c
@@ -1,14 +1,17 @@
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include <GL/gl.h>
+#include <neofx/math.h>
#include <zoom/types.h>
-#include <zoom/level.h>
#include <zoom/texture.h>
-#include <neofx/math.h>
+#include <zoom/level.h>
+
extern GLuint sphere;
extern GLuint meditex_blue;
extern float objrot;
+extern LIGHT light;
int LoadLevel(char *filename, LEVEL *level) {
FILE *file;
@@ -39,9 +42,9 @@ int LoadLevel(char *filename, LEVEL *level) {
level->rooms[i].walls = malloc(roomheader.nWalls * sizeof(WALL));
fread(level->rooms[i].walls, sizeof(WALL), roomheader.nWalls, file);
- level->rooms[i].nObjects = roomheader.nObjects;
- level->rooms[i].objects = malloc(roomheader.nObjects * sizeof(OBJECT));
- fread(level->rooms[i].objects, sizeof(OBJECT), roomheader.nObjects, file);
+ level->rooms[i].nThings = roomheader.nThings;
+ level->rooms[i].things = malloc(roomheader.nThings * sizeof(THING));
+ fread(level->rooms[i].things, sizeof(THING), roomheader.nThings, file);
level->rooms[i].nGates = roomheader.nGates;
level->rooms[i].gates = malloc(roomheader.nGates * sizeof(GATE));
@@ -65,40 +68,29 @@ int LoadLevel(char *filename, LEVEL *level) {
return 1;
}
-void DrawRoom(LEVEL *level, int room) {
+void DrawRoom(LEVEL *level, int nr) {
int i;
int r, g;
GLfloat std_emission[] = {0.0, 0.0, 0.0, 1.0};
GLfloat medipak100_emission[] = {1.0, 0.0, 0.0, 1.0};
+ ROOM room = level->rooms[nr];
WALL t1, t2;
VERTEX p1, p2;
- VECTOR v1, v2;
+ VECTOR v1, v2, n, v;
+ float s, t, d;
MATRIX transform;
- for(i = 0; i < level->rooms[room].nWalls; i++) {
- glBindTexture(GL_TEXTURE_2D, level->textures[level->rooms[room].walls[i].texture]);
-
- glBegin(GL_TRIANGLES);
-
- glNormal3fv((GLfloat*)&level->rooms[room].walls[i].normal);
- glTexCoord2fv((GLfloat*)&level->rooms[room].walls[i].texcoords[0]);
- glVertex3fv((GLfloat*)&level->rooms[room].walls[i].vertices[0]);
- glTexCoord2fv((GLfloat*)&level->rooms[room].walls[i].texcoords[1]);
- glVertex3fv((GLfloat*)&level->rooms[room].walls[i].vertices[1]);
- glTexCoord2fv((GLfloat*)&level->rooms[room].walls[i].texcoords[2]);
- glVertex3fv((GLfloat*)&level->rooms[room].walls[i].vertices[2]);
-
- glEnd();
- }
+ for(i = 0; i < room.nWalls; i++)
+ RenderWall(room.walls[i], level->textures);
- for(i = 0; i < level->rooms[room].nObjects; i++) {
- if(!level->rooms[room].objects[i].visible) continue;
- switch(level->rooms[room].objects[i].type) {
- case OBJECT_MEDIPAK100:
+ for(i = 0; i < room.nThings; i++) {
+ if(!room.things[i].visible) continue;
+ switch(room.things[i].type) {
+ case THING_MEDIPAK100:
glPushMatrix();
- glBindTexture(GL_TEXTURE_2D, meditex_blue);
+ //glBindTexture(GL_TEXTURE_2D, meditex_blue);
glMaterialfv(GL_FRONT, GL_EMISSION, medipak100_emission);
- glTranslatef(level->rooms[room].objects[i].pos.x, level->rooms[room].objects[i].pos.y, level->rooms[room].objects[i].pos.z);
+ glTranslatef(room.things[i].pos.x, room.things[i].pos.y, room.things[i].pos.z);
glRotatef(objrot*10, 0.0, 1.0, 0.0);
glScalef(0.3, 0.3, 0.3);
glCallList(sphere);
@@ -107,58 +99,58 @@ void DrawRoom(LEVEL *level, int room) {
}
}
- for(i = 0; i < level->rooms[room].nGates; i++) {
- if(level->rooms[room].gateinfo[i].state == STATE_CLOSED) {
- glBindTexture(GL_TEXTURE_2D, level->textures[level->rooms[room].gates[i].walls[0].texture]);
+ for(i = 0; i < room.nGates; i++) {
+ if(room.gateinfo[i].state == STATE_CLOSED) {
+ //glBindTexture(GL_TEXTURE_2D, level->textures[room.gates[i].walls[0].texture]);
glBegin(GL_TRIANGLES);
- glNormal3fv((GLfloat*)&level->rooms[room].gates[i].walls[0].normal);
- glTexCoord2fv((GLfloat*)&level->rooms[room].gates[i].walls[0].texcoords[0]);
- glVertex3fv((GLfloat*)&level->rooms[room].gates[i].walls[0].vertices[0]);
- glTexCoord2fv((GLfloat*)&level->rooms[room].gates[i].walls[0].texcoords[1]);
- glVertex3fv((GLfloat*)&level->rooms[room].gates[i].walls[0].vertices[1]);
- glTexCoord2fv((GLfloat*)&level->rooms[room].gates[i].walls[0].texcoords[2]);
- glVertex3fv((GLfloat*)&level->rooms[room].gates[i].walls[0].vertices[2]);
+ glNormal3fv((GLfloat*)&room.gates[i].walls[0].normal);
+ glTexCoord2fv((GLfloat*)&room.gates[i].walls[0].texcoords[0]);
+ glVertex3fv((GLfloat*)&room.gates[i].walls[0].vertices[0]);
+ glTexCoord2fv((GLfloat*)&room.gates[i].walls[0].texcoords[1]);
+ glVertex3fv((GLfloat*)&room.gates[i].walls[0].vertices[1]);
+ glTexCoord2fv((GLfloat*)&room.gates[i].walls[0].texcoords[2]);
+ glVertex3fv((GLfloat*)&room.gates[i].walls[0].vertices[2]);
glEnd();
- glBindTexture(GL_TEXTURE_2D, level->textures[level->rooms[room].gates[i].walls[0].texture]);
+ //glBindTexture(GL_TEXTURE_2D, level->textures[room.gates[i].walls[0].texture]);
glBegin(GL_TRIANGLES);
- glNormal3fv((GLfloat*)&level->rooms[room].gates[i].walls[1].normal);
- glTexCoord2fv((GLfloat*)&level->rooms[room].gates[i].walls[1].texcoords[0]);
- glVertex3fv((GLfloat*)&level->rooms[room].gates[i].walls[1].vertices[0]);
- glTexCoord2fv((GLfloat*)&level->rooms[room].gates[i].walls[1].texcoords[1]);
- glVertex3fv((GLfloat*)&level->rooms[room].gates[i].walls[1].vertices[1]);
- glTexCoord2fv((GLfloat*)&level->rooms[room].gates[i].walls[1].texcoords[2]);
- glVertex3fv((GLfloat*)&level->rooms[room].gates[i].walls[1].vertices[2]);
+ glNormal3fv((GLfloat*)&room.gates[i].walls[1].normal);
+ glTexCoord2fv((GLfloat*)&room.gates[i].walls[1].texcoords[0]);
+ glVertex3fv((GLfloat*)&room.gates[i].walls[1].vertices[0]);
+ glTexCoord2fv((GLfloat*)&room.gates[i].walls[1].texcoords[1]);
+ glVertex3fv((GLfloat*)&room.gates[i].walls[1].vertices[1]);
+ glTexCoord2fv((GLfloat*)&room.gates[i].walls[1].texcoords[2]);
+ glVertex3fv((GLfloat*)&room.gates[i].walls[1].vertices[2]);
glEnd();
}
- else if(level->rooms[room].gateinfo[i].state == STATE_OPENING) {
- t1 = level->rooms[room].gates[i].walls[0];
- t2 = level->rooms[room].gates[i].walls[1];
+ else if(room.gateinfo[i].state == STATE_OPENING) {
+ t1 = room.gates[i].walls[0];
+ t2 = room.gates[i].walls[1];
- t1.vertices[2] = VectorAdd(VectorMul(t1.vertices[2], level->rooms[room].gateinfo[i].timer/1000.0),
- VectorMul(t1.vertices[1], 1 - (level->rooms[room].gateinfo[i].timer/1000.0)));
+ t1.vertices[2] = VectorAdd(VectorMul(t1.vertices[2], room.gateinfo[i].timer/1000.0),
+ VectorMul(t1.vertices[1], 1 - (room.gateinfo[i].timer/1000.0)));
t2.vertices[1] = t1.vertices[2];
- t2.vertices[2] = VectorAdd(VectorMul(t2.vertices[2], level->rooms[room].gateinfo[i].timer/1000.0),
- VectorMul(t2.vertices[0], 1 - (level->rooms[room].gateinfo[i].timer/1000.0)));
-
-
- t1.texcoords[0].s = t1.texcoords[0].s * level->rooms[room].gateinfo[i].timer/1000.0
- + t2.texcoords[2].s * (1 - level->rooms[room].gateinfo[i].timer/1000.0);
- t1.texcoords[0].t = t1.texcoords[0].t * level->rooms[room].gateinfo[i].timer/1000.0
- + t2.texcoords[2].t * (1 - level->rooms[room].gateinfo[i].timer/1000.0);
- t1.texcoords[1].s = t1.texcoords[1].s * level->rooms[room].gateinfo[i].timer/1000.0
- + t1.texcoords[2].s * (1 - level->rooms[room].gateinfo[i].timer/1000.0);
- t1.texcoords[1].t = t1.texcoords[1].t * level->rooms[room].gateinfo[i].timer/1000.0
- + t1.texcoords[2].t * (1 - level->rooms[room].gateinfo[i].timer/1000.0);
+ t2.vertices[2] = VectorAdd(VectorMul(t2.vertices[2], room.gateinfo[i].timer/1000.0),
+ VectorMul(t2.vertices[0], 1 - (room.gateinfo[i].timer/1000.0)));
+
+
+ t1.texcoords[0].s = t1.texcoords[0].s * room.gateinfo[i].timer/1000.0
+ + t2.texcoords[2].s * (1 - room.gateinfo[i].timer/1000.0);
+ t1.texcoords[0].t = t1.texcoords[0].t * room.gateinfo[i].timer/1000.0
+ + t2.texcoords[2].t * (1 - room.gateinfo[i].timer/1000.0);
+ t1.texcoords[1].s = t1.texcoords[1].s * room.gateinfo[i].timer/1000.0
+ + t1.texcoords[2].s * (1 - room.gateinfo[i].timer/1000.0);
+ t1.texcoords[1].t = t1.texcoords[1].t * room.gateinfo[i].timer/1000.0
+ + t1.texcoords[2].t * (1 - room.gateinfo[i].timer/1000.0);
t2.texcoords[0] = t1.texcoords[0];
- glBindTexture(GL_TEXTURE_2D, level->textures[t1.texture]);
+ //glBindTexture(GL_TEXTURE_2D, level->textures[t1.texture]);
glBegin(GL_TRIANGLES);
@@ -172,7 +164,7 @@ void DrawRoom(LEVEL *level, int room) {
glEnd();
- glBindTexture(GL_TEXTURE_2D, level->textures[t2.texture]);
+ //glBindTexture(GL_TEXTURE_2D, level->textures[t2.texture]);
glBegin(GL_TRIANGLES);
@@ -186,12 +178,12 @@ void DrawRoom(LEVEL *level, int room) {
glEnd();
- r = level->rooms[room].gates[i].room;
- g = level->rooms[room].gates[i].gate;
+ r = room.gates[i].room;
+ g = room.gates[i].gate;
- t1 = level->rooms[room].gates[i].walls[0];
- t2 = level->rooms[room].gates[i].walls[1];
- p1 = level->rooms[room].gates[i].point;
+ t1 = room.gates[i].walls[0];
+ t2 = room.gates[i].walls[1];
+ p1 = room.gates[i].point;
v1 = t1.normal;
t1 = level->rooms[r].gates[g].walls[0];
@@ -205,28 +197,28 @@ void DrawRoom(LEVEL *level, int room) {
DrawRoom(level, r);
glPopMatrix();
}
- else if(level->rooms[room].gateinfo[i].state == STATE_CLOSING) {
- t1 = level->rooms[room].gates[i].walls[0];
- t2 = level->rooms[room].gates[i].walls[1];
+ else if(room.gateinfo[i].state == STATE_CLOSING) {
+ t1 = room.gates[i].walls[0];
+ t2 = room.gates[i].walls[1];
- t1.vertices[2] = VectorAdd(VectorMul(t1.vertices[2], 1 - (level->rooms[room].gateinfo[i].timer/1000.0)),
- VectorMul(t1.vertices[1], level->rooms[room].gateinfo[i].timer/1000.0));
+ t1.vertices[2] = VectorAdd(VectorMul(t1.vertices[2], 1 - (room.gateinfo[i].timer/1000.0)),
+ VectorMul(t1.vertices[1], room.gateinfo[i].timer/1000.0));
t2.vertices[1] = t1.vertices[2];
- t2.vertices[2] = VectorAdd(VectorMul(t2.vertices[2], 1 - (level->rooms[room].gateinfo[i].timer/1000.0)),
- VectorMul(t2.vertices[0], level->rooms[room].gateinfo[i].timer/1000.0));
-
-
- t1.texcoords[0].s = t1.texcoords[0].s * (1 - level->rooms[room].gateinfo[i].timer/1000.0)
- + t2.texcoords[2].s * level->rooms[room].gateinfo[i].timer/1000.0;
- t1.texcoords[0].t = t1.texcoords[0].t * (1 - level->rooms[room].gateinfo[i].timer/1000.0)
- + t2.texcoords[2].t * level->rooms[room].gateinfo[i].timer/1000.0;
- t1.texcoords[1].s = t1.texcoords[1].s * (1 - level->rooms[room].gateinfo[i].timer/1000.0)
- + t1.texcoords[2].s * level->rooms[room].gateinfo[i].timer/1000.0;
- t1.texcoords[1].t = t1.texcoords[1].t * (1 - level->rooms[room].gateinfo[i].timer/1000.0)
- + t1.texcoords[2].t * level->rooms[room].gateinfo[i].timer/1000.0;
+ t2.vertices[2] = VectorAdd(VectorMul(t2.vertices[2], 1 - (room.gateinfo[i].timer/1000.0)),
+ VectorMul(t2.vertices[0], room.gateinfo[i].timer/1000.0));
+
+
+ t1.texcoords[0].s = t1.texcoords[0].s * (1 - room.gateinfo[i].timer/1000.0)
+ + t2.texcoords[2].s * room.gateinfo[i].timer/1000.0;
+ t1.texcoords[0].t = t1.texcoords[0].t * (1 - room.gateinfo[i].timer/1000.0)
+ + t2.texcoords[2].t * room.gateinfo[i].timer/1000.0;
+ t1.texcoords[1].s = t1.texcoords[1].s * (1 - room.gateinfo[i].timer/1000.0)
+ + t1.texcoords[2].s * room.gateinfo[i].timer/1000.0;
+ t1.texcoords[1].t = t1.texcoords[1].t * (1 - room.gateinfo[i].timer/1000.0)
+ + t1.texcoords[2].t * room.gateinfo[i].timer/1000.0;
t2.texcoords[0] = t1.texcoords[0];
- glBindTexture(GL_TEXTURE_2D, level->textures[t1.texture]);
+ //glBindTexture(GL_TEXTURE_2D, level->textures[t1.texture]);
glBegin(GL_TRIANGLES);
@@ -240,7 +232,7 @@ void DrawRoom(LEVEL *level, int room) {
glEnd();
- glBindTexture(GL_TEXTURE_2D, level->textures[t2.texture]);
+ //glBindTexture(GL_TEXTURE_2D, level->textures[t2.texture]);
glBegin(GL_TRIANGLES);
@@ -254,12 +246,12 @@ void DrawRoom(LEVEL *level, int room) {
glEnd();
- r = level->rooms[room].gates[i].room;
- g = level->rooms[room].gates[i].gate;
+ r = room.gates[i].room;
+ g = room.gates[i].gate;
- t1 = level->rooms[room].gates[i].walls[0];
- t2 = level->rooms[room].gates[i].walls[1];
- p1 = level->rooms[room].gates[i].point;
+ t1 = room.gates[i].walls[0];
+ t2 = room.gates[i].walls[1];
+ p1 = room.gates[i].point;
v1 = t1.normal;
t1 = level->rooms[r].gates[g].walls[0];
@@ -274,12 +266,12 @@ void DrawRoom(LEVEL *level, int room) {
glPopMatrix();
}
else {
- r = level->rooms[room].gates[i].room;
- g = level->rooms[room].gates[i].gate;
+ r = room.gates[i].room;
+ g = room.gates[i].gate;
- t1 = level->rooms[room].gates[i].walls[0];
- t2 = level->rooms[room].gates[i].walls[1];
- p1 = level->rooms[room].gates[i].point;
+ t1 = room.gates[i].walls[0];
+ t2 = room.gates[i].walls[1];
+ p1 = room.gates[i].point;
v1 = t1.normal;
t1 = level->rooms[r].gates[g].walls[0];
@@ -302,7 +294,7 @@ void FreeLevel(LEVEL *level) {
if(level->nRooms) {
for(i = 0; i < level->nRooms; i++) {
if(level->rooms[i].nWalls) free(level->rooms[i].walls);
- if(level->rooms[i].nObjects) free(level->rooms[i].objects);
+ if(level->rooms[i].nThings) free(level->rooms[i].things);
if(level->rooms[i].nGates) free(level->rooms[i].gates);
}
free(level->rooms);