summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--level.c92
-rw-r--r--player.c28
-rw-r--r--zoom/level.h6
-rw-r--r--zoom/types.h16
4 files changed, 78 insertions, 64 deletions
diff --git a/level.c b/level.c
index d884341..ccee0bc 100644
--- a/level.c
+++ b/level.c
@@ -35,9 +35,9 @@ int LoadLevel(char *filename, LEVEL *level) {
for(i = 0; i < levelheader.nRooms; i++) {
fread(&roomheader, sizeof(ROOMHEADER), 1, file);
- level->rooms[i].nTriangles = roomheader.nTriangles;
- level->rooms[i].triangles = malloc(roomheader.nTriangles * sizeof(TRIANGLE));
- fread(level->rooms[i].triangles, sizeof(TRIANGLE), roomheader.nTriangles, file);
+ level->rooms[i].nWalls = roomheader.nWalls;
+ 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));
@@ -70,23 +70,23 @@ void DrawRoom(LEVEL *level, int room) {
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};
- TRIANGLE t1, t2;
+ WALL t1, t2;
VERTEX p1, p2;
VECTOR v1, v2;
MATRIX transform;
- for(i = 0; i < level->rooms[room].nTriangles; i++) {
- glBindTexture(GL_TEXTURE_2D, level->textures[level->rooms[room].triangles[i].texture]);
+ 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].triangles[i].normal);
- glTexCoord2fv((GLfloat*)&level->rooms[room].triangles[i].texcoords[0]);
- glVertex3fv((GLfloat*)&level->rooms[room].triangles[i].vertices[0]);
- glTexCoord2fv((GLfloat*)&level->rooms[room].triangles[i].texcoords[1]);
- glVertex3fv((GLfloat*)&level->rooms[room].triangles[i].vertices[1]);
- glTexCoord2fv((GLfloat*)&level->rooms[room].triangles[i].texcoords[2]);
- glVertex3fv((GLfloat*)&level->rooms[room].triangles[i].vertices[2]);
+ 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();
}
@@ -109,37 +109,37 @@ 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].triangles[0].texture]);
+ glBindTexture(GL_TEXTURE_2D, level->textures[level->rooms[room].gates[i].walls[0].texture]);
glBegin(GL_TRIANGLES);
- glNormal3fv((GLfloat*)&level->rooms[room].gates[i].triangles[0].normal);
- glTexCoord2fv((GLfloat*)&level->rooms[room].gates[i].triangles[0].texcoords[0]);
- glVertex3fv((GLfloat*)&level->rooms[room].gates[i].triangles[0].vertices[0]);
- glTexCoord2fv((GLfloat*)&level->rooms[room].gates[i].triangles[0].texcoords[1]);
- glVertex3fv((GLfloat*)&level->rooms[room].gates[i].triangles[0].vertices[1]);
- glTexCoord2fv((GLfloat*)&level->rooms[room].gates[i].triangles[0].texcoords[2]);
- glVertex3fv((GLfloat*)&level->rooms[room].gates[i].triangles[0].vertices[2]);
+ 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]);
glEnd();
- glBindTexture(GL_TEXTURE_2D, level->textures[level->rooms[room].gates[i].triangles[0].texture]);
+ glBindTexture(GL_TEXTURE_2D, level->textures[level->rooms[room].gates[i].walls[0].texture]);
glBegin(GL_TRIANGLES);
- glNormal3fv((GLfloat*)&level->rooms[room].gates[i].triangles[1].normal);
- glTexCoord2fv((GLfloat*)&level->rooms[room].gates[i].triangles[1].texcoords[0]);
- glVertex3fv((GLfloat*)&level->rooms[room].gates[i].triangles[1].vertices[0]);
- glTexCoord2fv((GLfloat*)&level->rooms[room].gates[i].triangles[1].texcoords[1]);
- glVertex3fv((GLfloat*)&level->rooms[room].gates[i].triangles[1].vertices[1]);
- glTexCoord2fv((GLfloat*)&level->rooms[room].gates[i].triangles[1].texcoords[2]);
- glVertex3fv((GLfloat*)&level->rooms[room].gates[i].triangles[1].vertices[2]);
+ 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]);
glEnd();
}
else if(level->rooms[room].gateinfo[i].state == STATE_OPENING) {
- t1 = level->rooms[room].gates[i].triangles[0];
- t2 = level->rooms[room].gates[i].triangles[1];
+ t1 = level->rooms[room].gates[i].walls[0];
+ t2 = level->rooms[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)));
@@ -189,13 +189,13 @@ void DrawRoom(LEVEL *level, int room) {
r = level->rooms[room].gates[i].room;
g = level->rooms[room].gates[i].gate;
- t1 = level->rooms[room].gates[i].triangles[0];
- t2 = level->rooms[room].gates[i].triangles[1];
+ t1 = level->rooms[room].gates[i].walls[0];
+ t2 = level->rooms[room].gates[i].walls[1];
p1 = level->rooms[room].gates[i].point;
v1 = t1.normal;
- t1 = level->rooms[r].gates[g].triangles[0];
- t2 = level->rooms[r].gates[g].triangles[1];
+ t1 = level->rooms[r].gates[g].walls[0];
+ t2 = level->rooms[r].gates[g].walls[1];
p2 = level->rooms[r].gates[g].point;
v2 = VectorNeg(t1.normal);
@@ -206,8 +206,8 @@ void DrawRoom(LEVEL *level, int room) {
glPopMatrix();
}
else if(level->rooms[room].gateinfo[i].state == STATE_CLOSING) {
- t1 = level->rooms[room].gates[i].triangles[0];
- t2 = level->rooms[room].gates[i].triangles[1];
+ t1 = level->rooms[room].gates[i].walls[0];
+ t2 = level->rooms[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));
@@ -257,13 +257,13 @@ void DrawRoom(LEVEL *level, int room) {
r = level->rooms[room].gates[i].room;
g = level->rooms[room].gates[i].gate;
- t1 = level->rooms[room].gates[i].triangles[0];
- t2 = level->rooms[room].gates[i].triangles[1];
+ t1 = level->rooms[room].gates[i].walls[0];
+ t2 = level->rooms[room].gates[i].walls[1];
p1 = level->rooms[room].gates[i].point;
v1 = t1.normal;
- t1 = level->rooms[r].gates[g].triangles[0];
- t2 = level->rooms[r].gates[g].triangles[1];
+ t1 = level->rooms[r].gates[g].walls[0];
+ t2 = level->rooms[r].gates[g].walls[1];
p2 = level->rooms[r].gates[g].point;
v2 = VectorNeg(t1.normal);
@@ -277,13 +277,13 @@ void DrawRoom(LEVEL *level, int room) {
r = level->rooms[room].gates[i].room;
g = level->rooms[room].gates[i].gate;
- t1 = level->rooms[room].gates[i].triangles[0];
- t2 = level->rooms[room].gates[i].triangles[1];
+ t1 = level->rooms[room].gates[i].walls[0];
+ t2 = level->rooms[room].gates[i].walls[1];
p1 = level->rooms[room].gates[i].point;
v1 = t1.normal;
- t1 = level->rooms[r].gates[g].triangles[0];
- t2 = level->rooms[r].gates[g].triangles[1];
+ t1 = level->rooms[r].gates[g].walls[0];
+ t2 = level->rooms[r].gates[g].walls[1];
p2 = level->rooms[r].gates[g].point;
v2 = VectorNeg(t1.normal);
@@ -301,7 +301,7 @@ void FreeLevel(LEVEL *level) {
if(level->nRooms) {
for(i = 0; i < level->nRooms; i++) {
- if(level->rooms[i].nTriangles) free(level->rooms[i].triangles);
+ if(level->rooms[i].nWalls) free(level->rooms[i].walls);
if(level->rooms[i].nObjects) free(level->rooms[i].objects);
if(level->rooms[i].nGates) free(level->rooms[i].gates);
}
diff --git a/player.c b/player.c
index 9f4d531..e5b0fdf 100644
--- a/player.c
+++ b/player.c
@@ -114,8 +114,8 @@ void DoInput(int delta) {
if(input & INPUT_OPEN) {
for(i = 0; i < level.rooms[room].nGates; i++) {
if(level.rooms[room].gateinfo[i].state != STATE_CLOSED) continue;
- if(CollisionSphereTriangle(player.pos, 1.0, level.rooms[room].gates[i].triangles[0]) ||
- CollisionSphereTriangle(player.pos, 1.0, level.rooms[room].gates[i].triangles[1])) {
+ if(CollisionSphereTriangle(player.pos, 1.0, level.rooms[room].gates[i].walls[0].triangle) ||
+ CollisionSphereTriangle(player.pos, 1.0, level.rooms[room].gates[i].walls[1].triangle)) {
level.rooms[room].gateinfo[i].state = STATE_OPENING;
level.rooms[room].gateinfo[i].timer = 1000;
}
@@ -128,18 +128,18 @@ void DoInput(int delta) {
if(falling) pos.y -= delta/100.0;
for(i = 0; i < level.rooms[room].nGates; i++) {
- if(CollisionSphereTriangle(pos, 0.3, level.rooms[room].gates[i].triangles[0]) ||
- CollisionSphereTriangle(pos, 0.3, level.rooms[room].gates[i].triangles[1])) {
+ if(CollisionSphereTriangle(pos, 0.3, level.rooms[room].gates[i].walls[0].triangle) ||
+ CollisionSphereTriangle(pos, 0.3, level.rooms[room].gates[i].walls[1].triangle)) {
if(level.rooms[room].gateinfo[i].state == STATE_OPENED) {
- if(CollisionPointTriangle(pos, level.rooms[room].gates[i].triangles[0]) ||
- CollisionPointTriangle(pos, level.rooms[room].gates[i].triangles[1])) {
+ if(CollisionPointTriangle(pos, level.rooms[room].gates[i].walls[0].triangle) ||
+ CollisionPointTriangle(pos, level.rooms[room].gates[i].walls[1].triangle)) {
p1 = level.rooms[room].gates[i].point;
- v1 = level.rooms[room].gates[i].triangles[0].normal;
+ v1 = level.rooms[room].gates[i].walls[0].normal;
level.rooms[room].gateinfo[i].state = STATE_CLOSED;
g = level.rooms[room].gates[i].gate;
room = level.rooms[room].gates[i].room;
p2 = level.rooms[room].gates[g].point;
- v2 = VectorNeg(level.rooms[room].gates[g].triangles[0].normal);
+ v2 = VectorNeg(level.rooms[room].gates[g].walls[0].normal);
level.rooms[room].gateinfo[g].state = STATE_OPENED;
level.rooms[room].gateinfo[g].timer = 5000;
transform = VectorMatrix(p2, v2, p1, v1);
@@ -158,9 +158,9 @@ void DoInput(int delta) {
}
}
falling = 1;
- for(i = 0; i < level.rooms[room].nTriangles; i++) {
- if(level.rooms[room].triangles[i].type == TRIANGLE_WALL &&
- CollisionMovingSphereTriangle(VectorSub(pos, VectorMul(move, delta/150.0)), 0.3, move, delta/150.0, level.rooms[room].triangles[i])) {
+ for(i = 0; i < level.rooms[room].nWalls; i++) {
+ if(level.rooms[room].walls[i].type == TRIANGLE_WALL &&
+ CollisionMovingSphereTriangle(VectorSub(pos, VectorMul(move, delta/150.0)), 0.3, move, delta/150.0, level.rooms[room].walls[i].triangle)) {
pos = player.pos;
if(player.room != room) {
level.rooms[room].gateinfo[g].state = STATE_CLOSED;
@@ -173,12 +173,12 @@ void DoInput(int delta) {
falling = 0;
break;
}
- else if(level.rooms[room].triangles[i].type == TRIANGLE_FLOOR) {
+ else if(level.rooms[room].walls[i].type == TRIANGLE_FLOOR) {
pos.y -= 1.81;
- if(CollisionPointTriangle(pos, level.rooms[room].triangles[i])) {
+ if(CollisionPointTriangle(pos, level.rooms[room].walls[i].triangle)) {
falling = 0;
pos.y += 1.81;
- if(wasfalling && CollisionRayTriangle(pos, v, level.rooms[room].triangles[i], &f)) pos.y -= f - 1.8;
+ if(wasfalling && CollisionRayTriangle(pos, v, level.rooms[room].walls[i].triangle, &f)) pos.y -= f - 1.8;
}
else pos.y += 1.81;
}
diff --git a/zoom/level.h b/zoom/level.h
index 223afe1..c9f5345 100644
--- a/zoom/level.h
+++ b/zoom/level.h
@@ -12,7 +12,7 @@ typedef struct _LEVELHEADER {
} LEVELHEADER;
typedef struct _ROOMHEADER {
- int nTriangles;
+ int nWalls;
int nObjects;
int nGates;
} ROOMHEADER;
@@ -23,10 +23,10 @@ typedef struct _GATEINFO {
} GATEINFO;
typedef struct _ROOM {
- int nTriangles;
+ int nWalls;
int nObjects;
int nGates;
- TRIANGLE *triangles;
+ WALL *walls;
OBJECT *objects;
GATE *gates;
GATEINFO *gateinfo;
diff --git a/zoom/types.h b/zoom/types.h
index 51dc259..eeacde7 100644
--- a/zoom/types.h
+++ b/zoom/types.h
@@ -22,6 +22,20 @@
#define STATE_CLOSING 4
#pragma pack(push, 2)
+typedef struct WALL {
+ unsigned char type;
+ unsigned char visible;
+ union {
+ TRIANGLE triangle;
+ struct {
+ VERTEX vertices[3];
+ VECTOR normal;
+ };
+ };
+ int texture;
+ TEXCOORDS texcoords[3];
+} WALL;
+
typedef struct _OBJECT {
unsigned char type;
unsigned char visible;
@@ -31,7 +45,7 @@ typedef struct _OBJECT {
typedef struct _GATE {
unsigned char type;
unsigned char open;
- TRIANGLE triangles[2];
+ WALL walls[2];
VERTEX point;
int room;
int gate;