From 79801b6b794a5fb50a3a013354323a48de37c050 Mon Sep 17 00:00:00 2001 From: neoraider Date: Fri, 20 Oct 2006 12:57:05 +0000 Subject: Physik-Engine angefangen. Lightmaps implementiert. --- config.h.in | 3 - configure | 105 -------------------------------- configure.in | 1 - init.c | 26 ++++++-- level.c | 192 ++++++++++++++++++++++++++++------------------------------ player.c | 45 ++++++++++++-- render.c | 69 +++++++++++++++++++-- zoom/level.h | 8 +-- zoom/player.h | 2 +- zoom/types.h | 27 +++++++-- 10 files changed, 241 insertions(+), 237 deletions(-) diff --git a/config.h.in b/config.h.in index c520dc9..54389a2 100644 --- a/config.h.in +++ b/config.h.in @@ -26,9 +26,6 @@ and to 0 otherwise. */ #undef HAVE_REALLOC -/* Define to 1 if you have the `sqrt' function. */ -#undef HAVE_SQRT - /* Define to 1 if you have the header file. */ #undef HAVE_STDDEF_H diff --git a/configure b/configure index be14ca0..3568e73 100755 --- a/configure +++ b/configure @@ -21074,111 +21074,6 @@ fi -for ac_func in sqrt -do -as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh` -echo "$as_me:$LINENO: checking for $ac_func" >&5 -echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6 -if eval "test \"\${$as_ac_var+set}\" = set"; then - echo $ECHO_N "(cached) $ECHO_C" >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ -/* Define $ac_func to an innocuous variant, in case declares $ac_func. - For example, HP-UX 11i declares gettimeofday. */ -#define $ac_func innocuous_$ac_func - -/* System header to define __stub macros and hopefully few prototypes, - which can conflict with char $ac_func (); below. - Prefer to if __STDC__ is defined, since - exists even on freestanding compilers. */ - -#ifdef __STDC__ -# include -#else -# include -#endif - -#undef $ac_func - -/* Override any gcc2 internal prototype to avoid an error. */ -#ifdef __cplusplus -extern "C" -{ -#endif -/* We use char because int might match the return type of a gcc2 - builtin and then its argument prototype would still apply. */ -char $ac_func (); -/* The GNU C library defines this for functions which it implements - to always fail with ENOSYS. Some functions are actually named - something starting with __ and the normal name is an alias. */ -#if defined (__stub_$ac_func) || defined (__stub___$ac_func) -choke me -#else -char (*f) () = $ac_func; -#endif -#ifdef __cplusplus -} -#endif - -int -main () -{ -return f != $ac_func; - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext conftest$ac_exeext -if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 - (eval $ac_link) 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; } && - { ac_try='test -s conftest$ac_exeext' - { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 - (eval $ac_try) 2>&5 - ac_status=$? - echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); }; }; then - eval "$as_ac_var=yes" -else - echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - -eval "$as_ac_var=no" -fi -rm -f conftest.err conftest.$ac_objext \ - conftest$ac_exeext conftest.$ac_ext -fi -echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_var'}'`" >&5 -echo "${ECHO_T}`eval echo '${'$as_ac_var'}'`" >&6 -if test `eval echo '${'$as_ac_var'}'` = yes; then - cat >>confdefs.h <<_ACEOF -#define `echo "HAVE_$ac_func" | $as_tr_cpp` 1 -_ACEOF - -else - { { echo "$as_me:$LINENO: error: required function sqrt not found" >&5 -echo "$as_me: error: required function sqrt not found" >&2;} - { (exit 1); exit 1; }; } -fi -done - - for ac_func in strcasecmp do as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh` diff --git a/configure.in b/configure.in index e481a1d..d64987e 100644 --- a/configure.in +++ b/configure.in @@ -36,7 +36,6 @@ AC_HEADER_TIME # Checks for library functions. AC_FUNC_MALLOC AC_FUNC_REALLOC -AC_CHECK_FUNCS([sqrt], , AC_MSG_ERROR([required function sqrt not found])) AC_CHECK_FUNCS([strcasecmp], , AC_MSG_ERROR([required function strcasecmp not found])) AC_CONFIG_FILES([Makefile]) diff --git a/init.c b/init.c index fbf9416..a5febfc 100644 --- a/init.c +++ b/init.c @@ -8,11 +8,12 @@ LEVEL level; GLuint sphere; GLuint meditex_blue; +LIGHT light = {LIGHT_POINT, {1.0, 1.0, 1.0}, {0.0, 0.0, 0.0}}; extern TEXLIST *texlist; int InitGame() { - GLfloat mat_ambient_and_diffuse[] = { 0.5, 0.5, 0.5, 1.0}; + //GLfloat mat_ambient_and_diffuse[] = { 0.5, 0.5, 0.5, 1.0}; glViewport(0, 0, 640, 480); glMatrixMode(GL_PROJECTION); @@ -33,14 +34,27 @@ int InitGame() { glEnable(GL_CULL_FACE); glFrontFace(GL_CCW); - glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, mat_ambient_and_diffuse); + //glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient_and_diffuse); - glEnable(GL_LIGHTING); - glEnable(GL_LIGHT0); + glDisable(GL_LIGHTING); + //glEnable(GL_LIGHT0); meditex_blue = LoadTexture("medib.tex"); - glEnable(GL_TEXTURE_2D); - glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); + + glActiveTexture(GL_TEXTURE0); + + glBindTexture(GL_TEXTURE_2D, LoadTexture("lightmap.tex")); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_ADD); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); + + glActiveTexture(GL_TEXTURE1); + + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); GLUquadricObj *quadric = gluNewQuadric(); gluQuadricDrawStyle(quadric, GLU_FILL); diff --git a/level.c b/level.c index ccee0bc..f8c1fda 100644 --- a/level.c +++ b/level.c @@ -1,14 +1,17 @@ #include #include +#include #include +#include #include -#include #include -#include +#include + 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); diff --git a/player.c b/player.c index e5b0fdf..7250009 100644 --- a/player.c +++ b/player.c @@ -20,6 +20,7 @@ float rotxspeed = 0, rotyspeed = 0; float objrot = 0; extern LEVEL level; +extern LIGHT light; void MouseInput(int x, int y) { roty += x * 0.3; @@ -188,12 +189,12 @@ void DoInput(int delta) { player.rotysin = s; player.rotycos = c; - for(i = 0; i < level.rooms[player.room].nObjects; i++) { - pos = VectorSub(level.rooms[player.room].objects[i].pos, player.pos); + for(i = 0; i < level.rooms[player.room].nThings; i++) { + pos = VectorSub(level.rooms[player.room].things[i].pos, player.pos); pos.y += 0.9; - switch(level.rooms[player.room].objects[i].type) { - case OBJECT_MEDIPAK100: - if((pos.x*pos.x + (pos.y*pos.y)/3 + pos.z*pos.z) < 0.36) level.rooms[player.room].objects[i].visible = 0; + switch(level.rooms[player.room].things[i].type) { + case THING_MEDIPAK100: + if((pos.x*pos.x + (pos.y*pos.y)/3 + pos.z*pos.z) < 0.36) level.rooms[player.room].things[i].visible = 0; } } @@ -212,4 +213,38 @@ void DoInput(int delta) { } else level.rooms[player.room].gateinfo[i].timer -= delta; } + + static int lightpos = 0; + + lightpos += delta; + lightpos %= 24000; + + if(lightpos < 12000) i = lightpos; + else i = 24000 - lightpos; + + if(i == 0) { + light.pos.x = 0.0; + light.pos.y = 0.0; + light.pos.z = 0.0; + } + else if(i < 4000) { + light.pos.x = 0.0; + light.pos.y = 0.0; + light.pos.z = -i * 0.001; + } + else if(i < 8000) { + light.pos.x = (i-4000) * 0.001; + light.pos.y = 0.0; + light.pos.z = -4.0; + } + else if(i < 12000) { + light.pos.x = 4.0; + light.pos.y = 0.0; + light.pos.z = -4.0 - (i-8000) * 0.001; + } + else { + light.pos.x = 4.0; + light.pos.y = 0.0; + light.pos.z = -8.0; + } } diff --git a/render.c b/render.c index 5816090..508be8a 100644 --- a/render.c +++ b/render.c @@ -3,15 +3,67 @@ #include #include #include +#include #include extern PLAYER player; extern LEVEL level; extern GLuint sphere; +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(); +} void Render() { - GLfloat light_position[] = { 0.0, 0.0, 0.0, 1.0 }; - GLfloat light_emission[] = {1.0, 1.0, 1.0, 1.0}; + //GLfloat light_position[] = { 0.0, 0.0, 0.0, 1.0 }; + //GLfloat light_emission[] = {1.0, 1.0, 1.0, 1.0}; GLfloat std_emission[] = {0.0, 0.0, 0.0, 1.0}; MATRIX rotate = { player.rotycos, 0.0, -player.rotysin, 0.0, @@ -19,6 +71,8 @@ void Render() { player.rotysin, 0.0, player.rotycos, 0.0, 0.0, 0.0, 0.0, 1.0 }; + COLOR color_light = {1.0, 1.0, 1.0}; + COLOR color_ambient = {0.1, 0.1, 0.1}; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); @@ -29,17 +83,20 @@ void Render() { glTranslatef(-player.pos.x, -player.pos.y, -player.pos.z); - glLightfv(GL_LIGHT0, GL_POSITION, light_position); + //glLightfv(GL_LIGHT0, GL_POSITION, light_position); glPushMatrix(); glDisable(GL_TEXTURE_2D); - glMaterialfv(GL_FRONT, GL_EMISSION, light_emission); - glTranslatef(light_position[0], light_position[1], light_position[2]); + glColor3fv((GLfloat*)&color_light); + //glMaterialfv(GL_FRONT, GL_EMISSION, light_emission); + glTranslatef(light.pos.x, light.pos.y, light.pos.z); glScalef(0.1, 0.1, 0.1); glCallList(sphere); - glMaterialfv(GL_FRONT, GL_EMISSION, std_emission); + //glMaterialfv(GL_FRONT, GL_EMISSION, std_emission); glEnable(GL_TEXTURE_2D); glPopMatrix(); + glColor3fv((GLfloat*)&color_ambient); + DrawRoom(&level, player.room); glFlush(); diff --git a/zoom/level.h b/zoom/level.h index c9f5345..0ed961c 100644 --- a/zoom/level.h +++ b/zoom/level.h @@ -2,7 +2,7 @@ #define ZOOM_LEVEL_H #include -#include "types.h" +#include #pragma pack(push, 2) typedef struct _LEVELHEADER { @@ -13,7 +13,7 @@ typedef struct _LEVELHEADER { typedef struct _ROOMHEADER { int nWalls; - int nObjects; + int nThings; int nGates; } ROOMHEADER; @@ -24,10 +24,10 @@ typedef struct _GATEINFO { typedef struct _ROOM { int nWalls; - int nObjects; + int nThings; int nGates; WALL *walls; - OBJECT *objects; + THING *things; GATE *gates; GATEINFO *gateinfo; } ROOM; diff --git a/zoom/player.h b/zoom/player.h index 06c0e28..e9beec6 100644 --- a/zoom/player.h +++ b/zoom/player.h @@ -1,7 +1,7 @@ #ifndef ZOOM_PLAYER_H #define ZOOM_PLAYER_H -#include "types.h" +#include #define INPUT_UP 1 #define INPUT_DOWN 2 diff --git a/zoom/types.h b/zoom/types.h index eeacde7..9e40ea6 100644 --- a/zoom/types.h +++ b/zoom/types.h @@ -7,10 +7,15 @@ #define TRIANGLE_WALL 1 #define TRIANGLE_FLOOR 2 -#define OBJECT_UNKNOWN 0 -#define OBJECT_MEDIPAK25 1 -#define OBJECT_MEDIPAK50 2 -#define OBJECT_MEDIPAK100 3 +#define LIGHT_UNKNOWN 0 +#define LIGHT_POINT 1 +#define LIGHT_DIRECTIONAL 2 +#define LIGHT_SPOT 3 + +#define THING_UNKNOWN 0 +#define THING_MEDIPAK25 1 +#define THING_MEDIPAK50 2 +#define THING_MEDIPAK100 3 #define GATE_UNKNOWN 0 #define GATE_SIDE 1 @@ -36,11 +41,21 @@ typedef struct WALL { TEXCOORDS texcoords[3]; } WALL; -typedef struct _OBJECT { +typedef struct _COLOR { + float r, g, b; +} COLOR; + +typedef struct _LIGHT { + unsigned char type; + COLOR diffuse; + VERTEX pos; +} LIGHT; + +typedef struct _THING { unsigned char type; unsigned char visible; VERTEX pos; -} OBJECT; +} THING; typedef struct _GATE { unsigned char type; -- cgit v1.2.3