2005-04-18 15:27:00 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2006-10-20 12:57:05 +00:00
|
|
|
#include <string.h>
|
2005-04-18 15:27:00 +00:00
|
|
|
#include <GL/gl.h>
|
2006-10-20 12:57:05 +00:00
|
|
|
#include <neofx/math.h>
|
2005-04-18 15:27:00 +00:00
|
|
|
#include <zoom/types.h>
|
|
|
|
#include <zoom/texture.h>
|
2006-10-20 12:57:05 +00:00
|
|
|
#include <zoom/level.h>
|
2006-10-24 15:04:02 +00:00
|
|
|
#include <zoom/light.h>
|
2007-05-14 17:38:01 +00:00
|
|
|
#include <libxml/parser.h>
|
|
|
|
#include <libxml/tree.h>
|
|
|
|
#include <libxml/valid.h>
|
2006-10-20 12:57:05 +00:00
|
|
|
|
2005-04-18 15:27:00 +00:00
|
|
|
|
|
|
|
extern GLuint sphere;
|
|
|
|
extern GLuint meditex_blue;
|
|
|
|
extern float objrot;
|
2006-10-24 15:04:02 +00:00
|
|
|
extern LIGHT *lights;
|
|
|
|
extern int nLights;
|
2005-04-18 15:27:00 +00:00
|
|
|
|
2007-05-14 17:38:01 +00:00
|
|
|
|
|
|
|
static int SortTextures(const void *t1, const void *t2) {
|
|
|
|
return strcmp(((TEXTURE*)t1)->name, ((TEXTURE*)t2)->name);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LEVEL *LoadLevel(char *filename) {
|
|
|
|
LEVEL *level;
|
|
|
|
xmlDocPtr doc;
|
|
|
|
xmlDtdPtr dtd;
|
|
|
|
xmlValidCtxtPtr validCtxt;
|
|
|
|
xmlNodePtr root, node, node2, node3, rooms = NULL;
|
|
|
|
xmlChar *data;
|
|
|
|
char *name;
|
|
|
|
int i, j, k;
|
|
|
|
VECTOR v;
|
|
|
|
TEXTURE tex;
|
|
|
|
TEXTURE *texp;
|
|
|
|
|
|
|
|
|
|
|
|
name = malloc(strlen(filename)+8);
|
|
|
|
strcpy(name, "levels/");
|
|
|
|
strcat(name, filename);
|
|
|
|
|
|
|
|
doc = xmlParseFile(name);
|
|
|
|
|
|
|
|
free(name);
|
|
|
|
|
|
|
|
if(!doc)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
dtd = xmlParseDTD("-//libzoom//DTD level 0.1//EN", "levels/level.dtd");
|
|
|
|
|
|
|
|
if(!dtd) {
|
|
|
|
xmlFreeDoc(doc);
|
|
|
|
xmlCleanupParser();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
validCtxt = xmlNewValidCtxt();
|
|
|
|
|
|
|
|
if(!validCtxt) {
|
|
|
|
xmlFreeDtd(dtd);
|
|
|
|
xmlFreeDoc(doc);
|
|
|
|
xmlCleanupParser();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!xmlValidateDtd(validCtxt, doc, dtd)) {
|
|
|
|
xmlFreeValidCtxt(validCtxt);
|
|
|
|
xmlFreeDtd(dtd);
|
|
|
|
xmlFreeDoc(doc);
|
|
|
|
xmlCleanupParser();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
xmlFreeValidCtxt(validCtxt);
|
|
|
|
xmlFreeDtd(dtd);
|
|
|
|
|
|
|
|
root = xmlDocGetRootElement(doc);
|
|
|
|
if(!root || xmlStrcmp(root->name, "level")) {
|
|
|
|
xmlFreeDoc(doc);
|
|
|
|
xmlCleanupParser();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
level = calloc(1, sizeof(LEVEL));
|
|
|
|
|
|
|
|
for(node = root->children; node = node->next; node != NULL) {
|
|
|
|
if(node->type != XML_ELEMENT_NODE) continue;
|
|
|
|
|
|
|
|
if(!xmlStrcmp(node->name, "info")) {
|
|
|
|
level->info = calloc(1, sizeof(LEVELINFO));
|
|
|
|
|
|
|
|
for(node2 = node->children; node2 = node2->next; node2 != NULL) {
|
|
|
|
if(node2->type != XML_ELEMENT_NODE) continue;
|
|
|
|
|
|
|
|
if(!xmlStrcmp(node2->name, "name")) {
|
|
|
|
if(level->info->name != NULL) continue;
|
|
|
|
|
|
|
|
data = xmlNodeGetContent(node2);
|
|
|
|
level->info->name = strdup(data);
|
|
|
|
xmlFree(data);
|
|
|
|
}
|
|
|
|
else if(!xmlStrcmp(node2->name, "desc")) {
|
|
|
|
if(level->info->desc != NULL) continue;
|
|
|
|
|
|
|
|
data = xmlNodeGetContent(node2);
|
|
|
|
level->info->desc = strdup(data);
|
|
|
|
xmlFree(data);
|
|
|
|
}
|
|
|
|
else if(!xmlStrcmp(node2->name, "start")) {
|
|
|
|
data = xmlGetProp(node2, "x");
|
|
|
|
if(data) level->info->start.x = atof(data);
|
|
|
|
xmlFree(data);
|
|
|
|
|
|
|
|
data = xmlGetProp(node2, "y");
|
|
|
|
if(data) level->info->start.y = atof(data);
|
|
|
|
xmlFree(data);
|
|
|
|
|
|
|
|
data = xmlGetProp(node2, "z");
|
|
|
|
if(data) level->info->start.z = atof(data);
|
|
|
|
xmlFree(data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(!xmlStrcmp(node->name, "rooms")) {
|
|
|
|
if(rooms != NULL) continue;
|
|
|
|
|
|
|
|
rooms = node;
|
|
|
|
|
|
|
|
for(node2 = node->children; node2 = node2->next; node2 != NULL) {
|
|
|
|
if(node2->type == XML_ELEMENT_NODE && !xmlStrcmp(node2->name, "room")) level->nRooms++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(!xmlStrcmp(node->name, "textures")) {
|
|
|
|
if(level->textures != NULL) continue;
|
|
|
|
|
|
|
|
for(node2 = node->children; node2 = node2->next; node2 != NULL) {
|
|
|
|
if(node2->type == XML_ELEMENT_NODE && !xmlStrcmp(node2->name, "texture")) level->nTextures++;
|
|
|
|
}
|
|
|
|
|
|
|
|
level->textures = calloc(level->nTextures, sizeof(TEXTURE));
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
for(node2 = node->children; node2 = node2->next; node2 != NULL) {
|
|
|
|
if(node2->type != XML_ELEMENT_NODE || xmlStrcmp(node2->name, "texture")) continue;
|
|
|
|
|
|
|
|
data = xmlGetProp(node2, "name");
|
|
|
|
if(data) {
|
|
|
|
level->textures[i].id = LoadTexture(data);
|
|
|
|
|
|
|
|
xmlFree(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
data = xmlGetProp(node2, "id");
|
|
|
|
if(data) {
|
|
|
|
level->textures[i].name = strdup(data);
|
|
|
|
|
|
|
|
xmlFree(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
qsort(level->textures, level->nTextures, sizeof(TEXTURE), SortTextures);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
level->rooms = calloc(level->nRooms, sizeof(ROOM));
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
for(node = rooms->children; node = node->next; node != NULL) {
|
|
|
|
if(node->type != XML_ELEMENT_NODE || xmlStrcmp(node->name, "room")) continue;
|
|
|
|
|
|
|
|
for(node2 = node->children; node2 = node2->next; node2 != NULL) {
|
|
|
|
if(node2->type == XML_ELEMENT_NODE && !xmlStrcmp(node2->name, "triangle")) level->rooms[i].nWalls++;
|
|
|
|
}
|
|
|
|
|
|
|
|
level->rooms[i].walls = calloc(level->rooms[i].nWalls, sizeof(WALL));
|
|
|
|
|
|
|
|
j = 0;
|
|
|
|
for(node2 = node->children; node2 = node2->next; node2 != NULL) {
|
|
|
|
if(node2->type != XML_ELEMENT_NODE || xmlStrcmp(node2->name, "triangle")) continue;
|
|
|
|
|
|
|
|
data = xmlGetProp(node2, "type");
|
|
|
|
if(data) {
|
|
|
|
if(!xmlStrcmp(data, "wall")) level->rooms[i].walls[j].type = TRIANGLE_WALL;
|
|
|
|
else if(!xmlStrcmp(data, "floor")) level->rooms[i].walls[j].type = TRIANGLE_FLOOR;
|
|
|
|
else level->rooms[i].walls[j].type = TRIANGLE_UNKNOWN;
|
|
|
|
xmlFree(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
level->rooms[i].walls[j].visible = 1;
|
|
|
|
data = xmlGetProp(node2, "visible");
|
|
|
|
if(data) {
|
|
|
|
if(!xmlStrcmp(data, "false")) level->rooms[i].walls[j].visible = 0;
|
|
|
|
xmlFree(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
data = xmlGetProp(node2, "texture");
|
|
|
|
if(data) {
|
|
|
|
tex.name = data;
|
|
|
|
texp = bsearch(&tex, level->textures, level->nTextures, sizeof(TEXTURE), SortTextures);
|
|
|
|
|
|
|
|
if(texp) level->rooms[i].walls[j].texture = texp->id;
|
|
|
|
|
|
|
|
xmlFree(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
k = -1;
|
|
|
|
for(node3 = node2->children; node3 = node3->next; node3 != NULL) {
|
|
|
|
if(node3->type != XML_ELEMENT_NODE) continue;
|
|
|
|
|
|
|
|
if(!xmlStrcmp(node3->name, "vertex")) {
|
|
|
|
if(++k > 2) break;
|
|
|
|
|
|
|
|
data = xmlGetProp(node3, "x");
|
|
|
|
if(data) {
|
|
|
|
level->rooms[i].walls[j].vertices[k].x = atof(data);
|
|
|
|
xmlFree(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
data = xmlGetProp(node3, "y");
|
|
|
|
if(data) {
|
|
|
|
level->rooms[i].walls[j].vertices[k].y = atof(data);
|
|
|
|
xmlFree(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
data = xmlGetProp(node3, "z");
|
|
|
|
if(data) {
|
|
|
|
level->rooms[i].walls[j].vertices[k].z = atof(data);
|
|
|
|
xmlFree(data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(!xmlStrcmp(node3->name, "normal")) {
|
|
|
|
if(k < 0) continue;
|
|
|
|
|
|
|
|
data = xmlGetProp(node3, "x");
|
|
|
|
if(data) {
|
|
|
|
level->rooms[i].walls[j].normals[k].x = atof(data);
|
|
|
|
xmlFree(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
data = xmlGetProp(node3, "y");
|
|
|
|
if(data) {
|
|
|
|
level->rooms[i].walls[j].normals[k].y = atof(data);
|
|
|
|
xmlFree(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
data = xmlGetProp(node3, "z");
|
|
|
|
if(data) {
|
|
|
|
level->rooms[i].walls[j].normals[k].z = atof(data);
|
|
|
|
xmlFree(data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(!xmlStrcmp(node3->name, "texcoords")) {
|
|
|
|
if(k < 0) continue;
|
|
|
|
|
|
|
|
data = xmlGetProp(node3, "s");
|
|
|
|
if(data) {
|
|
|
|
level->rooms[i].walls[j].texcoords[k].s = atof(data);
|
|
|
|
xmlFree(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
data = xmlGetProp(node3, "t");
|
|
|
|
if(data) {
|
|
|
|
level->rooms[i].walls[j].texcoords[k].t = atof(data);
|
|
|
|
xmlFree(data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-05-14 19:11:02 +00:00
|
|
|
|
2007-05-14 17:38:01 +00:00
|
|
|
v = VectorCross(
|
|
|
|
VectorSub(level->rooms[i].walls[j].vertices[1], level->rooms[i].walls[j].vertices[0]),
|
|
|
|
VectorSub(level->rooms[i].walls[j].vertices[2], level->rooms[i].walls[j].vertices[0])
|
|
|
|
);
|
2007-05-14 19:11:02 +00:00
|
|
|
if(VectorLengthSq(v) > 0.0) {
|
|
|
|
level->rooms[i].walls[j].normal = VectorNormalize(v);
|
|
|
|
|
|
|
|
for(k = 0; k < 3; k++) {
|
|
|
|
if(VectorLengthSq(level->rooms[i].walls[j].normals[k]) == 0.0)
|
|
|
|
level->rooms[i].walls[j].normals[k] = level->rooms[i].walls[j].normal;
|
|
|
|
}
|
|
|
|
}
|
2007-05-14 17:38:01 +00:00
|
|
|
|
|
|
|
j++;
|
|
|
|
}
|
|
|
|
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
xmlFreeDoc(doc);
|
|
|
|
xmlCleanupParser();
|
|
|
|
|
|
|
|
return level;
|
2005-04-18 15:27:00 +00:00
|
|
|
}
|
|
|
|
|
2006-10-24 15:04:02 +00:00
|
|
|
POLYGON_LIST *DrawRoom(LEVEL *level, int nr) {
|
|
|
|
ROOM room = level->rooms[nr];
|
|
|
|
POLYGON_LIST *p;
|
2005-04-18 15:27:00 +00:00
|
|
|
int i;
|
2007-05-14 17:38:01 +00:00
|
|
|
|
2006-10-24 15:04:02 +00:00
|
|
|
p = malloc(sizeof(POLYGON_LIST)+sizeof(POLYGON)*room.nWalls);
|
|
|
|
p->nPolygons = room.nWalls;
|
|
|
|
|
|
|
|
for(i = 0; i < room.nWalls; i++) {
|
|
|
|
p->polygons[i].vertices[0] = room.walls[i].vertices[0];
|
|
|
|
p->polygons[i].vertices[1] = room.walls[i].vertices[1];
|
|
|
|
p->polygons[i].vertices[2] = room.walls[i].vertices[2];
|
|
|
|
|
|
|
|
p->polygons[i].normal = room.walls[i].normal;
|
2007-05-14 17:38:01 +00:00
|
|
|
p->polygons[i].normals[0] = room.walls[i].normals[0];
|
|
|
|
p->polygons[i].normals[1] = room.walls[i].normals[1];
|
|
|
|
p->polygons[i].normals[2] = room.walls[i].normals[2];
|
2006-10-24 15:04:02 +00:00
|
|
|
|
2007-05-14 17:38:01 +00:00
|
|
|
p->polygons[i].texture = room.walls[i].texture;
|
2006-10-24 15:04:02 +00:00
|
|
|
|
|
|
|
p->polygons[i].texcoords[0] = room.walls[i].texcoords[0];
|
|
|
|
p->polygons[i].texcoords[1] = room.walls[i].texcoords[1];
|
|
|
|
p->polygons[i].texcoords[2] = room.walls[i].texcoords[2];
|
|
|
|
}
|
|
|
|
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*void DrawRoom(LEVEL *level, int nr) {
|
|
|
|
int i, j;
|
2005-04-18 15:27:00 +00:00
|
|
|
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};
|
2006-10-20 12:57:05 +00:00
|
|
|
ROOM room = level->rooms[nr];
|
2005-04-23 11:41:04 +00:00
|
|
|
WALL t1, t2;
|
2005-04-18 15:27:00 +00:00
|
|
|
VERTEX p1, p2;
|
2006-10-20 12:57:05 +00:00
|
|
|
VECTOR v1, v2, n, v;
|
|
|
|
float s, t, d;
|
2005-04-18 15:27:00 +00:00
|
|
|
MATRIX transform;
|
|
|
|
|
2006-10-24 15:04:02 +00:00
|
|
|
|
2006-10-20 12:57:05 +00:00
|
|
|
for(i = 0; i < room.nWalls; i++)
|
2006-10-24 15:04:02 +00:00
|
|
|
RenderWallDepth(room.walls[i]);
|
|
|
|
|
|
|
|
for(i = 0; i < nLights; i++) {
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
|
|
|
for(j = 0; j < room.nWalls; j++)
|
|
|
|
RenderWallLight(room.walls[j], lights[i]);
|
|
|
|
|
|
|
|
glAccum(GL_ACCUM, 1.0/(nLights+1));
|
|
|
|
}
|
|
|
|
|
|
|
|
glAccum(GL_RETURN, 1.0);
|
|
|
|
|
|
|
|
//for(i = 0; i < room.nWalls; i++)
|
|
|
|
// RenderWall(room.walls[i], level->textures);
|
|
|
|
|
|
|
|
glColor3f(1.0/(nLights+1), 1.0/(nLights+1), 1.0/(nLights+1));
|
2005-04-18 15:27:00 +00:00
|
|
|
|
2006-10-20 12:57:05 +00:00
|
|
|
for(i = 0; i < room.nThings; i++) {
|
|
|
|
if(!room.things[i].visible) continue;
|
|
|
|
switch(room.things[i].type) {
|
|
|
|
case THING_MEDIPAK100:
|
2005-04-18 15:27:00 +00:00
|
|
|
glPushMatrix();
|
2006-10-24 15:04:02 +00:00
|
|
|
glBindTexture(GL_TEXTURE_2D, meditex_blue);
|
2005-04-18 15:27:00 +00:00
|
|
|
glMaterialfv(GL_FRONT, GL_EMISSION, medipak100_emission);
|
2006-10-20 12:57:05 +00:00
|
|
|
glTranslatef(room.things[i].pos.x, room.things[i].pos.y, room.things[i].pos.z);
|
2005-04-18 15:27:00 +00:00
|
|
|
glRotatef(objrot*10, 0.0, 1.0, 0.0);
|
|
|
|
glScalef(0.3, 0.3, 0.3);
|
|
|
|
glCallList(sphere);
|
|
|
|
glMaterialfv(GL_FRONT, GL_EMISSION, std_emission);
|
|
|
|
glPopMatrix();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-10-20 12:57:05 +00:00
|
|
|
for(i = 0; i < room.nGates; i++) {
|
|
|
|
if(room.gateinfo[i].state == STATE_CLOSED) {
|
2006-10-24 15:04:02 +00:00
|
|
|
glBindTexture(GL_TEXTURE_2D, level->textures[room.gates[i].walls[0].texture]);
|
2005-04-18 15:27:00 +00:00
|
|
|
|
|
|
|
glBegin(GL_TRIANGLES);
|
|
|
|
|
2006-10-20 12:57:05 +00:00
|
|
|
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]);
|
2005-04-18 15:27:00 +00:00
|
|
|
|
|
|
|
glEnd();
|
|
|
|
|
2006-10-24 15:04:02 +00:00
|
|
|
glBindTexture(GL_TEXTURE_2D, level->textures[room.gates[i].walls[0].texture]);
|
2005-04-18 15:27:00 +00:00
|
|
|
|
|
|
|
glBegin(GL_TRIANGLES);
|
|
|
|
|
2006-10-20 12:57:05 +00:00
|
|
|
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]);
|
2005-04-18 15:27:00 +00:00
|
|
|
|
|
|
|
glEnd();
|
|
|
|
}
|
2006-10-20 12:57:05 +00:00
|
|
|
else if(room.gateinfo[i].state == STATE_OPENING) {
|
|
|
|
t1 = room.gates[i].walls[0];
|
|
|
|
t2 = room.gates[i].walls[1];
|
2005-04-18 15:27:00 +00:00
|
|
|
|
2006-10-20 12:57:05 +00:00
|
|
|
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)));
|
2005-04-18 15:27:00 +00:00
|
|
|
t2.vertices[1] = t1.vertices[2];
|
2006-10-20 12:57:05 +00:00
|
|
|
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);
|
2005-04-18 15:27:00 +00:00
|
|
|
t2.texcoords[0] = t1.texcoords[0];
|
|
|
|
|
2006-10-24 15:04:02 +00:00
|
|
|
glBindTexture(GL_TEXTURE_2D, level->textures[t1.texture]);
|
2005-04-18 15:27:00 +00:00
|
|
|
|
|
|
|
glBegin(GL_TRIANGLES);
|
|
|
|
|
|
|
|
glNormal3fv((GLfloat*)&t1.normal);
|
|
|
|
glTexCoord2fv((GLfloat*)&t1.texcoords[0]);
|
|
|
|
glVertex3fv((GLfloat*)&t1.vertices[0]);
|
|
|
|
glTexCoord2fv((GLfloat*)&t1.texcoords[1]);
|
|
|
|
glVertex3fv((GLfloat*)&t1.vertices[1]);
|
|
|
|
glTexCoord2fv((GLfloat*)&t1.texcoords[2]);
|
|
|
|
glVertex3fv((GLfloat*)&t1.vertices[2]);
|
|
|
|
|
|
|
|
glEnd();
|
|
|
|
|
2006-10-24 15:04:02 +00:00
|
|
|
glBindTexture(GL_TEXTURE_2D, level->textures[t2.texture]);
|
2005-04-18 15:27:00 +00:00
|
|
|
|
|
|
|
glBegin(GL_TRIANGLES);
|
|
|
|
|
|
|
|
glNormal3fv((GLfloat*)&t2.normal);
|
|
|
|
glTexCoord2fv((GLfloat*)&t2.texcoords[0]);
|
|
|
|
glVertex3fv((GLfloat*)&t2.vertices[0]);
|
|
|
|
glTexCoord2fv((GLfloat*)&t2.texcoords[1]);
|
|
|
|
glVertex3fv((GLfloat*)&t2.vertices[1]);
|
|
|
|
glTexCoord2fv((GLfloat*)&t2.texcoords[2]);
|
|
|
|
glVertex3fv((GLfloat*)&t2.vertices[2]);
|
|
|
|
|
|
|
|
glEnd();
|
|
|
|
|
2006-10-20 12:57:05 +00:00
|
|
|
r = room.gates[i].room;
|
|
|
|
g = room.gates[i].gate;
|
2005-04-18 15:27:00 +00:00
|
|
|
|
2006-10-20 12:57:05 +00:00
|
|
|
t1 = room.gates[i].walls[0];
|
|
|
|
t2 = room.gates[i].walls[1];
|
|
|
|
p1 = room.gates[i].point;
|
2005-04-18 15:27:00 +00:00
|
|
|
v1 = t1.normal;
|
|
|
|
|
2005-04-23 11:41:04 +00:00
|
|
|
t1 = level->rooms[r].gates[g].walls[0];
|
|
|
|
t2 = level->rooms[r].gates[g].walls[1];
|
2005-04-18 15:27:00 +00:00
|
|
|
p2 = level->rooms[r].gates[g].point;
|
|
|
|
v2 = VectorNeg(t1.normal);
|
|
|
|
|
|
|
|
glPushMatrix();
|
|
|
|
transform = VectorMatrix(p1, v1, p2, v2);
|
|
|
|
glMultMatrixf(transform.f);
|
2006-10-24 15:04:02 +00:00
|
|
|
//DrawRoom(level, r);
|
2005-04-18 15:27:00 +00:00
|
|
|
glPopMatrix();
|
|
|
|
}
|
2006-10-20 12:57:05 +00:00
|
|
|
else if(room.gateinfo[i].state == STATE_CLOSING) {
|
|
|
|
t1 = room.gates[i].walls[0];
|
|
|
|
t2 = room.gates[i].walls[1];
|
2005-04-18 15:27:00 +00:00
|
|
|
|
2006-10-20 12:57:05 +00:00
|
|
|
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));
|
2005-04-18 15:27:00 +00:00
|
|
|
t2.vertices[1] = t1.vertices[2];
|
2006-10-20 12:57:05 +00:00
|
|
|
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;
|
2005-04-18 15:27:00 +00:00
|
|
|
t2.texcoords[0] = t1.texcoords[0];
|
|
|
|
|
2006-10-24 15:04:02 +00:00
|
|
|
glBindTexture(GL_TEXTURE_2D, level->textures[t1.texture]);
|
2005-04-18 15:27:00 +00:00
|
|
|
|
|
|
|
glBegin(GL_TRIANGLES);
|
|
|
|
|
|
|
|
glNormal3fv((GLfloat*)&t1.normal);
|
|
|
|
glTexCoord2fv((GLfloat*)&t1.texcoords[0]);
|
|
|
|
glVertex3fv((GLfloat*)&t1.vertices[0]);
|
|
|
|
glTexCoord2fv((GLfloat*)&t1.texcoords[1]);
|
|
|
|
glVertex3fv((GLfloat*)&t1.vertices[1]);
|
|
|
|
glTexCoord2fv((GLfloat*)&t1.texcoords[2]);
|
|
|
|
glVertex3fv((GLfloat*)&t1.vertices[2]);
|
|
|
|
|
|
|
|
glEnd();
|
|
|
|
|
2006-10-24 15:04:02 +00:00
|
|
|
glBindTexture(GL_TEXTURE_2D, level->textures[t2.texture]);
|
2005-04-18 15:27:00 +00:00
|
|
|
|
|
|
|
glBegin(GL_TRIANGLES);
|
|
|
|
|
|
|
|
glNormal3fv((GLfloat*)&t2.normal);
|
|
|
|
glTexCoord2fv((GLfloat*)&t2.texcoords[0]);
|
|
|
|
glVertex3fv((GLfloat*)&t2.vertices[0]);
|
|
|
|
glTexCoord2fv((GLfloat*)&t2.texcoords[1]);
|
|
|
|
glVertex3fv((GLfloat*)&t2.vertices[1]);
|
|
|
|
glTexCoord2fv((GLfloat*)&t2.texcoords[2]);
|
|
|
|
glVertex3fv((GLfloat*)&t2.vertices[2]);
|
|
|
|
|
|
|
|
glEnd();
|
|
|
|
|
2006-10-20 12:57:05 +00:00
|
|
|
r = room.gates[i].room;
|
|
|
|
g = room.gates[i].gate;
|
2005-04-18 15:27:00 +00:00
|
|
|
|
2006-10-20 12:57:05 +00:00
|
|
|
t1 = room.gates[i].walls[0];
|
|
|
|
t2 = room.gates[i].walls[1];
|
|
|
|
p1 = room.gates[i].point;
|
2005-04-18 15:27:00 +00:00
|
|
|
v1 = t1.normal;
|
|
|
|
|
2005-04-23 11:41:04 +00:00
|
|
|
t1 = level->rooms[r].gates[g].walls[0];
|
|
|
|
t2 = level->rooms[r].gates[g].walls[1];
|
2005-04-18 15:27:00 +00:00
|
|
|
p2 = level->rooms[r].gates[g].point;
|
|
|
|
v2 = VectorNeg(t1.normal);
|
|
|
|
|
|
|
|
glPushMatrix();
|
|
|
|
transform = VectorMatrix(p1, v1, p2, v2);
|
|
|
|
glMultMatrixf(transform.f);
|
2006-10-24 15:04:02 +00:00
|
|
|
//DrawRoom(level, r);
|
2005-04-18 15:27:00 +00:00
|
|
|
glPopMatrix();
|
|
|
|
}
|
|
|
|
else {
|
2006-10-20 12:57:05 +00:00
|
|
|
r = room.gates[i].room;
|
|
|
|
g = room.gates[i].gate;
|
2005-04-18 15:27:00 +00:00
|
|
|
|
2006-10-20 12:57:05 +00:00
|
|
|
t1 = room.gates[i].walls[0];
|
|
|
|
t2 = room.gates[i].walls[1];
|
|
|
|
p1 = room.gates[i].point;
|
2005-04-18 15:27:00 +00:00
|
|
|
v1 = t1.normal;
|
|
|
|
|
2005-04-23 11:41:04 +00:00
|
|
|
t1 = level->rooms[r].gates[g].walls[0];
|
|
|
|
t2 = level->rooms[r].gates[g].walls[1];
|
2005-04-18 15:27:00 +00:00
|
|
|
p2 = level->rooms[r].gates[g].point;
|
|
|
|
v2 = VectorNeg(t1.normal);
|
|
|
|
|
|
|
|
glPushMatrix();
|
|
|
|
transform = VectorMatrix(p1, v1, p2, v2);
|
|
|
|
glMultMatrixf(transform.f);
|
2006-10-24 15:04:02 +00:00
|
|
|
//DrawRoom(level, r);
|
2005-04-18 15:27:00 +00:00
|
|
|
glPopMatrix();
|
|
|
|
}
|
|
|
|
}
|
2006-10-24 15:04:02 +00:00
|
|
|
}*/
|
2005-04-18 15:27:00 +00:00
|
|
|
|
|
|
|
void FreeLevel(LEVEL *level) {
|
|
|
|
int i;
|
|
|
|
|
2007-05-14 17:38:01 +00:00
|
|
|
if(level) {
|
|
|
|
if(level->info) {
|
|
|
|
free(level->info->name);
|
|
|
|
free(level->info->desc);
|
|
|
|
free(level->info);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(level->nRooms) {
|
|
|
|
for(i = 0; i < level->nRooms; i++) {
|
|
|
|
if(level->rooms[i].nWalls) free(level->rooms[i].walls);
|
|
|
|
if(level->rooms[i].nThings) free(level->rooms[i].things);
|
|
|
|
if(level->rooms[i].nGates) {
|
|
|
|
free(level->rooms[i].gates);
|
|
|
|
free(level->rooms[i].gateinfo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free(level->rooms);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(level->nTextures) {
|
|
|
|
for(i = 0; i < level->nTextures; i++)
|
|
|
|
free(level->textures[i].name);
|
|
|
|
|
|
|
|
free(level->textures);
|
|
|
|
}
|
|
|
|
|
|
|
|
free(level);
|
|
|
|
}
|
2005-04-18 15:27:00 +00:00
|
|
|
}
|