From b9c3a15057a1e5d54a028cbaaf64ea067e951bc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Lemaire?= Date: Sun, 16 Feb 2014 14:34:15 +0100 Subject: [PATCH] Removed versioning information from sources --- src/3dutils.h | 81 +-- src/appearance.cpp | 164 ++--- src/appearance.h | 62 +- src/audio.cpp | 367 +++++----- src/audio.h | 119 +--- src/camera.cpp | 106 ++- src/camera.h | 57 +- src/collision.cpp | 1209 +++++++++++++++---------------- src/collision.h | 66 +- src/end.cpp | 163 ++--- src/end.h | 14 - src/fight.cpp | 1027 +++++++++++---------------- src/fight.h | 63 -- src/font.cpp | 127 ++-- src/font.h | 20 - src/glapi.cpp | 89 +-- src/glapi.h | 30 - src/graphics.cpp | 273 +++---- src/graphics.h | 43 +- src/legoblocks.cpp | 668 ++++++++--------- src/legoblocks.h | 102 +-- src/legoman.cpp | 1579 +++++++++++++++++++---------------------- src/legoman.h | 250 +++---- src/light.cpp | 276 ++++--- src/light.h | 58 +- src/main.cpp | 267 +++---- src/main.h | 51 -- src/material.cpp | 52 +- src/material.h | 46 +- src/menu.cpp | 1427 ++++++++++++++++++------------------- src/menu.h | 29 - src/mesh.cpp | 530 +++++++------- src/mesh.h | 138 ++-- src/object.cpp | 295 +++----- src/object.h | 235 +++--- src/objectfactory.cpp | 397 +++++------ src/objectfactory.h | 32 - src/particle.cpp | 202 +++--- src/particle.h | 45 +- src/run.cpp | 337 ++++----- src/run.h | 39 - src/shape.cpp | 44 +- src/shape.h | 62 +- src/sphere.cpp | 432 +++++------ src/sphere.h | 87 +-- src/texture.cpp | 50 +- src/texture.h | 37 +- src/utils.cpp | 52 +- src/utils.h | 29 - src/vector.cpp | 348 ++++----- src/vector.h | 41 +- src/world.cpp | 359 +++++----- src/world.h | 76 +- 53 files changed, 5111 insertions(+), 7641 deletions(-) diff --git a/src/3dutils.h b/src/3dutils.h index 5d44ec3..5476e8f 100644 --- a/src/3dutils.h +++ b/src/3dutils.h @@ -1,80 +1,3 @@ -/* - * $Id: 3dutils.h,v 1.22 2002/07/22 11:50:26 jkaarlas Exp $ - * - * - * $Log: 3dutils.h,v $ - * Revision 1.22 2002/07/22 11:50:26 jkaarlas - * naama - * - * Revision 1.21 2002/07/22 11:44:16 jkaarlas - * naama - * - * Revision 1.20 2002/07/19 20:33:28 msell - * #pragma once -> #ifndef - * - * Revision 1.19 2002/07/19 18:59:46 msell - * Alkuhommaa ja säätöä - * - * Revision 1.18 2002/07/19 14:05:51 msell - * Damagetextuurit näkyy - * - * Revision 1.17 2002/07/19 12:28:29 msell - * 2D-mode - * - * Revision 1.16 2002/07/17 20:32:47 msell - * Detail-optio toimii - * - * Revision 1.15 2002/07/17 19:06:39 jkaarlas - * skyboxin keskitys - * - * Revision 1.14 2002/07/17 16:40:33 msell - * Resoluution vaihto - * - * Revision 1.13 2002/07/16 17:16:34 msell - * Fontit ja valikot - * - * Revision 1.12 2002/07/16 00:42:43 msell - * Uusia skyboxeja ja areenan säätöä - * - * Revision 1.11 2002/07/15 22:03:22 msell - * MultiAppearance - * - * Revision 1.10 2002/07/15 21:42:58 msell - * Skybox-testi - * - * Revision 1.9 2002/07/15 15:22:07 msell - * Parantelua - * - * Revision 1.8 2002/07/14 21:27:48 jkaarlas - * uudet tekstuurit - * - * Revision 1.7 2002/07/14 21:22:40 jkaarlas - * skybox ja ukkojen säätö - * - * Revision 1.6 2002/06/20 22:50:12 msell - * Meshit - * - * Revision 1.5 2002/06/17 19:58:08 msell - * #includeiden parantelua - * - * Revision 1.4 2002/06/16 01:04:58 jkaarlas - * tulipa säädettyä includejen kanssa. oon tod.näk. eri mieltä aamulla - * - * Revision 1.3 2002/06/05 23:55:46 msell - * Pallo - * - * Revision 1.2 2002/06/04 16:28:32 msell - * #pragma once - * - * Revision 1.1 2002/06/03 23:06:38 msell - * no message - * - * - * - * $Date: 2002/07/22 11:50:26 $ - * - */ - #ifndef __3DUTILS_H_INCLUDED__ #define __3DUTILS_H_INCLUDED__ @@ -100,11 +23,11 @@ extern int SKYBOX; typedef struct{ - float x,y; + float x,y; } point2d; typedef struct{ - float x,y,z; + float x,y,z; } point3d; extern Texture *flaretexture; diff --git a/src/appearance.cpp b/src/appearance.cpp index 2a5bab5..15a77f7 100644 --- a/src/appearance.cpp +++ b/src/appearance.cpp @@ -1,41 +1,3 @@ -/* - * $Id: appearance.cpp,v 1.9 2002/07/15 22:03:23 msell Exp $ - * - * - * $Log: appearance.cpp,v $ - * Revision 1.9 2002/07/15 22:03:23 msell - * MultiAppearance - * - * Revision 1.8 2002/06/24 14:12:15 msell - * Nyt toimii sphere -> mesh -törmäykset, ihan tosi - * - * Revision 1.7 2002/06/20 00:21:01 jkaarlas - * materiaali- ja tekstuurihommia edistetty - * - * Revision 1.6 2002/06/17 20:49:04 msell - * free -> SDL_FreeSurface - * - * Revision 1.5 2002/06/16 01:04:58 jkaarlas - * tulipa säädettyä includejen kanssa. oon tod.näk. eri mieltä aamulla - * - * Revision 1.4 2002/06/05 23:55:46 msell - * Pallo - * - * Revision 1.3 2002/06/03 23:20:43 msell - * no message - * - * Revision 1.2 2002/06/03 23:06:38 msell - * no message - * - * Revision 1.1 2002/06/02 16:57:37 msell - * Objektirakenteen pohja - * - * - * - * $Date: 2002/07/15 22:03:23 $ - * - */ - #include "main.h" @@ -53,19 +15,19 @@ void Appearance::prepare(void){ /*BoxAppearance::BoxAppearance(void){ - setDimension(-1, 1, -1, 1, -1, 1); + setDimension(-1, 1, -1, 1, -1, 1); } BoxAppearance::setDimension(float x1, float x2, float y1, float y2, float z1, float z2){ - if (x1 > x2) swapFloat(&x1, &x2); - if (y1 > y2) swapFloat(&y1, &y2); - if (z1 > z2) swapFloat(&z1, &z2); - this->x1 = x1; - this->x2 = x2; - this->y1 = y1; - this->y2 = y2; - this->z1 = z1; - this->z2 = z2; + if (x1 > x2) swapFloat(&x1, &x2); + if (y1 > y2) swapFloat(&y1, &y2); + if (z1 > z2) swapFloat(&z1, &z2); + this->x1 = x1; + this->x2 = x2; + this->y1 = y1; + this->y2 = y2; + this->z1 = z1; + this->z2 = z2; } void BoxAppearance::draw(void){ @@ -74,43 +36,43 @@ void BoxAppearance::draw(void){ glBegin(GL_QUADS); - //Front Face - glNormal3f(0, 0, 1); - glVertex3f(x1, y1, z2); - glVertex3f(x2, y1, z2); - glVertex3f(x2, y2, z2); - glVertex3f(x1, y2, z2); - // Back Face - glNormal3f(0, 0, -1); - glVertex3f(x1, y1, z1); - glVertex3f(x1, y2, z1); - glVertex3f(x2, y2, z1); - glVertex3f(x2, y1, z1); - // Top Face - glNormal3f(0, 1, 0); - glVertex3f(x1, y2, z1); - glVertex3f(x1, y2, z2); - glVertex3f(x2, y2, z2); - glVertex3f(x2, y2, z1); - // Bottom Face - glNormal3f(0, -1, 0); - glVertex3f(x1, y1, z1); - glVertex3f(x2, y1, z1); - glVertex3f(x2, y1, z2); - glVertex3f(x1, y1, z2); - // Right face - glNormal3f(x2, 0, 0); - glVertex3f(x2, y1, z1); - glVertex3f(x2, y2, z1); - glVertex3f(x2, y2, z2); - glVertex3f(x2, y1, z2); - // Left Face - glNormal3f(x1, 0, 0); - glVertex3f(x1, y1, z1); - glVertex3f(x1, y1, z2); - glVertex3f(x1, y2, z2); - glVertex3f(x1, y2, z1); - glEnd(); + //Front Face + glNormal3f(0, 0, 1); + glVertex3f(x1, y1, z2); + glVertex3f(x2, y1, z2); + glVertex3f(x2, y2, z2); + glVertex3f(x1, y2, z2); + // Back Face + glNormal3f(0, 0, -1); + glVertex3f(x1, y1, z1); + glVertex3f(x1, y2, z1); + glVertex3f(x2, y2, z1); + glVertex3f(x2, y1, z1); + // Top Face + glNormal3f(0, 1, 0); + glVertex3f(x1, y2, z1); + glVertex3f(x1, y2, z2); + glVertex3f(x2, y2, z2); + glVertex3f(x2, y2, z1); + // Bottom Face + glNormal3f(0, -1, 0); + glVertex3f(x1, y1, z1); + glVertex3f(x2, y1, z1); + glVertex3f(x2, y1, z2); + glVertex3f(x1, y1, z2); + // Right face + glNormal3f(x2, 0, 0); + glVertex3f(x2, y1, z1); + glVertex3f(x2, y2, z1); + glVertex3f(x2, y2, z2); + glVertex3f(x2, y1, z2); + // Left Face + glNormal3f(x1, 0, 0); + glVertex3f(x1, y1, z1); + glVertex3f(x1, y1, z2); + glVertex3f(x1, y2, z2); + glVertex3f(x1, y2, z1); + glEnd(); this->material.disable(); }*/ @@ -128,28 +90,28 @@ void Appearance::setMaterial(Material matsku){ MultiAppearance::MultiAppearance(void){ - appearances = NULL; + appearances = NULL; } void MultiAppearance::addAppearance(Appearance *appearance){ - appearancelist *node = new appearancelist; - node->data = appearance; - node->next = appearances; - appearances = node; + appearancelist *node = new appearancelist; + node->data = appearance; + node->next = appearances; + appearances = node; } void MultiAppearance::prepare(void){ - appearancelist *node = appearances; - while (node != NULL){ - node->data->prepare(); - node = node->next; - } + appearancelist *node = appearances; + while (node != NULL){ + node->data->prepare(); + node = node->next; + } } void MultiAppearance::draw(void){ - appearancelist *node = appearances; - while (node != NULL){ - node->data->draw(); - node = node->next; - } -} \ No newline at end of file + appearancelist *node = appearances; + while (node != NULL){ + node->data->draw(); + node = node->next; + } +} diff --git a/src/appearance.h b/src/appearance.h index 6f16756..19c278e 100644 --- a/src/appearance.h +++ b/src/appearance.h @@ -1,47 +1,3 @@ -/* - * $Id: appearance.h,v 1.11 2002/07/19 20:33:28 msell Exp $ - * - * - * $Log: appearance.h,v $ - * Revision 1.11 2002/07/19 20:33:28 msell - * #pragma once -> #ifndef - * - * Revision 1.10 2002/07/15 22:03:23 msell - * MultiAppearance - * - * Revision 1.9 2002/07/07 17:53:21 msell - * Legoukon alku - * - * Revision 1.8 2002/06/24 14:12:15 msell - * Nyt toimii sphere -> mesh -törmäykset, ihan tosi - * - * Revision 1.7 2002/06/20 00:21:01 jkaarlas - * materiaali- ja tekstuurihommia edistetty - * - * Revision 1.6 2002/06/17 20:49:04 msell - * free -> SDL_FreeSurface - * - * Revision 1.5 2002/06/17 19:58:08 msell - * #includeiden parantelua - * - * Revision 1.4 2002/06/04 16:28:32 msell - * #pragma once - * - * Revision 1.3 2002/06/03 23:20:43 msell - * no message - * - * Revision 1.2 2002/06/03 23:06:38 msell - * no message - * - * Revision 1.1 2002/06/02 16:57:37 msell - * Objektirakenteen pohja - * - * - * - * $Date: 2002/07/19 20:33:28 $ - * - */ - #ifndef __APPEARANCE_H_INCLUDED__ #define __APPEARANCE_H_INCLUDED__ @@ -62,26 +18,26 @@ public: Material* getMaterial(void); void setMaterial(Material mat); - virtual void prepare(void); - virtual void draw(void) = 0; + virtual void prepare(void); + virtual void draw(void) = 0; }; struct appearancelist{ - Appearance *data; - appearancelist *next; + Appearance *data; + appearancelist *next; }; class MultiAppearance : public Appearance{ private: - appearancelist *appearances; + appearancelist *appearances; public: - MultiAppearance(void); - void addAppearance(Appearance *appearance); + MultiAppearance(void); + void addAppearance(Appearance *appearance); - void prepare(void); - void draw(void); + void prepare(void); + void draw(void); }; #endif diff --git a/src/audio.cpp b/src/audio.cpp index e06168c..b357633 100644 --- a/src/audio.cpp +++ b/src/audio.cpp @@ -1,42 +1,3 @@ -/* - * $Id: audio.cpp,v 1.9 2002/07/21 15:03:11 msell Exp $ - * - * - * $Log: audio.cpp,v $ - * Revision 1.9 2002/07/21 15:03:11 msell - * Äänet disabloitu - * - * Revision 1.8 2002/07/19 18:59:46 msell - * Alkuhommaa ja säätöä - * - * Revision 1.7 2002/07/18 23:05:31 msell - * Partikkelit ja kakkospelaajan liike - * - * Revision 1.6 2002/06/02 16:57:37 msell - * Objektirakenteen pohja - * - * Revision 1.5 2002/05/19 13:40:19 msell - * Säätöä - * - * Revision 1.4 2002/05/18 12:29:35 msell - * Valot ja äänijärjestelmän parantelua - * - * Revision 1.3 2002/05/15 21:07:23 msell - * Äänisäätöä - * - * Revision 1.2 2002/05/15 15:21:00 msell - * Äänisäätöä - * - * Revision 1.1 2002/05/15 14:36:38 msell - * Yksinkertainen SDL-runko (Kääntyy toistaiseksi vain windowsissa). - * Mukana myös musiikinsoitto fmodilla. - * - * - * - * $Date: 2002/07/21 15:03:11 $ - * - */ - #include "main.h" #include @@ -51,259 +12,259 @@ struct soundlist{ - Sound *sound; - soundlist *next; + Sound *sound; + soundlist *next; }; soundlist *allsounds = NULL; Sound::Sound(Sound *source){ - memcpy(this, source, sizeof(Sound)); - soundlist *node = new soundlist; - node->sound = this; - node->next = allsounds; - allsounds = node; + memcpy(this, source, sizeof(Sound)); + soundlist *node = new soundlist; + node->sound = this; + node->next = allsounds; + allsounds = node; } Sound::Sound(char *filename){ - load(filename, SOUNDTYPE_AUTODETECT, false); - //printf("%s: %p, %p, %p, %p\n", filename, this, stream, sample, module); + load(filename, SOUNDTYPE_AUTODETECT, false); + //printf("%s: %p, %p, %p, %p\n", filename, this, stream, sample, module); } Sound::Sound(char *filename, int type){ - load(filename, type, false); + load(filename, type, false); } Sound::Sound(char *filename, bool loops){ - load(filename, SOUNDTYPE_AUTODETECT, loops); - //printf("%s: %p, %p, %p, %p\n", filename, this, stream, sample, module); + load(filename, SOUNDTYPE_AUTODETECT, loops); + //printf("%s: %p, %p, %p, %p\n", filename, this, stream, sample, module); } Sound::Sound(char *filename, int type, bool loops){ - load(filename, type, loops); + load(filename, type, loops); } bool endsWith(char *str1, char *str2){ - char *str3 = str1 + strlen(str1) - strlen(str2); + char *str3 = str1 + strlen(str1) - strlen(str2); #ifdef WIN32 - if (stricmp(str3, str2)) return false; + if (stricmp(str3, str2)) return false; #else - if (strcasecmp(str3, str2)) return false; + if (strcasecmp(str3, str2)) return false; #endif - else return true; + else return true; } void Sound::load(char *filename, int type, bool loops){ - this->filename = filename; - if (type == SOUNDTYPE_AUTODETECT){ - if (endsWith(filename, "mp3") || - endsWith(filename, "mp2") || - endsWith(filename, "ogg")) type = SOUNDTYPE_STREAM; + this->filename = filename; + if (type == SOUNDTYPE_AUTODETECT){ + if (endsWith(filename, "mp3") || + endsWith(filename, "mp2") || + endsWith(filename, "ogg")) type = SOUNDTYPE_STREAM; - if (endsWith(filename, "wav") || - endsWith(filename, "raw")) type = SOUNDTYPE_SAMPLE; - - if (endsWith(filename, "s3m") || - endsWith(filename, "xm") || - endsWith(filename, "it") || - endsWith(filename, "mid") || - endsWith(filename, "rmi") || - endsWith(filename, "sgr") || - endsWith(filename, "mod")) type = SOUNDTYPE_MODULE; - } + if (endsWith(filename, "wav") || + endsWith(filename, "raw")) type = SOUNDTYPE_SAMPLE; + + if (endsWith(filename, "s3m") || + endsWith(filename, "xm") || + endsWith(filename, "it") || + endsWith(filename, "mid") || + endsWith(filename, "rmi") || + endsWith(filename, "sgr") || + endsWith(filename, "mod")) type = SOUNDTYPE_MODULE; + } #ifdef AUDIO_FMOD - sample = NULL; - module = NULL; - stream = NULL; - this->type = type; - if (type == SOUNDTYPE_MODULE){ - module = FMUSIC_LoadSong(filename); - this->loops = false; - } else if (type == SOUNDTYPE_SAMPLE){ - if (loops){ - sample = FSOUND_Sample_Load(FSOUND_FREE, filename, FSOUND_LOOP_NORMAL, 0); - FSOUND_Sample_SetLoopMode(sample, FSOUND_LOOP_NORMAL); - } else{ - sample = FSOUND_Sample_Load(FSOUND_FREE, filename, FSOUND_LOOP_OFF, 0); - FSOUND_Sample_SetLoopMode(sample, FSOUND_LOOP_OFF); - } - this->loops = loops; - } else if (type == SOUNDTYPE_STREAM){ - if (loops){ - stream = FSOUND_Stream_OpenFile(filename, FSOUND_LOOP_NORMAL, 0); - } else{ - stream = FSOUND_Stream_OpenFile(filename, FSOUND_LOOP_OFF, 0); - } - this->loops = loops; - } + sample = NULL; + module = NULL; + stream = NULL; + this->type = type; + if (type == SOUNDTYPE_MODULE){ + module = FMUSIC_LoadSong(filename); + this->loops = false; + } else if (type == SOUNDTYPE_SAMPLE){ + if (loops){ + sample = FSOUND_Sample_Load(FSOUND_FREE, filename, FSOUND_LOOP_NORMAL, 0); + FSOUND_Sample_SetLoopMode(sample, FSOUND_LOOP_NORMAL); + } else{ + sample = FSOUND_Sample_Load(FSOUND_FREE, filename, FSOUND_LOOP_OFF, 0); + FSOUND_Sample_SetLoopMode(sample, FSOUND_LOOP_OFF); + } + this->loops = loops; + } else if (type == SOUNDTYPE_STREAM){ + if (loops){ + stream = FSOUND_Stream_OpenFile(filename, FSOUND_LOOP_NORMAL, 0); + } else{ + stream = FSOUND_Stream_OpenFile(filename, FSOUND_LOOP_OFF, 0); + } + this->loops = loops; + } #endif - stopcallback = NULL; - soundlist *node = new soundlist; - node->sound = this; - node->next = allsounds; - allsounds = node; - minduration = 0; - setVolume(1.0); + stopcallback = NULL; + soundlist *node = new soundlist; + node->sound = this; + node->next = allsounds; + allsounds = node; + minduration = 0; + setVolume(1.0); } bool Sound::play(){ - //printf("Playing %s: %p, %p, %p, %p\n", filename, this, stream, sample, module); - if (minduration > 0) return false; - running = true; - finished = false; - fademode = SOUND_FADENONE; - minduration = 0; + //printf("Playing %s: %p, %p, %p, %p\n", filename, this, stream, sample, module); + if (minduration > 0) return false; + running = true; + finished = false; + fademode = SOUND_FADENONE; + minduration = 0; #ifdef AUDIO_FMOD - if (type == SOUNDTYPE_MODULE){ - FMUSIC_PlaySong(module); - FMUSIC_SetMasterVolume(module, volume*256); - } else if (type == SOUNDTYPE_SAMPLE){ - channel = FSOUND_PlaySound(FSOUND_FREE, sample); - FSOUND_SetVolume(channel, volume*256); - if (!loops){ - running = false; - finished = false; - } - } else if (type == SOUNDTYPE_STREAM){ - channel = FSOUND_Stream_Play(FSOUND_FREE, stream); - FSOUND_SetVolume(channel, volume*256); - } + if (type == SOUNDTYPE_MODULE){ + FMUSIC_PlaySong(module); + FMUSIC_SetMasterVolume(module, volume*256); + } else if (type == SOUNDTYPE_SAMPLE){ + channel = FSOUND_PlaySound(FSOUND_FREE, sample); + FSOUND_SetVolume(channel, volume*256); + if (!loops){ + running = false; + finished = false; + } + } else if (type == SOUNDTYPE_STREAM){ + channel = FSOUND_Stream_Play(FSOUND_FREE, stream); + FSOUND_SetVolume(channel, volume*256); + } #endif - //printf("Done: %f\n", volume); - return true; + //printf("Done: %f\n", volume); + return true; } void Sound::play(int minduration){ - if (play()) this->minduration = minduration; + if (play()) this->minduration = minduration; } void Sound::stop(){ #ifdef AUDIO_FMOD - if (type == SOUNDTYPE_MODULE){ - FMUSIC_StopSong(module); - } else if (type == SOUNDTYPE_SAMPLE){ - FSOUND_StopSound(channel); - } else if (type == SOUNDTYPE_STREAM){ - FSOUND_Stream_Stop(stream); - } + if (type == SOUNDTYPE_MODULE){ + FMUSIC_StopSong(module); + } else if (type == SOUNDTYPE_SAMPLE){ + FSOUND_StopSound(channel); + } else if (type == SOUNDTYPE_STREAM){ + FSOUND_Stream_Stop(stream); + } #endif } void Sound::setVolume(float volume){ - //printf("Volume %s: %f\n", filename, volume); + //printf("Volume %s: %f\n", filename, volume); #ifdef AUDIO_FMOD - if (type == SOUNDTYPE_MODULE){ - FMUSIC_SetMasterVolume(module, volume*256); - } else if (type == SOUNDTYPE_SAMPLE){ - FSOUND_SetVolume(channel, volume*256); - } else if (type == SOUNDTYPE_STREAM){ - FSOUND_SetVolume(channel, volume*256); - } + if (type == SOUNDTYPE_MODULE){ + FMUSIC_SetMasterVolume(module, volume*256); + } else if (type == SOUNDTYPE_SAMPLE){ + FSOUND_SetVolume(channel, volume*256); + } else if (type == SOUNDTYPE_STREAM){ + FSOUND_SetVolume(channel, volume*256); + } #endif - this->volume = volume; + this->volume = volume; } #ifdef AUDIO_FMOD signed char streamendcallback(FSOUND_STREAM *stream, void *buff, int len, int param){ - Sound *sound = (Sound *)param; - sound->setFinished(); - return true; + Sound *sound = (Sound *)param; + sound->setFinished(); + return true; } #endif void Sound::setStopCallback(STOPCALLBACK callback){ - stopcallback = callback; + stopcallback = callback; #ifdef AUDIO_FMOD - if (type == SOUNDTYPE_MODULE){ - } else if (type == SOUNDTYPE_SAMPLE){ - //NOT SUPPORTED - } else if (type == SOUNDTYPE_STREAM){ - FSOUND_Stream_SetEndCallback(stream, streamendcallback, (int)this); - } + if (type == SOUNDTYPE_MODULE){ + } else if (type == SOUNDTYPE_SAMPLE){ + //NOT SUPPORTED + } else if (type == SOUNDTYPE_STREAM){ + FSOUND_Stream_SetEndCallback(stream, streamendcallback, (int)this); + } #endif } void Sound::setFinished(void){ - finished = true; + finished = true; } bool Sound::isFinished(void){ #ifdef AUDIO_FMOD - if (type == SOUNDTYPE_MODULE){ - if (FMUSIC_IsFinished(module)) return true; - } else if (type == SOUNDTYPE_SAMPLE){ - //NOT SUPPORTED - } else if (type == SOUNDTYPE_STREAM){ - if (finished) return true; - } + if (type == SOUNDTYPE_MODULE){ + if (FMUSIC_IsFinished(module)) return true; + } else if (type == SOUNDTYPE_SAMPLE){ + //NOT SUPPORTED + } else if (type == SOUNDTYPE_STREAM){ + if (finished) return true; + } #endif - return false; + return false; } void Sound::update(void){ - if (running){ - if (isFinished()){ - running = false; - if (stopcallback != NULL) stopcallback(this); - } else{ - if (fademode == SOUND_FADEIN){ - if (fadepos < fadetarget){ - fadepos++; - setVolume((float)fadepos/fadetarget); - } else fademode = SOUND_FADENONE; - } - if (fademode == SOUND_FADEOUT){ - if (fadepos < fadetarget){ - fadepos++; - setVolume(1.0 - (float)fadepos/fadetarget); - } else{ - fademode = SOUND_FADENONE; - stop(); - } - } - } - } - if (minduration > 0) minduration--; + if (running){ + if (isFinished()){ + running = false; + if (stopcallback != NULL) stopcallback(this); + } else{ + if (fademode == SOUND_FADEIN){ + if (fadepos < fadetarget){ + fadepos++; + setVolume((float)fadepos/fadetarget); + } else fademode = SOUND_FADENONE; + } + if (fademode == SOUND_FADEOUT){ + if (fadepos < fadetarget){ + fadepos++; + setVolume(1.0 - (float)fadepos/fadetarget); + } else{ + fademode = SOUND_FADENONE; + stop(); + } + } + } + } + if (minduration > 0) minduration--; } void Sound::fadeIn(int length){ - fademode = SOUND_FADEIN; - fadepos = 0; - fadetarget = length; + fademode = SOUND_FADEIN; + fadepos = 0; + fadetarget = length; } void Sound::fadeOut(int length){ - if (fademode == SOUND_FADEIN){ - float percent = 1.0 - (float)fadepos/fadetarget; - fadepos = fadetarget * percent; - } - fadepos = 0; - fadetarget = length; - fademode = SOUND_FADEOUT; + if (fademode == SOUND_FADEIN){ + float percent = 1.0 - (float)fadepos/fadetarget; + fadepos = fadetarget * percent; + } + fadepos = 0; + fadetarget = length; + fademode = SOUND_FADEOUT; } void initAudio(void){ #ifdef AUDIO_FMOD - FSOUND_Init(44100, 32, 0); + FSOUND_Init(44100, 32, 0); #endif } void uninitAudio(void){ #ifdef AUDIO_FMOD - FSOUND_Close(); + FSOUND_Close(); #endif } void updateAudio(void){ - soundlist *node = allsounds; - while (node != NULL){ - Sound *sound = node->sound; - sound->update(); - node = node->next; - } -} \ No newline at end of file + soundlist *node = allsounds; + while (node != NULL){ + Sound *sound = node->sound; + sound->update(); + node = node->next; + } +} diff --git a/src/audio.h b/src/audio.h index 3f73123..73daa86 100644 --- a/src/audio.h +++ b/src/audio.h @@ -1,54 +1,3 @@ -/* - * $Id: audio.h,v 1.13 2002/07/21 15:12:16 msell Exp $ - * - * - * $Log: audio.h,v $ - * Revision 1.13 2002/07/21 15:12:16 msell - * Äänet enabloitu :) - * - * Revision 1.12 2002/07/21 15:03:12 msell - * Äänet disabloitu - * - * Revision 1.11 2002/07/19 20:33:28 msell - * #pragma once -> #ifndef - * - * Revision 1.10 2002/07/19 18:59:46 msell - * Alkuhommaa ja säätöä - * - * Revision 1.9 2002/07/18 23:05:31 msell - * Partikkelit ja kakkospelaajan liike - * - * Revision 1.8 2002/07/14 21:22:40 jkaarlas - * skybox ja ukkojen säätö - * - * Revision 1.7 2002/06/04 16:28:32 msell - * #pragma once - * - * Revision 1.6 2002/05/19 13:40:19 msell - * Säätöä - * - * Revision 1.5 2002/05/18 12:29:35 msell - * Valot ja äänijärjestelmän parantelua - * - * Revision 1.4 2002/05/16 18:41:16 msell - * Vektorifunctioita ja kamera - * - * Revision 1.3 2002/05/15 21:07:23 msell - * Äänisäätöä - * - * Revision 1.2 2002/05/15 15:21:00 msell - * Äänisäätöä - * - * Revision 1.1 2002/05/15 14:36:39 msell - * Yksinkertainen SDL-runko (Kääntyy toistaiseksi vain windowsissa). - * Mukana myös musiikinsoitto fmodilla. - * - * - * - * $Date: 2002/07/21 15:12:16 $ - * - */ - #ifndef __AUDIO_H_INCLUDED__ #define __AUDIO_H_INCLUDED__ @@ -79,47 +28,47 @@ typedef void(* STOPCALLBACK)(Sound *sound); class Sound{ private: #ifdef AUDIO_FMOD - int type; - FMUSIC_MODULE *module; - FSOUND_STREAM *stream; - FSOUND_SAMPLE *sample; - int channel; + int type; + FMUSIC_MODULE *module; + FSOUND_STREAM *stream; + FSOUND_SAMPLE *sample; + int channel; #endif - bool loops; - bool finished; - bool running; - float volume; - STOPCALLBACK stopcallback; - bool isFinished(void); + bool loops; + bool finished; + bool running; + float volume; + STOPCALLBACK stopcallback; + bool isFinished(void); - int fadepos, fadetarget; - int fademode; + int fadepos, fadetarget; + int fademode; - int minduration; + int minduration; - char *filename; + char *filename; public: - Sound(Sound *source); - Sound(char *filename); - Sound(char *filename, int type); - Sound(char *filename, bool loops); - Sound(char *filename, int type, bool loops); - void load(char *filename, int type, bool loops); - bool play(void); + Sound(Sound *source); + Sound(char *filename); + Sound(char *filename, int type); + Sound(char *filename, bool loops); + Sound(char *filename, int type, bool loops); + void load(char *filename, int type, bool loops); + bool play(void); - //Plays sound for at least minduration frames until sound - //can be played again. Doesn't prevent stopping of the sound - void play(int minduration); - void stop(); - void setStopCallback(STOPCALLBACK callback); - void setVolume(float volume); - void fadeIn(int length); - void fadeOut(int length); - - //Do not use methods below - void setFinished(void); - void update(void); + //Plays sound for at least minduration frames until sound + //can be played again. Doesn't prevent stopping of the sound + void play(int minduration); + void stop(); + void setStopCallback(STOPCALLBACK callback); + void setVolume(float volume); + void fadeIn(int length); + void fadeOut(int length); + + //Do not use methods below + void setFinished(void); + void update(void); }; void initAudio(void); diff --git a/src/camera.cpp b/src/camera.cpp index 5c0237f..e873a68 100644 --- a/src/camera.cpp +++ b/src/camera.cpp @@ -1,29 +1,3 @@ -/* - * $Id: camera.cpp,v 1.5 2002/07/22 01:14:14 msell Exp $ - * - * - * $Log: camera.cpp,v $ - * Revision 1.5 2002/07/22 01:14:14 msell - * Lopetussysteemi - * - * Revision 1.4 2002/06/17 20:49:04 msell - * free -> SDL_FreeSurface - * - * Revision 1.3 2002/06/16 01:04:58 jkaarlas - * tulipa säädettyä includejen kanssa. oon tod.näk. eri mieltä aamulla - * - * Revision 1.2 2002/06/03 23:06:38 msell - * no message - * - * Revision 1.1 2002/05/16 18:42:07 msell - * Vektorifunctioita ja kamera - * - * - * - * $Date: 2002/07/22 01:14:14 $ - * - */ - #include "main.h" #include "camera.h" @@ -31,83 +5,83 @@ #include "glapi.h" Camera::Camera(void){ - right = &matrix[0]; - up = &matrix[3]; - forward = &matrix[6]; + right = &matrix[0]; + up = &matrix[3]; + forward = &matrix[6]; - vectorSet(position, 0, 2, 2); - vectorSet(target, 0, 0, 0); - vectorSet(up, 0, 1, 0); + vectorSet(position, 0, 2, 2); + vectorSet(target, 0, 0, 0); + vectorSet(up, 0, 1, 0); - calculateMatrix(); + calculateMatrix(); } void Camera::setPosition(float position[3]){ - vectorCopy(this->position, position); + vectorCopy(this->position, position); } void Camera::setPosition(float x, float y, float z){ - this->position[0] = x; - this->position[1] = y; - this->position[2] = z; + this->position[0] = x; + this->position[1] = y; + this->position[2] = z; } void Camera::getPosition(float *position){ - vectorCopy(position, this->position); + vectorCopy(position, this->position); } void Camera::setTarget(float target[3]){ - vectorCopy(this->target, target); + vectorCopy(this->target, target); } void Camera::getTarget(float *target){ - vectorCopy(target, this->target); + vectorCopy(target, this->target); } void Camera::setUp(float up[3]){ - vectorCopy(this->up, up); + vectorCopy(this->up, up); } void Camera::getMatrix(float *matrix){ - vectorCopy(&matrix[0], &this->matrix[0]); - vectorCopy(&matrix[3], &this->matrix[3]); - vectorCopy(&matrix[6], &this->matrix[6]); + vectorCopy(&matrix[0], &this->matrix[0]); + vectorCopy(&matrix[3], &this->matrix[3]); + vectorCopy(&matrix[6], &this->matrix[6]); } void Camera::moveRight(float amount){ - float movevector[3]; - vectorScale(movevector, right, amount); - vectorAdd(position, movevector); - //vectorAdd(target, movevector); - calculateMatrix(); + float movevector[3]; + vectorScale(movevector, right, amount); + vectorAdd(position, movevector); + //vectorAdd(target, movevector); + calculateMatrix(); } void Camera::moveUp(float amount){ - float movevector[3]; - vectorScale(movevector, up, amount); - vectorAdd(position, movevector); - //vectorAdd(target, movevector); - calculateMatrix(); + float movevector[3]; + vectorScale(movevector, up, amount); + vectorAdd(position, movevector); + //vectorAdd(target, movevector); + calculateMatrix(); } void Camera::moveForward(float amount){ - float movevector[3]; - vectorScale(movevector, forward, amount); - vectorAdd(position, movevector); - //vectorAdd(target, movevector); - calculateMatrix(); + float movevector[3]; + vectorScale(movevector, forward, amount); + vectorAdd(position, movevector); + //vectorAdd(target, movevector); + calculateMatrix(); } void Camera::glUpdate(void){ - //glLoadIdentity(); + //glLoadIdentity(); - gluLookAt(position[0], position[1], position[2], - target[0], target[1], target[2], - up[0], up[1], up[2]); + gluLookAt(position[0], position[1], position[2], + target[0], target[1], target[2], + up[0], up[1], up[2]); } void Camera::calculateMatrix(void){ - vectorSub(forward, target, position); - vectorNormalize(forward); - vectorCross(right, forward, up); + vectorSub(forward, target, position); + vectorNormalize(forward); + vectorCross(right, forward, up); } diff --git a/src/camera.h b/src/camera.h index 5d6037f..e3e9591 100644 --- a/src/camera.h +++ b/src/camera.h @@ -1,54 +1,31 @@ -/* - * $Id: camera.h,v 1.4 2002/07/19 20:33:28 msell Exp $ - * - * - * $Log: camera.h,v $ - * Revision 1.4 2002/07/19 20:33:28 msell - * #pragma once -> #ifndef - * - * Revision 1.3 2002/06/04 16:28:32 msell - * #pragma once - * - * Revision 1.2 2002/06/03 23:06:38 msell - * no message - * - * Revision 1.1 2002/05/16 18:42:07 msell - * Vektorifunctioita ja kamera - * - * - * - * $Date: 2002/07/19 20:33:28 $ - * - */ - #ifndef __CAMERA_H_INCLUDED__ #define __CAMERA_H_INCLUDED__ class Camera{ private: - float position[3]; - float target[3]; - float matrix[9]; - float *right, *up, *forward; + float position[3]; + float target[3]; + float matrix[9]; + float *right, *up, *forward; - void calculateMatrix(void); + void calculateMatrix(void); public: - Camera(void); + Camera(void); - void setPosition(float position[3]); - void setPosition(float x, float y, float z); - void getPosition(float *position); - void setTarget(float target[3]); - void getTarget(float *target); - void setUp(float up[3]); - void getMatrix(float *matrix); + void setPosition(float position[3]); + void setPosition(float x, float y, float z); + void getPosition(float *position); + void setTarget(float target[3]); + void getTarget(float *target); + void setUp(float up[3]); + void getMatrix(float *matrix); - void moveRight(float amount); - void moveUp(float amount); - void moveForward(float amount); + void moveRight(float amount); + void moveUp(float amount); + void moveForward(float amount); - void glUpdate(void); + void glUpdate(void); }; #endif diff --git a/src/collision.cpp b/src/collision.cpp index 4e3dcbe..e43255a 100644 --- a/src/collision.cpp +++ b/src/collision.cpp @@ -1,88 +1,3 @@ -/* - * $Id: collision.cpp,v 1.24 2002/07/21 15:03:12 msell Exp $ - * - * - * $Log: collision.cpp,v $ - * Revision 1.24 2002/07/21 15:03:12 msell - * Äänet disabloitu - * - * Revision 1.23 2002/07/19 18:59:46 msell - * Alkuhommaa ja säätöä - * - * Revision 1.22 2002/07/18 23:05:31 msell - * Partikkelit ja kakkospelaajan liike - * - * Revision 1.21 2002/07/17 22:45:53 msell - * Ääniä vähän - * - * Revision 1.20 2002/07/15 15:22:07 msell - * Parantelua - * - * Revision 1.19 2002/07/14 21:40:43 msell - * Conflictit pois, liikkumiset (hyppy, kävely, lyönti), uusi areena - * - * Revision 1.18 2002/07/10 17:13:44 msell - * Törmäystarkastelun parantelua - * - * Revision 1.17 2002/07/08 22:53:38 msell - * Säätöä - * - * Revision 1.16 2002/07/08 18:28:47 msell - * Törmäystä ja ukkoja - * - * Revision 1.15 2002/07/07 23:21:11 msell - * Pientä parantelua - * - * Revision 1.14 2002/07/07 23:05:22 msell - * Osien liimaaminen toisiinsa (kesken) - * - * Revision 1.13 2002/07/07 15:29:07 msell - * Törmäyksien parantelua - * - * Revision 1.12 2002/07/04 21:05:41 msell - * Se toimii!! =) - * Törmäystarkistukset siis - * - * Revision 1.11 2002/06/30 16:05:04 msell - * Törmäyksien parantelua, transformaatioita mukana - * - * Revision 1.10 2002/06/27 14:39:48 msell - * Toimiva maila :) - * Pyörivät kappaleet siis antaa liike-energiaa liikkuville kappaleille (ei toisin päin vielä) - * - * Revision 1.9 2002/06/27 00:08:04 msell - * Kimmotukset palloille myös pyöritettyihin mesheihin - * - * Revision 1.8 2002/06/23 20:12:19 msell - * Parempi törmäystarkistus palloista mesheihin - * - * Revision 1.7 2002/06/20 22:50:12 msell - * Meshit - * - * Revision 1.6 2002/06/17 12:42:46 msell - * Hieman parempi törmäysmallinnus taas - * - * Revision 1.5 2002/06/15 22:56:37 msell - * Säätöä - * - * Revision 1.4 2002/06/15 17:18:37 msell - * Toimiva törmäystarkastus kiinteille laatikoille - * - * Revision 1.3 2002/06/14 00:26:17 msell - * 100 kimpoilevaa palloa ja vähän vaimennusta - * - * Revision 1.2 2002/06/14 00:05:05 msell - * Törmäyssimulaatio kunnossa toivon mukaan - * - * Revision 1.1 2002/06/11 23:11:45 msell - * Törmäystarkistusta - * - * - * - * $Date: 2002/07/21 15:03:12 $ - * - */ - #include #include @@ -102,496 +17,496 @@ Contact *contacts; int contactcount; void initCollisions(void){ - int i; - for (i = 0; i < 32; i++){ - //collisionlists[i] = NULL; - collisionlinks[i] = 0; - } + int i; + for (i = 0; i < 32; i++){ + //collisionlists[i] = NULL; + collisionlinks[i] = 0; + } } /*void addCollisionObject(Object *object, int group){ - objectlist *node = new objectlist; - node->object = object; - node->next = collisionlists[group]; - collisionlists[group] = node; + objectlist *node = new objectlist; + node->object = object; + node->next = collisionlists[group]; + collisionlists[group] = node; }*/ void addCollisionLink(int source, int target){ - collisionlinks[source] |= (1<object1 = source; - contact->object2 = target; - vectorCopy(contact->normal, normal); - vectorCopy(contact->position, contactpoint); + float *normal, float *contactpoint){ + if (contactcount == MAXCONTACTS){ + printf("Too many contacts!\n"); + return; + } + Contact *contact = &contacts[contactcount++]; + contact->object1 = source; + contact->object2 = target; + vectorCopy(contact->normal, normal); + vectorCopy(contact->position, contactpoint); } #define KINETICFRICTION 0.4 bool handleCollision(Contact *contact){ - Object *source = contact->object1; - Object *target = contact->object2; - float *normal = contact->normal; - float *contactpoint = contact->position; + Object *source = contact->object1; + Object *target = contact->object2; + float *normal = contact->normal; + float *contactpoint = contact->position; - float sourcevelocity[3], targetvelocity[3]; - float sourcecontactpoint[3], targetcontactpoint[3]; + float sourcevelocity[3], targetvelocity[3]; + float sourcecontactpoint[3], targetcontactpoint[3]; - vectorSub(sourcecontactpoint, contactpoint, source->position); - source->getVelocity(sourcevelocity, sourcecontactpoint); - - if (target == NULL){ - vectorSet(targetcontactpoint, 0, 0, 0); - vectorSet(targetvelocity, 0, 0, 0); - } else{ - vectorSub(targetcontactpoint, contactpoint, target->position); - target->getVelocity(targetvelocity, targetcontactpoint); - } + vectorSub(sourcecontactpoint, contactpoint, source->position); + source->getVelocity(sourcevelocity, sourcecontactpoint); - float deltavelocity[3]; - vectorSub(deltavelocity, sourcevelocity, targetvelocity); - float dot = vectorDot(deltavelocity, normal); + if (target == NULL){ + vectorSet(targetcontactpoint, 0, 0, 0); + vectorSet(targetvelocity, 0, 0, 0); + } else{ + vectorSub(targetcontactpoint, contactpoint, target->position); + target->getVelocity(targetvelocity, targetcontactpoint); + } - //if (fabs(dot) < EPSILON) return false; - //if (dot > -1.0e-5 && dot < 1.0e-5) return false; - //if (dot >= 0) return false; - if (dot > -1.0e-5) return false; + float deltavelocity[3]; + vectorSub(deltavelocity, sourcevelocity, targetvelocity); + float dot = vectorDot(deltavelocity, normal); + + //if (fabs(dot) < EPSILON) return false; + //if (dot > -1.0e-5 && dot < 1.0e-5) return false; + //if (dot >= 0) return false; + if (dot > -1.0e-5) return false; - float invmass1; - invmass1 = source->invmass; + float invmass1; + invmass1 = source->invmass; - float invmass2; - if (target == NULL) invmass2 = 0; - else invmass2 = target->invmass; + float invmass2; + if (target == NULL) invmass2 = 0; + else invmass2 = target->invmass; - float t1; - if (source->invmomentofinertia == 0){ - t1 = 0; - } else{ - float v1[3]; - vectorCross(v1, sourcecontactpoint, normal); - vectorScale(v1, source->invmomentofinertia); - float w1[3]; - vectorCross(w1, v1, sourcecontactpoint); - t1 = vectorDot(normal, w1); - } + float t1; + if (source->invmomentofinertia == 0){ + t1 = 0; + } else{ + float v1[3]; + vectorCross(v1, sourcecontactpoint, normal); + vectorScale(v1, source->invmomentofinertia); + float w1[3]; + vectorCross(w1, v1, sourcecontactpoint); + t1 = vectorDot(normal, w1); + } - float t2; - if (target == NULL || target->invmomentofinertia == 0){ - t2 = 0; - } else{ - float v1[3]; - vectorCross(v1, targetcontactpoint, normal); - vectorScale(v1, target->invmomentofinertia); - float w1[3]; - vectorCross(w1, v1, targetcontactpoint); - t2 = vectorDot(normal, w1); - } + float t2; + if (target == NULL || target->invmomentofinertia == 0){ + t2 = 0; + } else{ + float v1[3]; + vectorCross(v1, targetcontactpoint, normal); + vectorScale(v1, target->invmomentofinertia); + float w1[3]; + vectorCross(w1, v1, targetcontactpoint); + t2 = vectorDot(normal, w1); + } - float denominator = invmass1 + invmass2 + t1 + t2; + float denominator = invmass1 + invmass2 + t1 + t2; - float e = 1.0 - COLLISIONFRICTION; + float e = 1.0 - COLLISIONFRICTION; - float impulsesize = (1 + e) * dot / denominator; + float impulsesize = (1 + e) * dot / denominator; - //printf("%f\n", impulsesize); + //printf("%f\n", impulsesize); - float impulse[3]; - vectorScale(impulse, normal, impulsesize); + float impulse[3]; + vectorScale(impulse, normal, impulsesize); - float friction[3]; - vectorScale(friction, normal, vectorDot(deltavelocity, normal)); - vectorAdd(friction, deltavelocity); - vectorNormalize(friction); - float frictionsize = 10*KINETICFRICTION*dot/denominator; - float maxfrictionsize = 0.1*vectorLength(deltavelocity); - if (frictionsize < -maxfrictionsize) frictionsize = -maxfrictionsize; - vectorScale(friction, -frictionsize); - vectorAdd(impulse, friction); + float friction[3]; + vectorScale(friction, normal, vectorDot(deltavelocity, normal)); + vectorAdd(friction, deltavelocity); + vectorNormalize(friction); + float frictionsize = 10*KINETICFRICTION*dot/denominator; + float maxfrictionsize = 0.1*vectorLength(deltavelocity); + if (frictionsize < -maxfrictionsize) frictionsize = -maxfrictionsize; + vectorScale(friction, -frictionsize); + vectorAdd(impulse, friction); - if (target != NULL){ - target->addImpulse(impulse, targetcontactpoint); - target->calculateStateVariables(); - } + if (target != NULL){ + target->addImpulse(impulse, targetcontactpoint); + target->calculateStateVariables(); + } - float speed; - float speed2[3]; + float speed; + float speed2[3]; - if (target != NULL && source != NULL){ - //float kvel[3]; - //source->getVelocity(kvel); - float k = vectorLength(sourcevelocity)*0.1; - //if (k > 1) k = 1; - speed = -impulsesize*target->invmass*k; - vectorScale(speed2, impulse, target->invmass*k); - /*float kvel[3]; - source->getVelocity(kvel); - float k = 0;//vectorDot(speed2, kvel); - if (k < EPSILON) k = 0; - speed *= k; - vectorScale(speed2, k); - if (k > 0) */target->hitForce(speed, speed2, source); - } + if (target != NULL && source != NULL){ + //float kvel[3]; + //source->getVelocity(kvel); + float k = vectorLength(sourcevelocity)*0.1; + //if (k > 1) k = 1; + speed = -impulsesize*target->invmass*k; + vectorScale(speed2, impulse, target->invmass*k); + /*float kvel[3]; + source->getVelocity(kvel); + float k = 0;//vectorDot(speed2, kvel); + if (k < EPSILON) k = 0; + speed *= k; + vectorScale(speed2, k); + if (k > 0) */target->hitForce(speed, speed2, source); + } - vectorScale(impulse, -1); - source->addImpulse(impulse, sourcecontactpoint); - source->calculateStateVariables(); + vectorScale(impulse, -1); + source->addImpulse(impulse, sourcecontactpoint); + source->calculateStateVariables(); - //vectorScale(speed, source->invmass); - if (target != NULL && source != NULL){ - //float kvel[3]; - //target->getVelocity(kvel); - float k = vectorLength(targetvelocity)*0.1; - //if (k > 1) k = 1; - speed = -impulsesize*source->invmass*k; - vectorScale(speed2, impulse, source->invmass*k); - /*float kvel[3]; - target->getVelocity(kvel); - float k = 0;//vectorDot(speed2, kvel); - if (k < EPSILON) k = 0; - speed *= k; - vectorScale(speed2, k); - if (k > 0) */source->hitForce(speed, speed2, target); - } + //vectorScale(speed, source->invmass); + if (target != NULL && source != NULL){ + //float kvel[3]; + //target->getVelocity(kvel); + float k = vectorLength(targetvelocity)*0.1; + //if (k > 1) k = 1; + speed = -impulsesize*source->invmass*k; + vectorScale(speed2, impulse, source->invmass*k); + /*float kvel[3]; + target->getVelocity(kvel); + float k = 0;//vectorDot(speed2, kvel); + if (k < EPSILON) k = 0; + speed *= k; + vectorScale(speed2, k); + if (k > 0) */source->hitForce(speed, speed2, target); + } - return true; + return true; } bool handleLink(ObjectLink *link){ - if (!link->enabled) return false; + if (!link->enabled) return false; - Object *source = link->object1; - Object *target = link->object2; + Object *source = link->object1; + Object *target = link->object2; - float normal[3]; - float contactpoint1[3], contactpoint2[3]; - source->transformPoint(contactpoint1, link->point1); - target->transformPoint(contactpoint2, link->point2); - - float diff[3]; - vectorSub(diff, contactpoint1, contactpoint2); - vectorNormalize(normal, diff); + float normal[3]; + float contactpoint1[3], contactpoint2[3]; + source->transformPoint(contactpoint1, link->point1); + target->transformPoint(contactpoint2, link->point2); - float strength = vectorDot(diff, diff); + float diff[3]; + vectorSub(diff, contactpoint1, contactpoint2); + vectorNormalize(normal, diff); - if (strength < 1.0e-5) return false; + float strength = vectorDot(diff, diff); - float sourcevelocity[3], targetvelocity[3]; - float sourcecontactpoint[3], targetcontactpoint[3]; + if (strength < 1.0e-5) return false; - vectorSub(sourcecontactpoint, contactpoint1, source->position); - source->getVelocity(sourcevelocity, sourcecontactpoint); - - vectorSub(targetcontactpoint, contactpoint2, target->position); - target->getVelocity(targetvelocity, targetcontactpoint); + float sourcevelocity[3], targetvelocity[3]; + float sourcecontactpoint[3], targetcontactpoint[3]; - float deltavelocity[3]; - vectorSub(deltavelocity, sourcevelocity, targetvelocity); - float dot = vectorDot(deltavelocity, normal); + vectorSub(sourcecontactpoint, contactpoint1, source->position); + source->getVelocity(sourcevelocity, sourcecontactpoint); - //if (fabs(dot) < EPSILON) return false; - //if (dot > -1.0e-5 && dot < 1.0e-5) return false; - //if (dot >= 0) return false; - //if (dot > -1.0e-5) return false; + vectorSub(targetcontactpoint, contactpoint2, target->position); + target->getVelocity(targetvelocity, targetcontactpoint); + + float deltavelocity[3]; + vectorSub(deltavelocity, sourcevelocity, targetvelocity); + float dot = vectorDot(deltavelocity, normal); + + //if (fabs(dot) < EPSILON) return false; + //if (dot > -1.0e-5 && dot < 1.0e-5) return false; + //if (dot >= 0) return false; + //if (dot > -1.0e-5) return false; - float invmass1 = source->invmass; - float invmass2 = target->invmass; + float invmass1 = source->invmass; + float invmass2 = target->invmass; - float t1; - if (source->invmomentofinertia == 0){ - t1 = 0; - } else{ - float v1[3]; - vectorCross(v1, sourcecontactpoint, normal); - vectorScale(v1, source->invmomentofinertia); - float w1[3]; - vectorCross(w1, v1, sourcecontactpoint); - t1 = vectorDot(normal, w1); - } + float t1; + if (source->invmomentofinertia == 0){ + t1 = 0; + } else{ + float v1[3]; + vectorCross(v1, sourcecontactpoint, normal); + vectorScale(v1, source->invmomentofinertia); + float w1[3]; + vectorCross(w1, v1, sourcecontactpoint); + t1 = vectorDot(normal, w1); + } - float t2; - if (target->invmomentofinertia == 0){ - t2 = 0; - } else{ - float v1[3]; - vectorCross(v1, targetcontactpoint, normal); - vectorScale(v1, target->invmomentofinertia); - float w1[3]; - vectorCross(w1, v1, targetcontactpoint); - t2 = vectorDot(normal, w1); - } + float t2; + if (target->invmomentofinertia == 0){ + t2 = 0; + } else{ + float v1[3]; + vectorCross(v1, targetcontactpoint, normal); + vectorScale(v1, target->invmomentofinertia); + float w1[3]; + vectorCross(w1, v1, targetcontactpoint); + t2 = vectorDot(normal, w1); + } - float denominator = invmass1 + invmass2 + t1 + t2; + float denominator = invmass1 + invmass2 + t1 + t2; - float impulsesize = (dot + strength*100) / denominator; + float impulsesize = (dot + strength*100) / denominator; - //printf("%f\n", impulsesize); + //printf("%f\n", impulsesize); - float impulse[3]; - vectorScale(impulse, normal, impulsesize); + float impulse[3]; + vectorScale(impulse, normal, impulsesize); - target->addImpulse(impulse, targetcontactpoint); - target->calculateStateVariables(); + target->addImpulse(impulse, targetcontactpoint); + target->calculateStateVariables(); - vectorScale(impulse, -1); - source->addImpulse(impulse, sourcecontactpoint); - source->calculateStateVariables(); + vectorScale(impulse, -1); + source->addImpulse(impulse, sourcecontactpoint); + source->calculateStateVariables(); - return true; + return true; } bool checkCollisions(Object *object, float *contactnormal){ - //bool collision = false; - int group = object->getCollisionGroup(); - int groups = collisionlinks[group]; - group = 0; - int collisions = 0; - /*float oldmomentum[3]; - vectorCopy(oldmomentum, object->momentum); + //bool collision = false; + int group = object->getCollisionGroup(); + int groups = collisionlinks[group]; + group = 0; + int collisions = 0; + /*float oldmomentum[3]; + vectorCopy(oldmomentum, object->momentum); - while (groups){ - if (groups & 1){ - objectlist *node = collisionlists[group]; - while (node != NULL){ - Object *object2 = node->object; - node = node->next; - if (object != object2){ - if (object2->geometry->checkCollision(object, contactnormal)){ - collisions++; - } - } - } - } - group++; - groups >>= 1; - } - /*float temp[3]; - vectorSub(temp, object->momentum, oldmomentum); - vectorScale(temp, 1.0/DT); - object->addForce(temp);*/ - //vectorSub(object-> - //vectorCopy(object->momentum, oldmomentum); - //printf("%i\n", collisions); - //vectorScale(object->force, 1.0/collisions); - /*if (collisions > 0){ - vectorScale(object->force, 2.0/vectorLength(object->momentum)); - }*/ - return collisions > 0; + while (groups){ + if (groups & 1){ + objectlist *node = collisionlists[group]; + while (node != NULL){ + Object *object2 = node->object; + node = node->next; + if (object != object2){ + if (object2->geometry->checkCollision(object, contactnormal)){ + collisions++; + } + } + } + } + group++; + groups >>= 1; + } + /*float temp[3]; + vectorSub(temp, object->momentum, oldmomentum); + vectorScale(temp, 1.0/DT); + object->addForce(temp);*/ + //vectorSub(object-> + //vectorCopy(object->momentum, oldmomentum); + //printf("%i\n", collisions); + //vectorScale(object->force, 1.0/collisions); + /*if (collisions > 0){ + vectorScale(object->force, 2.0/vectorLength(object->momentum)); + }*/ + return collisions > 0; } /* * mass = 0 means infinite mass */ /*void collide(float *velocity1, float *velocity2, - float mass1, float mass2, - float *normal, float *newimpulse){ - float deltavelocity[3]; - vectorSub(deltavelocity, velocity1, velocity2); - float dot = vectorDot(deltavelocity, normal); - float massinverse1 = 0; - float massinverse2 = 0; - if (mass1 != 0) massinverse1 = 1.0 / mass1; - if (mass2 != 0) massinverse2 = 1.0 / mass2; - float impulsesize = -1 * dot / (massinverse1 + massinverse2); - vectorScale(newimpulse, normal, impulsesize); - if (dot > 0){ - vectorSet(newimpulse, 0, 0, 0); - } + float mass1, float mass2, + float *normal, float *newimpulse){ + float deltavelocity[3]; + vectorSub(deltavelocity, velocity1, velocity2); + float dot = vectorDot(deltavelocity, normal); + float massinverse1 = 0; + float massinverse2 = 0; + if (mass1 != 0) massinverse1 = 1.0 / mass1; + if (mass2 != 0) massinverse2 = 1.0 / mass2; + float impulsesize = -1 * dot / (massinverse1 + massinverse2); + vectorScale(newimpulse, normal, impulsesize); + if (dot > 0){ + vectorSet(newimpulse, 0, 0, 0); + } }*/ void collide(Object *source, Object *target, float *normal, float *contactpoint){ /* float momentum[3]; - source->getMomentum(momentum); + source->getMomentum(momentum); - float sourcevelocity[3], targetvelocity[3]; - float sourcecontactpoint[3], targetcontactpoint[3]; + float sourcevelocity[3], targetvelocity[3]; + float sourcecontactpoint[3], targetcontactpoint[3]; - //source->unTransformPoint(sourcecontactpoint, contactpoint); - //target->unTransformPoint(targetcontactpoint, contactpoint); - vectorSub(sourcecontactpoint, contactpoint, source->position); - vectorSub(targetcontactpoint, contactpoint, target->position); + //source->unTransformPoint(sourcecontactpoint, contactpoint); + //target->unTransformPoint(targetcontactpoint, contactpoint); + vectorSub(sourcecontactpoint, contactpoint, source->position); + vectorSub(targetcontactpoint, contactpoint, target->position); - source->getVelocity(sourcevelocity);//, sourcecontactpoint); - float sourcemass = source->getMass(); - - target->getVelocity(targetvelocity);//, targetcontactpoint); - float targetmass = target->getMass(); + source->getVelocity(sourcevelocity);//, sourcecontactpoint); + float sourcemass = source->getMass(); - float deltavelocity[3]; - vectorSub(deltavelocity, sourcevelocity, targetvelocity); - float dot = vectorDot(deltavelocity, normal); - float massinverse1 = 0; - float massinverse2 = 0; - if (sourcemass != 0) massinverse1 = 1.0 / sourcemass; - if (targetmass != 0) massinverse2 = 1.0 / targetmass; + target->getVelocity(targetvelocity);//, targetcontactpoint); + float targetmass = target->getMass(); - float t1; - if (source->invmomentofinertia == 0){ - t1 = 0; - } else{ - float v1[3]; - vectorCross(v1, sourcecontactpoint, normal); - vectorScale(v1, 1.0/source->momentofinertia); - float w1[3]; - vectorCross(w1, v1, sourcecontactpoint); - t1 = vectorDot(normal, w1); - } - //printf("S: %f, %f, %f\n", sourcecontactpoint[0], source->momentofinertia, v1); + float deltavelocity[3]; + vectorSub(deltavelocity, sourcevelocity, targetvelocity); + float dot = vectorDot(deltavelocity, normal); + float massinverse1 = 0; + float massinverse2 = 0; + if (sourcemass != 0) massinverse1 = 1.0 / sourcemass; + if (targetmass != 0) massinverse2 = 1.0 / targetmass; - float t2; - if (target->momentofinertia == 0){ - t2 = 0; - } else{ - float v2[3]; - vectorCross(v2, targetcontactpoint, normal); - vectorScale(v2, 1.0/target->momentofinertia); - float w2[3]; - vectorCross(w2, v2, targetcontactpoint); - t2 = vectorDot(normal, w2); - } - //printf("T: %f, %f, %f\n", targetcontactpoint[0], target->momentofinertia, v2); + float t1; + if (source->invmomentofinertia == 0){ + t1 = 0; + } else{ + float v1[3]; + vectorCross(v1, sourcecontactpoint, normal); + vectorScale(v1, 1.0/source->momentofinertia); + float w1[3]; + vectorCross(w1, v1, sourcecontactpoint); + t1 = vectorDot(normal, w1); + } + //printf("S: %f, %f, %f\n", sourcecontactpoint[0], source->momentofinertia, v1); + + float t2; + if (target->momentofinertia == 0){ + t2 = 0; + } else{ + float v2[3]; + vectorCross(v2, targetcontactpoint, normal); + vectorScale(v2, 1.0/target->momentofinertia); + float w2[3]; + vectorCross(w2, v2, targetcontactpoint); + t2 = vectorDot(normal, w2); + } + //printf("T: %f, %f, %f\n", targetcontactpoint[0], target->momentofinertia, v2); - float divisor; - divisor = massinverse1 + massinverse2;// + t1 + t2; + float divisor; + divisor = massinverse1 + massinverse2;// + t1 + t2; - printf("%f, %f, %f, %f : %f\n", massinverse1, massinverse2, t1, t2, divisor); + printf("%f, %f, %f, %f : %f\n", massinverse1, massinverse2, t1, t2, divisor); - float impulsesize = -dot / divisor; + float impulsesize = -dot / divisor; - float impulse[3]; - vectorScale(impulse, normal, impulsesize); - //collide(sourcevelocity, targetvelocity, sourcemass, targetmass, normal, impulse); + float impulse[3]; + vectorScale(impulse, normal, impulsesize); + //collide(sourcevelocity, targetvelocity, sourcemass, targetmass, normal, impulse); - //vectorAdd(source->momentum, impulse); + //vectorAdd(source->momentum, impulse); - float *force = impulse; + float *force = impulse; - //vectorScale(force, 2.0/DT); - printf("F: %f, %f, %f\n", impulse[0], impulse[1], impulse[2]); + //vectorScale(force, 2.0/DT); + printf("F: %f, %f, %f\n", impulse[0], impulse[1], impulse[2]); - //float cp[3]; - //vectorSub(cp, contactpoint, source->position); - //source->addForce(force, sourcecontactpoint);*/ + //float cp[3]; + //vectorSub(cp, contactpoint, source->position); + //source->addForce(force, sourcecontactpoint);*/ } bool checkSphereMeshCollision(float *sphereposition, float r, Mesh *mesh, float *normal, float *contactpoint){ - float linenormal[3]; - float pointnormal[3]; - float maxdist = 0; - bool planecollision = false; - bool linecollision = false; - bool pointcollision = false; + float linenormal[3]; + float pointnormal[3]; + float maxdist = 0; + bool planecollision = false; + bool linecollision = false; + bool pointcollision = false; - int i, j; + int i, j; - for (i = 0; i < mesh->polygoncount; i++){ - class Polygon *polygon = &mesh->polygons[i]; + for (i = 0; i < mesh->polygoncount; i++){ + class Polygon *polygon = &mesh->polygons[i]; - float dist = distanceFromPlane(sphereposition, polygon->planenormal, polygon->planedistance); - if (dist < r && dist > -r){ - bool directcollision = true; - for (j = 0; j < polygon->vertexcount; j++){ - float *p1 = polygon->vertices[j]->position; - float *p2 = polygon->vertices[(j+1)%polygon->vertexcount]->position; - float *p3 = polygon->vertices[(j+2)%polygon->vertexcount]->position; - float v1[3], v2[3]; - vectorSub(v1, p2, p1); + float dist = distanceFromPlane(sphereposition, polygon->planenormal, polygon->planedistance); + if (dist < r && dist > -r){ + bool directcollision = true; + for (j = 0; j < polygon->vertexcount; j++){ + float *p1 = polygon->vertices[j]->position; + float *p2 = polygon->vertices[(j+1)%polygon->vertexcount]->position; + float *p3 = polygon->vertices[(j+2)%polygon->vertexcount]->position; + float v1[3], v2[3]; + vectorSub(v1, p2, p1); - //Collision for polygon surface - vectorSub(v2, p3, p2); - float t1[3]; - vectorProject(t1, v2, v1); - float norm[3]; - vectorSub(norm, v2, t1); - vectorNormalize(norm); + //Collision for polygon surface + vectorSub(v2, p3, p2); + float t1[3]; + vectorProject(t1, v2, v1); + float norm[3]; + vectorSub(norm, v2, t1); + vectorNormalize(norm); - //Collision for polygon edges - float newpoint[3]; - vectorSub(newpoint, sphereposition, p1); - float dist2 = vectorDot(newpoint, norm); - if (dist2 < 0){ - directcollision = false; - float projloc = vectorDot(newpoint, v1) / vectorDot(v1, v1); - if (projloc >= 0 && projloc <= 1){ - float proj[3]; - vectorScale(proj, v1, projloc); - float projorth[3]; - vectorSub(projorth, newpoint, proj); - float l2 = vectorDot(projorth, projorth); - if (l2 < r*r){ - vectorNormalize(linenormal, projorth); - if (dist < 0) vectorScale(linenormal, -1); - linecollision = true; - } - } - } + //Collision for polygon edges + float newpoint[3]; + vectorSub(newpoint, sphereposition, p1); + float dist2 = vectorDot(newpoint, norm); + if (dist2 < 0){ + directcollision = false; + float projloc = vectorDot(newpoint, v1) / vectorDot(v1, v1); + if (projloc >= 0 && projloc <= 1){ + float proj[3]; + vectorScale(proj, v1, projloc); + float projorth[3]; + vectorSub(projorth, newpoint, proj); + float l2 = vectorDot(projorth, projorth); + if (l2 < r*r){ + vectorNormalize(linenormal, projorth); + if (dist < 0) vectorScale(linenormal, -1); + linecollision = true; + } + } + } - //Collision for polygon vertices - float pointdiff[3]; - vectorSub(pointdiff, sphereposition, p1); - float l3 = vectorDot(pointdiff, pointdiff); - if (l3 < r*r){ - vectorScale(pointnormal, pointdiff, 1.0 / sqrt(l3)); - if (dist < 0) vectorScale(pointnormal, -1); - pointcollision = true; - } - } - if (directcollision){ - if (dist > maxdist || !planecollision){ - vectorCopy(normal, polygon->planenormal); - maxdist = dist; - planecollision = true; - } - } - } - } + //Collision for polygon vertices + float pointdiff[3]; + vectorSub(pointdiff, sphereposition, p1); + float l3 = vectorDot(pointdiff, pointdiff); + if (l3 < r*r){ + vectorScale(pointnormal, pointdiff, 1.0 / sqrt(l3)); + if (dist < 0) vectorScale(pointnormal, -1); + pointcollision = true; + } + } + if (directcollision){ + if (dist > maxdist || !planecollision){ + vectorCopy(normal, polygon->planenormal); + maxdist = dist; + planecollision = true; + } + } + } + } - if (planecollision){ - vectorScale(contactpoint, normal, -r); - vectorAdd(contactpoint, sphereposition); - } else if (linecollision){ - vectorScale(contactpoint, linenormal, -r); - vectorAdd(contactpoint, sphereposition); - vectorCopy(normal, linenormal); - } else if (pointcollision){ - vectorScale(contactpoint, pointnormal, -r); - vectorAdd(contactpoint, sphereposition); - vectorCopy(normal, pointnormal); - } else{ - return false; - } + if (planecollision){ + vectorScale(contactpoint, normal, -r); + vectorAdd(contactpoint, sphereposition); + } else if (linecollision){ + vectorScale(contactpoint, linenormal, -r); + vectorAdd(contactpoint, sphereposition); + vectorCopy(normal, linenormal); + } else if (pointcollision){ + vectorScale(contactpoint, pointnormal, -r); + vectorAdd(contactpoint, sphereposition); + vectorCopy(normal, pointnormal); + } else{ + return false; + } - return true; + return true; } @@ -599,244 +514,244 @@ bool checkSphereMeshCollision(float *sphereposition, float r, Mesh *mesh, float bool checkPointMeshCollision(float *position, Mesh *mesh, float *normal, float *contactpoint){ - float maxdist = 0; - bool planecollision = false; + float maxdist = 0; + bool planecollision = false; - int i; + int i; - for (i = 0; i < mesh->polygoncount; i++){ - class Polygon *polygon = &mesh->polygons[i]; + for (i = 0; i < mesh->polygoncount; i++){ + class Polygon *polygon = &mesh->polygons[i]; - float dist = distanceFromPlane(position, polygon->planenormal, polygon->planedistance); - if (dist < 0){ - bool directcollision = true; - /*for (j = 0; j < polygon->vertexcount; j++){ - float *p1 = polygon->vertices[j]->position; - float *p2 = polygon->vertices[(j+1)%polygon->vertexcount]->position; - float *p3 = polygon->vertices[(j+2)%polygon->vertexcount]->position; - float v1[3], v2[3]; - vectorSub(v1, p2, p1); + float dist = distanceFromPlane(position, polygon->planenormal, polygon->planedistance); + if (dist < 0){ + bool directcollision = true; + /*for (j = 0; j < polygon->vertexcount; j++){ + float *p1 = polygon->vertices[j]->position; + float *p2 = polygon->vertices[(j+1)%polygon->vertexcount]->position; + float *p3 = polygon->vertices[(j+2)%polygon->vertexcount]->position; + float v1[3], v2[3]; + vectorSub(v1, p2, p1); - //Collision for polygon surface - vectorSub(v2, p3, p2); - float t1[3]; - vectorProject(t1, v2, v1); - float norm[3]; - vectorSub(norm, v2, t1); - vectorNormalize(norm); + //Collision for polygon surface + vectorSub(v2, p3, p2); + float t1[3]; + vectorProject(t1, v2, v1); + float norm[3]; + vectorSub(norm, v2, t1); + vectorNormalize(norm); - //Collision for polygon edges - float newpoint[3]; - vectorSub(newpoint, position, p1); - float dist2 = vectorDot(newpoint, norm); - if (dist2 < 0) directcollision = false; - }*/ - if (directcollision){ - if (dist > maxdist || !planecollision){ - vectorCopy(normal, polygon->planenormal); - maxdist = dist; - planecollision = true; - } - } - } else{ - return false; - } - } + //Collision for polygon edges + float newpoint[3]; + vectorSub(newpoint, position, p1); + float dist2 = vectorDot(newpoint, norm); + if (dist2 < 0) directcollision = false; + }*/ + if (directcollision){ + if (dist > maxdist || !planecollision){ + vectorCopy(normal, polygon->planenormal); + maxdist = dist; + planecollision = true; + } + } + } else{ + return false; + } + } - if (planecollision){ - vectorCopy(contactpoint, position); - } else{ - return false; - } + if (planecollision){ + vectorCopy(contactpoint, position); + } else{ + return false; + } - return true; + return true; } #define MAXPOLYGONS 1000 struct tracehit{ - float t; - Polygon *polygon; + float t; + Polygon *polygon; }; bool tracePlane(tracehit *result, float *origin, float *ray, class Polygon *polygon){ - float *normal = polygon->planenormal; - float D = polygon->planedistance; - float denominator = vectorDot(normal, ray); - if (denominator == 0){ - if (vectorDot(normal, origin) > 0) result->t = 1000000; - else result->t = -1000000; - result->polygon = polygon; - return true; - } + float *normal = polygon->planenormal; + float D = polygon->planedistance; + float denominator = vectorDot(normal, ray); + if (denominator == 0){ + if (vectorDot(normal, origin) > 0) result->t = 1000000; + else result->t = -1000000; + result->polygon = polygon; + return true; + } - float t = - (vectorDot(normal, origin) + D) / denominator; + float t = - (vectorDot(normal, origin) + D) / denominator; - result->t = t; - result->polygon = polygon; + result->t = t; + result->polygon = polygon; - //if (t < 0 || t > 1) return false; - - return true; + //if (t < 0 || t > 1) return false; + + return true; } Edge *findSharingEdge(class Polygon *p1, class Polygon *p2){ - //printf("Edges:\n"); - int i, j; - for (i = 0; i < p1->vertexcount; i++){ - //printf("%p\n", p1->edges[i]); - for (j = 0; j < p2->vertexcount; j++){ - if (p1->edges[i] == p2->edges[j]) return p1->edges[i]; - } - } - return NULL; + //printf("Edges:\n"); + int i, j; + for (i = 0; i < p1->vertexcount; i++){ + //printf("%p\n", p1->edges[i]); + for (j = 0; j < p2->vertexcount; j++){ + if (p1->edges[i] == p2->edges[j]) return p1->edges[i]; + } + } + return NULL; } /*Polygon *findSharingPolygon(Mesh *mesh, class Polygon *p1, class Polygon *p2){ - //printf("Edges:\n"); - int i, j; - for (i = 0; i < p1->vertexcount; i++){ - //printf("%p\n", p1->edges[i]); - for (j = 0; j < p2->vertexcount; j++){ - if (p1->edges[i] == p2->edges[j]) return p1->edges[i]; - } - } - return NULL; + //printf("Edges:\n"); + int i, j; + for (i = 0; i < p1->vertexcount; i++){ + //printf("%p\n", p1->edges[i]); + for (j = 0; j < p2->vertexcount; j++){ + if (p1->edges[i] == p2->edges[j]) return p1->edges[i]; + } + } + return NULL; }*/ Polygon *findNearestPolygon(class Polygon *polygon, float *point){ - int i; - float mindist = 0; - Polygon *nearestpolygon = NULL; - for (i = 0; i < polygon->edgecount; i++){ - Edge *edge = polygon->edges[i]; - Polygon *polygon2 = edge->p1; - if (polygon2 == polygon) polygon2 = edge->p2; - float newdist = distanceFromPlane(point, polygon2->planenormal, polygon2->planedistance); - if (newdist > 0) return NULL; - if (mindist == 0 || newdist > mindist){ - mindist = newdist; - nearestpolygon = polygon2; - } - } - return nearestpolygon; + int i; + float mindist = 0; + Polygon *nearestpolygon = NULL; + for (i = 0; i < polygon->edgecount; i++){ + Edge *edge = polygon->edges[i]; + Polygon *polygon2 = edge->p1; + if (polygon2 == polygon) polygon2 = edge->p2; + float newdist = distanceFromPlane(point, polygon2->planenormal, polygon2->planedistance); + if (newdist > 0) return NULL; + if (mindist == 0 || newdist > mindist){ + mindist = newdist; + nearestpolygon = polygon2; + } + } + return nearestpolygon; } bool checkEdgeMeshCollision(float *p1, float *p2, Mesh *mesh, float *normal, float *contactpoint){ - float ray[3]; - vectorSub(ray, p2, p1); + float ray[3]; + vectorSub(ray, p2, p1); - float maxdist = 0; - bool collision = false; + float maxdist = 0; + bool collision = false; - int i, j; + int i, j; - tracehit hits[MAXPOLYGONS]; - int hitcount = 0; + tracehit hits[MAXPOLYGONS]; + int hitcount = 0; - for (i = 0; i < mesh->polygoncount; i++){ - class Polygon *polygon = &mesh->polygons[i]; + for (i = 0; i < mesh->polygoncount; i++){ + class Polygon *polygon = &mesh->polygons[i]; - if (tracePlane(&hits[hitcount], p1, ray, polygon)){ - hitcount++; - } - } + if (tracePlane(&hits[hitcount], p1, ray, polygon)){ + hitcount++; + } + } - if (hitcount < 2) return false; + if (hitcount < 2) return false; - for (i = 1; i < hitcount; i++){ - for (j = i; j > 0; j--){ - if (hits[j].t < hits[j-1].t){ - float tempt = hits[j].t; - hits[j].t = hits[j-1].t; - hits[j-1].t = tempt; - class Polygon *tempp = hits[j].polygon; - hits[j].polygon = hits[j-1].polygon; - hits[j-1].polygon = tempp; - } else break; - } - } + for (i = 1; i < hitcount; i++){ + for (j = i; j > 0; j--){ + if (hits[j].t < hits[j-1].t){ + float tempt = hits[j].t; + hits[j].t = hits[j-1].t; + hits[j-1].t = tempt; + class Polygon *tempp = hits[j].polygon; + hits[j].polygon = hits[j-1].polygon; + hits[j-1].polygon = tempp; + } else break; + } + } - int negative = -1, positive = -1; + int negative = -1, positive = -1; - for (i = 0; i < hitcount; i++){ - float t = hits[i].t; - class Polygon *polygon = hits[i].polygon; + for (i = 0; i < hitcount; i++){ + float t = hits[i].t; + class Polygon *polygon = hits[i].polygon; - float dot = vectorDot(ray, polygon->planenormal); + float dot = vectorDot(ray, polygon->planenormal); - if (dot > 0 && positive == -1) positive = i; - if (dot < 0) negative = i; + if (dot > 0 && positive == -1) positive = i; + if (dot < 0) negative = i; - if (dot < 0 && positive != -1) return false; - } + if (dot < 0 && positive != -1) return false; + } - if (negative == -1 || positive == -1) return false; + if (negative == -1 || positive == -1) return false; - /*for (i = 0; i < hitcount; i++){ - float t = hits[i].t; - class Polygon *polygon = hits[i].polygon; + /*for (i = 0; i < hitcount; i++){ + float t = hits[i].t; + class Polygon *polygon = hits[i].polygon; - float dot = vectorDot(ray, polygon->planenormal); + float dot = vectorDot(ray, polygon->planenormal); - printf("%f ", dot); - } - printf("\n");*/ + printf("%f ", dot); + } + printf("\n");*/ - if (hits[negative].t < 0 || hits[positive].t > 1) return false; + if (hits[negative].t < 0 || hits[positive].t > 1) return false; - Edge *edge2 = findSharingEdge(hits[negative].polygon, hits[positive].polygon); + Edge *edge2 = findSharingEdge(hits[negative].polygon, hits[positive].polygon); - //fflush(stdout); - float cp1[3], cp2[3]; - vectorScale(cp1, ray, hits[negative].t); - vectorAdd(cp1, p1); - vectorScale(cp2, ray, hits[positive].t); - vectorAdd(cp2, p1); + //fflush(stdout); + float cp1[3], cp2[3]; + vectorScale(cp1, ray, hits[negative].t); + vectorAdd(cp1, p1); + vectorScale(cp2, ray, hits[positive].t); + vectorAdd(cp2, p1); - if (edge2 != NULL){ + if (edge2 != NULL){ - /*float ev1[3]; - vectorSub(ev1, edge2->v2->position, edge2->v1->position); - vectorCross(normal, ev1, ray); - vectorScale(normal, vectorDot(normal, hits[positive].polygon->planenormal)); - vectorNormalize(normal); + /*float ev1[3]; + vectorSub(ev1, edge2->v2->position, edge2->v1->position); + vectorCross(normal, ev1, ray); + vectorScale(normal, vectorDot(normal, hits[positive].polygon->planenormal)); + vectorNormalize(normal); - float at = (hits[negative].t + hits[positive].t) / 2; - vectorScale(contactpoint, ray, at); - vectorAdd(contactpoint, p1);*/ + float at = (hits[negative].t + hits[positive].t) / 2; + vectorScale(contactpoint, ray, at); + vectorAdd(contactpoint, p1);*/ - float dot1 = fabs(vectorDot(ray, hits[negative].polygon->planenormal)); - float dot2 = fabs(vectorDot(ray, hits[positive].polygon->planenormal)); + float dot1 = fabs(vectorDot(ray, hits[negative].polygon->planenormal)); + float dot2 = fabs(vectorDot(ray, hits[positive].polygon->planenormal)); - if (dot1 > dot2){ - //vectorScale(contactpoint, ray, hits[negative].t); - //vectorAdd(contactpoint, p1); - vectorCopy(contactpoint, cp1); - vectorCopy(normal, hits[positive].polygon->planenormal); - } else{ - //vectorScale(contactpoint, ray, hits[positive].t); - //vectorAdd(contactpoint, p1); - vectorCopy(contactpoint, cp2); - vectorCopy(normal, hits[negative].polygon->planenormal); - } - } else{ - Polygon *polygon = findNearestPolygon(hits[negative].polygon, cp1); - if (polygon != NULL){ - /*vectorCopy(contactpoint, cp1); - vectorAdd(contactpoint, cp2); - vectorScale(contactpoint, 0.5);*/ - float at = (hits[negative].t + hits[positive].t) / 2; - vectorScale(contactpoint, ray, at); - vectorAdd(contactpoint, p1); + if (dot1 > dot2){ + //vectorScale(contactpoint, ray, hits[negative].t); + //vectorAdd(contactpoint, p1); + vectorCopy(contactpoint, cp1); + vectorCopy(normal, hits[positive].polygon->planenormal); + } else{ + //vectorScale(contactpoint, ray, hits[positive].t); + //vectorAdd(contactpoint, p1); + vectorCopy(contactpoint, cp2); + vectorCopy(normal, hits[negative].polygon->planenormal); + } + } else{ + Polygon *polygon = findNearestPolygon(hits[negative].polygon, cp1); + if (polygon != NULL){ + /*vectorCopy(contactpoint, cp1); + vectorAdd(contactpoint, cp2); + vectorScale(contactpoint, 0.5);*/ + float at = (hits[negative].t + hits[positive].t) / 2; + vectorScale(contactpoint, ray, at); + vectorAdd(contactpoint, p1); - vectorCopy(normal, polygon->planenormal); - } else{ - return false; - } - } + vectorCopy(normal, polygon->planenormal); + } else{ + return false; + } + } - //shotsound->play(); - return true; -} \ No newline at end of file + //shotsound->play(); + return true; +} diff --git a/src/collision.h b/src/collision.h index 2baf11c..e8ae115 100644 --- a/src/collision.h +++ b/src/collision.h @@ -1,61 +1,3 @@ -/* - * $Id: collision.h,v 1.15 2002/07/19 20:33:28 msell Exp $ - * - * - * $Log: collision.h,v $ - * Revision 1.15 2002/07/19 20:33:28 msell - * #pragma once -> #ifndef - * - * Revision 1.14 2002/07/15 20:32:35 msell - * Uudet valot ja ulkoasun parantelua - * - * Revision 1.13 2002/07/14 21:40:43 msell - * Conflictit pois, liikkumiset (hyppy, kävely, lyönti), uusi areena - * - * Revision 1.12 2002/07/10 17:13:44 msell - * Törmäystarkastelun parantelua - * - * Revision 1.11 2002/07/08 22:53:38 msell - * Säätöä - * - * Revision 1.10 2002/07/08 18:28:47 msell - * Törmäystä ja ukkoja - * - * Revision 1.9 2002/07/07 23:05:22 msell - * Osien liimaaminen toisiinsa (kesken) - * - * Revision 1.8 2002/07/07 15:29:07 msell - * Törmäyksien parantelua - * - * Revision 1.7 2002/07/04 21:05:41 msell - * Se toimii!! =) - * Törmäystarkistukset siis - * - * Revision 1.6 2002/06/30 16:05:04 msell - * Törmäyksien parantelua, transformaatioita mukana - * - * Revision 1.5 2002/06/27 14:39:48 msell - * Toimiva maila :) - * Pyörivät kappaleet siis antaa liike-energiaa liikkuville kappaleille (ei toisin päin vielä) - * - * Revision 1.4 2002/06/27 00:08:04 msell - * Kimmotukset palloille myös pyöritettyihin mesheihin - * - * Revision 1.3 2002/06/23 20:12:19 msell - * Parempi törmäystarkistus palloista mesheihin - * - * Revision 1.2 2002/06/14 00:05:05 msell - * Törmäyssimulaatio kunnossa toivon mukaan - * - * Revision 1.1 2002/06/11 23:11:45 msell - * Törmäystarkistusta - * - * - * - * $Date: 2002/07/19 20:33:28 $ - * - */ - #ifndef __COLLISION_H_INCLUDED__ #define __COLLISION_H_INCLUDED__ @@ -79,9 +21,9 @@ bool isCollisionLink(int source, int target); class Contact{ public: - Object *object1, *object2; - float normal[3]; - float position[3]; + Object *object1, *object2; + float normal[3]; + float position[3]; }; extern Contact *contacts; @@ -91,7 +33,7 @@ extern int contactcount; //Contact point is world-relative and must be transformed //into coordinate system of both objects void addCollision(Object *source, Object *target, - float *normal, float *contactpoint); + float *normal, float *contactpoint); bool handleCollision(Contact *contact); bool handleLink(ObjectLink *link); diff --git a/src/end.cpp b/src/end.cpp index 67640b4..e1ef863 100644 --- a/src/end.cpp +++ b/src/end.cpp @@ -1,20 +1,3 @@ -/* - * $Id: end.cpp,v 1.2 2002/07/22 11:40:26 msell Exp $ - * - * - * $Log: end.cpp,v $ - * Revision 1.2 2002/07/22 11:40:26 msell - * Loppukuvaan lattia - * - * Revision 1.1 2002/07/22 01:14:14 msell - * Lopetussysteemi - * - * - * - * $Date: 2002/07/22 11:40:26 $ - * - */ - #include "main.h" #include @@ -26,7 +9,7 @@ #include "object.h" #include "appearance.h" #include "sphere.h" -#include "vector.h" +#include "vector.h" #include "collision.h" #include "utils.h" #include "graphics.h" @@ -48,114 +31,114 @@ Light endlight, endlight2; BasicBlock *endfloor;// = new BasicBlock(20, 1, 15); void initEnd(void){ - endlight.setColor(1, 1, 1); - endlight.setSpecular(1, 1, 1); - endlight.setPosition(-0.5, BLOCKHEIGHT*16, 0.5); - endlight.setAttenuation(0, 0.0, 0.005); + endlight.setColor(1, 1, 1); + endlight.setSpecular(1, 1, 1); + endlight.setPosition(-0.5, BLOCKHEIGHT*16, 0.5); + endlight.setAttenuation(0, 0.0, 0.005); - endlight2.setColor(1, 1, 1); - endlight2.setSpecular(1, 1, 1); - endlight2.setAttenuation(1.0, 0.0, 0.0); + endlight2.setColor(1, 1, 1); + endlight2.setSpecular(1, 1, 1); + endlight2.setAttenuation(1.0, 0.0, 0.0); - endfloor = new BasicBlock(30, 1, 20); - //endfloor->material.setColor(0, 1, 0, 1); - endfloor->setColor(0, 1, 0); - endfloor->setPosition(-10, -BLOCKHEIGHT*0.5, 0); - endfloor->prepare(); + endfloor = new BasicBlock(30, 1, 20); + //endfloor->material.setColor(0, 1, 0, 1); + endfloor->setColor(0, 1, 0); + endfloor->setPosition(-10, -BLOCKHEIGHT*0.5, 0); + endfloor->prepare(); } int endingcounter; void endRestart(void){ - endingcounter = 0; - //initEnd(); - //endfloor->prepare(); + endingcounter = 0; + //initEnd(); + //endfloor->prepare(); } void stopEnding(void){ - endlight.setEnabled(false); - changeGameMode(MENUMODE); - fightmusic->fadeOut(300); - menuRestart(); + endlight.setEnabled(false); + changeGameMode(MENUMODE); + fightmusic->fadeOut(300); + menuRestart(); } float endfade; void calculateEnd(int framecount){ - endfade = -1; + endfade = -1; - if (endingcounter < 200){ - endfade = 1-(float)endingcounter/200; - } - endingcounter++; + if (endingcounter < 200){ + endfade = 1-(float)endingcounter/200; + } + endingcounter++; - endlight.setEnabled(true); - //endlight2.setEnabled(true); + endlight.setEnabled(true); + //endlight2.setEnabled(true); - float target[3] = {0, 13, 0}; - endcamera.setTarget(target); - endcamera.setPosition(10+sin(framecount*0.002)*2, 20+sin(framecount*0.0017)*2, 25+cos(framecount*0.002)*2); - //endcamera.setPosition(sin(framecount*0.01)*25, sin(framecount*0.007)*6+20, cos(framecount*0.01)*25); + float target[3] = {0, 13, 0}; + endcamera.setTarget(target); + endcamera.setPosition(10+sin(framecount*0.002)*2, 20+sin(framecount*0.0017)*2, 25+cos(framecount*0.002)*2); + //endcamera.setPosition(sin(framecount*0.01)*25, sin(framecount*0.007)*6+20, cos(framecount*0.01)*25); - //endlight.setPosition(40, 20, 0); - endlight.setPosition(-sin(framecount*0.007)*10, 15, cos(framecount*0.007)*2+22); + //endlight.setPosition(40, 20, 0); + endlight.setPosition(-sin(framecount*0.007)*10, 15, cos(framecount*0.007)*2+22); - if (keys[SDLK_ESCAPE]){ - stopEnding(); - } + if (keys[SDLK_ESCAPE]){ + stopEnding(); + } } void drawEnd(int framecount){ - glLoadIdentity(); - glTranslatef(10, 0, 0); + glLoadIdentity(); + glTranslatef(10, 0, 0); - endcamera.glUpdate(); + endcamera.glUpdate(); - updateLights(); + updateLights(); - glEnable(GL_LIGHTING); - glDisable(GL_BLEND); - glEnable(GL_CULL_FACE); - glDisable(GL_TEXTURE_2D); + glEnable(GL_LIGHTING); + glDisable(GL_BLEND); + glEnable(GL_CULL_FACE); + glDisable(GL_TEXTURE_2D); - endfloor->draw(); + endfloor->draw(); - glColor3f(1, 1, 0); + glColor3f(1, 1, 0); - drawTrophy(); + drawTrophy(); - glRotatef(270, 0, 1, 0); - glTranslatef(2-BLOCKHEIGHT*0.5, 0, 15-BLOCKHEIGHT*0.5); - glScalef(3, 3, 3); + glRotatef(270, 0, 1, 0); + glTranslatef(2-BLOCKHEIGHT*0.5, 0, 15-BLOCKHEIGHT*0.5); + glScalef(3, 3, 3); - winner->head->draw(); - winner->torso->draw(); - winner->lefthand->draw(); - winner->righthand->draw(); - winner->waist->draw(); - winner->leftleg->draw(); - winner->rightleg->draw(); + winner->head->draw(); + winner->torso->draw(); + winner->lefthand->draw(); + winner->righthand->draw(); + winner->waist->draw(); + winner->leftleg->draw(); + winner->rightleg->draw(); - enable2D(); + enable2D(); - glColor3f(1, 1, 1); + glColor3f(1, 1, 1); - if (winner->side == PLAYER1) print(0.05, 0.05, "Player 1 is\nthe winner", 0.09); - if (winner->side == PLAYER2) print(0.05, 0.05, "Player 2 is\nthe winner", 0.09); + if (winner->side == PLAYER1) print(0.05, 0.05, "Player 1 is\nthe winner", 0.09); + if (winner->side == PLAYER2) print(0.05, 0.05, "Player 2 is\nthe winner", 0.09); - if (endfade != -1){ - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glColor4f(0, 0, 0, endfade); - glBegin(GL_QUADS); - glVertex2f(0, 0); - glVertex2f(1, 0); - glVertex2f(1, 1); - glVertex2f(0, 1); - glEnd(); - } + if (endfade != -1){ + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glColor4f(0, 0, 0, endfade); + glBegin(GL_QUADS); + glVertex2f(0, 0); + glVertex2f(1, 0); + glVertex2f(1, 1); + glVertex2f(0, 1); + glEnd(); + } - disable2D(); + disable2D(); } diff --git a/src/end.h b/src/end.h index 3dd69db..d629e5b 100644 --- a/src/end.h +++ b/src/end.h @@ -1,17 +1,3 @@ -/* - * $Id: end.h,v 1.1 2002/07/22 01:14:14 msell Exp $ - * - * - * $Log: end.h,v $ - * Revision 1.1 2002/07/22 01:14:14 msell - * Lopetussysteemi - * - * - * - * $Date: 2002/07/22 01:14:14 $ - * - */ - #ifndef __END_H_INCLUDED__ #define __END_H_INCLUDED__ diff --git a/src/fight.cpp b/src/fight.cpp index 0e0eccc..6ef13f0 100644 --- a/src/fight.cpp +++ b/src/fight.cpp @@ -1,208 +1,3 @@ -/* - * $Id: fight.cpp,v 1.64 2002/07/22 11:40:26 msell Exp $ - * - * - * $Log: fight.cpp,v $ - * Revision 1.64 2002/07/22 11:40:26 msell - * Loppukuvaan lattia - * - * Revision 1.63 2002/07/22 01:14:14 msell - * Lopetussysteemi - * - * Revision 1.62 2002/07/21 22:50:39 msell - * no message - * - * Revision 1.61 2002/07/21 20:14:28 msell - * no message - * - * Revision 1.60 2002/07/21 15:03:12 msell - * Äänet disabloitu - * - * Revision 1.59 2002/07/19 22:48:09 msell - * Säätöä - * - * Revision 1.58 2002/07/19 18:59:46 msell - * Alkuhommaa ja säätöä - * - * Revision 1.57 2002/07/19 14:05:51 msell - * Damagetextuurit näkyy - * - * Revision 1.56 2002/07/19 12:48:31 jkaarlas - * damagepää - * - * Revision 1.55 2002/07/18 23:05:31 msell - * Partikkelit ja kakkospelaajan liike - * - * Revision 1.54 2002/07/17 22:45:53 msell - * Ääniä vähän - * - * Revision 1.53 2002/07/17 19:06:39 jkaarlas - * skyboxin keskitys - * - * Revision 1.52 2002/07/17 19:02:14 jkaarlas - * skyboxin keskitys - * - * Revision 1.51 2002/07/17 16:40:33 msell - * Resoluution vaihto - * - * Revision 1.50 2002/07/16 19:54:38 jkaarlas - * poistettu turhaa roinaa ja lisätty DATAPATH tiedostonimien eteen - * - * Revision 1.49 2002/07/16 17:16:34 msell - * Fontit ja valikot - * - * Revision 1.48 2002/07/16 10:03:42 msell - * Pikkufixi - * - * Revision 1.47 2002/07/16 00:42:43 msell - * Uusia skyboxeja ja areenan säätöä - * - * Revision 1.46 2002/07/15 21:42:58 msell - * Skybox-testi - * - * Revision 1.45 2002/07/15 20:32:35 msell - * Uudet valot ja ulkoasun parantelua - * - * Revision 1.44 2002/07/15 15:22:07 msell - * Parantelua - * - * Revision 1.43 2002/07/14 21:40:43 msell - * Conflictit pois, liikkumiset (hyppy, kävely, lyönti), uusi areena - * - * Revision 1.42 2002/07/14 21:22:40 jkaarlas - * skybox ja ukkojen säätö - * - * Revision 1.41 2002/07/10 22:22:53 msell - * Cartoon-rendaus - * - * Revision 1.40 2002/07/10 22:07:23 jkaarlas - * skaalatut ja käännellyt ruumiinosat - * - * Revision 1.39 2002/07/10 17:13:44 msell - * Törmäystarkastelun parantelua - * - * Revision 1.38 2002/07/08 22:53:38 msell - * Säätöä - * - * Revision 1.37 2002/07/08 18:28:47 msell - * Törmäystä ja ukkoja - * - * Revision 1.36 2002/07/07 23:21:11 msell - * Pientä parantelua - * - * Revision 1.35 2002/07/07 23:05:22 msell - * Osien liimaaminen toisiinsa (kesken) - * - * Revision 1.34 2002/07/07 17:53:21 msell - * Legoukon alku - * - * Revision 1.33 2002/07/07 15:29:07 msell - * Törmäyksien parantelua - * - * Revision 1.32 2002/07/04 21:05:41 msell - * Se toimii!! =) - * Törmäystarkistukset siis - * - * Revision 1.31 2002/06/30 16:05:04 msell - * Törmäyksien parantelua, transformaatioita mukana - * - * Revision 1.30 2002/06/27 21:57:06 msell - * glEnd(); lisätty tekstuuritestaukseen - * - * Revision 1.29 2002/06/27 21:46:55 jkaarlas - * lisätty testikoodi transparentille tekstuurille (kommentoitu) vaihdettu tekstuuriquadin koordinaatit oikein päin - * - * Revision 1.28 2002/06/27 14:39:48 msell - * Toimiva maila :) - * Pyörivät kappaleet siis antaa liike-energiaa liikkuville kappaleille (ei toisin päin vielä) - * - * Revision 1.27 2002/06/27 00:08:04 msell - * Kimmotukset palloille myös pyöritettyihin mesheihin - * - * Revision 1.26 2002/06/26 22:32:20 jkaarlas - * mukana initissä asc-mallin lataus, tosin kommentoituna. samoin yksinkertainen quad, johon voi kokeilla tekstuurin lataamista - * - * Revision 1.25 2002/06/24 14:12:15 msell - * Nyt toimii sphere -> mesh -törmäykset, ihan tosi - * - * Revision 1.24 2002/06/23 20:12:19 msell - * Parempi törmäystarkistus palloista mesheihin - * - * Revision 1.23 2002/06/20 22:50:12 msell - * Meshit - * - * Revision 1.22 2002/06/20 15:31:13 jkaarlas - * turhat tekstuurilataukset pois - * - * Revision 1.21 2002/06/20 00:21:01 jkaarlas - * materiaali- ja tekstuurihommia edistetty - * - * Revision 1.20 2002/06/17 20:49:04 msell - * free -> SDL_FreeSurface - * - * Revision 1.19 2002/06/17 20:34:44 jkaarlas - * kutsuu tekstuurilatausta - * - * Revision 1.18 2002/06/17 19:58:08 msell - * #includeiden parantelua - * - * Revision 1.17 2002/06/16 01:04:58 jkaarlas - * tulipa säädettyä includejen kanssa. oon tod.näk. eri mieltä aamulla - * - * Revision 1.16 2002/06/15 22:56:37 msell - * Säätöä - * - * Revision 1.15 2002/06/15 17:18:37 msell - * Toimiva törmäystarkastus kiinteille laatikoille - * - * Revision 1.14 2002/06/14 19:01:09 msell - * Säätämistä ja testailua - * - * Revision 1.13 2002/06/14 00:26:17 msell - * 100 kimpoilevaa palloa ja vähän vaimennusta - * - * Revision 1.12 2002/06/14 00:05:05 msell - * Törmäyssimulaatio kunnossa toivon mukaan - * - * Revision 1.11 2002/06/11 23:11:45 msell - * Törmäystarkistusta - * - * Revision 1.10 2002/06/07 21:16:51 msell - * Fysiikkaenginen alkua - * - * Revision 1.9 2002/06/05 23:55:46 msell - * Pallo - * - * Revision 1.8 2002/06/05 18:39:04 msell - * Jotain pientä - * - * Revision 1.7 2002/06/05 15:00:41 msell - * Palikoihin lisää detailia, facet jaetaan halutun kokosiin osiin - * - * Revision 1.6 2002/06/03 23:06:38 msell - * no message - * - * Revision 1.5 2002/06/02 16:57:37 msell - * Objektirakenteen pohja - * - * Revision 1.4 2002/05/19 13:40:19 msell - * Säätöä - * - * Revision 1.3 2002/05/18 12:29:35 msell - * Valot ja äänijärjestelmän parantelua - * - * Revision 1.2 2002/05/17 23:13:30 msell - * Valot - * - * Revision 1.1 2002/05/16 18:42:07 msell - * Vektorifunctioita ja kamera - * - * - * - * $Date: 2002/07/22 11:40:26 $ - * - */ - #include "main.h" #include @@ -214,7 +9,7 @@ #include "object.h" #include "appearance.h" #include "sphere.h" -#include "vector.h" +#include "vector.h" #include "collision.h" #include "utils.h" #include "graphics.h" @@ -252,254 +47,254 @@ int points1, points2; bool fightinitialized = false; void initFight(void){ - if (!fightinitialized){ - initCollisions(); - addCollisionLink(COLLISIONGROUP_ARENA, COLLISIONGROUP_PARTICLE); - //addCollisionLink(COLLISIONGROUP_PARTICLE, COLLISIONGROUP_PARTICLE); + if (!fightinitialized){ + initCollisions(); + addCollisionLink(COLLISIONGROUP_ARENA, COLLISIONGROUP_PARTICLE); + //addCollisionLink(COLLISIONGROUP_PARTICLE, COLLISIONGROUP_PARTICLE); - addCollisionLink(COLLISIONGROUP_MAN1, COLLISIONGROUP_ARENA); - //addCollisionLink(COLLISIONGROUP_MAN1, COLLISIONGROUP_PARTICLE); - addCollisionLink(COLLISIONGROUP_MAN1, COLLISIONGROUP_MAN1); - addCollisionLink(COLLISIONGROUP_MAN1HAND, COLLISIONGROUP_ARENA); - //addCollisionLink(COLLISIONGROUP_MAN1HAND, COLLISIONGROUP_PARTICLE); + addCollisionLink(COLLISIONGROUP_MAN1, COLLISIONGROUP_ARENA); + //addCollisionLink(COLLISIONGROUP_MAN1, COLLISIONGROUP_PARTICLE); + addCollisionLink(COLLISIONGROUP_MAN1, COLLISIONGROUP_MAN1); + addCollisionLink(COLLISIONGROUP_MAN1HAND, COLLISIONGROUP_ARENA); + //addCollisionLink(COLLISIONGROUP_MAN1HAND, COLLISIONGROUP_PARTICLE); - addCollisionLink(COLLISIONGROUP_MAN2, COLLISIONGROUP_ARENA); - //addCollisionLink(COLLISIONGROUP_MAN2, COLLISIONGROUP_PARTICLE); - addCollisionLink(COLLISIONGROUP_MAN2, COLLISIONGROUP_MAN2); - addCollisionLink(COLLISIONGROUP_MAN2HAND, COLLISIONGROUP_ARENA); - //addCollisionLink(COLLISIONGROUP_MAN2HAND, COLLISIONGROUP_PARTICLE); + addCollisionLink(COLLISIONGROUP_MAN2, COLLISIONGROUP_ARENA); + //addCollisionLink(COLLISIONGROUP_MAN2, COLLISIONGROUP_PARTICLE); + addCollisionLink(COLLISIONGROUP_MAN2, COLLISIONGROUP_MAN2); + addCollisionLink(COLLISIONGROUP_MAN2HAND, COLLISIONGROUP_ARENA); + //addCollisionLink(COLLISIONGROUP_MAN2HAND, COLLISIONGROUP_PARTICLE); - addCollisionLink(COLLISIONGROUP_MAN1, COLLISIONGROUP_MAN2); - addCollisionLink(COLLISIONGROUP_MAN1, COLLISIONGROUP_MAN2HAND); - addCollisionLink(COLLISIONGROUP_MAN1HAND, COLLISIONGROUP_MAN2); - addCollisionLink(COLLISIONGROUP_MAN1HAND, COLLISIONGROUP_MAN2HAND); + addCollisionLink(COLLISIONGROUP_MAN1, COLLISIONGROUP_MAN2); + addCollisionLink(COLLISIONGROUP_MAN1, COLLISIONGROUP_MAN2HAND); + addCollisionLink(COLLISIONGROUP_MAN1HAND, COLLISIONGROUP_MAN2); + addCollisionLink(COLLISIONGROUP_MAN1HAND, COLLISIONGROUP_MAN2HAND); - //Sound* backgroundsong = new Sound("mixdown.mp3"); - Sound* backgroundsong = new Sound(BGSONG, true); - camera.setPosition(-5, 8, 18); - - arenaworld = new World(); + //Sound* backgroundsong = new Sound("mixdown.mp3"); + Sound* backgroundsong = new Sound(BGSONG, true); + camera.setPosition(-5, 8, 18); + + arenaworld = new World(); - //arenalight.setEnabled(true); - /*arenalight.setPosition(0, 10, 0); - Object *lamp = new Object(); - lamp->appearance = new LampAppearance(); - lamp->setPosition(0, 10, 0); - arenaworld->addChild(lamp);*/ + //arenalight.setEnabled(true); + /*arenalight.setPosition(0, 10, 0); + Object *lamp = new Object(); + lamp->appearance = new LampAppearance(); + lamp->setPosition(0, 10, 0); + arenaworld->addChild(lamp);*/ - } + } - light1.setColor(1, 1, 1); - light1.setSpecular(1, 1, 1); - light1.setPosition(-ARENASIZE+0.5, 5, -ARENASIZE+0.5); - light1.setAttenuation(0.2, 0.0, 0.02); + light1.setColor(1, 1, 1); + light1.setSpecular(1, 1, 1); + light1.setPosition(-ARENASIZE+0.5, 5, -ARENASIZE+0.5); + light1.setAttenuation(0.2, 0.0, 0.02); - light2.setColor(1, 1, 1); - light2.setSpecular(1, 1, 1); - light2.setPosition(ARENASIZE-0.5, 5, -ARENASIZE+0.5); - light2.setAttenuation(0.2, 0.0, 0.02); - - light3.setColor(1, 1, 1); - light3.setSpecular(1, 1, 1); - light3.setPosition(-ARENASIZE+0.5, 5, ARENASIZE-0.5); - light3.setAttenuation(0.2, 0.0, 0.02); + light2.setColor(1, 1, 1); + light2.setSpecular(1, 1, 1); + light2.setPosition(ARENASIZE-0.5, 5, -ARENASIZE+0.5); + light2.setAttenuation(0.2, 0.0, 0.02); - light4.setColor(1, 1, 1); - light4.setSpecular(1, 1, 1); - light4.setPosition(ARENASIZE-0.5, 5, ARENASIZE-0.5); - light4.setAttenuation(0.2, 0.0, 0.02); + light3.setColor(1, 1, 1); + light3.setSpecular(1, 1, 1); + light3.setPosition(-ARENASIZE+0.5, 5, ARENASIZE-0.5); + light3.setAttenuation(0.2, 0.0, 0.02); + + light4.setColor(1, 1, 1); + light4.setSpecular(1, 1, 1); + light4.setPosition(ARENASIZE-0.5, 5, ARENASIZE-0.5); + light4.setAttenuation(0.2, 0.0, 0.02); - if (!fightinitialized){ - Object *lamp; + if (!fightinitialized){ + Object *lamp; - lamp = new Object(); - lamp->appearance = new LampAppearance(); - lamp->setPosition(-ARENASIZE+0.5, (ARENAHEIGHT+0.5)*BLOCKHEIGHT, -ARENASIZE+0.5); - arenaworld->addChild(lamp); + lamp = new Object(); + lamp->appearance = new LampAppearance(); + lamp->setPosition(-ARENASIZE+0.5, (ARENAHEIGHT+0.5)*BLOCKHEIGHT, -ARENASIZE+0.5); + arenaworld->addChild(lamp); - lamp = new Object(); - lamp->appearance = new LampAppearance(); - lamp->setPosition(ARENASIZE-0.5, (ARENAHEIGHT+0.5)*BLOCKHEIGHT, -ARENASIZE+0.5); - arenaworld->addChild(lamp); + lamp = new Object(); + lamp->appearance = new LampAppearance(); + lamp->setPosition(ARENASIZE-0.5, (ARENAHEIGHT+0.5)*BLOCKHEIGHT, -ARENASIZE+0.5); + arenaworld->addChild(lamp); - lamp = new Object(); - lamp->appearance = new LampAppearance(); - lamp->setPosition(-ARENASIZE+0.5, (ARENAHEIGHT+0.5)*BLOCKHEIGHT, ARENASIZE-0.5); - arenaworld->addChild(lamp); + lamp = new Object(); + lamp->appearance = new LampAppearance(); + lamp->setPosition(-ARENASIZE+0.5, (ARENAHEIGHT+0.5)*BLOCKHEIGHT, ARENASIZE-0.5); + arenaworld->addChild(lamp); - lamp = new Object(); - lamp->appearance = new LampAppearance(); - lamp->setPosition(ARENASIZE-0.5, (ARENAHEIGHT+0.5)*BLOCKHEIGHT, ARENASIZE-0.5); - arenaworld->addChild(lamp); + lamp = new Object(); + lamp->appearance = new LampAppearance(); + lamp->setPosition(ARENASIZE-0.5, (ARENAHEIGHT+0.5)*BLOCKHEIGHT, ARENASIZE-0.5); + arenaworld->addChild(lamp); - //Floor - BasicBlock *floorblock; - floorblock = new BasicBlock(ARENASIZE*2, 3, ARENASIZE*2); - floorblock->setPosition(0, -BLOCKHEIGHT*3/2.0, 0); - floorblock->setColor(0, 1, 0); - floorblock->setCollisionGroup(COLLISIONGROUP_ARENA); - arenaworld->addChild(floorblock); + //Floor + BasicBlock *floorblock; + floorblock = new BasicBlock(ARENASIZE*2, 3, ARENASIZE*2); + floorblock->setPosition(0, -BLOCKHEIGHT*3/2.0, 0); + floorblock->setColor(0, 1, 0); + floorblock->setCollisionGroup(COLLISIONGROUP_ARENA); + arenaworld->addChild(floorblock); - //Corners - BasicBlock *arenacorner; + //Corners + BasicBlock *arenacorner; - arenacorner = new BasicBlock(1, ARENAHEIGHT, 1); - arenacorner->setColor(1, 0, 0); - //arenacorner->setCollisionGroup(COLLISIONGROUP_ARENA); - arenacorner->setPosition(ARENASIZE-0.5, BLOCKHEIGHT*ARENAHEIGHT/2.0, ARENASIZE-0.5); - arenaworld->addChild(arenacorner); + arenacorner = new BasicBlock(1, ARENAHEIGHT, 1); + arenacorner->setColor(1, 0, 0); + //arenacorner->setCollisionGroup(COLLISIONGROUP_ARENA); + arenacorner->setPosition(ARENASIZE-0.5, BLOCKHEIGHT*ARENAHEIGHT/2.0, ARENASIZE-0.5); + arenaworld->addChild(arenacorner); - arenacorner = new BasicBlock(1, ARENAHEIGHT, 1); - arenacorner->setColor(1, 0, 0); - //arenacorner->setCollisionGroup(COLLISIONGROUP_ARENA); - arenacorner->setPosition(-ARENASIZE+0.5, BLOCKHEIGHT*ARENAHEIGHT/2.0, ARENASIZE-0.5); - arenaworld->addChild(arenacorner); + arenacorner = new BasicBlock(1, ARENAHEIGHT, 1); + arenacorner->setColor(1, 0, 0); + //arenacorner->setCollisionGroup(COLLISIONGROUP_ARENA); + arenacorner->setPosition(-ARENASIZE+0.5, BLOCKHEIGHT*ARENAHEIGHT/2.0, ARENASIZE-0.5); + arenaworld->addChild(arenacorner); - arenacorner = new BasicBlock(1, ARENAHEIGHT, 1); - arenacorner->setColor(1, 0, 0); - //arenacorner->setCollisionGroup(COLLISIONGROUP_ARENA); - arenacorner->setPosition(ARENASIZE-0.5, BLOCKHEIGHT*ARENAHEIGHT/2.0, -ARENASIZE+0.5); - arenaworld->addChild(arenacorner); + arenacorner = new BasicBlock(1, ARENAHEIGHT, 1); + arenacorner->setColor(1, 0, 0); + //arenacorner->setCollisionGroup(COLLISIONGROUP_ARENA); + arenacorner->setPosition(ARENASIZE-0.5, BLOCKHEIGHT*ARENAHEIGHT/2.0, -ARENASIZE+0.5); + arenaworld->addChild(arenacorner); - arenacorner = new BasicBlock(1, ARENAHEIGHT, 1); - arenacorner->setColor(1, 0, 0); - //arenacorner->setCollisionGroup(COLLISIONGROUP_ARENA); - arenacorner->setPosition(-ARENASIZE+0.5, BLOCKHEIGHT*ARENAHEIGHT/2.0, -ARENASIZE+0.5); - arenaworld->addChild(arenacorner); + arenacorner = new BasicBlock(1, ARENAHEIGHT, 1); + arenacorner->setColor(1, 0, 0); + //arenacorner->setCollisionGroup(COLLISIONGROUP_ARENA); + arenacorner->setPosition(-ARENASIZE+0.5, BLOCKHEIGHT*ARENAHEIGHT/2.0, -ARENASIZE+0.5); + arenaworld->addChild(arenacorner); - //"Ropes" - MeshObject *arenaline; - Mesh *linegeometry; - MultiAppearance *lineappearance; - BasicBlockAppearance *line; - int geometryheight = BLOCKHEIGHT*ARENAHEIGHT; + //"Ropes" + MeshObject *arenaline; + Mesh *linegeometry; + MultiAppearance *lineappearance; + BasicBlockAppearance *line; + int geometryheight = BLOCKHEIGHT*ARENAHEIGHT; - linegeometry = createBox(-0.5, 0.5, -geometryheight/2, geometryheight/2-BLOCKHEIGHT, -ARENASIZE, ARENASIZE); - arenaline = new MeshObject(linegeometry); - lineappearance = new MultiAppearance(); - line = new BasicBlockAppearance(1, 1, ARENASIZE*2); - vectorSet(line->displacement, 0, -BLOCKHEIGHT*2.5, 0); - line->material.setColor(1, 0, 0, 1); - lineappearance->addAppearance(line), - line = new BasicBlockAppearance(1, 1, ARENASIZE*2); - vectorSet(line->displacement, 0, BLOCKHEIGHT*0.5, 0); - line->material.setColor(1, 0, 0, 1); - lineappearance->addAppearance(line), - line = new BasicBlockAppearance(1, 1, ARENASIZE*2); - vectorSet(line->displacement, 0, BLOCKHEIGHT*3.5, 0); - line->material.setColor(1, 0, 0, 1); - lineappearance->addAppearance(line), - arenaline->appearance = lineappearance; - arenaline->setCollisionGroup(COLLISIONGROUP_ARENA); - arenaline->setPosition(-ARENASIZE+0.5, geometryheight/2, 0); - arenaworld->addChild(arenaline); + linegeometry = createBox(-0.5, 0.5, -geometryheight/2, geometryheight/2-BLOCKHEIGHT, -ARENASIZE, ARENASIZE); + arenaline = new MeshObject(linegeometry); + lineappearance = new MultiAppearance(); + line = new BasicBlockAppearance(1, 1, ARENASIZE*2); + vectorSet(line->displacement, 0, -BLOCKHEIGHT*2.5, 0); + line->material.setColor(1, 0, 0, 1); + lineappearance->addAppearance(line), + line = new BasicBlockAppearance(1, 1, ARENASIZE*2); + vectorSet(line->displacement, 0, BLOCKHEIGHT*0.5, 0); + line->material.setColor(1, 0, 0, 1); + lineappearance->addAppearance(line), + line = new BasicBlockAppearance(1, 1, ARENASIZE*2); + vectorSet(line->displacement, 0, BLOCKHEIGHT*3.5, 0); + line->material.setColor(1, 0, 0, 1); + lineappearance->addAppearance(line), + arenaline->appearance = lineappearance; + arenaline->setCollisionGroup(COLLISIONGROUP_ARENA); + arenaline->setPosition(-ARENASIZE+0.5, geometryheight/2, 0); + arenaworld->addChild(arenaline); - linegeometry = createBox(-0.5, 0.5, -geometryheight/2, geometryheight/2-BLOCKHEIGHT, -ARENASIZE, ARENASIZE); - arenaline = new MeshObject(linegeometry); - lineappearance = new MultiAppearance(); - line = new BasicBlockAppearance(1, 1, ARENASIZE*2); - vectorSet(line->displacement, 0, -BLOCKHEIGHT*2.5, 0); - line->material.setColor(1, 0, 0, 1); - lineappearance->addAppearance(line), - line = new BasicBlockAppearance(1, 1, ARENASIZE*2); - vectorSet(line->displacement, 0, BLOCKHEIGHT*0.5, 0); - line->material.setColor(1, 0, 0, 1); - lineappearance->addAppearance(line), - line = new BasicBlockAppearance(1, 1, ARENASIZE*2); - vectorSet(line->displacement, 0, BLOCKHEIGHT*3.5, 0); - line->material.setColor(1, 0, 0, 1); - lineappearance->addAppearance(line), - arenaline->appearance = lineappearance; - arenaline->setCollisionGroup(COLLISIONGROUP_ARENA); - arenaline->setPosition(ARENASIZE-0.5, geometryheight/2, 0); - arenaworld->addChild(arenaline); + linegeometry = createBox(-0.5, 0.5, -geometryheight/2, geometryheight/2-BLOCKHEIGHT, -ARENASIZE, ARENASIZE); + arenaline = new MeshObject(linegeometry); + lineappearance = new MultiAppearance(); + line = new BasicBlockAppearance(1, 1, ARENASIZE*2); + vectorSet(line->displacement, 0, -BLOCKHEIGHT*2.5, 0); + line->material.setColor(1, 0, 0, 1); + lineappearance->addAppearance(line), + line = new BasicBlockAppearance(1, 1, ARENASIZE*2); + vectorSet(line->displacement, 0, BLOCKHEIGHT*0.5, 0); + line->material.setColor(1, 0, 0, 1); + lineappearance->addAppearance(line), + line = new BasicBlockAppearance(1, 1, ARENASIZE*2); + vectorSet(line->displacement, 0, BLOCKHEIGHT*3.5, 0); + line->material.setColor(1, 0, 0, 1); + lineappearance->addAppearance(line), + arenaline->appearance = lineappearance; + arenaline->setCollisionGroup(COLLISIONGROUP_ARENA); + arenaline->setPosition(ARENASIZE-0.5, geometryheight/2, 0); + arenaworld->addChild(arenaline); - linegeometry = createBox(-ARENASIZE, ARENASIZE, -geometryheight/2, geometryheight/2-BLOCKHEIGHT, -0.5, 0.5); - arenaline = new MeshObject(linegeometry); - lineappearance = new MultiAppearance(); - line = new BasicBlockAppearance(ARENASIZE*2, 1, 1); - vectorSet(line->displacement, 0, -BLOCKHEIGHT*2.5, 0); - line->material.setColor(1, 0, 0, 1); - lineappearance->addAppearance(line), - line = new BasicBlockAppearance(ARENASIZE*2, 1, 1); - vectorSet(line->displacement, 0, BLOCKHEIGHT*0.5, 0); - line->material.setColor(1, 0, 0, 1); - lineappearance->addAppearance(line), - line = new BasicBlockAppearance(ARENASIZE*2, 1, 1); - vectorSet(line->displacement, 0, BLOCKHEIGHT*3.5, 0); - line->material.setColor(1, 0, 0, 1); - lineappearance->addAppearance(line), - arenaline->appearance = lineappearance; - arenaline->setCollisionGroup(COLLISIONGROUP_ARENA); - arenaline->setPosition(0, geometryheight/2, -ARENASIZE+0.5); - arenaworld->addChild(arenaline); + linegeometry = createBox(-ARENASIZE, ARENASIZE, -geometryheight/2, geometryheight/2-BLOCKHEIGHT, -0.5, 0.5); + arenaline = new MeshObject(linegeometry); + lineappearance = new MultiAppearance(); + line = new BasicBlockAppearance(ARENASIZE*2, 1, 1); + vectorSet(line->displacement, 0, -BLOCKHEIGHT*2.5, 0); + line->material.setColor(1, 0, 0, 1); + lineappearance->addAppearance(line), + line = new BasicBlockAppearance(ARENASIZE*2, 1, 1); + vectorSet(line->displacement, 0, BLOCKHEIGHT*0.5, 0); + line->material.setColor(1, 0, 0, 1); + lineappearance->addAppearance(line), + line = new BasicBlockAppearance(ARENASIZE*2, 1, 1); + vectorSet(line->displacement, 0, BLOCKHEIGHT*3.5, 0); + line->material.setColor(1, 0, 0, 1); + lineappearance->addAppearance(line), + arenaline->appearance = lineappearance; + arenaline->setCollisionGroup(COLLISIONGROUP_ARENA); + arenaline->setPosition(0, geometryheight/2, -ARENASIZE+0.5); + arenaworld->addChild(arenaline); - linegeometry = createBox(-ARENASIZE, ARENASIZE, -geometryheight/2, geometryheight/2-BLOCKHEIGHT, -0.5, 0.5); - arenaline = new MeshObject(linegeometry); - lineappearance = new MultiAppearance(); - line = new BasicBlockAppearance(ARENASIZE*2, 1, 1); - vectorSet(line->displacement, 0, -BLOCKHEIGHT*2.5, 0); - line->material.setColor(1, 0, 0, 1); - lineappearance->addAppearance(line), - line = new BasicBlockAppearance(ARENASIZE*2, 1, 1); - vectorSet(line->displacement, 0, BLOCKHEIGHT*0.5, 0); - line->material.setColor(1, 0, 0, 1); - lineappearance->addAppearance(line), - line = new BasicBlockAppearance(ARENASIZE*2, 1, 1); - vectorSet(line->displacement, 0, BLOCKHEIGHT*3.5, 0); - line->material.setColor(1, 0, 0, 1); - lineappearance->addAppearance(line), - arenaline->appearance = lineappearance; - arenaline->setCollisionGroup(COLLISIONGROUP_ARENA); - arenaline->setPosition(0, geometryheight/2, ARENASIZE-0.5); - arenaworld->addChild(arenaline); + linegeometry = createBox(-ARENASIZE, ARENASIZE, -geometryheight/2, geometryheight/2-BLOCKHEIGHT, -0.5, 0.5); + arenaline = new MeshObject(linegeometry); + lineappearance = new MultiAppearance(); + line = new BasicBlockAppearance(ARENASIZE*2, 1, 1); + vectorSet(line->displacement, 0, -BLOCKHEIGHT*2.5, 0); + line->material.setColor(1, 0, 0, 1); + lineappearance->addAppearance(line), + line = new BasicBlockAppearance(ARENASIZE*2, 1, 1); + vectorSet(line->displacement, 0, BLOCKHEIGHT*0.5, 0); + line->material.setColor(1, 0, 0, 1); + lineappearance->addAppearance(line), + line = new BasicBlockAppearance(ARENASIZE*2, 1, 1); + vectorSet(line->displacement, 0, BLOCKHEIGHT*3.5, 0); + line->material.setColor(1, 0, 0, 1); + lineappearance->addAppearance(line), + arenaline->appearance = lineappearance; + arenaline->setCollisionGroup(COLLISIONGROUP_ARENA); + arenaline->setPosition(0, geometryheight/2, ARENASIZE-0.5); + arenaworld->addChild(arenaline); - float movement[3]; + float movement[3]; - man1 = new Legoman(PLAYER1); - man1->insertToWorld(arenaworld); - vectorSet(movement, -4, 0, 0); - man1->move(movement); - man1->lockPart(LEFTLEG | RIGHTLEG); + man1 = new Legoman(PLAYER1); + man1->insertToWorld(arenaworld); + vectorSet(movement, -4, 0, 0); + man1->move(movement); + man1->lockPart(LEFTLEG | RIGHTLEG); - man2 = new Legoman(PLAYER2); - man2->insertToWorld(arenaworld); - vectorSet(movement, 4, 0, 0); - man2->move(movement); - man2->lockPart(LEFTLEG | RIGHTLEG); + man2 = new Legoman(PLAYER2); + man2->insertToWorld(arenaworld); + vectorSet(movement, 4, 0, 0); + man2->move(movement); + man2->lockPart(LEFTLEG | RIGHTLEG); - man1->addOpponent(man2); - man2->addOpponent(man1); + man1->addOpponent(man2); + man2->addOpponent(man1); - initBloods(arenaworld); + initBloods(arenaworld); - hitsound1 = new Sound(DATAPATH"hit1.wav"); - softhitsound1 = new Sound(DATAPATH"hitsoft1.wav"); - softhitsound2 = new Sound(DATAPATH"hitsoft2.wav"); - jumpsound = new Sound(DATAPATH"jump.wav"); - fallsound1 = new Sound(DATAPATH"fall1.wav"); - fallsound2 = new Sound(DATAPATH"fall2.wav"); - fightsound = new Sound(DATAPATH"fight.wav"); - victorysound = new Sound(DATAPATH"victory.wav"); + hitsound1 = new Sound(DATAPATH"hit1.wav"); + softhitsound1 = new Sound(DATAPATH"hitsoft1.wav"); + softhitsound2 = new Sound(DATAPATH"hitsoft2.wav"); + jumpsound = new Sound(DATAPATH"jump.wav"); + fallsound1 = new Sound(DATAPATH"fall1.wav"); + fallsound2 = new Sound(DATAPATH"fall2.wav"); + fightsound = new Sound(DATAPATH"fight.wav"); + victorysound = new Sound(DATAPATH"victory.wav"); - fightmusic = new Sound(DATAPATH"fight.mp3", true); - } + fightmusic = new Sound(DATAPATH"fight.mp3", true); + } - float cameraTarget[3] = {0, 6, 0}; - camera.setTarget(cameraTarget); - arenaworld->prepare(); + float cameraTarget[3] = {0, 6, 0}; + camera.setTarget(cameraTarget); + arenaworld->prepare(); - points1 = 0; - points2 = 0; + points1 = 0; + points2 = 0; - winner = man1; + winner = man1; } #define MAXSCORE 3 @@ -507,17 +302,17 @@ void initFight(void){ int trophycounter = -1; void resetFight(void){ - float movement[3]; - man1->heal(); - man2->heal(); + float movement[3]; + man1->heal(); + man2->heal(); - vectorSet(movement, -4, 0, 0); - man1->move(movement); - vectorSet(movement, 4, 0, 0); - man2->move(movement); + vectorSet(movement, -4, 0, 0); + man1->move(movement); + vectorSet(movement, 4, 0, 0); + man2->move(movement); - man1->lockPart(LEFTLEG | RIGHTLEG); - man2->lockPart(LEFTLEG | RIGHTLEG); + man1->lockPart(LEFTLEG | RIGHTLEG); + man2->lockPart(LEFTLEG | RIGHTLEG); } int startcounter, endcounter; @@ -529,22 +324,22 @@ bool dead; Legoman *winner; void gameOver(Legoman *loser){ - endcounter = 0; - dead = true; - winner = loser->getOpponent(); + endcounter = 0; + dead = true; + winner = loser->getOpponent(); } void startFight(void){ - resetFight(); - fightmusic->setVolume(0); - fightmusic->play(); - fightmusic->fadeIn(300); - startcounter = 0; - trophycounter = -1; - fightfade = 1; - dead = false; - points1 = 0; - points2 = 0; + resetFight(); + fightmusic->setVolume(0); + fightmusic->play(); + fightmusic->fadeIn(300); + startcounter = 0; + trophycounter = -1; + fightfade = 1; + dead = false; + points1 = 0; + points2 = 0; } SDLKey player1left = SDLK_LEFT; @@ -563,27 +358,27 @@ SDLKey player2hit = SDLK_LCTRL; void stopGame(void){ - light1.setEnabled(false); - light2.setEnabled(false); - light3.setEnabled(false); - light4.setEnabled(false); - changeGameMode(MENUMODE); - fightmusic->fadeOut(300); - menuRestart(); + light1.setEnabled(false); + light2.setEnabled(false); + light3.setEnabled(false); + light4.setEnabled(false); + changeGameMode(MENUMODE); + fightmusic->fadeOut(300); + menuRestart(); } void endGame(void){ - trophycounter = 0; + trophycounter = 0; } void endGame2(void){ - light1.setEnabled(false); - light2.setEnabled(false); - light3.setEnabled(false); - light4.setEnabled(false); - changeGameMode(ENDMODE); - winner->heal(); - endRestart(); + light1.setEnabled(false); + light2.setEnabled(false); + light3.setEnabled(false); + light4.setEnabled(false); + changeGameMode(ENDMODE); + winner->heal(); + endRestart(); } #define READY 250 @@ -596,207 +391,207 @@ void endGame2(void){ #define TROPHYFADE 400 void calculateFight(int framecount){ - fightfade = -1; - if (startcounter < 200){ - fightfade = (200-startcounter)/200.0; - } - if (startcounter == FIGHT - 30){ - fightsound->play(); - } - startcounter++; + fightfade = -1; + if (startcounter < 200){ + fightfade = (200-startcounter)/200.0; + } + if (startcounter == FIGHT - 30){ + fightsound->play(); + } + startcounter++; - if (endcounter == VICTORY){ - victorysound->play(); - if (winner == man1) points1++; - if (winner == man2) points2++; - } - if (endcounter >= ENDFADE && endcounter <= STARTOVER){ - fightfade = (endcounter - ENDFADE)/(STARTOVER-ENDFADE); - } - if (endcounter == STARTOVER){ - if (points1 == MAXSCORE || points2 == MAXSCORE){ - endGame(); - } else{ - startcounter = 0; - resetFight(); - dead = false; - endcounter = 0; - } - } - if (dead) endcounter++; - if (trophycounter != -1){ - fightfade = (float)trophycounter/TROPHYFADE; - trophycounter++; - if (trophycounter == TROPHYFADE) endGame2(); - } + if (endcounter == VICTORY){ + victorysound->play(); + if (winner == man1) points1++; + if (winner == man2) points2++; + } + if (endcounter >= ENDFADE && endcounter <= STARTOVER){ + fightfade = (endcounter - ENDFADE)/(STARTOVER-ENDFADE); + } + if (endcounter == STARTOVER){ + if (points1 == MAXSCORE || points2 == MAXSCORE){ + endGame(); + } else{ + startcounter = 0; + resetFight(); + dead = false; + endcounter = 0; + } + } + if (dead) endcounter++; + if (trophycounter != -1){ + fightfade = (float)trophycounter/TROPHYFADE; + trophycounter++; + if (trophycounter == TROPHYFADE) endGame2(); + } - /*if (framecount % 10 == 0){ - float pos[3] = {0, 5, 0}; - float vel[3] = {randomf(2)-1, randomf(2)-1, randomf(2)-1}; - createBlood(pos, vel); - }*/ - //arenalight.setPosition(sin(framecount*0.01)*6, 3, cos(framecount*0.01)*4); - //light2.setPosition(sin(framecount*0.017)*6, 2, cos(framecount*0.027)*5); - //light3.setPosition(sin(framecount*0.023)*3, 4, cos(framecount*0.013)*3); - - camera.setPosition(sin(framecount*0.0005)*20, sin(framecount*0.0013)*5+15, cos(framecount*0.0005)*20); - - //camera.setPosition(8, 5, 5); - - float upmovement[3] = {0, 0.001, 0}; - man1->move(upmovement); - man2->move(upmovement); - man1->update(); - man2->update(); + /*if (framecount % 10 == 0){ + float pos[3] = {0, 5, 0}; + float vel[3] = {randomf(2)-1, randomf(2)-1, randomf(2)-1}; + createBlood(pos, vel); + }*/ + //arenalight.setPosition(sin(framecount*0.01)*6, 3, cos(framecount*0.01)*4); + //light2.setPosition(sin(framecount*0.017)*6, 2, cos(framecount*0.027)*5); + //light3.setPosition(sin(framecount*0.023)*3, 4, cos(framecount*0.013)*3); - if (startcounter >= FIGHT){ + camera.setPosition(sin(framecount*0.0005)*20, sin(framecount*0.0013)*5+15, cos(framecount*0.0005)*20); - if (man1->isAlive()){ - if (keys[player1left]) man1->turn(5); - if (keys[player1right]) man1->turn(-5); - if (keys[player1forward]) man1->walk(0.03); - if (keys[player1backward]) man1->walk(-0.03); - if (keys[player1jump]) man1->jump(); - if (keys[player1hit]) man1->hit(); - } + //camera.setPosition(8, 5, 5); - if (man2->isAlive()){ - if (keys[player2left]) man2->turn(5); - if (keys[player2right]) man2->turn(-5); - if (keys[player2forward]) man2->walk(0.03); - if (keys[player2backward]) man2->walk(-0.03); - if (keys[player2jump]) man2->jump(); - if (keys[player2hit]) man2->hit(); - } - } + float upmovement[3] = {0, 0.001, 0}; + man1->move(upmovement); + man2->move(upmovement); + man1->update(); + man2->update(); + + if (startcounter >= FIGHT){ + + if (man1->isAlive()){ + if (keys[player1left]) man1->turn(5); + if (keys[player1right]) man1->turn(-5); + if (keys[player1forward]) man1->walk(0.03); + if (keys[player1backward]) man1->walk(-0.03); + if (keys[player1jump]) man1->jump(); + if (keys[player1hit]) man1->hit(); + } + + if (man2->isAlive()){ + if (keys[player2left]) man2->turn(5); + if (keys[player2right]) man2->turn(-5); + if (keys[player2forward]) man2->walk(0.03); + if (keys[player2backward]) man2->walk(-0.03); + if (keys[player2jump]) man2->jump(); + if (keys[player2hit]) man2->hit(); + } + } - if (keys[SDLK_ESCAPE]){ - stopGame(); - } + if (keys[SDLK_ESCAPE]){ + stopGame(); + } - arenaworld->move(); + arenaworld->move(); } void drawDamageMeters(void){ - enable2D(); + enable2D(); - glEnable(GL_BLEND); + glEnable(GL_BLEND); - glPushMatrix(); - glTranslatef(0.925, 0.22-0.025, 0); - glScalef(0.08*3/4, 0.08, 0.1); - man1->drawVisuals(); - glPopMatrix(); + glPushMatrix(); + glTranslatef(0.925, 0.22-0.025, 0); + glScalef(0.08*3/4, 0.08, 0.1); + man1->drawVisuals(); + glPopMatrix(); - glPushMatrix(); - glTranslatef(0.075, 0.22-0.025, 0); - glScalef(0.08*3/4, 0.08, 0.1); - man2->drawVisuals(); - glPopMatrix(); + glPushMatrix(); + glTranslatef(0.075, 0.22-0.025, 0); + glScalef(0.08*3/4, 0.08, 0.1); + man2->drawVisuals(); + glPopMatrix(); - glDisable(GL_TEXTURE_2D); + glDisable(GL_TEXTURE_2D); - glColor3f(1, 1, 0); + glColor3f(1, 1, 0); - char pointstring[5]; - sprintf(pointstring, "%i", points1); - print(0.75, 0.05, pointstring, 0.15); + char pointstring[5]; + sprintf(pointstring, "%i", points1); + print(0.75, 0.05, pointstring, 0.15); - sprintf(pointstring, "%i", points2); - print(0.15, 0.05, pointstring, 0.15); + sprintf(pointstring, "%i", points2); + print(0.15, 0.05, pointstring, 0.15); - disable2D(); + disable2D(); } void drawFight(int framecount){ - glLoadIdentity(); - camera.glUpdate(); - //float position[3]; - //camera.getPosition((float*)position); - //createSkyBox(position[0], position[1], position[2], 50, 20, 50); - - createSkyBox(0, 10, 0, 50, 20, 50); - + glLoadIdentity(); + camera.glUpdate(); + //float position[3]; + //camera.getPosition((float*)position); + //createSkyBox(position[0], position[1], position[2], 50, 20, 50); - light1.setEnabled(true); - light2.setEnabled(true); - light3.setEnabled(true); - light4.setEnabled(true); - - updateLights(); - - arenaworld->draw(); - - drawDamageMeters(); + createSkyBox(0, 10, 0, 50, 20, 50); - flaretexture->enable(); - light1.createFlare(); - light2.createFlare(); - light3.createFlare(); - light4.createFlare(); - flaretexture->disable(); - + light1.setEnabled(true); + light2.setEnabled(true); + light3.setEnabled(true); + light4.setEnabled(true); - enable2D(); + updateLights(); - if (fightfade != -1){ - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glColor4f(0, 0, 0, fightfade); - glBegin(GL_QUADS); - glVertex2f(0, 0); - glVertex2f(1, 0); - glVertex2f(1, 1); - glVertex2f(0, 1); - glEnd(); - } + arenaworld->draw(); - if (startcounter >= READY && startcounter < FIGHT){ - float size = 0.2 - (startcounter - READY)*0.0001; - float alpha = 1 - (float)(startcounter - READY)/(FIGHT - READY); - float x = 0.5 - size*1.5; - float y = 0.5 - size*0.5; + drawDamageMeters(); - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glColor4f(alpha, 0, 0, alpha); - print(x, y, "Ready", size); - } - if (startcounter >= FIGHT && startcounter < FIGHT+200){ - float size = 0.2 + (startcounter - FIGHT)*0.0005; - float alpha = 1 - (float)(startcounter - FIGHT)/200; - float x = 0.5 - size*1.4; - float y = 0.5 - size*0.5; - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glColor4f(0, alpha, 0, alpha); - print(x, y, "Fight!", size); - } + flaretexture->enable(); + light1.createFlare(); + light2.createFlare(); + light3.createFlare(); + light4.createFlare(); + flaretexture->disable(); - if (dead){ - if (endcounter >= VICTORY && endcounter < VICTORYEND){ - float size = 0.18 + (endcounter - VICTORY)*0.0001; - float alpha = (float)(endcounter - VICTORY)/(VICTORYEND-VICTORY); - alpha = 1-4*(alpha-0.5)*(alpha-0.5); - alpha = pow(alpha, 0.5); - float x = 0.5 - size*1.9; - float y = 0.3 - size*0.5; - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glColor4f(0, 0, alpha, alpha); - print(x, y, "Victory!", size); - } - } + enable2D(); - disable2D(); + if (fightfade != -1){ + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glColor4f(0, 0, 0, fightfade); + glBegin(GL_QUADS); + glVertex2f(0, 0); + glVertex2f(1, 0); + glVertex2f(1, 1); + glVertex2f(0, 1); + glEnd(); + } - - glDisable(GL_BLEND); - glEnable(GL_DEPTH_TEST); + if (startcounter >= READY && startcounter < FIGHT){ + float size = 0.2 - (startcounter - READY)*0.0001; + float alpha = 1 - (float)(startcounter - READY)/(FIGHT - READY); + float x = 0.5 - size*1.5; + float y = 0.5 - size*0.5; + + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glColor4f(alpha, 0, 0, alpha); + print(x, y, "Ready", size); + } + if (startcounter >= FIGHT && startcounter < FIGHT+200){ + float size = 0.2 + (startcounter - FIGHT)*0.0005; + float alpha = 1 - (float)(startcounter - FIGHT)/200; + float x = 0.5 - size*1.4; + float y = 0.5 - size*0.5; + + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glColor4f(0, alpha, 0, alpha); + print(x, y, "Fight!", size); + } + + if (dead){ + if (endcounter >= VICTORY && endcounter < VICTORYEND){ + float size = 0.18 + (endcounter - VICTORY)*0.0001; + float alpha = (float)(endcounter - VICTORY)/(VICTORYEND-VICTORY); + alpha = 1-4*(alpha-0.5)*(alpha-0.5); + alpha = pow(alpha, 0.5); + float x = 0.5 - size*1.9; + float y = 0.3 - size*0.5; + + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glColor4f(0, 0, alpha, alpha); + print(x, y, "Victory!", size); + } + } + + disable2D(); + + + glDisable(GL_BLEND); + glEnable(GL_DEPTH_TEST); } diff --git a/src/fight.h b/src/fight.h index 48c3a5d..4d79d2c 100644 --- a/src/fight.h +++ b/src/fight.h @@ -1,66 +1,3 @@ -/* - * $Id: fight.h,v 1.17 2002/07/22 01:14:14 msell Exp $ - * - * - * $Log: fight.h,v $ - * Revision 1.17 2002/07/22 01:14:14 msell - * Lopetussysteemi - * - * Revision 1.16 2002/07/21 15:03:12 msell - * Äänet disabloitu - * - * Revision 1.15 2002/07/19 20:33:28 msell - * #pragma once -> #ifndef - * - * Revision 1.14 2002/07/19 20:06:32 msell - * Linux-porttausta - * - * Revision 1.13 2002/07/19 18:59:46 msell - * Alkuhommaa ja säätöä - * - * Revision 1.12 2002/07/19 14:05:52 msell - * Damagetextuurit näkyy - * - * Revision 1.11 2002/07/18 23:05:31 msell - * Partikkelit ja kakkospelaajan liike - * - * Revision 1.10 2002/07/17 22:45:54 msell - * Ääniä vähän - * - * Revision 1.9 2002/07/16 17:16:34 msell - * Fontit ja valikot - * - * Revision 1.8 2002/07/15 15:22:08 msell - * Parantelua - * - * Revision 1.7 2002/07/14 21:22:40 jkaarlas - * skybox ja ukkojen säätö - * - * Revision 1.6 2002/07/08 22:53:38 msell - * Säätöä - * - * Revision 1.5 2002/07/07 15:29:07 msell - * Törmäyksien parantelua - * - * Revision 1.4 2002/07/04 21:05:41 msell - * Se toimii!! =) - * Törmäystarkistukset siis - * - * Revision 1.3 2002/06/04 16:28:32 msell - * #pragma once - * - * Revision 1.2 2002/06/02 16:57:37 msell - * Objektirakenteen pohja - * - * Revision 1.1 2002/05/16 18:42:07 msell - * Vektorifunctioita ja kamera - * - * - * - * $Date: 2002/07/22 01:14:14 $ - * - */ - #ifndef __FIGHT_H_INCLUDED__ #define __FIGHT_H_INCLUDED__ diff --git a/src/font.cpp b/src/font.cpp index 85ead2f..b33bcfa 100644 --- a/src/font.cpp +++ b/src/font.cpp @@ -1,32 +1,3 @@ -/* - * $Id: font.cpp,v 1.6 2002/07/21 20:14:28 msell Exp $ - * - * - * $Log: font.cpp,v $ - * Revision 1.6 2002/07/21 20:14:28 msell - * no message - * - * Revision 1.5 2002/07/19 18:59:46 msell - * Alkuhommaa ja säätöä - * - * Revision 1.4 2002/07/19 14:05:52 msell - * Damagetextuurit näkyy - * - * Revision 1.3 2002/07/19 12:10:53 msell - * Hups - * - * Revision 1.2 2002/07/17 16:40:33 msell - * Resoluution vaihto - * - * Revision 1.1 2002/07/16 17:16:34 msell - * Fontit ja valikot - * - * - * - * $Date: 2002/07/21 20:14:28 $ - * - */ - #include "main.h" #include "font.h" @@ -35,68 +6,68 @@ Texture *fonttexture; void drawChar(float x, float y, char ch, float size){ - fonttexture->enable(); + fonttexture->enable(); - int tx = (ch&15)*64; - int ty = (ch>>4)*64; + int tx = (ch&15)*64; + int ty = (ch>>4)*64; - float w = size, h = size*4/3; + float w = size, h = size*4/3; - glEnable(GL_BLEND); - glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_COLOR); + glEnable(GL_BLEND); + glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_COLOR); - glBegin(GL_QUADS); - glTexCoord2f((tx)/1024.0, (ty)/1024.0); - glVertex2f(x, y); + glBegin(GL_QUADS); + glTexCoord2f((tx)/1024.0, (ty)/1024.0); + glVertex2f(x, y); - glTexCoord2f((tx)/1024.0, (ty+64)/1024.0); - glVertex2f(x, y+h); - - glTexCoord2f((tx+64)/1024.0, (ty+64)/1024.0); - glVertex2f(x+w, y+h); - - glTexCoord2f((tx+64)/1024.0, (ty)/1024.0); - glVertex2f(x+w, y); + glTexCoord2f((tx)/1024.0, (ty+64)/1024.0); + glVertex2f(x, y+h); - glEnd(); + glTexCoord2f((tx+64)/1024.0, (ty+64)/1024.0); + glVertex2f(x+w, y+h); - fonttexture->disable(); + glTexCoord2f((tx+64)/1024.0, (ty)/1024.0); + glVertex2f(x+w, y); + + glEnd(); + + fonttexture->disable(); } float letterwidth[256] = { - 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, - 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, - 0.5, 0.2, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.45, 0.2, 0.5, - 0.6, 0.5, 0.6, 0.6, 0.65, 0.65, 0.6, 0.65, 0.6, 0.6, 0.2, 1.0, 1.0, 1.0, 1.0, 0.5, - 1.0, 0.7, 0.6, 0.7, 0.7, 0.65, 0.6, 0.7, 0.8, 0.6, 0.7, 0.7, 0.6, 0.9, 0.85, 0.8, - 0.6, 0.9, 0.7, 0.7, 0.7, 0.7, 0.7, 1.0, 0.8, 0.7, 0.8, 1.0, 1.0, 1.0, 1.0, 1.0, - 1.0, 0.6, 0.6, 0.6, 0.6, 0.6, 0.5, 0.6, 0.6, 0.2, 0.4, 0.6, 0.2, 0.8, 0.5, 0.55, - 0.55, 0.55, 0.5, 0.55, 0.55, 0.55, 0.6, 0.8, 0.6, 0.6, 0.6, 1.0, 1.0, 1.0, 1.0, 1.0, - 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, - 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, - 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, - 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, - 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, - 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, - 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, - 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 + 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, + 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, + 0.5, 0.2, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.45, 0.2, 0.5, + 0.6, 0.5, 0.6, 0.6, 0.65, 0.65, 0.6, 0.65, 0.6, 0.6, 0.2, 1.0, 1.0, 1.0, 1.0, 0.5, + 1.0, 0.7, 0.6, 0.7, 0.7, 0.65, 0.6, 0.7, 0.8, 0.6, 0.7, 0.7, 0.6, 0.9, 0.85, 0.8, + 0.6, 0.9, 0.7, 0.7, 0.7, 0.7, 0.7, 1.0, 0.8, 0.7, 0.8, 1.0, 1.0, 1.0, 1.0, 1.0, + 1.0, 0.6, 0.6, 0.6, 0.6, 0.6, 0.5, 0.6, 0.6, 0.2, 0.4, 0.6, 0.2, 0.8, 0.5, 0.55, + 0.55, 0.55, 0.5, 0.55, 0.55, 0.55, 0.6, 0.8, 0.6, 0.6, 0.6, 1.0, 1.0, 1.0, 1.0, 1.0, + 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, + 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, + 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, + 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, + 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, + 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, + 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, + 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 }; void print(float x, float y, char *text, float size){ - int i; - int textlength = strlen(text); - float px = x; - float py = y; - for (i = 0; i < textlength; i++){ - char ch = text[i]; - if (ch == '\n'){ - px = x; - py += size*1.2; - } else{ - drawChar(px, py, ch, size); - px += size*letterwidth[ch]; - } - } + int i; + int textlength = strlen(text); + float px = x; + float py = y; + for (i = 0; i < textlength; i++){ + char ch = text[i]; + if (ch == '\n'){ + px = x; + py += size*1.2; + } else{ + drawChar(px, py, ch, size); + px += size*letterwidth[ch]; + } + } } diff --git a/src/font.h b/src/font.h index 0b7677b..2ec09a2 100644 --- a/src/font.h +++ b/src/font.h @@ -1,23 +1,3 @@ -/* - * $Id: font.h,v 1.3 2002/07/19 20:33:28 msell Exp $ - * - * - * $Log: font.h,v $ - * Revision 1.3 2002/07/19 20:33:28 msell - * #pragma once -> #ifndef - * - * Revision 1.2 2002/07/19 14:05:52 msell - * Damagetextuurit näkyy - * - * Revision 1.1 2002/07/16 17:16:34 msell - * Fontit ja valikot - * - * - * - * $Date: 2002/07/19 20:33:28 $ - * - */ - #ifndef __FONT_H_INCLUDED__ #define __FONT_H_INCLUDED__ diff --git a/src/glapi.cpp b/src/glapi.cpp index 8663184..13bbfb4 100644 --- a/src/glapi.cpp +++ b/src/glapi.cpp @@ -1,67 +1,28 @@ -/* - * $Id: glapi.cpp,v 1.9 2002/07/21 15:03:12 msell Exp $ - * - * - * $Log: glapi.cpp,v $ - * Revision 1.9 2002/07/21 15:03:12 msell - * Äänet disabloitu - * - * Revision 1.8 2002/07/15 20:32:35 msell - * Uudet valot ja ulkoasun parantelua - * - * Revision 1.7 2002/06/17 19:58:08 msell - * #includeiden parantelua - * - * Revision 1.6 2002/06/05 18:39:04 msell - * Jotain pientä - * - * Revision 1.5 2002/06/05 15:00:41 msell - * Palikoihin lisää detailia, facet jaetaan halutun kokosiin osiin - * - * Revision 1.4 2002/06/03 23:06:38 msell - * no message - * - * Revision 1.3 2002/05/17 23:13:30 msell - * Valot - * - * Revision 1.2 2002/05/16 18:41:16 msell - * Vektorifunctioita ja kamera - * - * Revision 1.1 2002/05/15 14:36:39 msell - * Yksinkertainen SDL-runko (Kääntyy toistaiseksi vain windowsissa). - * Mukana myös musiikinsoitto fmodilla. - * - * - * - * $Date: 2002/07/21 15:03:12 $ - * - */ - #include "main.h" #include "glapi.h" void setupOpengl(int width, int height){ - //float ratio = (float)width/height; - float ratio = 4.0/3.0; + //float ratio = (float)width/height; + float ratio = 4.0/3.0; - glShadeModel(GL_SMOOTH); + glShadeModel(GL_SMOOTH); - glCullFace(GL_BACK); - glFrontFace(GL_CCW); - glEnable(GL_CULL_FACE); + glCullFace(GL_BACK); + glFrontFace(GL_CCW); + glEnable(GL_CULL_FACE); - glEnable(GL_DEPTH_TEST); - glDepthFunc(GL_LEQUAL); - glClearDepth(1.0); + glEnable(GL_DEPTH_TEST); + glDepthFunc(GL_LEQUAL); + glClearDepth(1.0); - glClearColor(0, 0, 0, 0); + glClearColor(0, 0, 0, 0); - glEnable(GL_COLOR_MATERIAL); + glEnable(GL_COLOR_MATERIAL); - //Enables lighting with zero initial lights. Lights are created with Light-class - glEnable(GL_LIGHTING); - glDisable(GL_LIGHT0); + //Enables lighting with zero initial lights. Lights are created with Light-class + glEnable(GL_LIGHTING); + glDisable(GL_LIGHT0); float ambient[4]= {0.1, 0.1, 0.1, 1}; glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambient); @@ -70,34 +31,34 @@ void setupOpengl(int width, int height){ glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE); GLfloat zero[4] = {0, 0, 0, 1}; - GLfloat one[4] = {1, 1, 1, 1}; + GLfloat one[4] = {1, 1, 1, 1}; - //Default frontface lighting + //Default frontface lighting glMaterialfv(GL_FRONT, GL_AMBIENT, one); glMaterialfv(GL_FRONT, GL_DIFFUSE, one); - GLfloat specular[4] = {2, 2, 2, 1}; + GLfloat specular[4] = {2, 2, 2, 1}; glMaterialfv(GL_FRONT, GL_SPECULAR, specular); glMaterialf(GL_FRONT, GL_SHININESS, 120); - //Never any backface lighting, except ambient + //Never any backface lighting, except ambient glMaterialfv(GL_BACK, GL_AMBIENT, one); glMaterialfv(GL_BACK, GL_DIFFUSE, zero); glMaterialfv(GL_BACK, GL_SPECULAR, zero); - glViewport(0, 0, width, height); + glViewport(0, 0, width, height); - glDepthFunc(GL_LEQUAL); + glDepthFunc(GL_LEQUAL); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); - glEnable(GL_NORMALIZE); + glEnable(GL_NORMALIZE); - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); - gluPerspective(60.0, ratio, 1.0, 1024.0); + gluPerspective(60.0, ratio, 1.0, 1024.0); - //glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); + //glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); } diff --git a/src/glapi.h b/src/glapi.h index 8cafcd3..e6fba06 100644 --- a/src/glapi.h +++ b/src/glapi.h @@ -1,33 +1,3 @@ -/* - * $Id: glapi.h,v 1.6 2002/07/19 20:33:28 msell Exp $ - * - * - * $Log: glapi.h,v $ - * Revision 1.6 2002/07/19 20:33:28 msell - * #pragma once -> #ifndef - * - * Revision 1.5 2002/06/17 19:58:08 msell - * #includeiden parantelua - * - * Revision 1.4 2002/06/16 01:04:58 jkaarlas - * tulipa säädettyä includejen kanssa. oon tod.näk. eri mieltä aamulla - * - * Revision 1.3 2002/06/04 16:28:32 msell - * #pragma once - * - * Revision 1.2 2002/05/16 18:41:16 msell - * Vektorifunctioita ja kamera - * - * Revision 1.1 2002/05/15 14:36:39 msell - * Yksinkertainen SDL-runko (Kääntyy toistaiseksi vain windowsissa). - * Mukana myös musiikinsoitto fmodilla. - * - * - * - * $Date: 2002/07/19 20:33:28 $ - * - */ - #ifndef __GLAPI_H_INCLUDED__ #define __GLAPI_H_INCLUDED__ diff --git a/src/graphics.cpp b/src/graphics.cpp index 70caaec..3874dad 100644 --- a/src/graphics.cpp +++ b/src/graphics.cpp @@ -1,62 +1,3 @@ -/* - * $Id: graphics.cpp,v 1.17 2002/07/21 15:03:12 msell Exp $ - * - * - * $Log: graphics.cpp,v $ - * Revision 1.17 2002/07/21 15:03:12 msell - * Äänet disabloitu - * - * Revision 1.16 2002/07/19 22:01:35 msell - * Säätöä - * - * Revision 1.15 2002/07/19 21:32:54 msell - * Mipmap pois - * - * Revision 1.14 2002/07/19 21:17:06 msell - * bugifixi - * - * Revision 1.13 2002/07/17 16:40:33 msell - * Resoluution vaihto - * - * Revision 1.12 2002/07/14 21:22:39 jkaarlas - * skybox ja ukkojen säätö - * - * Revision 1.11 2002/06/28 14:51:40 jkaarlas - * transparenttilatausta korjailtu - * - * Revision 1.10 2002/06/27 21:42:32 jkaarlas - * lisätty transparentin tekstuurin lataus - * - * Revision 1.9 2002/06/26 18:54:43 jkaarlas - * Nyt se lataus vihdoin toimii - * - * Revision 1.8 2002/06/20 15:30:22 jkaarlas - * tekstuurisäätöä - * - * Revision 1.7 2002/06/19 22:44:56 jkaarlas - * lisätty glTexEnvf lataukseen - * - * Revision 1.6 2002/06/17 20:49:04 msell - * free -> SDL_FreeSurface - * - * Revision 1.5 2002/06/17 20:24:20 jkaarlas - * pahimmat bugit korjattu - * - * Revision 1.4 2002/06/17 19:58:08 msell - * #includeiden parantelua - * - * Revision 1.3 2002/06/17 16:51:38 jkaarlas - * realloc korjattu - * - * Revision 1.2 2002/06/16 01:05:18 jkaarlas - * vähän lihaa luiden ympärille näihinkin - * - * - * - * $Date: 2002/07/21 15:03:12 $ - * - */ - #include "graphics.h" #include @@ -90,7 +31,7 @@ void GraphicsDruid::destroy(void){ } GraphicsDruid &GraphicsDruid::getInstance(void){ - + if (!instance){ instance = new GraphicsDruid; init(); @@ -101,9 +42,9 @@ GraphicsDruid &GraphicsDruid::getInstance(void){ int GraphicsDruid::loadTexture(SDL_Surface *texture, int id, int format){ int textureID = id == -1 ? getNewTextureID(id) : id; - - // register texture in OpenGL - glBindTexture (GL_TEXTURE_2D, textureID); + + // register texture in OpenGL + glBindTexture (GL_TEXTURE_2D, textureID); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); @@ -112,48 +53,48 @@ int GraphicsDruid::loadTexture(SDL_Surface *texture, int id, int format){ //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);//_MIPMAP_NEAREST); //glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); - //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); - //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); - - //printf("w: %i, h: %i, format: %i, RGBA: %i, pixels: %p\n", - // texture->w, texture->h, format, GL_RGBA, texture->pixels); - //printf("Pitch: %i, Bpp: %i\n", texture->pitch, texture->format->BytesPerPixel); + //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); + //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); + + //printf("w: %i, h: %i, format: %i, RGBA: %i, pixels: %p\n", + // texture->w, texture->h, format, GL_RGBA, texture->pixels); + //printf("Pitch: %i, Bpp: %i\n", texture->pitch, texture->format->BytesPerPixel); /*gluBuild2DMipmaps(GL_TEXTURE_2D, - 4, - texture->w, + 4, + texture->w, texture->h, - format, - GL_UNSIGNED_BYTE, - texture->pixels);*/ - int w = texture->w; - int h = texture->h; - /*int i; - while (w > 0){ - w >>= 1; - i++; - } - w = 1; - for (;i > 1; i--) w <<= 1; - while (h > 0){ - h >>= 1; - i++; - } - h = 1; - for (;i > 1; i--) h <<= 1;*/ - //glTexImage2D(GL_TEXTURE_2D, 0, texture->format->BytesPerPixel, w, h, 0, format, GL_UNSIGNED_BYTE, texture->pixels); + format, + GL_UNSIGNED_BYTE, + texture->pixels);*/ + int w = texture->w; + int h = texture->h; + /*int i; + while (w > 0){ + w >>= 1; + i++; + } + w = 1; + for (;i > 1; i--) w <<= 1; + while (h > 0){ + h >>= 1; + i++; + } + h = 1; + for (;i > 1; i--) h <<= 1;*/ + //glTexImage2D(GL_TEXTURE_2D, 0, texture->format->BytesPerPixel, w, h, 0, format, GL_UNSIGNED_BYTE, texture->pixels); if (texture->format->BytesPerPixel == 3){ - glTexImage2D(GL_TEXTURE_2D, 0, 3, w, h, 0, GL_RGB, GL_UNSIGNED_BYTE, texture->pixels); - } else if (texture->format->BytesPerPixel == 4){ - glTexImage2D(GL_TEXTURE_2D, 0, 4, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, texture->pixels); - } + glTexImage2D(GL_TEXTURE_2D, 0, 3, w, h, 0, GL_RGB, GL_UNSIGNED_BYTE, texture->pixels); + } else if (texture->format->BytesPerPixel == 4){ + glTexImage2D(GL_TEXTURE_2D, 0, 4, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, texture->pixels); + } //SDL_FreeSurface(texture); //SDL_FreeSurface(alphaSurface); return textureID; } int GraphicsDruid::loadTexture(char* path, int id){ - + SDL_Surface* texture; texture = IMG_Load(path); @@ -164,61 +105,61 @@ int GraphicsDruid::loadTexture(char* path, int id){ return -1; } int textureID = getNewTextureID(id); - - // register texture in OpenGL - glBindTexture (GL_TEXTURE_2D, textureID); + + // register texture in OpenGL + glBindTexture (GL_TEXTURE_2D, textureID); //glPixelStorei (GL_UNPACK_ALIGNMENT, 1); - // NOTE : Making some assumptions about texture parameters - //glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - //glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); + // NOTE : Making some assumptions about texture parameters + //glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + //glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); - glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); - //printf("w: %i, h: %i, RGBA: %i, pixels: %p\n", - // texture->w, texture->h, GL_RGBA, texture->pixels); - //printf("Pitch: %i, Bpp: %i\n", texture->pitch, texture->format->BytesPerPixel); + //printf("w: %i, h: %i, RGBA: %i, pixels: %p\n", + // texture->w, texture->h, GL_RGBA, texture->pixels); + //printf("Pitch: %i, Bpp: %i\n", texture->pitch, texture->format->BytesPerPixel); if (texture->format->BytesPerPixel == 3){ /*gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, texture->w, texture->h, - GL_RGB, GL_UNSIGNED_BYTE, - texture->pixels);*/ - glTexImage2D(GL_TEXTURE_2D, 0, 3, texture->w, texture->h, 0, GL_RGB, GL_UNSIGNED_BYTE, texture->pixels); - } - else if (texture->format->BytesPerPixel == 4){ - /*gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, - texture->w, - texture->h, - GL_RGBA, GL_UNSIGNED_BYTE, - texture->pixels);*/ - glTexImage2D(GL_TEXTURE_2D, 0, 4, texture->w, texture->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, texture->pixels); - } + GL_RGB, GL_UNSIGNED_BYTE, + texture->pixels);*/ + glTexImage2D(GL_TEXTURE_2D, 0, 3, texture->w, texture->h, 0, GL_RGB, GL_UNSIGNED_BYTE, texture->pixels); + } + else if (texture->format->BytesPerPixel == 4){ + /*gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, + texture->w, + texture->h, + GL_RGBA, GL_UNSIGNED_BYTE, + texture->pixels);*/ + glTexImage2D(GL_TEXTURE_2D, 0, 4, texture->w, texture->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, texture->pixels); + } /* - - - gluBuild2DMipmaps(GL_TEXTURE_2D, - 0, - texture->w, + + + gluBuild2DMipmaps(GL_TEXTURE_2D, + 0, + texture->w, texture->h, - GL_RGBA, - GL_UNSIGNED_BYTE, - texture->pixels); + GL_RGBA, + GL_UNSIGNED_BYTE, + texture->pixels); */ SDL_FreeSurface(texture); - return textureID; + return textureID; } int GraphicsDruid::loadTranspTexture(char* path, float* transpColor, int id){ - + SDL_Surface* texture; texture = IMG_Load(path); if (!texture){ @@ -227,62 +168,62 @@ int GraphicsDruid::loadTranspTexture(char* path, float* transpColor, int id){ #endif return -1; } - - - Uint32 colorKey = SDL_MapRGB(texture->format, - (Uint8)(transpColor[0] * 255), - (Uint8)(transpColor[1] * 255), + + + Uint32 colorKey = SDL_MapRGB(texture->format, + (Uint8)(transpColor[0] * 255), + (Uint8)(transpColor[1] * 255), (Uint8)(transpColor[2] * 255)); //SDL_SetAlpha(texture, 0, SDL_ALPHA_OPAQUE); SDL_SetColorKey(texture, SDL_SRCCOLORKEY, colorKey); - + //SDL_Surface* alphaSurface = SDL_DisplayFormatAlpha(texture); texture = SDL_DisplayFormatAlpha(texture); - return loadTexture(texture); + return loadTexture(texture); } int GraphicsDruid::getNewTextureID(int id){ - if (id != -1){ - for (int i = 0; i < instance->reserved; i++){ - if (instance->idArray[i] == id){ - freeTexture(id); - instance->textureCount--; - break; - } - } - } + if (id != -1){ + for (int i = 0; i < instance->reserved; i++){ + if (instance->idArray[i] == id){ + freeTexture(id); + instance->textureCount--; + break; + } + } + } - GLuint newId; + GLuint newId; - if (id == -1){ - glGenTextures (1, &newId); - } - else - newId = id; - - int index = 0; + if (id == -1){ + glGenTextures (1, &newId); + } + else + newId = id; + + int index = 0; while (instance->idArray[index] != -1 && index < instance->reserved){ - index++; + index++; } - // out of space, make more - if (index >= instance->reserved){ - instance->idArray = (int*) realloc(instance->idArray, (instance->reserved + ID_ARRAY_GROW)*sizeof(int)); - - for (int i = instance->reserved + 1; i < instance->reserved + ID_ARRAY_GROW; i++) - instance->idArray[i] = -1; + // out of space, make more + if (index >= instance->reserved){ + instance->idArray = (int*) realloc(instance->idArray, (instance->reserved + ID_ARRAY_GROW)*sizeof(int)); - instance->reserved += ID_ARRAY_GROW; - } - else - instance->idArray[index] = newId; + for (int i = instance->reserved + 1; i < instance->reserved + ID_ARRAY_GROW; i++) + instance->idArray[i] = -1; - - instance->textureCount++; - return newId; + instance->reserved += ID_ARRAY_GROW; + } + else + instance->idArray[index] = newId; + + + instance->textureCount++; + return newId; } void GraphicsDruid::freeTexture(int id){ diff --git a/src/graphics.h b/src/graphics.h index 8e2868b..0aad030 100644 --- a/src/graphics.h +++ b/src/graphics.h @@ -1,38 +1,3 @@ -/* - * $Id: graphics.h,v 1.9 2002/07/19 20:33:28 msell Exp $ - * - * - * $Log: graphics.h,v $ - * Revision 1.9 2002/07/19 20:33:28 msell - * #pragma once -> #ifndef - * - * Revision 1.8 2002/07/17 16:40:33 msell - * Resoluution vaihto - * - * Revision 1.7 2002/06/28 14:51:40 jkaarlas - * transparenttilatausta korjailtu - * - * Revision 1.6 2002/06/27 21:42:32 jkaarlas - * lisätty transparentin tekstuurin lataus - * - * Revision 1.5 2002/06/17 20:49:04 msell - * free -> SDL_FreeSurface - * - * Revision 1.4 2002/06/17 20:24:20 jkaarlas - * pahimmat bugit korjattu - * - * Revision 1.3 2002/06/17 16:51:38 jkaarlas - * realloc korjattu - * - * Revision 1.2 2002/06/16 01:05:18 jkaarlas - * vähän lihaa luiden ympärille näihinkin - * - * - * - * $Date: 2002/07/19 20:33:28 $ - * - */ - #ifndef __GRAPHICS_H_INCLUDED__ #define __GRAPHICS_H_INCLUDED__ @@ -66,17 +31,17 @@ private: int* idArray; int textureCount; int reserved; - + GraphicsDruid(void); ~GraphicsDruid(void); - + static void init(void); static void destroy(void); public: - + static GraphicsDruid &getInstance(void); - int loadTexture(SDL_Surface *texture, int id = -1, int format = GL_RGB); + int loadTexture(SDL_Surface *texture, int id = -1, int format = GL_RGB); int loadTexture(char* path, int id = -1); int loadTranspTexture(char* path, float* transpColor, int id = -1); void freeTexture(int id); diff --git a/src/legoblocks.cpp b/src/legoblocks.cpp index 7432e36..63882c6 100644 --- a/src/legoblocks.cpp +++ b/src/legoblocks.cpp @@ -1,75 +1,3 @@ -/* - * $Id: legoblocks.cpp,v 1.20 2002/07/22 11:44:37 jkaarlas Exp $ - * - * - * $Log: legoblocks.cpp,v $ - * Revision 1.20 2002/07/22 11:44:37 jkaarlas - * naama - * - * Revision 1.19 2002/07/18 23:05:31 msell - * Partikkelit ja kakkospelaajan liike - * - * Revision 1.18 2002/07/17 20:32:47 msell - * Detail-optio toimii - * - * Revision 1.17 2002/07/16 17:16:34 msell - * Fontit ja valikot - * - * Revision 1.16 2002/07/16 00:42:43 msell - * Uusia skyboxeja ja areenan säätöä - * - * Revision 1.15 2002/07/15 20:32:35 msell - * Uudet valot ja ulkoasun parantelua - * - * Revision 1.14 2002/07/15 15:22:08 msell - * Parantelua - * - * Revision 1.13 2002/07/14 21:40:43 msell - * Conflictit pois, liikkumiset (hyppy, kävely, lyönti), uusi areena - * - * Revision 1.12 2002/06/30 16:05:04 msell - * Törmäyksien parantelua, transformaatioita mukana - * - * Revision 1.11 2002/06/27 00:08:04 msell - * Kimmotukset palloille myös pyöritettyihin mesheihin - * - * Revision 1.10 2002/06/24 14:12:15 msell - * Nyt toimii sphere -> mesh -törmäykset, ihan tosi - * - * Revision 1.9 2002/06/24 04:41:43 jkaarlas - * tekstuurikoordinaatteja korjattu - * - * Revision 1.8 2002/06/20 22:50:12 msell - * Meshit - * - * Revision 1.7 2002/06/20 00:21:01 jkaarlas - * materiaali- ja tekstuurihommia edistetty - * - * Revision 1.6 2002/06/17 19:58:08 msell - * #includeiden parantelua - * - * Revision 1.5 2002/06/15 17:18:37 msell - * Toimiva törmäystarkastus kiinteille laatikoille - * - * Revision 1.4 2002/06/05 18:39:04 msell - * Jotain pientä - * - * Revision 1.3 2002/06/05 15:00:41 msell - * Palikoihin lisää detailia, facet jaetaan halutun kokosiin osiin - * - * Revision 1.2 2002/06/04 16:28:32 msell - * #pragma once - * - * Revision 1.1 2002/06/03 23:06:38 msell - * no message - * - * - * - * - * $Date: 2002/07/22 11:44:37 $ - * - */ - #include "main.h" #include @@ -82,131 +10,131 @@ #include "glapi.h" BasicBlock::BasicBlock(int width, int height, int depth) : MeshObject(createBox(-width/2.0, width/2.0, -height/2.0*BLOCKHEIGHT, BLOCKHEIGHT*height/2.0, -depth/2.0, depth/2.0)){ - appearance = new BasicBlockAppearance(width, height, depth); - //geometry = new MeshShape(this); + appearance = new BasicBlockAppearance(width, height, depth); + //geometry = new MeshShape(this); } void BasicBlock::setColor(float red, float green, float blue){ - appearance->getMaterial()->setColor(red, green, blue, 1); + appearance->getMaterial()->setColor(red, green, blue, 1); } BasicBlockAppearance::BasicBlockAppearance(int width, int height, int depth){ - this->width = width; - this->height = height; - this->depth = depth; - vectorSet(displacement, 0, 0, 0); - gllist = glGenLists(1); - usematerial = true; + this->width = width; + this->height = height; + this->depth = depth; + vectorSet(displacement, 0, 0, 0); + gllist = glGenLists(1); + usematerial = true; } void BasicBlockAppearance::prepare(){ - glNewList(gllist, GL_COMPILE); + glNewList(gllist, GL_COMPILE); - - float width = this->width; - float height = this->height * BLOCKHEIGHT; + + float width = this->width; + float height = this->height * BLOCKHEIGHT; if (usematerial) material.enable(); - {//Block - //Front Face - glPushMatrix(); - glTranslatef(-width/2.0, -height/2.0, depth/2.0); - drawDetailRectangle(width, height); - glPopMatrix(); + {//Block + //Front Face + glPushMatrix(); + glTranslatef(-width/2.0, -height/2.0, depth/2.0); + drawDetailRectangle(width, height); + glPopMatrix(); - // Back Face - glPushMatrix(); - glTranslatef(width/2.0, -height/2.0, -depth/2.0); - glRotatef(180, 0, 1, 0); - drawDetailRectangle(width, height); - glPopMatrix(); + // Back Face + glPushMatrix(); + glTranslatef(width/2.0, -height/2.0, -depth/2.0); + glRotatef(180, 0, 1, 0); + drawDetailRectangle(width, height); + glPopMatrix(); - // Top Face - glPushMatrix(); - glTranslatef(-width/2.0, height/2.0, depth/2.0); - glRotatef(-90, 1, 0, 0); - drawDetailRectangle(width, depth); - glPopMatrix(); + // Top Face + glPushMatrix(); + glTranslatef(-width/2.0, height/2.0, depth/2.0); + glRotatef(-90, 1, 0, 0); + drawDetailRectangle(width, depth); + glPopMatrix(); - // Bottom Face - glPushMatrix(); - glTranslatef(-width/2.0, -height/2.0, -depth/2.0); - glRotatef(90, 1, 0, 0); - drawDetailRectangle(width, depth); - glPopMatrix(); + // Bottom Face + glPushMatrix(); + glTranslatef(-width/2.0, -height/2.0, -depth/2.0); + glRotatef(90, 1, 0, 0); + drawDetailRectangle(width, depth); + glPopMatrix(); - // Right face - glPushMatrix(); - glTranslatef(width/2.0, -height/2.0, depth/2.0); - glRotatef(90, 0, 1, 0); - drawDetailRectangle(depth, height); - glPopMatrix(); + // Right face + glPushMatrix(); + glTranslatef(width/2.0, -height/2.0, depth/2.0); + glRotatef(90, 0, 1, 0); + drawDetailRectangle(depth, height); + glPopMatrix(); - // Left Face - glPushMatrix(); - glTranslatef(-width/2.0, -height/2.0, -depth/2.0); - glRotatef(-90, 0, 1, 0); - drawDetailRectangle(depth, height); - glPopMatrix(); - } + // Left Face + glPushMatrix(); + glTranslatef(-width/2.0, -height/2.0, -depth/2.0); + glRotatef(-90, 0, 1, 0); + drawDetailRectangle(depth, height); + glPopMatrix(); + } - glPushMatrix(); - glTranslatef(0.5 - width/2.0, height - height/2.0, 0.5 - depth/2.0); - int x, z; - for (x = 0; x < width; x++){ - //glPushMatrix(); - for (z = 0; z < depth; z++){ - createKnob(); - glTranslatef(0, 0, 1); - } - glTranslatef(1, 0, -depth); - //glPopMatrix(); - } - glPopMatrix(); + glPushMatrix(); + glTranslatef(0.5 - width/2.0, height - height/2.0, 0.5 - depth/2.0); + int x, z; + for (x = 0; x < width; x++){ + //glPushMatrix(); + for (z = 0; z < depth; z++){ + createKnob(); + glTranslatef(0, 0, 1); + } + glTranslatef(1, 0, -depth); + //glPopMatrix(); + } + glPopMatrix(); if (usematerial) material.disable(); - glEndList(); + glEndList(); } void BasicBlockAppearance::draw(){ - glPushMatrix(); - glTranslatef(displacement[0], displacement[1], displacement[2]); - glCallList(gllist); - glPopMatrix(); - //prepare(); + glPushMatrix(); + glTranslatef(displacement[0], displacement[1], displacement[2]); + glCallList(gllist); + glPopMatrix(); + //prepare(); } #define BLOCKDETAILGRID 1 void drawDetailRectangle(float width, float height){ - glBegin(GL_QUADS); - float x, y, x2, y2; - glNormal3f(0, 0, 1); - - for (y = 0; y < height; y += BLOCKDETAILGRID){ - y2 = y + BLOCKDETAILGRID; - if (y2 > height) y2 = height; - for (x = 0; x < width; x += BLOCKDETAILGRID){ - x2 = x + BLOCKDETAILGRID; - if (x2 > width) x2 = width; - - glTexCoord2f(x / width, y / height); - glVertex3f(x, y, 0); + glBegin(GL_QUADS); + float x, y, x2, y2; + glNormal3f(0, 0, 1); - glTexCoord2f(x2 / width, y / height); - glVertex3f(x2, y, 0); + for (y = 0; y < height; y += BLOCKDETAILGRID){ + y2 = y + BLOCKDETAILGRID; + if (y2 > height) y2 = height; + for (x = 0; x < width; x += BLOCKDETAILGRID){ + x2 = x + BLOCKDETAILGRID; + if (x2 > width) x2 = width; - glTexCoord2f(x2 / width, y2 / height); - glVertex3f(x2, y2, 0); + glTexCoord2f(x / width, y / height); + glVertex3f(x, y, 0); - glTexCoord2f(x / width, y2 / height); - glVertex3f(x, y2, 0); - } - } - glEnd(); + glTexCoord2f(x2 / width, y / height); + glVertex3f(x2, y, 0); + + glTexCoord2f(x2 / width, y2 / height); + glVertex3f(x2, y2, 0); + + glTexCoord2f(x / width, y2 / height); + glVertex3f(x, y2, 0); + } + } + glEnd(); } #define KNOBROUNDNESS 0.03 @@ -215,43 +143,43 @@ int knobgllist; int knobdetail; void renderKnob(int knobsegments){ - point2d knobpoints[4]; - knobpoints[0].x = 0.3; - knobpoints[0].y = 0; - knobpoints[1].x = 0.3; - knobpoints[1].y = BLOCKHEIGHT*0.5 - KNOBROUNDNESS; - knobpoints[2].x = 0.3 - KNOBROUNDNESS; - knobpoints[2].y = BLOCKHEIGHT*0.5; - knobpoints[3].x = 0; - knobpoints[3].y = BLOCKHEIGHT*0.5; + point2d knobpoints[4]; + knobpoints[0].x = 0.3; + knobpoints[0].y = 0; + knobpoints[1].x = 0.3; + knobpoints[1].y = BLOCKHEIGHT*0.5 - KNOBROUNDNESS; + knobpoints[2].x = 0.3 - KNOBROUNDNESS; + knobpoints[2].y = BLOCKHEIGHT*0.5; + knobpoints[3].x = 0; + knobpoints[3].y = BLOCKHEIGHT*0.5; - point2d knobderivates[4]; - knobderivates[0].x = 0; - knobderivates[0].y = knobpoints[1].y - knobpoints[0].y; - knobderivates[1].x = 0; - knobderivates[1].y = knobpoints[2].y - knobpoints[1].y; - knobderivates[2].x = knobpoints[2].x - knobpoints[1].x; - knobderivates[2].y = 0; - knobderivates[3].x = knobpoints[3].x - knobpoints[2].x; - knobderivates[3].y = 0; + point2d knobderivates[4]; + knobderivates[0].x = 0; + knobderivates[0].y = knobpoints[1].y - knobpoints[0].y; + knobderivates[1].x = 0; + knobderivates[1].y = knobpoints[2].y - knobpoints[1].y; + knobderivates[2].x = knobpoints[2].x - knobpoints[1].x; + knobderivates[2].y = 0; + knobderivates[3].x = knobpoints[3].x - knobpoints[2].x; + knobderivates[3].y = 0; - createLathedSurface(knobpoints, knobderivates, 4, knobsegments, 4); + createLathedSurface(knobpoints, knobderivates, 4, knobsegments, 4); } void initKnob(void){ - glNewList(knobgllist, GL_COMPILE); + glNewList(knobgllist, GL_COMPILE); - renderKnob(knobdetail); - - glEndList(); + renderKnob(knobdetail); + + glEndList(); } void createKnob(int knobsegments){ - if (knobsegments != -1){ - renderKnob(knobsegments); - return; - } - glCallList(knobgllist); + if (knobsegments != -1){ + renderKnob(knobsegments); + return; + } + glCallList(knobgllist); } @@ -262,53 +190,53 @@ float knobroundness=0.05; float pillarroundness=0.03; HeadAppearance::HeadAppearance(void){ - gllist = glGenLists(1); + gllist = glGenLists(1); } void HeadAppearance::prepare(void){ - glNewList(gllist, GL_COMPILE); - - glPushMatrix(); + glNewList(gllist, GL_COMPILE); - glTranslatef(0, -0.5, 0); + glPushMatrix(); - point2d headpoints[14]; + glTranslatef(0, -0.5, 0); - headpoints[0].x=0.0; headpoints[0].y=BLOCKHEIGHT*(0); - headpoints[1].x=0.4; headpoints[1].y=BLOCKHEIGHT*(0); - headpoints[2].x=0.45; headpoints[2].y=BLOCKHEIGHT*(0.35); - headpoints[3].x=0.55; headpoints[3].y=BLOCKHEIGHT*(0.5); - headpoints[4].x=0.62*1.0; headpoints[4].y=BLOCKHEIGHT*(0.65); - headpoints[5].x=0.65*1.0; headpoints[5].y=BLOCKHEIGHT*(1); - headpoints[6].x=0.65*1.0; headpoints[6].y=BLOCKHEIGHT*(1.75); - headpoints[7].x=0.65*1.0; headpoints[7].y=BLOCKHEIGHT*(2.35); - headpoints[8].x=0.62*1.0; headpoints[8].y=BLOCKHEIGHT*(2.60); - headpoints[9].x=0.55*1.0; headpoints[9].y=BLOCKHEIGHT*(2.80); - headpoints[10].x=0.4; headpoints[10].y=BLOCKHEIGHT*(2.95); - headpoints[11].x=0.3; headpoints[11].y=BLOCKHEIGHT*3.5-pillarroundness; - headpoints[12].x=0.3-pillarroundness; headpoints[12].y=BLOCKHEIGHT*3.5; - headpoints[13].x=0; headpoints[13].y=BLOCKHEIGHT*3.5; - headpoints[11].x=0; headpoints[11].y=BLOCKHEIGHT*3.0; + point2d headpoints[14]; - glColor4f(0.8,0.8,0.0,1.0); + headpoints[0].x=0.0; headpoints[0].y=BLOCKHEIGHT*(0); + headpoints[1].x=0.4; headpoints[1].y=BLOCKHEIGHT*(0); + headpoints[2].x=0.45; headpoints[2].y=BLOCKHEIGHT*(0.35); + headpoints[3].x=0.55; headpoints[3].y=BLOCKHEIGHT*(0.5); + headpoints[4].x=0.62*1.0; headpoints[4].y=BLOCKHEIGHT*(0.65); + headpoints[5].x=0.65*1.0; headpoints[5].y=BLOCKHEIGHT*(1); + headpoints[6].x=0.65*1.0; headpoints[6].y=BLOCKHEIGHT*(1.75); + headpoints[7].x=0.65*1.0; headpoints[7].y=BLOCKHEIGHT*(2.35); + headpoints[8].x=0.62*1.0; headpoints[8].y=BLOCKHEIGHT*(2.60); + headpoints[9].x=0.55*1.0; headpoints[9].y=BLOCKHEIGHT*(2.80); + headpoints[10].x=0.4; headpoints[10].y=BLOCKHEIGHT*(2.95); + headpoints[11].x=0.3; headpoints[11].y=BLOCKHEIGHT*3.5-pillarroundness; + headpoints[12].x=0.3-pillarroundness; headpoints[12].y=BLOCKHEIGHT*3.5; + headpoints[13].x=0; headpoints[13].y=BLOCKHEIGHT*3.5; + headpoints[11].x=0; headpoints[11].y=BLOCKHEIGHT*3.0; - - faceTexture->enable(); - glBlendFunc(GL_ONE, GL_SRC_ALPHA); - createLathedSurface(headpoints,NULL,12,16,24); - faceTexture->disable(); + glColor4f(0.8,0.8,0.0,1.0); - glTranslatef(0, BLOCKHEIGHT*3-0.05, 0); - createKnob(16); + faceTexture->enable(); + glBlendFunc(GL_ONE, GL_SRC_ALPHA); + createLathedSurface(headpoints,NULL,12,16,24); + faceTexture->disable(); - glPopMatrix(); + glTranslatef(0, BLOCKHEIGHT*3-0.05, 0); - glEndList(); + createKnob(16); + + glPopMatrix(); + + glEndList(); } void HeadAppearance::draw(void){ - glCallList(gllist); + glCallList(gllist); } @@ -316,106 +244,106 @@ void HeadAppearance::draw(void){ FlowerAppearance::FlowerAppearance(int color1, int color2, int color3){ - gllist = glGenLists(1); - this->color1 = color1; - this->color2 = color2; - this->color3 = color3; + gllist = glGenLists(1); + this->color1 = color1; + this->color2 = color2; + this->color3 = color3; } void FlowerAppearance::prepare(void){ - glNewList(gllist, GL_COMPILE); - - glPushMatrix(); + glNewList(gllist, GL_COMPILE); + + glPushMatrix(); - int colors[]={color1,color2,color3}; + int colors[]={color1,color2,color3}; - glColor3f(0.0,0.6,0.0); + glColor3f(0.0,0.6,0.0); - point2d basepoints[8]; - basepoints[0].x=0.4; basepoints[0].y=0; - basepoints[1].x=0.4; basepoints[1].y=BLOCKHEIGHT*1.5-pillarroundness; - basepoints[2].x=0.4-pillarroundness; basepoints[2].y=BLOCKHEIGHT*1.5; - basepoints[3].x=0.3+pillarroundness; basepoints[3].y=BLOCKHEIGHT*1.5; - basepoints[4].x=0.3; basepoints[4].y=BLOCKHEIGHT*1.5+pillarroundness; - basepoints[5].x=0.3; basepoints[5].y=BLOCKHEIGHT*2.0-pillarroundness; - basepoints[6].x=0.3-pillarroundness; basepoints[6].y=BLOCKHEIGHT*2.0; - basepoints[7].x=0; basepoints[7].y=BLOCKHEIGHT*2.0; + point2d basepoints[8]; + basepoints[0].x=0.4; basepoints[0].y=0; + basepoints[1].x=0.4; basepoints[1].y=BLOCKHEIGHT*1.5-pillarroundness; + basepoints[2].x=0.4-pillarroundness; basepoints[2].y=BLOCKHEIGHT*1.5; + basepoints[3].x=0.3+pillarroundness; basepoints[3].y=BLOCKHEIGHT*1.5; + basepoints[4].x=0.3; basepoints[4].y=BLOCKHEIGHT*1.5+pillarroundness; + basepoints[5].x=0.3; basepoints[5].y=BLOCKHEIGHT*2.0-pillarroundness; + basepoints[6].x=0.3-pillarroundness; basepoints[6].y=BLOCKHEIGHT*2.0; + basepoints[7].x=0; basepoints[7].y=BLOCKHEIGHT*2.0; - point2d basederivates[8]; - basederivates[0].x=0; basederivates[0].y=basepoints[1].y-basepoints[0].y; - basederivates[1].x=0; basederivates[1].y=basepoints[2].y-basepoints[1].y; - basederivates[2].x=basepoints[2].x-basepoints[1].x; basederivates[2].y=0; - basederivates[3].x=basepoints[4].x-basepoints[3].x; basederivates[3].y=0; - basederivates[4].x=0; basederivates[4].y=basepoints[4].y-basepoints[3].y; - basederivates[5].x=0; basederivates[5].y=basepoints[6].y-basepoints[5].y; - basederivates[6].x=basepoints[6].x-basepoints[5].x; basederivates[6].y=0; - basederivates[7].x=basepoints[7].x-basepoints[6].x; basederivates[7].y=0; + point2d basederivates[8]; + basederivates[0].x=0; basederivates[0].y=basepoints[1].y-basepoints[0].y; + basederivates[1].x=0; basederivates[1].y=basepoints[2].y-basepoints[1].y; + basederivates[2].x=basepoints[2].x-basepoints[1].x; basederivates[2].y=0; + basederivates[3].x=basepoints[4].x-basepoints[3].x; basederivates[3].y=0; + basederivates[4].x=0; basederivates[4].y=basepoints[4].y-basepoints[3].y; + basederivates[5].x=0; basederivates[5].y=basepoints[6].y-basepoints[5].y; + basederivates[6].x=basepoints[6].x-basepoints[5].x; basederivates[6].y=0; + basederivates[7].x=basepoints[7].x-basepoints[6].x; basederivates[7].y=0; - createLathedSurface(basepoints,basederivates,8,8,8); + createLathedSurface(basepoints,basederivates,8,8,8); - int i,j; - for (i=0;i<3;i++){ - glColor3f(0.0,0.6,0.0); - glPushMatrix(); - glTranslatef(0,BLOCKHEIGHT,0.4); - glRotatef(20-90,1,0,0); - gluCylinder(gluNewQuadric(),0.1,0.1,BLOCKHEIGHT*(3+i*0.7),4,1); - glRotatef(90,1,0,0); - glTranslatef(0,BLOCKHEIGHT*(3+i*0.7),0); + int i,j; + for (i=0;i<3;i++){ + glColor3f(0.0,0.6,0.0); + glPushMatrix(); + glTranslatef(0,BLOCKHEIGHT,0.4); + glRotatef(20-90,1,0,0); + gluCylinder(gluNewQuadric(),0.1,0.1,BLOCKHEIGHT*(3+i*0.7),4,1); + glRotatef(90,1,0,0); + glTranslatef(0,BLOCKHEIGHT*(3+i*0.7),0); - float r,g,b; - switch(colors[i]){ - case FLOWER_RED: - r=1.0; g=0.0; b=0.0; - break; - case FLOWER_YELLOW: - r=1.0; g=1.0; b=0.0; - break; - case FLOWER_WHITE: - r=1.0; g=1.0; b=1.0; - break; - } - - glDisable(GL_CULL_FACE); - glColor3f(r,g,b); - createKnob(); + float r,g,b; + switch(colors[i]){ + case FLOWER_RED: + r=1.0; g=0.0; b=0.0; + break; + case FLOWER_YELLOW: + r=1.0; g=1.0; b=0.0; + break; + case FLOWER_WHITE: + r=1.0; g=1.0; b=1.0; + break; + } + + glDisable(GL_CULL_FACE); + glColor3f(r,g,b); + createKnob(); /* Terälehdet tehdään triangle-fanilla */ - glBegin(GL_TRIANGLE_FAN); - glNormal3f(0.0,1.0,0.0); - glVertex3f(0.0,0.0,0.0); - float x,z; - for (j=0;j<24;j+=4){ - x=sin((j+0)*2*PI/24)*0.4; - z=cos((j+0)*2*PI/24)*0.4; - glVertex3f(x,0.0,z); - x=sin((j+1)*2*PI/24)*0.55; - z=cos((j+1)*2*PI/24)*0.55; - glVertex3f(x,0.0,z); - x=sin((j+2)*2*PI/24)*0.6; - z=cos((j+2)*2*PI/24)*0.6; - glVertex3f(x,0.0,z); - x=sin((j+3)*2*PI/24)*0.55; - z=cos((j+3)*2*PI/24)*0.55; - glVertex3f(x,0.0,z); - } - glVertex3f(0,0.0,0.4); - glEnd(); - glEnable(GL_CULL_FACE); + glBegin(GL_TRIANGLE_FAN); + glNormal3f(0.0,1.0,0.0); + glVertex3f(0.0,0.0,0.0); + float x,z; + for (j=0;j<24;j+=4){ + x=sin((j+0)*2*PI/24)*0.4; + z=cos((j+0)*2*PI/24)*0.4; + glVertex3f(x,0.0,z); + x=sin((j+1)*2*PI/24)*0.55; + z=cos((j+1)*2*PI/24)*0.55; + glVertex3f(x,0.0,z); + x=sin((j+2)*2*PI/24)*0.6; + z=cos((j+2)*2*PI/24)*0.6; + glVertex3f(x,0.0,z); + x=sin((j+3)*2*PI/24)*0.55; + z=cos((j+3)*2*PI/24)*0.55; + glVertex3f(x,0.0,z); + } + glVertex3f(0,0.0,0.4); + glEnd(); + glEnable(GL_CULL_FACE); - glPopMatrix(); + glPopMatrix(); - glRotatef(120,0,1,0); - } + glRotatef(120,0,1,0); + } - glPopMatrix(); + glPopMatrix(); - glEndList(); + glEndList(); } void FlowerAppearance::draw(void){ - glCallList(gllist); + glCallList(gllist); } @@ -423,100 +351,100 @@ void FlowerAppearance::draw(void){ LampAppearance::LampAppearance(void){ - gllist = glGenLists(1); + gllist = glGenLists(1); } void LampAppearance::prepare(void){ - glNewList(gllist, GL_COMPILE); - - glPushMatrix(); + glNewList(gllist, GL_COMPILE); - //glTranslatef(0, -1, 0); + glPushMatrix(); - //glRotatef(180, 1, 0, 0); + //glTranslatef(0, -1, 0); + + //glRotatef(180, 1, 0, 0); glDisable(GL_LIGHTING); - point2d lightpoints[11]; - lightpoints[0].x=0.4; lightpoints[0].y=BLOCKHEIGHT*(0); - lightpoints[1].x=0.55; lightpoints[1].y=BLOCKHEIGHT*(0); - lightpoints[2].x=0.62; lightpoints[2].y=BLOCKHEIGHT*(0+0.15); - lightpoints[3].x=0.65; lightpoints[3].y=BLOCKHEIGHT*(0+0.5); - lightpoints[4].x=0.68; lightpoints[4].y=BLOCKHEIGHT*(0+1.25); - lightpoints[5].x=0.65; lightpoints[5].y=BLOCKHEIGHT*(0+2); - lightpoints[6].x=0.62; lightpoints[6].y=BLOCKHEIGHT*(0+2.35); - lightpoints[7].x=0.55; lightpoints[7].y=BLOCKHEIGHT*(0+2.5); - lightpoints[8].x=0.4; lightpoints[8].y=BLOCKHEIGHT*(0+2.5); - lightpoints[9].x=0.4; lightpoints[9].y=BLOCKHEIGHT*(0+3); - lightpoints[10].x=0.0; lightpoints[10].y=BLOCKHEIGHT*(0+3); - glColor4f(0.8,0.8,0.8,0.5); - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); + point2d lightpoints[11]; + lightpoints[0].x=0.4; lightpoints[0].y=BLOCKHEIGHT*(0); + lightpoints[1].x=0.55; lightpoints[1].y=BLOCKHEIGHT*(0); + lightpoints[2].x=0.62; lightpoints[2].y=BLOCKHEIGHT*(0+0.15); + lightpoints[3].x=0.65; lightpoints[3].y=BLOCKHEIGHT*(0+0.5); + lightpoints[4].x=0.68; lightpoints[4].y=BLOCKHEIGHT*(0+1.25); + lightpoints[5].x=0.65; lightpoints[5].y=BLOCKHEIGHT*(0+2); + lightpoints[6].x=0.62; lightpoints[6].y=BLOCKHEIGHT*(0+2.35); + lightpoints[7].x=0.55; lightpoints[7].y=BLOCKHEIGHT*(0+2.5); + lightpoints[8].x=0.4; lightpoints[8].y=BLOCKHEIGHT*(0+2.5); + lightpoints[9].x=0.4; lightpoints[9].y=BLOCKHEIGHT*(0+3); + lightpoints[10].x=0.0; lightpoints[10].y=BLOCKHEIGHT*(0+3); + glColor4f(0.8,0.8,0.8,0.5); + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); - createLathedSurface(lightpoints,NULL,11,8,11); + createLathedSurface(lightpoints,NULL,11,8,11); - glEnable(GL_LIGHTING); + glEnable(GL_LIGHTING); - /*glColor3f(0.5, 0.5, 0.5); + /*glColor3f(0.5, 0.5, 0.5); - glBegin(GL_LINES); - glVertex3f(0, 1, 0); - glVertex3f(0, -100, 0); - glEnd();*/ + glBegin(GL_LINES); + glVertex3f(0, 1, 0); + glVertex3f(0, -100, 0); + glEnd();*/ - /*float screencoords[3] - getPointCoordinates(0,lighty,0); + /*float screencoords[3] + getPointCoordinates(0,lighty,0); - glLoadIdentity(); - glTranslatef(screencoords.x,screencoords.y,0); - glDisable(GL_DEPTH_TEST); - glEnable(GL_CULL_FACE); - glEnable(GL_BLEND); + glLoadIdentity(); + glTranslatef(screencoords.x,screencoords.y,0); + glDisable(GL_DEPTH_TEST); + glEnable(GL_CULL_FACE); + glEnable(GL_BLEND); - glBlendFunc(GL_ONE,GL_ONE); - glEnable(GL_TEXTURE_2D); - glBindTexture(GL_TEXTURE_2D,*flaretexture); + glBlendFunc(GL_ONE,GL_ONE); + glEnable(GL_TEXTURE_2D); + glBindTexture(GL_TEXTURE_2D,*flaretexture); - glMatrixMode(GL_PROJECTION); - glPushMatrix(); - glLoadIdentity(); - float sizey=8.0/distance*staticlightflarebrightnesses[lightnumber]; - float sizex=sizey*height/width; + glMatrixMode(GL_PROJECTION); + glPushMatrix(); + glLoadIdentity(); + float sizey=8.0/distance*staticlightflarebrightnesses[lightnumber]; + float sizex=sizey*height/width; - if (distance>0.5){ - glBegin(GL_QUADS); - glColor3f(staticlightflarebrightnesses[lightnumber],staticlightflarebrightnesses[lightnumber],staticlightflarebrightnesses[lightnumber]); + if (distance>0.5){ + glBegin(GL_QUADS); + glColor3f(staticlightflarebrightnesses[lightnumber],staticlightflarebrightnesses[lightnumber],staticlightflarebrightnesses[lightnumber]); - glTexCoord2f(0.0, 0.0); - glVertex2f(-sizex,sizey); + glTexCoord2f(0.0, 0.0); + glVertex2f(-sizex,sizey); - glTexCoord2f(0.0, 1.0); - glVertex2f(-sizex,-sizey); - - glTexCoord2f(1.0, 1.0); - glVertex2f( sizex,-sizey); - - glTexCoord2f(1.0, 0.0); - glVertex2f( sizex,sizey); - glEnd(); - } + glTexCoord2f(0.0, 1.0); + glVertex2f(-sizex,-sizey); - glDisable(GL_TEXTURE_2D); + glTexCoord2f(1.0, 1.0); + glVertex2f( sizex,-sizey); - glDisable(GL_BLEND); + glTexCoord2f(1.0, 0.0); + glVertex2f( sizex,sizey); + glEnd(); + } - glPopMatrix(); - glMatrixMode(GL_MODELVIEW); - glLoadIdentity();*/ + glDisable(GL_TEXTURE_2D); + + glDisable(GL_BLEND); + + glPopMatrix(); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity();*/ - glPopMatrix(); + glPopMatrix(); - glEndList(); + glEndList(); } void LampAppearance::draw(void){ - glCallList(gllist); -} \ No newline at end of file + glCallList(gllist); +} diff --git a/src/legoblocks.h b/src/legoblocks.h index 4ee031a..572c84d 100644 --- a/src/legoblocks.h +++ b/src/legoblocks.h @@ -1,57 +1,3 @@ -/* - * $Id: legoblocks.h,v 1.14 2002/07/19 20:33:28 msell Exp $ - * - * - * $Log: legoblocks.h,v $ - * Revision 1.14 2002/07/19 20:33:28 msell - * #pragma once -> #ifndef - * - * Revision 1.13 2002/07/18 23:05:31 msell - * Partikkelit ja kakkospelaajan liike - * - * Revision 1.12 2002/07/17 20:32:47 msell - * Detail-optio toimii - * - * Revision 1.11 2002/07/16 17:16:34 msell - * Fontit ja valikot - * - * Revision 1.10 2002/07/16 00:42:43 msell - * Uusia skyboxeja ja areenan säätöä - * - * Revision 1.9 2002/07/15 20:32:35 msell - * Uudet valot ja ulkoasun parantelua - * - * Revision 1.8 2002/07/15 15:22:08 msell - * Parantelua - * - * Revision 1.7 2002/06/24 14:12:15 msell - * Nyt toimii sphere -> mesh -törmäykset, ihan tosi - * - * Revision 1.6 2002/06/20 00:21:01 jkaarlas - * materiaali- ja tekstuurihommia edistetty - * - * Revision 1.5 2002/06/17 20:49:04 msell - * free -> SDL_FreeSurface - * - * Revision 1.4 2002/06/05 18:39:05 msell - * Jotain pientä - * - * Revision 1.3 2002/06/05 15:00:41 msell - * Palikoihin lisää detailia, facet jaetaan halutun kokosiin osiin - * - * Revision 1.2 2002/06/04 16:28:32 msell - * #pragma once - * - * Revision 1.1 2002/06/03 23:06:38 msell - * no message - * - * - * - * - * $Date: 2002/07/19 20:33:28 $ - * - */ - #ifndef __LEGOBLOCKS_H_INCLUDED__ #define __LEGOBLOCKS_H_INCLUDED__ @@ -64,30 +10,30 @@ class BasicBlock : public MeshObject{ private: - int width, height, depth; + int width, height, depth; public: - BasicBlock(int width, int height, int depth); + BasicBlock(int width, int height, int depth); - void setColor(float red, float green, float blue); + void setColor(float red, float green, float blue); }; class BasicBlockAppearance : public Appearance{ private: - int width, height, depth; - int gllist; + int width, height, depth; + int gllist; protected: - bool usematerial; + bool usematerial; public: - float displacement[3]; + float displacement[3]; - BasicBlockAppearance(int width, int height, int depth); - - virtual void prepare(void); - virtual void draw(void); + BasicBlockAppearance(int width, int height, int depth); + + virtual void prepare(void); + virtual void draw(void); }; void drawDetailRectangle(float width, float height); @@ -101,13 +47,13 @@ void createKnob(int knobsegments = -1); class HeadAppearance : public Appearance{ private: - int gllist; + int gllist; public: - HeadAppearance(void); + HeadAppearance(void); - void prepare(void); - void draw(void); + void prepare(void); + void draw(void); }; @@ -118,27 +64,27 @@ public: class FlowerAppearance : public Appearance{ private: - int gllist; - int color1, color2, color3; + int gllist; + int color1, color2, color3; public: - FlowerAppearance(int color1, int color2, int color3); + FlowerAppearance(int color1, int color2, int color3); - void prepare(void); - void draw(void); + void prepare(void); + void draw(void); }; class LampAppearance : public Appearance{ private: - int gllist; + int gllist; public: - LampAppearance(void); + LampAppearance(void); - void prepare(void); - void draw(void); + void prepare(void); + void draw(void); }; diff --git a/src/legoman.cpp b/src/legoman.cpp index c1bbc43..71ddea1 100644 --- a/src/legoman.cpp +++ b/src/legoman.cpp @@ -1,92 +1,3 @@ -/* - * $Id: legoman.cpp,v 1.26 2002/07/22 12:07:36 msell Exp $ - * - * - * $Log: legoman.cpp,v $ - * Revision 1.26 2002/07/22 12:07:36 msell - * Pää kiinni - * - * Revision 1.25 2002/07/22 01:14:14 msell - * Lopetussysteemi - * - * Revision 1.24 2002/07/21 22:50:39 msell - * no message - * - * Revision 1.23 2002/07/21 20:14:28 msell - * no message - * - * Revision 1.22 2002/07/21 16:37:00 msell - * no message - * - * Revision 1.21 2002/07/21 15:12:16 msell - * Äänet enabloitu :) - * - * Revision 1.20 2002/07/21 15:03:12 msell - * Äänet disabloitu - * - * Revision 1.19 2002/07/19 18:59:46 msell - * Alkuhommaa ja säätöä - * - * Revision 1.18 2002/07/18 23:05:31 msell - * Partikkelit ja kakkospelaajan liike - * - * Revision 1.17 2002/07/17 22:45:54 msell - * Ääniä vähän - * - * Revision 1.16 2002/07/16 19:52:09 jkaarlas - * kämmenet hienosäädetty - * - * Revision 1.15 2002/07/16 07:27:32 jkaarlas - * nyt latautuu kämmen. paikka ja väri pitää vielä säätää - * - * Revision 1.14 2002/07/16 00:42:43 msell - * Uusia skyboxeja ja areenan säätöä - * - * Revision 1.13 2002/07/15 22:03:23 msell - * MultiAppearance - * - * Revision 1.12 2002/07/15 15:22:08 msell - * Parantelua - * - * Revision 1.11 2002/07/14 21:40:43 msell - * Conflictit pois, liikkumiset (hyppy, kävely, lyönti), uusi areena - * - * Revision 1.10 2002/07/14 21:22:39 jkaarlas - * skybox ja ukkojen säätö - * - * Revision 1.9 2002/07/11 18:33:58 jkaarlas - * mallit paikoillaan, vaatii säätöä - * - * Revision 1.8 2002/07/10 22:22:53 msell - * Cartoon-rendaus - * - * Revision 1.7 2002/07/10 21:17:02 msell - * Ukon geometrian viilausta - * - * Revision 1.6 2002/07/10 17:13:44 msell - * Törmäystarkastelun parantelua - * - * Revision 1.5 2002/07/08 22:53:38 msell - * Säätöä - * - * Revision 1.4 2002/07/08 18:28:47 msell - * Törmäystä ja ukkoja - * - * Revision 1.3 2002/07/07 23:21:11 msell - * Pientä parantelua - * - * Revision 1.2 2002/07/07 23:05:22 msell - * Osien liimaaminen toisiinsa (kesken) - * - * Revision 1.1 2002/07/07 17:53:21 msell - * Legoukon alku - * - * - * - * $Date: 2002/07/22 12:07:36 $ - * - */ - #include "main.h" #include @@ -108,68 +19,68 @@ BodyPart::BodyPart(Legoman *parent, float strength){ - this->parent = parent; - this->strength = strength; - reset(); + this->parent = parent; + this->strength = strength; + reset(); } void BodyPart::reset(void){ - this->energy = 1; - this->attached = true; - this->immortal = 0; - vectorSet(position, 0, 0, 0); - vectorSet(momentum, 0, 0, 0); - matrixIdentity(rotation); - vectorSet(angularmomentum, 0, 0, 0); + this->energy = 1; + this->attached = true; + this->immortal = 0; + vectorSet(position, 0, 0, 0); + vectorSet(momentum, 0, 0, 0); + matrixIdentity(rotation); + vectorSet(angularmomentum, 0, 0, 0); } void BodyPart::move(void){ - if (immortal > 0) immortal--; - Object::move(); + if (immortal > 0) immortal--; + Object::move(); } void BodyPart::hitForce(float speed, float *speed2, Object *source){ - if (parent->isHarmfulObject(source)){ - float tolerance = 0.3; - if (speed > tolerance){ - Sound *sound; - sound = hitsound1; - float volume = (speed-tolerance)*0.4; - if (volume > 1) volume = 1; - volume = 1; - sound->setVolume(volume); - sound->play(30 + random(120)); + if (parent->isHarmfulObject(source)){ + float tolerance = 0.3; + if (speed > tolerance){ + Sound *sound; + sound = hitsound1; + float volume = (speed-tolerance)*0.4; + if (volume > 1) volume = 1; + volume = 1; + sound->setVolume(volume); + sound->play(30 + random(120)); - int i; - for (i = 0; i < (int)(speed-0.5); i++){ - float vel[3] = {randomf(2)-1, randomf(3), randomf(2)-1}; - vectorAdd(vel, speed2); - createBlood(position, vel); - } + int i; + for (i = 0; i < (int)(speed-0.5); i++){ + float vel[3] = {randomf(2)-1, randomf(3), randomf(2)-1}; + vectorAdd(vel, speed2); + createBlood(position, vel); + } - //makeDamage(0.1); - if (this == parent->head && source == parent->opponent->head){ - speed *= 0.1; - } - makeDamage(speed*0.1); - } - } else{ - Object::hitForce(speed, speed2, source); - } + //makeDamage(0.1); + if (this == parent->head && source == parent->opponent->head){ + speed *= 0.1; + } + makeDamage(speed*0.1); + } + } else{ + Object::hitForce(speed, speed2, source); + } } void BodyPart::makeDamage(float amount){ - if (strength == 0) return; - if (energy == 0) return; - if (!parent->opponent->isAlive()) return; - if (immortal > 0) return; + if (strength == 0) return; + if (energy == 0) return; + if (!parent->opponent->isAlive()) return; + if (immortal > 0) return; - energy -= amount/strength; - if (energy < 0) energy = 0; - if (energy == 0){ - parent->releasePart(this); - } - immortal = 30; + energy -= amount/strength; + if (energy < 0) energy = 0; + if (energy == 0){ + parent->releasePart(this); + } + immortal = 30; } @@ -177,41 +88,41 @@ Sensor::Sensor(){ } void Sensor::attach(Object *object, float *relativeposition){ - vectorCopy(this->relativeposition, relativeposition); - this->object = object; - update(); - update(); - update(); - update(); + vectorCopy(this->relativeposition, relativeposition); + this->object = object; + update(); + update(); + update(); + update(); } void Sensor::attach(Object *object){ - float position[3] = {0, 0, 0}; - attach(object, position); + float position[3] = {0, 0, 0}; + attach(object, position); } void Sensor::update(void){ - vectorCopy(oldposition, position); - vectorCopy(oldvelocity, velocity); + vectorCopy(oldposition, position); + vectorCopy(oldvelocity, velocity); - object->transformPoint(position, relativeposition); + object->transformPoint(position, relativeposition); - vectorSub(velocity, position, oldposition); - vectorSub(acceleration, velocity, oldvelocity); + vectorSub(velocity, position, oldposition); + vectorSub(acceleration, velocity, oldvelocity); - //printf("V: %f, %f, %f\n", velocity[0], velocity[1], velocity[2]); + //printf("V: %f, %f, %f\n", velocity[0], velocity[1], velocity[2]); } void Sensor::getPosition(float *target){ - vectorCopy(target, position); + vectorCopy(target, position); } void Sensor::getVelocity(float *target){ - vectorCopy(target, velocity); + vectorCopy(target, velocity); } void Sensor::getAcceleration(float *target){ - vectorCopy(target, acceleration); + vectorCopy(target, acceleration); } //float rightHandOffset[3] = {-0.60, 0.45, 0.0}; @@ -227,437 +138,437 @@ float rightLegOffset[3] = {-0.15, 0.4, 0.0}; float leftLegOffset[3] = {0.1, 0.4, 0.0}; Legoman::Legoman(int side){ - this->side = side; + this->side = side; - int collisiongroup, collisiongrouphand; - if (side == PLAYER1){ - collisiongroup = COLLISIONGROUP_MAN1; - collisiongrouphand = COLLISIONGROUP_MAN1HAND; - } - if (side == PLAYER2){ - collisiongroup = COLLISIONGROUP_MAN2; - collisiongrouphand = COLLISIONGROUP_MAN2HAND; - } + int collisiongroup, collisiongrouphand; + if (side == PLAYER1){ + collisiongroup = COLLISIONGROUP_MAN1; + collisiongrouphand = COLLISIONGROUP_MAN1HAND; + } + if (side == PLAYER2){ + collisiongroup = COLLISIONGROUP_MAN2; + collisiongrouphand = COLLISIONGROUP_MAN2HAND; + } - float torsocolor[3], legcolor[3]; + float torsocolor[3], legcolor[3]; - if (side == PLAYER1){ - vectorSet(torsocolor, 1, 0, 0); - vectorSet(legcolor, 0, 0, 1); - } else if (side == PLAYER2){ - vectorSet(torsocolor, 0, 0, 1); - vectorSet(legcolor, 1, 0, 0); - } + if (side == PLAYER1){ + vectorSet(torsocolor, 1, 0, 0); + vectorSet(legcolor, 0, 0, 1); + } else if (side == PLAYER2){ + vectorSet(torsocolor, 0, 0, 1); + vectorSet(legcolor, 1, 0, 0); + } - //Legs + //Legs Mesh* geomLegMesh = createBox(-0.45, 0.45, -BLOCKHEIGHT*LEGHEIGHT/2.0, BLOCKHEIGHT*LEGHEIGHT/2.0, -0.5, 0.5); - float tmpScale = 1.0; - - //Left leg - { - leftleg = new BodyPart(this, 8); - Mesh* leftLegMesh = loadAscModel((char*)LEFTLEGASC, MODELSCALE, leftLegOffset); - MeshShape *leftLegGeom = new MeshShape(leftleg, geomLegMesh); - leftleg->geometry = leftLegGeom; - leftleg->appearance = new MeshAppearance(leftLegMesh); - //leftleg->appearance = new MeshAppearance(geomLegMesh); - leftleg->appearance->material.setColor(legcolor[0], legcolor[1], legcolor[2], 1); - vectorSet(leftleg->position, -0.6, BLOCKHEIGHT*(LEGHEIGHT/2.0), 0); - leftleg->setGravity(true); - leftleg->setMass(LEGHEIGHT/3.0); - leftleg->setCollisionGroup(collisiongroup); - } + float tmpScale = 1.0; - //Right leg - { - rightleg = new BodyPart(this, 8); + //Left leg + { + leftleg = new BodyPart(this, 8); + Mesh* leftLegMesh = loadAscModel((char*)LEFTLEGASC, MODELSCALE, leftLegOffset); + MeshShape *leftLegGeom = new MeshShape(leftleg, geomLegMesh); + leftleg->geometry = leftLegGeom; + leftleg->appearance = new MeshAppearance(leftLegMesh); + //leftleg->appearance = new MeshAppearance(geomLegMesh); + leftleg->appearance->material.setColor(legcolor[0], legcolor[1], legcolor[2], 1); + vectorSet(leftleg->position, -0.6, BLOCKHEIGHT*(LEGHEIGHT/2.0), 0); + leftleg->setGravity(true); + leftleg->setMass(LEGHEIGHT/3.0); + leftleg->setCollisionGroup(collisiongroup); + } + + //Right leg + { + rightleg = new BodyPart(this, 8); Mesh* rightLegMesh = loadAscModel((char*)RIGHTLEGASC, MODELSCALE, rightLegOffset); - MeshShape *rightLegGeom = new MeshShape(rightleg, geomLegMesh); - rightleg->geometry = rightLegGeom; - rightleg->appearance = new MeshAppearance(rightLegMesh); - //rightleg->appearance = new MeshAppearance(geomLegMesh); - rightleg->appearance->material.setColor(legcolor[0], legcolor[1], legcolor[2], 1); - vectorSet(rightleg->position, 0.6, BLOCKHEIGHT*(LEGHEIGHT/2.0), 0); - rightleg->setGravity(true); - rightleg->setMass(LEGHEIGHT/3.0); - rightleg->setCollisionGroup(collisiongroup); - } - - - //Waist - { - waist = new BodyPart(this, 0); + MeshShape *rightLegGeom = new MeshShape(rightleg, geomLegMesh); + rightleg->geometry = rightLegGeom; + rightleg->appearance = new MeshAppearance(rightLegMesh); + //rightleg->appearance = new MeshAppearance(geomLegMesh); + rightleg->appearance->material.setColor(legcolor[0], legcolor[1], legcolor[2], 1); + vectorSet(rightleg->position, 0.6, BLOCKHEIGHT*(LEGHEIGHT/2.0), 0); + rightleg->setGravity(true); + rightleg->setMass(LEGHEIGHT/3.0); + rightleg->setCollisionGroup(collisiongroup); + } + + + //Waist + { + waist = new BodyPart(this, 0); Mesh* waistMesh = loadAscModel((char*)WAISTASC, MODELSCALE, waistOffset); MeshAppearance* waistappearance = new MeshAppearance(waistMesh); - waistappearance->material.setColor(0, 1, 0, 1); + waistappearance->material.setColor(0, 1, 0, 1); - Mesh *waistGeomMesh = createBox(-1 + 0.1, 1 - 0.1, 0, BLOCKHEIGHT*WAISTHEIGHT/2.0, 0.1, 0.4); - MeshShape *waistgeometry = new MeshShape(waist, waistGeomMesh); - waist->geometry = waistgeometry; - waist->appearance = waistappearance; - //waist->appearance = new MeshAppearance(waistGeomMesh); - vectorSet(waist->position, 0, BLOCKHEIGHT*(LEGHEIGHT + WAISTHEIGHT/2.0), 0); - waist->setGravity(true); - waist->setMass(2*WAISTHEIGHT/3.0); - waist->setCollisionGroup(collisiongroup); - } - - - //Torso - { - torso = new BodyPart(this, 4); + Mesh *waistGeomMesh = createBox(-1 + 0.1, 1 - 0.1, 0, BLOCKHEIGHT*WAISTHEIGHT/2.0, 0.1, 0.4); + MeshShape *waistgeometry = new MeshShape(waist, waistGeomMesh); + waist->geometry = waistgeometry; + waist->appearance = waistappearance; + //waist->appearance = new MeshAppearance(waistGeomMesh); + vectorSet(waist->position, 0, BLOCKHEIGHT*(LEGHEIGHT + WAISTHEIGHT/2.0), 0); + waist->setGravity(true); + waist->setMass(2*WAISTHEIGHT/3.0); + waist->setCollisionGroup(collisiongroup); + } + + + //Torso + { + torso = new BodyPart(this, 4); Mesh* torsoMesh = loadAscModel((char*)TORSOASC, TORSOSCALE); - //int i; - //for (i = 0; i < torsoMesh->polygoncount; i++) torsoMesh->polygons[i].smooth = false; + //int i; + //for (i = 0; i < torsoMesh->polygoncount; i++) torsoMesh->polygons[i].smooth = false; MeshAppearance* torsoAppearance = new MeshAppearance(torsoMesh); - torsoAppearance->material.setColor(torsocolor[0], torsocolor[1], torsocolor[2], 1); - Mesh *torsoGeomMesh = createBox(-1, 1, -BLOCKHEIGHT*TORSOHEIGHT/2.0, BLOCKHEIGHT*TORSOHEIGHT/2.0, -0.5, 0.5); - MeshShape *torsogeometry = new MeshShape(torso, torsoGeomMesh); - torso->geometry = torsogeometry; - torso->appearance = torsoAppearance; - //torso->appearance = new MeshAppearance(torsoGeomMesh); - vectorSet(torso->position, 0, BLOCKHEIGHT*(LEGHEIGHT + WAISTHEIGHT + TORSOHEIGHT/2.0), 0); - torso->setGravity(true); - torso->setMass(2*TORSOHEIGHT/3.0); - torso->setCollisionGroup(collisiongroup); - } - - - //Hands - //Mesh *handMeshGeom = createBox(-0.4, 0.4, -BLOCKHEIGHT*HANDHEIGHT/2.0, BLOCKHEIGHT*HANDHEIGHT/2.0, -0.5, 0.5); - Mesh *handMeshGeom = createBox(-0.2, 0.2, -BLOCKHEIGHT*HANDHEIGHT/2.0, BLOCKHEIGHT*HANDHEIGHT/2.0, -0.5, 0.5); + torsoAppearance->material.setColor(torsocolor[0], torsocolor[1], torsocolor[2], 1); + Mesh *torsoGeomMesh = createBox(-1, 1, -BLOCKHEIGHT*TORSOHEIGHT/2.0, BLOCKHEIGHT*TORSOHEIGHT/2.0, -0.5, 0.5); + MeshShape *torsogeometry = new MeshShape(torso, torsoGeomMesh); + torso->geometry = torsogeometry; + torso->appearance = torsoAppearance; + //torso->appearance = new MeshAppearance(torsoGeomMesh); + vectorSet(torso->position, 0, BLOCKHEIGHT*(LEGHEIGHT + WAISTHEIGHT + TORSOHEIGHT/2.0), 0); + torso->setGravity(true); + torso->setMass(2*TORSOHEIGHT/3.0); + torso->setCollisionGroup(collisiongroup); + } - //Left hand - { - lefthand = new BodyPart(this, 5); - + //Hands + //Mesh *handMeshGeom = createBox(-0.4, 0.4, -BLOCKHEIGHT*HANDHEIGHT/2.0, BLOCKHEIGHT*HANDHEIGHT/2.0, -0.5, 0.5); + Mesh *handMeshGeom = createBox(-0.2, 0.2, -BLOCKHEIGHT*HANDHEIGHT/2.0, BLOCKHEIGHT*HANDHEIGHT/2.0, -0.5, 0.5); + + + //Left hand + { + lefthand = new BodyPart(this, 5); + Mesh* leftHandMesh = loadAscModel((char*)LEFTARMASC, MODELSCALE, leftHandOffset); - Mesh* leftPalmMesh = loadAscModel((char*)LEFTPALMASC, MODELSCALE, leftPalmOffset); - MultiAppearance *a = new MultiAppearance(); - Appearance *arm = new MeshAppearance(leftHandMesh); - Appearance *palm = new MeshAppearance(leftPalmMesh); - arm->material.setColor(torsocolor[0], torsocolor[1], torsocolor[2], 1); - palm->material.setColor(1, 1, 0, 1); - a->addAppearance(arm); - a->addAppearance(palm); - MeshShape *lefthandgeometry = new MeshShape(lefthand, handMeshGeom); - lefthand->geometry = lefthandgeometry; - lefthand->appearance = a;//new MeshAppearance(leftHandMesh); - //lefthand->appearance = new MeshAppearance(handMeshGeom); - //lefthand->appearance->material.setColor(1, 0, 0, 1); - vectorSet(lefthand->position, -1.3, BLOCKHEIGHT*(LEGHEIGHT + WAISTHEIGHT + TORSOHEIGHT - HANDHEIGHT/2.0), 0); - lefthand->setGravity(true); - lefthand->setMass(HANDHEIGHT/3.0); - lefthand->setCollisionGroup(collisiongrouphand); - } + Mesh* leftPalmMesh = loadAscModel((char*)LEFTPALMASC, MODELSCALE, leftPalmOffset); + MultiAppearance *a = new MultiAppearance(); + Appearance *arm = new MeshAppearance(leftHandMesh); + Appearance *palm = new MeshAppearance(leftPalmMesh); + arm->material.setColor(torsocolor[0], torsocolor[1], torsocolor[2], 1); + palm->material.setColor(1, 1, 0, 1); + a->addAppearance(arm); + a->addAppearance(palm); + MeshShape *lefthandgeometry = new MeshShape(lefthand, handMeshGeom); + lefthand->geometry = lefthandgeometry; + lefthand->appearance = a;//new MeshAppearance(leftHandMesh); + //lefthand->appearance = new MeshAppearance(handMeshGeom); + //lefthand->appearance->material.setColor(1, 0, 0, 1); + vectorSet(lefthand->position, -1.3, BLOCKHEIGHT*(LEGHEIGHT + WAISTHEIGHT + TORSOHEIGHT - HANDHEIGHT/2.0), 0); + lefthand->setGravity(true); + lefthand->setMass(HANDHEIGHT/3.0); + lefthand->setCollisionGroup(collisiongrouphand); + } - //Right hand - { - righthand = new BodyPart(this, 5); + //Right hand + { + righthand = new BodyPart(this, 5); Mesh* rightHandMesh = loadAscModel((char*)RIGHTARMASC, MODELSCALE, rightHandOffset); - Mesh* rightPalmMesh = loadAscModel((char*)RIGHTPALMASC, MODELSCALE, rightPalmOffset); - MultiAppearance *a = new MultiAppearance(); - Appearance *arm = new MeshAppearance(rightHandMesh); - arm->material.setColor(torsocolor[0], torsocolor[1], torsocolor[2], 1); - Appearance *palm = new MeshAppearance(rightPalmMesh); - palm->material.setColor(1, 1, 0, 1); - a->addAppearance(arm); - a->addAppearance(palm); - MeshShape *righthandgeometry = new MeshShape(righthand, handMeshGeom); - righthand->geometry = righthandgeometry; - righthand->appearance = a; - //righthand->appearance = new MeshAppearance(handMeshGeom); - vectorSet(righthand->position, 1.3, BLOCKHEIGHT*(LEGHEIGHT + WAISTHEIGHT + TORSOHEIGHT - HANDHEIGHT/2.0), 0); - righthand->setGravity(true); - righthand->setMass(HANDHEIGHT/3.0); - righthand->setCollisionGroup(collisiongrouphand); - } - - - //Head - { - head = new BodyPart(this, 2); - Appearance *headappearance = new HeadAppearance(); - float r = BLOCKHEIGHT*HEADHEIGHT/2; - /*SphereAppearance *headappearance = new SphereAppearance(); - headappearance->setRadius(r); - headappearance->material.setColor(1, 1, 0, 1);*/ - SphereShape *headgeometry = new SphereShape(head); - headgeometry->setRadius(r); - head->geometry = headgeometry; - head->appearance = headappearance; - vectorSet(head->position, 0, BLOCKHEIGHT*(LEGHEIGHT + WAISTHEIGHT + TORSOHEIGHT + HEADHEIGHT/2 + 0.5), 0); - head->setGravity(true); - head->setMass(4.0/3*PI*r*r*r); - head->setCollisionGroup(collisiongroup); - } + Mesh* rightPalmMesh = loadAscModel((char*)RIGHTPALMASC, MODELSCALE, rightPalmOffset); + MultiAppearance *a = new MultiAppearance(); + Appearance *arm = new MeshAppearance(rightHandMesh); + arm->material.setColor(torsocolor[0], torsocolor[1], torsocolor[2], 1); + Appearance *palm = new MeshAppearance(rightPalmMesh); + palm->material.setColor(1, 1, 0, 1); + a->addAppearance(arm); + a->addAppearance(palm); + MeshShape *righthandgeometry = new MeshShape(righthand, handMeshGeom); + righthand->geometry = righthandgeometry; + righthand->appearance = a; + //righthand->appearance = new MeshAppearance(handMeshGeom); + vectorSet(righthand->position, 1.3, BLOCKHEIGHT*(LEGHEIGHT + WAISTHEIGHT + TORSOHEIGHT - HANDHEIGHT/2.0), 0); + righthand->setGravity(true); + righthand->setMass(HANDHEIGHT/3.0); + righthand->setCollisionGroup(collisiongrouphand); + } - headsensor = new Sensor(); - torsosensor = new Sensor(); + //Head + { + head = new BodyPart(this, 2); + Appearance *headappearance = new HeadAppearance(); + float r = BLOCKHEIGHT*HEADHEIGHT/2; + /*SphereAppearance *headappearance = new SphereAppearance(); + headappearance->setRadius(r); + headappearance->material.setColor(1, 1, 0, 1);*/ + SphereShape *headgeometry = new SphereShape(head); + headgeometry->setRadius(r); + head->geometry = headgeometry; + head->appearance = headappearance; + vectorSet(head->position, 0, BLOCKHEIGHT*(LEGHEIGHT + WAISTHEIGHT + TORSOHEIGHT + HEADHEIGHT/2 + 0.5), 0); + head->setGravity(true); + head->setMass(4.0/3*PI*r*r*r); + head->setCollisionGroup(collisiongroup); + } + + + headsensor = new Sensor(); + torsosensor = new Sensor(); - headvisual = new DamageVisual(head, damageHead, false, - -0.5, -2, 0.5, -1); - - torsovisual = new DamageVisual(torso, damageTorso, false, - -0.5, -1, 0.5, 0); - - lefthandvisual = new DamageVisual(lefthand, damageHand, true, - 0.4, -1, 0.9, 0); - - righthandvisual = new DamageVisual(righthand, damageHand, true, - -0.4, -1, -0.9, 0); - - leftlegvisual = new DamageVisual(leftleg, damageLeg, true, - 0, 0, 0.5, 1); - - rightlegvisual = new DamageVisual(rightleg, damageLeg, true, - -0, 0, -0.5, 1); + headvisual = new DamageVisual(head, damageHead, false, + -0.5, -2, 0.5, -1); + + torsovisual = new DamageVisual(torso, damageTorso, false, + -0.5, -1, 0.5, 0); + + lefthandvisual = new DamageVisual(lefthand, damageHand, true, + 0.4, -1, 0.9, 0); + + righthandvisual = new DamageVisual(righthand, damageHand, true, + -0.4, -1, -0.9, 0); + + leftlegvisual = new DamageVisual(leftleg, damageLeg, true, + 0, 0, 0.5, 1); + + rightlegvisual = new DamageVisual(rightleg, damageLeg, true, + -0, 0, -0.5, 1); - harmfulobjects = NULL; + harmfulobjects = NULL; - walkphase = 0; - jumpphase = 0; - hitside = 0; + walkphase = 0; + jumpphase = 0; + hitside = 0; - alive = true; + alive = true; } void Legoman::insertToWorld(World *world){ - this->world = world; + this->world = world; - world->addChild(rightleg); - world->addChild(leftleg); - world->addChild(waist); - world->addChild(torso); - world->addChild(lefthand); - world->addChild(righthand); - world->addChild(head); - float linkpoint[3]; + world->addChild(rightleg); + world->addChild(leftleg); + world->addChild(waist); + world->addChild(torso); + world->addChild(lefthand); + world->addChild(righthand); + world->addChild(head); + float linkpoint[3]; - vectorSet(linkpoint, 0, BLOCKHEIGHT*(LEGHEIGHT + WAISTHEIGHT + TORSOHEIGHT + HEADHEIGHT), 0); - headlinks[0] = world->addLink(head, torso, linkpoint); + vectorSet(linkpoint, 0, BLOCKHEIGHT*(LEGHEIGHT + WAISTHEIGHT + TORSOHEIGHT + HEADHEIGHT), 0); + headlinks[0] = world->addLink(head, torso, linkpoint); - vectorSet(linkpoint, 0, BLOCKHEIGHT*(LEGHEIGHT + WAISTHEIGHT + TORSOHEIGHT), 0); - headlinks[1] = world->addLink(head, torso, linkpoint); + vectorSet(linkpoint, 0, BLOCKHEIGHT*(LEGHEIGHT + WAISTHEIGHT + TORSOHEIGHT), 0); + headlinks[1] = world->addLink(head, torso, linkpoint); - vectorSet(linkpoint, 0, BLOCKHEIGHT*(LEGHEIGHT + WAISTHEIGHT + TORSOHEIGHT + HEADHEIGHT*0.5), 1); - headlinks[2] = world->addLink(head, torso, linkpoint); + vectorSet(linkpoint, 0, BLOCKHEIGHT*(LEGHEIGHT + WAISTHEIGHT + TORSOHEIGHT + HEADHEIGHT*0.5), 1); + headlinks[2] = world->addLink(head, torso, linkpoint); - head->attached = true; + head->attached = true; - vectorSet(linkpoint, -1, BLOCKHEIGHT*(LEGHEIGHT + WAISTHEIGHT + TORSOHEIGHT) - 0.5, 0); - lefthandlinks[0] = world->addLink(torso, lefthand, linkpoint); + vectorSet(linkpoint, -1, BLOCKHEIGHT*(LEGHEIGHT + WAISTHEIGHT + TORSOHEIGHT) - 0.5, 0); + lefthandlinks[0] = world->addLink(torso, lefthand, linkpoint); - vectorSet(linkpoint, -2, BLOCKHEIGHT*(LEGHEIGHT + WAISTHEIGHT + TORSOHEIGHT) - 0.5, 0); - lefthandlinks[1] = world->addLink(torso, lefthand, linkpoint); + vectorSet(linkpoint, -2, BLOCKHEIGHT*(LEGHEIGHT + WAISTHEIGHT + TORSOHEIGHT) - 0.5, 0); + lefthandlinks[1] = world->addLink(torso, lefthand, linkpoint); - lefthand->attached = true; + lefthand->attached = true; - vectorSet(linkpoint, 1, BLOCKHEIGHT*(LEGHEIGHT + WAISTHEIGHT + TORSOHEIGHT) - 0.5, 0); - righthandlinks[0] = world->addLink(torso, righthand, linkpoint); + vectorSet(linkpoint, 1, BLOCKHEIGHT*(LEGHEIGHT + WAISTHEIGHT + TORSOHEIGHT) - 0.5, 0); + righthandlinks[0] = world->addLink(torso, righthand, linkpoint); - vectorSet(linkpoint, 2, BLOCKHEIGHT*(LEGHEIGHT + WAISTHEIGHT + TORSOHEIGHT) - 0.5, 0); - righthandlinks[1] = world->addLink(torso, righthand, linkpoint); + vectorSet(linkpoint, 2, BLOCKHEIGHT*(LEGHEIGHT + WAISTHEIGHT + TORSOHEIGHT) - 0.5, 0); + righthandlinks[1] = world->addLink(torso, righthand, linkpoint); - righthand->attached = true; + righthand->attached = true; - vectorSet(linkpoint, -1, BLOCKHEIGHT*(LEGHEIGHT + WAISTHEIGHT), -0.5); - world->addLink(torso, waist, linkpoint); + vectorSet(linkpoint, -1, BLOCKHEIGHT*(LEGHEIGHT + WAISTHEIGHT), -0.5); + world->addLink(torso, waist, linkpoint); - vectorSet(linkpoint, 1, BLOCKHEIGHT*(LEGHEIGHT + WAISTHEIGHT), -0.5); - world->addLink(torso, waist, linkpoint); + vectorSet(linkpoint, 1, BLOCKHEIGHT*(LEGHEIGHT + WAISTHEIGHT), -0.5); + world->addLink(torso, waist, linkpoint); - vectorSet(linkpoint, -1, BLOCKHEIGHT*(LEGHEIGHT + WAISTHEIGHT), 0.5); - world->addLink(torso, waist, linkpoint); + vectorSet(linkpoint, -1, BLOCKHEIGHT*(LEGHEIGHT + WAISTHEIGHT), 0.5); + world->addLink(torso, waist, linkpoint); - vectorSet(linkpoint, 1, BLOCKHEIGHT*(LEGHEIGHT + WAISTHEIGHT), 0.5); - world->addLink(torso, waist, linkpoint); + vectorSet(linkpoint, 1, BLOCKHEIGHT*(LEGHEIGHT + WAISTHEIGHT), 0.5); + world->addLink(torso, waist, linkpoint); - waist->attached = true; + waist->attached = true; - vectorSet(linkpoint, -1, BLOCKHEIGHT*(LEGHEIGHT + WAISTHEIGHT)-0.5, 0); - leftleglinks[0] = world->addLink(waist, leftleg, linkpoint); + vectorSet(linkpoint, -1, BLOCKHEIGHT*(LEGHEIGHT + WAISTHEIGHT)-0.5, 0); + leftleglinks[0] = world->addLink(waist, leftleg, linkpoint); - vectorSet(linkpoint, 0, BLOCKHEIGHT*(LEGHEIGHT + WAISTHEIGHT)-0.5, 0); - leftleglinks[1] = world->addLink(waist, leftleg, linkpoint); - - lll = leftleglinks[1]; + vectorSet(linkpoint, 0, BLOCKHEIGHT*(LEGHEIGHT + WAISTHEIGHT)-0.5, 0); + leftleglinks[1] = world->addLink(waist, leftleg, linkpoint); - leftleg->attached = true; + lll = leftleglinks[1]; + + leftleg->attached = true; - vectorSet(linkpoint, 0, BLOCKHEIGHT*(LEGHEIGHT + WAISTHEIGHT)-0.5, 0); - rightleglinks[0] = world->addLink(waist, rightleg, linkpoint); + vectorSet(linkpoint, 0, BLOCKHEIGHT*(LEGHEIGHT + WAISTHEIGHT)-0.5, 0); + rightleglinks[0] = world->addLink(waist, rightleg, linkpoint); - vectorSet(linkpoint, 1, BLOCKHEIGHT*(LEGHEIGHT + WAISTHEIGHT)-0.5, 0); - rightleglinks[1] = world->addLink(waist, rightleg, linkpoint); + vectorSet(linkpoint, 1, BLOCKHEIGHT*(LEGHEIGHT + WAISTHEIGHT)-0.5, 0); + rightleglinks[1] = world->addLink(waist, rightleg, linkpoint); - rll = rightleglinks[0]; + rll = rightleglinks[0]; - rightleg->attached = true; + rightleg->attached = true; - leftleglinks[2] = world->addLink(waist, leftleg, NULL); - leftleglink = leftleglinks[2]; - leftleglink->enabled = false; - rightleglinks[2] = world->addLink(waist, rightleg, NULL); - rightleglink = rightleglinks[2]; - rightleglink->enabled = false; + leftleglinks[2] = world->addLink(waist, leftleg, NULL); + leftleglink = leftleglinks[2]; + leftleglink->enabled = false; + rightleglinks[2] = world->addLink(waist, rightleg, NULL); + rightleglink = rightleglinks[2]; + rightleglink->enabled = false; - lefthandlinks[2] = world->addLink(torso, lefthand, NULL); - lefthandlink = lefthandlinks[2]; - lefthandlink->enabled = false; - righthandlinks[2] = world->addLink(torso, righthand, NULL); - righthandlink = righthandlinks[2]; - righthandlink->enabled = false; + lefthandlinks[2] = world->addLink(torso, lefthand, NULL); + lefthandlink = lefthandlinks[2]; + lefthandlink->enabled = false; + righthandlinks[2] = world->addLink(torso, righthand, NULL); + righthandlink = righthandlinks[2]; + righthandlink->enabled = false; } void Legoman::heal(void){ - headlinks[0]->enabled = true; - headlinks[1]->enabled = true; - headlinks[2]->enabled = true; - lefthandlinks[0]->enabled = true; - lefthandlinks[1]->enabled = true; - lefthandlinks[2]->enabled = true; - righthandlinks[0]->enabled = true; - righthandlinks[1]->enabled = true; - righthandlinks[2]->enabled = true; - leftleglinks[0]->enabled = true; - leftleglinks[1]->enabled = true; - leftleglinks[2]->enabled = true; - rightleglinks[0]->enabled = true; - rightleglinks[1]->enabled = true; - rightleglinks[2]->enabled = true; + headlinks[0]->enabled = true; + headlinks[1]->enabled = true; + headlinks[2]->enabled = true; + lefthandlinks[0]->enabled = true; + lefthandlinks[1]->enabled = true; + lefthandlinks[2]->enabled = true; + righthandlinks[0]->enabled = true; + righthandlinks[1]->enabled = true; + righthandlinks[2]->enabled = true; + leftleglinks[0]->enabled = true; + leftleglinks[1]->enabled = true; + leftleglinks[2]->enabled = true; + rightleglinks[0]->enabled = true; + rightleglinks[1]->enabled = true; + rightleglinks[2]->enabled = true; - leftleglink->enabled = false; - rightleglink->enabled = false; - lefthandlink->enabled = false; - righthandlink->enabled = false; + leftleglink->enabled = false; + rightleglink->enabled = false; + lefthandlink->enabled = false; + righthandlink->enabled = false; - leftleg->reset(); - rightleg->reset(); - waist->reset(); - torso->reset(); - lefthand->reset(); - righthand->reset(); - head->reset(); - vectorSet(leftleg->position, -0.6, BLOCKHEIGHT*(LEGHEIGHT/2.0), 0); - vectorSet(rightleg->position, 0.6, BLOCKHEIGHT*(LEGHEIGHT/2.0), 0); - vectorSet(waist->position, 0, BLOCKHEIGHT*(LEGHEIGHT + WAISTHEIGHT/2.0), 0); - vectorSet(torso->position, 0, BLOCKHEIGHT*(LEGHEIGHT + WAISTHEIGHT + TORSOHEIGHT/2.0), 0); - vectorSet(lefthand->position, -1.3, BLOCKHEIGHT*(LEGHEIGHT + WAISTHEIGHT + TORSOHEIGHT - HANDHEIGHT/2.0), 0); - vectorSet(righthand->position, 1.3, BLOCKHEIGHT*(LEGHEIGHT + WAISTHEIGHT + TORSOHEIGHT - HANDHEIGHT/2.0), 0); - vectorSet(head->position, 0, BLOCKHEIGHT*(LEGHEIGHT + WAISTHEIGHT + TORSOHEIGHT + HEADHEIGHT/2 + 0.5), 0); + leftleg->reset(); + rightleg->reset(); + waist->reset(); + torso->reset(); + lefthand->reset(); + righthand->reset(); + head->reset(); + vectorSet(leftleg->position, -0.6, BLOCKHEIGHT*(LEGHEIGHT/2.0), 0); + vectorSet(rightleg->position, 0.6, BLOCKHEIGHT*(LEGHEIGHT/2.0), 0); + vectorSet(waist->position, 0, BLOCKHEIGHT*(LEGHEIGHT + WAISTHEIGHT/2.0), 0); + vectorSet(torso->position, 0, BLOCKHEIGHT*(LEGHEIGHT + WAISTHEIGHT + TORSOHEIGHT/2.0), 0); + vectorSet(lefthand->position, -1.3, BLOCKHEIGHT*(LEGHEIGHT + WAISTHEIGHT + TORSOHEIGHT - HANDHEIGHT/2.0), 0); + vectorSet(righthand->position, 1.3, BLOCKHEIGHT*(LEGHEIGHT + WAISTHEIGHT + TORSOHEIGHT - HANDHEIGHT/2.0), 0); + vectorSet(head->position, 0, BLOCKHEIGHT*(LEGHEIGHT + WAISTHEIGHT + TORSOHEIGHT + HEADHEIGHT/2 + 0.5), 0); - headsensor->attach(head); - torsosensor->attach(torso); + headsensor->attach(head); + torsosensor->attach(torso); - alive = true; + alive = true; } void Legoman::lockPart(int part){ - if (part & LEFTLEG && leftleg->energy > 0){ - float linkpoint[3]; - vectorScale(linkpoint, &leftleg->rotation[3], -1); - //vectorAdd(linkpoint, leftleg->position); - vectorAdd(linkpoint, waist->position); - vectorAdd(linkpoint, lll->point1); - world->renewLink(leftleglink, linkpoint); - } - if (part & RIGHTLEG && rightleg->energy > 0){ - float linkpoint[3]; - vectorScale(linkpoint, &rightleg->rotation[3], -1); - //vectorAdd(linkpoint, rightleg->position); - vectorAdd(linkpoint, waist->position); - vectorAdd(linkpoint, rll->point1); - world->renewLink(rightleglink, linkpoint); - } - if (part & LEFTHAND && lefthand->energy > 0){ - float linkpoint[3]; - vectorScale(linkpoint, &lefthand->rotation[3], -1); - vectorAdd(linkpoint, lefthand->position); - world->renewLink(lefthandlink, linkpoint); - } - if (part & RIGHTHAND && righthand->energy > 0){ - float linkpoint[3]; - vectorScale(linkpoint, &righthand->rotation[3], -1); - vectorAdd(linkpoint, righthand->position); - world->renewLink(righthandlink, linkpoint); - } + if (part & LEFTLEG && leftleg->energy > 0){ + float linkpoint[3]; + vectorScale(linkpoint, &leftleg->rotation[3], -1); + //vectorAdd(linkpoint, leftleg->position); + vectorAdd(linkpoint, waist->position); + vectorAdd(linkpoint, lll->point1); + world->renewLink(leftleglink, linkpoint); + } + if (part & RIGHTLEG && rightleg->energy > 0){ + float linkpoint[3]; + vectorScale(linkpoint, &rightleg->rotation[3], -1); + //vectorAdd(linkpoint, rightleg->position); + vectorAdd(linkpoint, waist->position); + vectorAdd(linkpoint, rll->point1); + world->renewLink(rightleglink, linkpoint); + } + if (part & LEFTHAND && lefthand->energy > 0){ + float linkpoint[3]; + vectorScale(linkpoint, &lefthand->rotation[3], -1); + vectorAdd(linkpoint, lefthand->position); + world->renewLink(lefthandlink, linkpoint); + } + if (part & RIGHTHAND && righthand->energy > 0){ + float linkpoint[3]; + vectorScale(linkpoint, &righthand->rotation[3], -1); + vectorAdd(linkpoint, righthand->position); + world->renewLink(righthandlink, linkpoint); + } - headsensor->attach(head); - torsosensor->attach(torso); + headsensor->attach(head); + torsosensor->attach(torso); } void Legoman::addHarmfulObject(Object *object){ - objectlist *node = new objectlist(); - node->object = object; - node->next = harmfulobjects; - harmfulobjects = node; + objectlist *node = new objectlist(); + node->object = object; + node->next = harmfulobjects; + harmfulobjects = node; } bool Legoman::isHarmfulObject(Object *object){ - objectlist *node = harmfulobjects; - while (node != NULL){ - if (node->object == object) return true; - node = node->next; - } - return false; + objectlist *node = harmfulobjects; + while (node != NULL){ + if (node->object == object) return true; + node = node->next; + } + return false; } float Legoman::getInvMass(void){ - float mass = torso->getMass() + waist->getMass(); - if (head->attached) mass += head->getMass(); - if (lefthand->attached) mass += lefthand->getMass(); - if (righthand->attached) mass += righthand->getMass(); - if (leftleg->attached) mass += leftleg->getMass(); - if (rightleg->attached) mass += rightleg->getMass(); - return 1.0/mass; + float mass = torso->getMass() + waist->getMass(); + if (head->attached) mass += head->getMass(); + if (lefthand->attached) mass += lefthand->getMass(); + if (righthand->attached) mass += righthand->getMass(); + if (leftleg->attached) mass += leftleg->getMass(); + if (rightleg->attached) mass += rightleg->getMass(); + return 1.0/mass; } void Legoman::addOpponent(Legoman *opponent){ - this->opponent = opponent; - opponent->addHarmfulObject(head); - opponent->addHarmfulObject(lefthand); - opponent->addHarmfulObject(righthand); - opponent->addHarmfulObject(leftleg); - opponent->addHarmfulObject(rightleg); + this->opponent = opponent; + opponent->addHarmfulObject(head); + opponent->addHarmfulObject(lefthand); + opponent->addHarmfulObject(righthand); + opponent->addHarmfulObject(leftleg); + opponent->addHarmfulObject(rightleg); } void Legoman::unlockPart(int part){ - if (part & LEFTLEG){ - leftleglink->enabled = false; - } - if (part & RIGHTLEG){ - rightleglink->enabled = false; - } - if (part & LEFTHAND){ - lefthandlink->enabled = false; - } - if (part & RIGHTHAND){ - righthandlink->enabled = false; - } + if (part & LEFTLEG){ + leftleglink->enabled = false; + } + if (part & RIGHTLEG){ + rightleglink->enabled = false; + } + if (part & LEFTHAND){ + lefthandlink->enabled = false; + } + if (part & RIGHTHAND){ + righthandlink->enabled = false; + } } void Legoman::move(float *movement){ - vectorAdd(leftleg->position, movement); - vectorAdd(rightleg->position, movement); - vectorAdd(waist->position, movement); - vectorAdd(torso->position, movement); - vectorAdd(lefthand->position, movement); - vectorAdd(righthand->position, movement); - vectorAdd(head->position, movement); + vectorAdd(leftleg->position, movement); + vectorAdd(rightleg->position, movement); + vectorAdd(waist->position, movement); + vectorAdd(torso->position, movement); + vectorAdd(lefthand->position, movement); + vectorAdd(righthand->position, movement); + vectorAdd(head->position, movement); } #define LEGSPEED 0.03 @@ -665,446 +576,446 @@ void Legoman::move(float *movement){ #define BALANCEANGLE (PI/12) void Legoman::balance(void){ - if (!alive || !head->attached) return; + if (!alive || !head->attached) return; - float headpos[3], torsopos[3]; - headsensor->getPosition(headpos); - torsosensor->getPosition(torsopos); - float posdiff[3]; - vectorSub(posdiff, headpos, torsopos); - float posdifflen = vectorLength(posdiff); - float angle = acos(posdiff[1]/posdifflen); + float headpos[3], torsopos[3]; + headsensor->getPosition(headpos); + torsosensor->getPosition(torsopos); + float posdiff[3]; + vectorSub(posdiff, headpos, torsopos); + float posdifflen = vectorLength(posdiff); + float angle = acos(posdiff[1]/posdifflen); - float headtarget[3]; - vectorSet(headtarget, 0, posdifflen, 0); - vectorAdd(headtarget, torsopos); + float headtarget[3]; + vectorSet(headtarget, 0, posdifflen, 0); + vectorAdd(headtarget, torsopos); - float force[3]; - vectorSub(force, headtarget, headpos); + float force[3]; + vectorSub(force, headtarget, headpos); - float headvel[3], torsovel[3]; - headsensor->getVelocity(headvel); - torsosensor->getVelocity(torsovel); - float veldiff[3]; - vectorSub(veldiff, headvel, torsovel); - vectorScale(veldiff, 50); + float headvel[3], torsovel[3]; + headsensor->getVelocity(headvel); + torsosensor->getVelocity(torsovel); + float veldiff[3]; + vectorSub(veldiff, headvel, torsovel); + vectorScale(veldiff, 50); - vectorSaturate(veldiff, 0, 10); + vectorSaturate(veldiff, 0, 10); - vectorSub(force, veldiff); + vectorSub(force, veldiff); - if (angle < BALANCEANGLE){ - vectorScale(force, pow(1-angle/BALANCEANGLE, 0.1)); - vectorScale(force, 100); - head->addExternalForce(force); - } + if (angle < BALANCEANGLE){ + vectorScale(force, pow(1-angle/BALANCEANGLE, 0.1)); + vectorScale(force, 100); + head->addExternalForce(force); + } - if (walkdelay == 0){ - if (walkphase > 0){ - walkphase --; - updateLegs(); - } - } + if (walkdelay == 0){ + if (walkphase > 0){ + walkphase --; + updateLegs(); + } + } - vectorScale(lefthand->angularmomentum, 0.98); - vectorScale(righthand->angularmomentum, 0.98); + vectorScale(lefthand->angularmomentum, 0.98); + vectorScale(righthand->angularmomentum, 0.98); } void Legoman::update(void){ - if (walkdelay > 0){ - walkdelay--; - } + if (walkdelay > 0){ + walkdelay--; + } - /*if (jumpphase > 0){ - jumpphase--; - }*/ - if (torso->momentum[1] < 0 && isOnGround()){ - jumpphase--; - if (jumpphase == 0) jumpenabled = true; - } + /*if (jumpphase > 0){ + jumpphase--; + }*/ + if (torso->momentum[1] < 0 && isOnGround()){ + jumpphase--; + if (jumpphase == 0) jumpenabled = true; + } - if (hitside < 10) hitside += 2; - //hitside = -hitside; - /*if (hitside > 0){ - hitside = -hitside; - }/* else{ - hitside = 0; - }*/ + if (hitside < 10) hitside += 2; + //hitside = -hitside; + /*if (hitside > 0){ + hitside = -hitside; + }/* else{ + hitside = 0; + }*/ - if (alive){ - if (head->position[1] < 0){// && torso->momentum[1] < 0){ - fallOff(); - } + if (alive){ + if (head->position[1] < 0){// && torso->momentum[1] < 0){ + fallOff(); + } - headsensor->update(); - torsosensor->update(); + headsensor->update(); + torsosensor->update(); - balance(); - } + balance(); + } } void Legoman::updateLegs(void){ - float temp[3]; - float angle; + float temp[3]; + float angle; - walkphase = sfmod(walkphase, PI/LEGSPEED); + walkphase = sfmod(walkphase, PI/LEGSPEED); - //Left leg - angle = sfmod(walkphase*LEGSPEED, PI); - if (angle > PI/4) angle = PI/2 - angle; - if (angle < -PI/4) angle = -PI/2 - angle; - vectorSet(temp, 0, -cos(angle), -sin(angle)); - vectorAdd(temp, lll->point1); - vectorCopy(leftleglink->point1, temp); + //Left leg + angle = sfmod(walkphase*LEGSPEED, PI); + if (angle > PI/4) angle = PI/2 - angle; + if (angle < -PI/4) angle = -PI/2 - angle; + vectorSet(temp, 0, -cos(angle), -sin(angle)); + vectorAdd(temp, lll->point1); + vectorCopy(leftleglink->point1, temp); - //Right leg - angle = sfmod(walkphase*LEGSPEED + PI/2, PI); - if (angle > PI/4) angle = PI/2 - angle; - if (angle < -PI/4) angle = -PI/2 - angle; - vectorSet(temp, 0, -cos(angle), -sin(angle)); - vectorAdd(temp, rll->point1); - vectorCopy(rightleglink->point1, temp); + //Right leg + angle = sfmod(walkphase*LEGSPEED + PI/2, PI); + if (angle > PI/4) angle = PI/2 - angle; + if (angle < -PI/4) angle = -PI/2 - angle; + vectorSet(temp, 0, -cos(angle), -sin(angle)); + vectorAdd(temp, rll->point1); + vectorCopy(rightleglink->point1, temp); } void Legoman::walk(float amount){ - walkdelay = 20; + walkdelay = 20; - float sign; - if (amount > 0) sign = 1; - else sign = -1; + float sign; + if (amount > 0) sign = 1; + else sign = -1; - walkphase += sign; + walkphase += sign; - updateLegs(); + updateLegs(); - if (!isStanding()) return; + if (!isStanding()) return; - float movement[3]; - float xdir[3], ydir[3], zdir[3]; + float movement[3]; + float xdir[3], ydir[3], zdir[3]; - //vectorScale(ydir, &torso->rotation[3], 1); - vectorSet(ydir, 0, 1, 0); - vectorScale(zdir, &torso->rotation[6], -1); - vectorCross(xdir, ydir, zdir); - vectorNormalize(xdir); - //vectorScale(xdir, &torso->rotation[0], 1); + //vectorScale(ydir, &torso->rotation[3], 1); + vectorSet(ydir, 0, 1, 0); + vectorScale(zdir, &torso->rotation[6], -1); + vectorCross(xdir, ydir, zdir); + vectorNormalize(xdir); + //vectorScale(xdir, &torso->rotation[0], 1); - float oldmomentum[3]; - vectorCopy(oldmomentum, torso->momentum); + float oldmomentum[3]; + vectorCopy(oldmomentum, torso->momentum); - float xmove[3], ymove[3], zmove[3]; + float xmove[3], ymove[3], zmove[3]; - vectorProject(xmove, oldmomentum, xdir); - vectorProject(ymove, oldmomentum, ydir); - vectorProject(zmove, oldmomentum, zdir); + vectorProject(xmove, oldmomentum, xdir); + vectorProject(ymove, oldmomentum, ydir); + vectorProject(zmove, oldmomentum, zdir); - vectorScale(xmove, 0.5); - float wh = waist->position[1]; - if (wh < WAISTHEIGHT + 1.0){ - float hd = WAISTHEIGHT + 1.0 - wh; - vectorScale(ymove, ydir, hd*10); - } - float newz[3]; - vectorScale(newz, zdir, 6*sign); - float ztemp[3]; - vectorProject(ztemp, newz, ydir); - vectorSub(newz, ztemp); - vectorScale(newz, 0.8); - vectorScale(zmove, 0.2); - vectorAdd(zmove, newz); + vectorScale(xmove, 0.5); + float wh = waist->position[1]; + if (wh < WAISTHEIGHT + 1.0){ + float hd = WAISTHEIGHT + 1.0 - wh; + vectorScale(ymove, ydir, hd*10); + } + float newz[3]; + vectorScale(newz, zdir, 6*sign); + float ztemp[3]; + vectorProject(ztemp, newz, ydir); + vectorSub(newz, ztemp); + vectorScale(newz, 0.8); + vectorScale(zmove, 0.2); + vectorAdd(zmove, newz); - vectorCopy(movement, xmove); - vectorAdd(movement, ymove); - vectorAdd(movement, zmove); + vectorCopy(movement, xmove); + vectorAdd(movement, ymove); + vectorAdd(movement, zmove); - //if (isStanding() && isOnGround()) + //if (isStanding() && isOnGround()) - vectorCopy(torso->momentum, movement); - vectorScale(movement, torso->invmass*waist->getMass()); - vectorCopy(waist->momentum, movement); + vectorCopy(torso->momentum, movement); + vectorScale(movement, torso->invmass*waist->getMass()); + vectorCopy(waist->momentum, movement); - /*float speed = vectorDot(oldmomentum, movement); - float speedadd = 1; - float maxspeed = 5; - /*speed += speedadd; - if (speed > maxspeed) speed = maxspeed; - if (speed + speedadd > maxspeed){ - speedadd = maxspeed - speed; - } + /*float speed = vectorDot(oldmomentum, movement); + float speedadd = 1; + float maxspeed = 5; + /*speed += speedadd; + if (speed > maxspeed) speed = maxspeed; + if (speed + speedadd > maxspeed){ + speedadd = maxspeed - speed; + } - vectorScale(movement, speedadd); - if (waist->position[1] < WAISTHEIGHT + 1.0){ - movement[1] = 3; - } - vectorAdd(torso->momentum, movement);*/ + vectorScale(movement, speedadd); + if (waist->position[1] < WAISTHEIGHT + 1.0){ + movement[1] = 3; + } + vectorAdd(torso->momentum, movement);*/ - /*float proj[3]; - vectorProject(proj, oldmomentum, movement); - float len = vectorLength(proj); - vectorAdd(movement, proj); - vectorSaturate(movement, 0, - - movement[1] = 300; - //torso->addExternalForce(movement); - }*/ - - /*float linkpoint[3]; - vectorScale(linkpoint, &leftleg->rotation[3], -1); - vectorAdd(linkpoint, leftleg->position);*/ + /*float proj[3]; + vectorProject(proj, oldmomentum, movement); + float len = vectorLength(proj); + vectorAdd(movement, proj); + vectorSaturate(movement, 0, - /*float movement[3]; - float temp[3]; - vectorScale(temp, &torso->rotation[3], amount*0.1); - vectorScale(movement, &torso->rotation[6], amount); - vectorAdd(movement, temp); + movement[1] = 300; + //torso->addExternalForce(movement); + }*/ - if (walkphase == 0){ - walkphase = 40; - vectorAdd(leftleg->momentum, movement); - } - if (walkphase == 20){ - walkphase = 19; - vectorAdd(rightleg->momentum, movement); - }*/ + /*float linkpoint[3]; + vectorScale(linkpoint, &leftleg->rotation[3], -1); + vectorAdd(linkpoint, leftleg->position);*/ - /*float axis[3]; - vectorScale(axis, &leftleg->rotation[0], amount); + /*float movement[3]; + float temp[3]; + vectorScale(temp, &torso->rotation[3], amount*0.1); + vectorScale(movement, &torso->rotation[6], amount); + vectorAdd(movement, temp); - if (walkphase == 0){ - //walkphase = 40; - vectorAdd(leftleg->angularmomentum, axis); - vectorAdd(rightleg->angularmomentum, axis); - }*/ - /*if (walkphase == 0){ - walkphase = 1; - vectorAdd(rightleg->momentum, movement); - }*/ - /*float axis[3]; - float movement[3]; + if (walkphase == 0){ + walkphase = 40; + vectorAdd(leftleg->momentum, movement); + } + if (walkphase == 20){ + walkphase = 19; + vectorAdd(rightleg->momentum, movement); + }*/ - if (walkphase == 0){ - unlockPart(LEFTLEG); + /*float axis[3]; + vectorScale(axis, &leftleg->rotation[0], amount); - vectorScale(axis, &leftleg->rotation[0], 5); - vectorAdd(leftleg->angularmomentum, axis); - - float temp[3]; - vectorScale(temp, &torso->rotation[6], -10); - vectorScale(movement, &torso->rotation[3], 5); - vectorAdd(movement, temp); - vectorAdd(torso->momentum, movement); - vectorAdd(leftleg->momentum, movement); + if (walkphase == 0){ + //walkphase = 40; + vectorAdd(leftleg->angularmomentum, axis); + vectorAdd(rightleg->angularmomentum, axis); + }*/ + /*if (walkphase == 0){ + walkphase = 1; + vectorAdd(rightleg->momentum, movement); + }*/ + /*float axis[3]; + float movement[3]; - walkphase = 40; - }*/ + if (walkphase == 0){ + unlockPart(LEFTLEG); + + vectorScale(axis, &leftleg->rotation[0], 5); + vectorAdd(leftleg->angularmomentum, axis); + + float temp[3]; + vectorScale(temp, &torso->rotation[6], -10); + vectorScale(movement, &torso->rotation[3], 5); + vectorAdd(movement, temp); + vectorAdd(torso->momentum, movement); + vectorAdd(leftleg->momentum, movement); + + walkphase = 40; + }*/ } void Legoman::turn(float amount){ - float axis[3]; - if (isStanding()){ - vectorScale(axis, &torso->rotation[3], amount); - vectorCopy(torso->angularmomentum, axis); - } else{ - vectorScale(axis, &torso->rotation[3], amount*0.3); - vectorAdd(torso->angularmomentum, axis); - } + float axis[3]; + if (isStanding()){ + vectorScale(axis, &torso->rotation[3], amount); + vectorCopy(torso->angularmomentum, axis); + } else{ + vectorScale(axis, &torso->rotation[3], amount*0.3); + vectorAdd(torso->angularmomentum, axis); + } } void Legoman::hit(void){ - if (!lefthand->attached && !righthand->attached) return; - /*float leftdot = vectorDot(&lefthand->rotation[3], &torso->rotation[6]); - float rightdot = vectorDot(&righthand->rotation[3], &torso->rotation[6]); - if (leftdot < rightdot){ - hitside = LEFTHAND; - } else{ - hitside = RIGHTHAND; - }*/ + if (!lefthand->attached && !righthand->attached) return; + /*float leftdot = vectorDot(&lefthand->rotation[3], &torso->rotation[6]); + float rightdot = vectorDot(&righthand->rotation[3], &torso->rotation[6]); + if (leftdot < rightdot){ + hitside = LEFTHAND; + } else{ + hitside = RIGHTHAND; + }*/ - if (hitside >= 10) hitside -= 9; - else hitside -= 2; + if (hitside >= 10) hitside -= 9; + else hitside -= 2; - if ((hitside & 1) && !lefthand->attached) hitside++; - if (!(hitside & 1) && !righthand->attached) hitside++; + if ((hitside & 1) && !lefthand->attached) hitside++; + if (!(hitside & 1) && !righthand->attached) hitside++; - float axis[3]; - if (hitside & 1){ - vectorScale(axis, &lefthand->rotation[0], 20); - vectorCopy(lefthand->angularmomentum, axis); - } else{ - vectorScale(axis, &righthand->rotation[0], 20); - vectorCopy(righthand->angularmomentum, axis); - } + float axis[3]; + if (hitside & 1){ + vectorScale(axis, &lefthand->rotation[0], 20); + vectorCopy(lefthand->angularmomentum, axis); + } else{ + vectorScale(axis, &righthand->rotation[0], 20); + vectorCopy(righthand->angularmomentum, axis); + } } void Legoman::jump(void){ - if (!leftleg->attached && !rightleg->attached) return; - if (jumpenabled){// == 0 && isOnGround()){ - float r = BLOCKHEIGHT*HEADHEIGHT/2; - float strength = (2*LEGHEIGHT + 2*WAISTHEIGHT + 2*TORSOHEIGHT - + 2*HANDHEIGHT + 4.0*PI*r*r*r)/3.0*getInvMass(); - float jumpvector[3] = {0, 100.0/strength, 0}; + if (!leftleg->attached && !rightleg->attached) return; + if (jumpenabled){// == 0 && isOnGround()){ + float r = BLOCKHEIGHT*HEADHEIGHT/2; + float strength = (2*LEGHEIGHT + 2*WAISTHEIGHT + 2*TORSOHEIGHT + + 2*HANDHEIGHT + 4.0*PI*r*r*r)/3.0*getInvMass(); + float jumpvector[3] = {0, 100.0/strength, 0}; - //vectorCopy(torso->momentum, jumpvector); - torso->momentum[1] = jumpvector[1]; - head->momentum[1] = 0;// jumpvector[1]; - waist->momentum[1] = 0;// jumpvector[1]; - leftleg->momentum[1] = 0;// jumpvector[1]; - rightleg->momentum[1] = 0;// jumpvector[1]; - lefthand->momentum[1] = 0;// jumpvector[1]; - righthand->momentum[1] = 0;// jumpvector[1]; - //vectorSet(head->momentum, 0, 0, 0); - //jumpphase = 150; - jumpsound->play(); - jumpenabled = false; - } - jumpphase = 2; + //vectorCopy(torso->momentum, jumpvector); + torso->momentum[1] = jumpvector[1]; + head->momentum[1] = 0;// jumpvector[1]; + waist->momentum[1] = 0;// jumpvector[1]; + leftleg->momentum[1] = 0;// jumpvector[1]; + rightleg->momentum[1] = 0;// jumpvector[1]; + lefthand->momentum[1] = 0;// jumpvector[1]; + righthand->momentum[1] = 0;// jumpvector[1]; + //vectorSet(head->momentum, 0, 0, 0); + //jumpphase = 150; + jumpsound->play(); + jumpenabled = false; + } + jumpphase = 2; } bool Legoman::isOnGround(void){ - //if (!isStanding()) return false; - float wh = waist->position[1]; - if (wh > WAISTHEIGHT + 1.5) return false; - if (fabs(torso->momentum[1]) > 10) return false; - //if (fabs(head->momentum[1]) > 10) return false; - //if (fabs(waist->momentum[1]) > 3) return false; - return true; + //if (!isStanding()) return false; + float wh = waist->position[1]; + if (wh > WAISTHEIGHT + 1.5) return false; + if (fabs(torso->momentum[1]) > 10) return false; + //if (fabs(head->momentum[1]) > 10) return false; + //if (fabs(waist->momentum[1]) > 3) return false; + return true; } bool Legoman::isStanding(void){ - if (!leftleg->attached && !rightleg->attached) return false; - float headpos[3], torsopos[3]; - headsensor->getPosition(headpos); - torsosensor->getPosition(torsopos); - float posdiff[3]; - vectorSub(posdiff, headpos, torsopos); - float posdifflen = vectorLength(posdiff); - float angle = acos(posdiff[1]/posdifflen); + if (!leftleg->attached && !rightleg->attached) return false; + float headpos[3], torsopos[3]; + headsensor->getPosition(headpos); + torsosensor->getPosition(torsopos); + float posdiff[3]; + vectorSub(posdiff, headpos, torsopos); + float posdifflen = vectorLength(posdiff); + float angle = acos(posdiff[1]/posdifflen); - if (angle < BALANCEANGLE) return true; - else return false; + if (angle < BALANCEANGLE) return true; + else return false; } void Legoman::fallOff(void){ - if (dead) return; - if (rand()&1) fallsound1->play(); - else fallsound2->play(); - die(); - head->energy = 0; - torso->energy = 0; - lefthand->energy = 0; - righthand->energy = 0; - waist->energy = 0; - leftleg->energy = 0; - rightleg->energy = 0; + if (dead) return; + if (rand()&1) fallsound1->play(); + else fallsound2->play(); + die(); + head->energy = 0; + torso->energy = 0; + lefthand->energy = 0; + righthand->energy = 0; + waist->energy = 0; + leftleg->energy = 0; + rightleg->energy = 0; } void Legoman::releasePart(BodyPart *part){ - if (dead) return; - if (part == head){ - headlinks[0]->enabled = false; - headlinks[1]->enabled = false; - headlinks[2]->enabled = false; - head->attached = false; - //float move[3]; - //vectorScale(move, &head->rotation[3], 1); - //vectorAdd(head->position, move); - die(); - } else if (part == lefthand){ - lefthandlinks[0]->enabled = false; - lefthandlinks[1]->enabled = false; - lefthandlinks[2]->enabled = false; - lefthand->attached = false; - } else if (part == righthand){ - righthandlinks[0]->enabled = false; - righthandlinks[1]->enabled = false; - righthandlinks[2]->enabled = false; - righthand->attached = false; - } else if (part == leftleg){ - leftleglinks[0]->enabled = false; - leftleglinks[1]->enabled = false; - leftleglinks[2]->enabled = false; - leftleg->attached = false; - } else if (part == rightleg){ - rightleglinks[0]->enabled = false; - rightleglinks[1]->enabled = false; - rightleglinks[2]->enabled = false; - rightleg->attached = false; - } else if (part == torso){ - die(); - } - if (!lefthand->attached && !righthand->attached && - !leftleg->attached && !rightleg->attached) die(); + if (dead) return; + if (part == head){ + headlinks[0]->enabled = false; + headlinks[1]->enabled = false; + headlinks[2]->enabled = false; + head->attached = false; + //float move[3]; + //vectorScale(move, &head->rotation[3], 1); + //vectorAdd(head->position, move); + die(); + } else if (part == lefthand){ + lefthandlinks[0]->enabled = false; + lefthandlinks[1]->enabled = false; + lefthandlinks[2]->enabled = false; + lefthand->attached = false; + } else if (part == righthand){ + righthandlinks[0]->enabled = false; + righthandlinks[1]->enabled = false; + righthandlinks[2]->enabled = false; + righthand->attached = false; + } else if (part == leftleg){ + leftleglinks[0]->enabled = false; + leftleglinks[1]->enabled = false; + leftleglinks[2]->enabled = false; + leftleg->attached = false; + } else if (part == rightleg){ + rightleglinks[0]->enabled = false; + rightleglinks[1]->enabled = false; + rightleglinks[2]->enabled = false; + rightleg->attached = false; + } else if (part == torso){ + die(); + } + if (!lefthand->attached && !righthand->attached && + !leftleg->attached && !rightleg->attached) die(); } void Legoman::die(void){ - if (dead) return; - alive = false; - lll->enabled = false; - rll->enabled = false; - gameOver(this); + if (dead) return; + alive = false; + lll->enabled = false; + rll->enabled = false; + gameOver(this); } bool Legoman::isAlive(void){ - return alive; + return alive; } Legoman *Legoman::getOpponent(void){ - return opponent; + return opponent; } void Legoman::drawVisuals(void){ - headvisual->draw(); - torsovisual->draw(); - lefthandvisual->draw(); - righthandvisual->draw(); - leftlegvisual->draw(); - rightlegvisual->draw(); + headvisual->draw(); + torsovisual->draw(); + lefthandvisual->draw(); + righthandvisual->draw(); + leftlegvisual->draw(); + rightlegvisual->draw(); } DamageVisual::DamageVisual(BodyPart *object, Texture *texture, bool mirror, - float x1, float y1, float x2, float y2){ - this->object = object; - this->texture = texture; + float x1, float y1, float x2, float y2){ + this->object = object; + this->texture = texture; - this->x1 = x1; - this->y1 = y1; - this->x2 = x2; - this->y2 = y2; + this->x1 = x1; + this->y1 = y1; + this->x2 = x2; + this->y2 = y2; - float d = 3.0/512; + float d = 3.0/512; - if (mirror){ - this->tx1 = 1-d; - this->tx2 = 0+d+0.01; - } else{ - this->tx1 = 0+d+0.01; - this->tx2 = 1-d; - } - this->ty1 = 0+d; - this->ty2 = 1-d; + if (mirror){ + this->tx1 = 1-d; + this->tx2 = 0+d+0.01; + } else{ + this->tx1 = 0+d+0.01; + this->tx2 = 1-d; + } + this->ty1 = 0+d; + this->ty2 = 1-d; } void DamageVisual::draw(void){ - float energy = object->energy; - texture->enable(); + float energy = object->energy; + texture->enable(); - glBegin(GL_QUADS); - if (energy > 0) glColor3f(1-energy, energy, 0); - else glColor3f(0.3, 0.3, 0.3); + glBegin(GL_QUADS); + if (energy > 0) glColor3f(1-energy, energy, 0); + else glColor3f(0.3, 0.3, 0.3); - glTexCoord2f(tx1, ty1); - glVertex2f(x1, y1); - - glTexCoord2f(tx1, ty2); - glVertex2f(x1, y2); - - glTexCoord2f(tx2, ty2); - glVertex2f(x2, y2); - - glTexCoord2f(tx2, ty1); - glVertex2f(x2, y1); - glEnd(); + glTexCoord2f(tx1, ty1); + glVertex2f(x1, y1); + + glTexCoord2f(tx1, ty2); + glVertex2f(x1, y2); + + glTexCoord2f(tx2, ty2); + glVertex2f(x2, y2); + + glTexCoord2f(tx2, ty1); + glVertex2f(x2, y1); + glEnd(); } diff --git a/src/legoman.h b/src/legoman.h index 2387df1..61ae7a4 100644 --- a/src/legoman.h +++ b/src/legoman.h @@ -1,77 +1,3 @@ -/* - * $Id: legoman.h,v 1.21 2002/07/22 12:07:36 msell Exp $ - * - * - * $Log: legoman.h,v $ - * Revision 1.21 2002/07/22 12:07:36 msell - * Pää kiinni - * - * Revision 1.20 2002/07/22 06:08:18 msell - * Filenimet pienellä - * - * Revision 1.19 2002/07/22 01:14:14 msell - * Lopetussysteemi - * - * Revision 1.18 2002/07/21 22:50:39 msell - * no message - * - * Revision 1.17 2002/07/21 20:14:28 msell - * no message - * - * Revision 1.16 2002/07/21 15:16:41 msell - * no message - * - * Revision 1.15 2002/07/21 15:03:12 msell - * Äänet disabloitu - * - * Revision 1.14 2002/07/19 20:33:28 msell - * #pragma once -> #ifndef - * - * Revision 1.13 2002/07/19 18:59:46 msell - * Alkuhommaa ja säätöä - * - * Revision 1.12 2002/07/18 23:05:31 msell - * Partikkelit ja kakkospelaajan liike - * - * Revision 1.11 2002/07/17 22:45:54 msell - * Ääniä vähän - * - * Revision 1.10 2002/07/17 16:40:33 msell - * Resoluution vaihto - * - * Revision 1.9 2002/07/16 07:27:32 jkaarlas - * nyt latautuu kämmen. paikka ja väri pitää vielä säätää - * - * Revision 1.8 2002/07/14 21:40:43 msell - * Conflictit pois, liikkumiset (hyppy, kävely, lyönti), uusi areena - * - * Revision 1.7 2002/07/14 21:22:39 jkaarlas - * skybox ja ukkojen säätö - * - * Revision 1.6 2002/07/11 18:33:58 jkaarlas - * mallit paikoillaan, vaatii säätöä - * - * Revision 1.5 2002/07/10 17:13:44 msell - * Törmäystarkastelun parantelua - * - * Revision 1.4 2002/07/08 22:53:38 msell - * Säätöä - * - * Revision 1.3 2002/07/08 18:28:47 msell - * Törmäystä ja ukkoja - * - * Revision 1.2 2002/07/07 23:05:22 msell - * Osien liimaaminen toisiinsa (kesken) - * - * Revision 1.1 2002/07/07 17:53:21 msell - * Legoukon alku - * - * - * - * $Date: 2002/07/22 12:07:36 $ - * - */ - #ifndef __LEGOMAN_H_INCLUDED__ #define __LEGOMAN_H_INCLUDED__ @@ -114,135 +40,135 @@ const char RIGHTPALMASC[] = DATAPATH"rightpalm.asc"; class BodyPart : public Object{ private: - float energy; - float strength; - Legoman *parent; + float energy; + float strength; + Legoman *parent; - bool attached; + bool attached; - int immortal; + int immortal; public: - BodyPart(Legoman *parent, float strength); + BodyPart(Legoman *parent, float strength); - void move(void); + void move(void); - void hitForce(float speed, float *speed2, Object *source); + void hitForce(float speed, float *speed2, Object *source); - void makeDamage(float amount); + void makeDamage(float amount); - void reset(void); + void reset(void); - friend class DamageVisual; - friend class Legoman; + friend class DamageVisual; + friend class Legoman; }; class Sensor{ private: - float relativeposition[3]; - Object *object; + float relativeposition[3]; + Object *object; - float position[3], oldposition[3]; - float velocity[3], oldvelocity[3]; - float acceleration[3]; + float position[3], oldposition[3]; + float velocity[3], oldvelocity[3]; + float acceleration[3]; public: - Sensor(); + Sensor(); - void attach(Object *object, float *relativeposition); - void attach(Object *object); - void update(void); + void attach(Object *object, float *relativeposition); + void attach(Object *object); + void update(void); - void getPosition(float *target); - void getVelocity(float *target); - void getAcceleration(float *target); + void getPosition(float *target); + void getVelocity(float *target); + void getAcceleration(float *target); }; class Legoman{ private: - int side; + int side; - bool alive; + bool alive; - BodyPart *head; - BodyPart *torso; - BodyPart *waist; - BodyPart *lefthand, *righthand; - BodyPart *leftleg, *rightleg; + BodyPart *head; + BodyPart *torso; + BodyPart *waist; + BodyPart *lefthand, *righthand; + BodyPart *leftleg, *rightleg; - DamageVisual *headvisual; - DamageVisual *torsovisual; - DamageVisual *lefthandvisual, *righthandvisual; - DamageVisual *leftlegvisual, *rightlegvisual; + DamageVisual *headvisual; + DamageVisual *torsovisual; + DamageVisual *lefthandvisual, *righthandvisual; + DamageVisual *leftlegvisual, *rightlegvisual; - ObjectLink *leftleglink, *rightleglink; - ObjectLink *lefthandlink, *righthandlink; - ObjectLink *lll, *rll; + ObjectLink *leftleglink, *rightleglink; + ObjectLink *lefthandlink, *righthandlink; + ObjectLink *lll, *rll; - ObjectLink *leftleglinks[3], *rightleglinks[3]; - ObjectLink *lefthandlinks[3], *righthandlinks[3]; - ObjectLink *headlinks[3]; + ObjectLink *leftleglinks[3], *rightleglinks[3]; + ObjectLink *lefthandlinks[3], *righthandlinks[3]; + ObjectLink *headlinks[3]; - objectlist *harmfulobjects; + objectlist *harmfulobjects; - Legoman *opponent; + Legoman *opponent; - Sensor *headsensor, *torsosensor; + Sensor *headsensor, *torsosensor; - int walkphase, walkdelay; - int jumpphase; - int hitside; + int walkphase, walkdelay; + int jumpphase; + int hitside; - bool jumpenabled; - int hitcounter; + bool jumpenabled; + int hitcounter; - World *world; + World *world; - void balance(void); - void updateLegs(void); - bool isStanding(void); - bool isOnGround(void); - float getInvMass(void); + void balance(void); + void updateLegs(void); + bool isStanding(void); + bool isOnGround(void); + float getInvMass(void); - void fallOff(void); - void releasePart(BodyPart *part); - void die(void); + void fallOff(void); + void releasePart(BodyPart *part); + void die(void); public: - Legoman(int side); + Legoman(int side); - void insertToWorld(World *world); - void heal(void); + void insertToWorld(World *world); + void heal(void); - void addHarmfulObject(Object *object); - bool isHarmfulObject(Object *object); + void addHarmfulObject(Object *object); + bool isHarmfulObject(Object *object); - void addOpponent(Legoman *opponent); + void addOpponent(Legoman *opponent); - //Call once per frame - void update(void); + //Call once per frame + void update(void); - //Lock both legs at the same time by calling - //lockLeg(LEFTLEG | RIGHTLEG); - void lockPart(int part); - void unlockPart(int part); + //Lock both legs at the same time by calling + //lockLeg(LEFTLEG | RIGHTLEG); + void lockPart(int part); + void unlockPart(int part); - //Relative movement - void move(float *movement); + //Relative movement + void move(float *movement); - void turn(float amount); - void walk(float amount); + void turn(float amount); + void walk(float amount); - void jump(void); - void hit(void); + void jump(void); + void hit(void); - bool isAlive(void); - Legoman *getOpponent(void); + bool isAlive(void); + Legoman *getOpponent(void); - void drawVisuals(); + void drawVisuals(); - friend class BodyPart; - friend void drawEnd(int framecount); + friend class BodyPart; + friend void drawEnd(int framecount); }; @@ -255,16 +181,16 @@ extern Texture *damageLeg; class DamageVisual{ private: - BodyPart *object; - float x1, y1, x2, y2; - float tx1, ty1, tx2, ty2; - Texture *texture; + BodyPart *object; + float x1, y1, x2, y2; + float tx1, ty1, tx2, ty2; + Texture *texture; public: - DamageVisual(BodyPart *object, Texture *texture, bool mirror, - float x1, float y1, float x2, float y2); + DamageVisual(BodyPart *object, Texture *texture, bool mirror, + float x1, float y1, float x2, float y2); - void draw(void); + void draw(void); }; #endif diff --git a/src/light.cpp b/src/light.cpp index 420b7a9..b00c2c3 100644 --- a/src/light.cpp +++ b/src/light.cpp @@ -1,29 +1,3 @@ -/* - * $Id: light.cpp,v 1.5 2002/07/15 20:32:35 msell Exp $ - * - * - * $Log: light.cpp,v $ - * Revision 1.5 2002/07/15 20:32:35 msell - * Uudet valot ja ulkoasun parantelua - * - * Revision 1.4 2002/06/17 20:49:05 msell - * free -> SDL_FreeSurface - * - * Revision 1.3 2002/06/16 01:04:58 jkaarlas - * tulipa säädettyä includejen kanssa. oon tod.näk. eri mieltä aamulla - * - * Revision 1.2 2002/06/03 23:20:43 msell - * no message - * - * Revision 1.1 2002/05/18 12:29:35 msell - * Valot ja äänijärjestelmän parantelua - * - * - * - * $Date: 2002/07/15 20:32:35 $ - * - */ - #include "main.h" #include "light.h" @@ -36,183 +10,183 @@ static int glnextlightnum = 0; static Light *lights[GL_MAX_LIGHTS]; Light::Light(void){ - setPosition(0, 0, 0); - setColor(1, 1, 1); - setSpecular(0, 0, 0); - setAttenuation(1, 0, 0); - setEnabled(false); - glnum = GL_LIGHT0 + glnextlightnum; - lights[glnextlightnum] = this; - glnextlightnum++; + setPosition(0, 0, 0); + setColor(1, 1, 1); + setSpecular(0, 0, 0); + setAttenuation(1, 0, 0); + setEnabled(false); + glnum = GL_LIGHT0 + glnextlightnum; + lights[glnextlightnum] = this; + glnextlightnum++; } void Light::setPosition(float x, float y, float z){ - position[0] = x; - position[1] = y; - position[2] = z; - position[3] = 1; + position[0] = x; + position[1] = y; + position[2] = z; + position[3] = 1; } void Light::setDirection(float x, float y, float z){ - position[0] = -x; - position[1] = -y; - position[2] = -z; - position[3] = 0; + position[0] = -x; + position[1] = -y; + position[2] = -z; + position[3] = 0; } void Light::setColor(float red, float green, float blue){ - diffuse[0] = red; - diffuse[1] = green; - diffuse[2] = blue; - diffuse[3] = 1; - glLightfv(glnum, GL_DIFFUSE, diffuse); + diffuse[0] = red; + diffuse[1] = green; + diffuse[2] = blue; + diffuse[3] = 1; + glLightfv(glnum, GL_DIFFUSE, diffuse); } void Light::setSpecular(float red, float green, float blue){ - specular[0] = red; - specular[1] = green; - specular[2] = blue; - specular[3] = 1; - glLightfv(glnum, GL_SPECULAR, specular); + specular[0] = red; + specular[1] = green; + specular[2] = blue; + specular[3] = 1; + glLightfv(glnum, GL_SPECULAR, specular); } void Light::setAttenuation(float constant, float linear, float quadratic){ - attenuation[0] = constant; - attenuation[1] = linear; - attenuation[2] = quadratic; - glLightf(glnum, GL_CONSTANT_ATTENUATION, attenuation[0]); - glLightf(glnum, GL_LINEAR_ATTENUATION, attenuation[1]); - glLightf(glnum, GL_QUADRATIC_ATTENUATION, attenuation[2]); + attenuation[0] = constant; + attenuation[1] = linear; + attenuation[2] = quadratic; + glLightf(glnum, GL_CONSTANT_ATTENUATION, attenuation[0]); + glLightf(glnum, GL_LINEAR_ATTENUATION, attenuation[1]); + glLightf(glnum, GL_QUADRATIC_ATTENUATION, attenuation[2]); } void Light::setEnabled(bool enabled){ - this->enabled = enabled; - if (enabled) glEnable(glnum); - else glDisable(glnum); + this->enabled = enabled; + if (enabled) glEnable(glnum); + else glDisable(glnum); } void Light::glUpdate(void){ - glLightfv(glnum, GL_POSITION, position); + glLightfv(glnum, GL_POSITION, position); } extern Camera camera; void Light::createFlare(void){ - glPushMatrix(); + glPushMatrix(); - GLint viewport[4]; - glGetIntegerv(GL_VIEWPORT, viewport); + GLint viewport[4]; + glGetIntegerv(GL_VIEWPORT, viewport); - int width = viewport[2]; - int height = viewport[3]; - - glTranslatef(position[0], position[1], position[2]); + int width = viewport[2]; + int height = viewport[3]; - GLboolean lightingenabled = glIsEnabled(GL_LIGHTING); + glTranslatef(position[0], position[1], position[2]); + + GLboolean lightingenabled = glIsEnabled(GL_LIGHTING); glDisable(GL_LIGHTING); - /*float cx=cameratarget.x-cameraposition.x; - float cy=cameratarget.y-cameraposition.y; - float cz=cameratarget.z-cameraposition.z; - float len=sqrt(cx*cx+cy*cy+cz*cz); - cx/=len; - cy/=len; - cz/=len;*/ - float dir[3]; - float cameratarget[3], cameraposition[3]; - camera.getTarget(cameratarget); - camera.getPosition(cameraposition); - vectorSub(dir, cameratarget, cameraposition); - vectorNormalize(dir); + /*float cx=cameratarget.x-cameraposition.x; + float cy=cameratarget.y-cameraposition.y; + float cz=cameratarget.z-cameraposition.z; + float len=sqrt(cx*cx+cy*cy+cz*cz); + cx/=len; + cy/=len; + cz/=len;*/ + float dir[3]; + float cameratarget[3], cameraposition[3]; + camera.getTarget(cameratarget); + camera.getPosition(cameraposition); + vectorSub(dir, cameratarget, cameraposition); + vectorNormalize(dir); - float dir2[3]; - vectorSub(dir2, position, cameraposition); - float distance = vectorDot(dir2, dir); + float dir2[3]; + vectorSub(dir2, position, cameraposition); + float distance = vectorDot(dir2, dir); - /*float xd=(staticlightpositions[lightnumber].x-cameraposition.x)*cx; - float yd=(staticlightpositions[lightnumber].y-cameraposition.y)*cy; - float zd=(staticlightpositions[lightnumber].z-cameraposition.z)*cz; - float distance=xd+yd+zd;*/ + /*float xd=(staticlightpositions[lightnumber].x-cameraposition.x)*cx; + float yd=(staticlightpositions[lightnumber].y-cameraposition.y)*cy; + float zd=(staticlightpositions[lightnumber].z-cameraposition.z)*cz; + float distance=xd+yd+zd;*/ - float screencoords[3]; - /*GLint viewport[4]; - glGetIntegerv(GL_VIEWPORT, viewport); + float screencoords[3]; + /*GLint viewport[4]; + glGetIntegerv(GL_VIEWPORT, viewport); int width=viewport[2]; - int height=viewport[3];*/ + int height=viewport[3];*/ - GLdouble modelviewm[16], projectionm[16]; - glGetDoublev(GL_MODELVIEW_MATRIX, modelviewm); - glGetDoublev(GL_PROJECTION_MATRIX, projectionm); + GLdouble modelviewm[16], projectionm[16]; + glGetDoublev(GL_MODELVIEW_MATRIX, modelviewm); + glGetDoublev(GL_PROJECTION_MATRIX, projectionm); - GLdouble wx,wy,wz; - if (gluProject(0, 0, 0, modelviewm, projectionm, viewport, &wx, &wy, &wz) == GL_FALSE){ - printf("Failure\n"); - } + GLdouble wx,wy,wz; + if (gluProject(0, 0, 0, modelviewm, projectionm, viewport, &wx, &wy, &wz) == GL_FALSE){ + printf("Failure\n"); + } - screencoords[0] = (float)(2*wx-width)/width; - screencoords[1] = (float)(2*wy-height)/height; - screencoords[2] = wz; + screencoords[0] = (float)(2*wx-width)/width; + screencoords[1] = (float)(2*wy-height)/height; + screencoords[2] = wz; - //getPointCoordinates(screencoords); - //point3d screencoords = getPointCoordinates(0, 0, 0); - - glLoadIdentity(); - glTranslatef(screencoords[0], screencoords[1], 0); - glDisable(GL_DEPTH_TEST); - glEnable(GL_CULL_FACE); - glEnable(GL_BLEND); + //getPointCoordinates(screencoords); + //point3d screencoords = getPointCoordinates(0, 0, 0); - glBlendFunc(GL_ONE,GL_ONE); - //glEnable(GL_TEXTURE_2D); - //glBindTexture(GL_TEXTURE_2D, flaretexture->getId()); + glLoadIdentity(); + glTranslatef(screencoords[0], screencoords[1], 0); + glDisable(GL_DEPTH_TEST); + glEnable(GL_CULL_FACE); + glEnable(GL_BLEND); - glMatrixMode(GL_PROJECTION); - glPushMatrix(); - glLoadIdentity(); - float sizey = 6.0/distance * 1.0;//staticlightflarebrightnesses[lightnumber]; - float sizex = sizey * height/width; + glBlendFunc(GL_ONE,GL_ONE); + //glEnable(GL_TEXTURE_2D); + //glBindTexture(GL_TEXTURE_2D, flaretexture->getId()); - if (distance>0.5){ - glBegin(GL_QUADS); - //glColor3f(staticlightflarebrightnesses[lightnumber],staticlightflarebrightnesses[lightnumber],staticlightflarebrightnesses[lightnumber]); - glColor3fv(diffuse); - - glTexCoord2f(0.0, 0.0); - glVertex2f(-sizex,sizey); + glMatrixMode(GL_PROJECTION); + glPushMatrix(); + glLoadIdentity(); + float sizey = 6.0/distance * 1.0;//staticlightflarebrightnesses[lightnumber]; + float sizex = sizey * height/width; - glTexCoord2f(0.0, 1.0); - glVertex2f(-sizex,-sizey); - - glTexCoord2f(1.0, 1.0); - glVertex2f( sizex,-sizey); - - glTexCoord2f(1.0, 0.0); - glVertex2f( sizex,sizey); - glEnd(); - } + if (distance>0.5){ + glBegin(GL_QUADS); + //glColor3f(staticlightflarebrightnesses[lightnumber],staticlightflarebrightnesses[lightnumber],staticlightflarebrightnesses[lightnumber]); + glColor3fv(diffuse); - //glDisable(GL_TEXTURE_2D); + glTexCoord2f(0.0, 0.0); + glVertex2f(-sizex,sizey); - glDisable(GL_BLEND); + glTexCoord2f(0.0, 1.0); + glVertex2f(-sizex,-sizey); - glPopMatrix(); - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); + glTexCoord2f(1.0, 1.0); + glVertex2f( sizex,-sizey); - if (lightingenabled) glEnable(GL_LIGHTING); - glEnable(GL_DEPTH_TEST); + glTexCoord2f(1.0, 0.0); + glVertex2f( sizex,sizey); + glEnd(); + } - glPopMatrix(); + //glDisable(GL_TEXTURE_2D); + + glDisable(GL_BLEND); + + glPopMatrix(); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + + if (lightingenabled) glEnable(GL_LIGHTING); + glEnable(GL_DEPTH_TEST); + + glPopMatrix(); } void updateLights(void){ - int i; - for (i = 0; i < glnextlightnum; i++){ - Light *light = lights[i]; - light->glUpdate(); - } -} \ No newline at end of file + int i; + for (i = 0; i < glnextlightnum; i++){ + Light *light = lights[i]; + light->glUpdate(); + } +} diff --git a/src/light.h b/src/light.h index 2d85b94..56715cc 100644 --- a/src/light.h +++ b/src/light.h @@ -1,53 +1,27 @@ -/* - * $Id: light.h,v 1.5 2002/07/19 20:33:28 msell Exp $ - * - * - * $Log: light.h,v $ - * Revision 1.5 2002/07/19 20:33:28 msell - * #pragma once -> #ifndef - * - * Revision 1.4 2002/07/15 20:32:35 msell - * Uudet valot ja ulkoasun parantelua - * - * Revision 1.3 2002/06/04 16:28:32 msell - * #pragma once - * - * Revision 1.2 2002/06/03 23:20:43 msell - * no message - * - * Revision 1.1 2002/05/18 12:29:35 msell - * Valot ja äänijärjestelmän parantelua - * - * - * - * $Date: 2002/07/19 20:33:28 $ - * - */ - #ifndef __LIGHT_H_INCLUDED__ #define __LIGHT_H_INCLUDED__ class Light{ private: - float position[4]; - float diffuse[4]; - float specular[4]; - float attenuation[3]; - bool enabled; - int glnum; + float position[4]; + float diffuse[4]; + float specular[4]; + float attenuation[3]; + bool enabled; + int glnum; public: - //Creates DISABLED light - Light(void); + //Creates DISABLED light + Light(void); - void setPosition(float x, float y, float z); - void setDirection(float x, float y, float z); - void setColor(float red, float green, float blue); - void setSpecular(float red, float green, float blue); - void setAttenuation(float constant, float linear, float quadratic); - void setEnabled(bool enabled); - void glUpdate(void); - void createFlare(void); + void setPosition(float x, float y, float z); + void setDirection(float x, float y, float z); + void setColor(float red, float green, float blue); + void setSpecular(float red, float green, float blue); + void setAttenuation(float constant, float linear, float quadratic); + void setEnabled(bool enabled); + void glUpdate(void); + void createFlare(void); }; void updateLights(void); diff --git a/src/main.cpp b/src/main.cpp index 1f29630..e86217a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,106 +1,3 @@ -/* - * $Id: main.cpp,v 1.30 2002/07/21 15:03:12 msell Exp $ - * - * - * $Log: main.cpp,v $ - * Revision 1.30 2002/07/21 15:03:12 msell - * Äänet disabloitu - * - * Revision 1.29 2002/07/19 20:39:31 msell - * Linux-porttausta - * - * Revision 1.28 2002/07/19 20:33:28 msell - * #pragma once -> #ifndef - * - * Revision 1.27 2002/07/19 20:06:32 msell - * Linux-porttausta - * - * Revision 1.26 2002/07/19 18:59:46 msell - * Alkuhommaa ja säätöä - * - * Revision 1.25 2002/07/19 12:42:44 msell - * Loading... - * - * Revision 1.24 2002/07/19 12:28:29 msell - * 2D-mode - * - * Revision 1.23 2002/07/18 23:05:31 msell - * Partikkelit ja kakkospelaajan liike - * - * Revision 1.22 2002/07/17 16:40:33 msell - * Resoluution vaihto - * - * Revision 1.21 2002/07/16 17:16:34 msell - * Fontit ja valikot - * - * Revision 1.20 2002/07/14 21:40:43 msell - * Conflictit pois, liikkumiset (hyppy, kävely, lyönti), uusi areena - * - * Revision 1.19 2002/07/14 21:22:39 jkaarlas - * skybox ja ukkojen säätö - * - * Revision 1.18 2002/07/11 18:33:30 jkaarlas - * turhat äänet pois - * - * Revision 1.17 2002/07/08 22:53:38 msell - * Säätöä - * - * Revision 1.16 2002/07/04 21:05:41 msell - * Se toimii!! =) - * Törmäystarkistukset siis - * - * Revision 1.15 2002/06/20 22:50:12 msell - * Meshit - * - * Revision 1.14 2002/06/17 20:49:05 msell - * free -> SDL_FreeSurface - * - * Revision 1.13 2002/06/17 19:58:08 msell - * #includeiden parantelua - * - * Revision 1.12 2002/06/16 01:04:58 jkaarlas - * tulipa säädettyä includejen kanssa. oon tod.näk. eri mieltä aamulla - * - * Revision 1.11 2002/06/15 22:56:37 msell - * Säätöä - * - * Revision 1.10 2002/06/11 23:11:45 msell - * Törmäystarkistusta - * - * Revision 1.9 2002/06/07 21:16:51 msell - * Fysiikkaenginen alkua - * - * Revision 1.8 2002/06/02 16:57:37 msell - * Objektirakenteen pohja - * - * Revision 1.7 2002/05/19 13:40:19 msell - * Säätöä - * - * Revision 1.6 2002/05/18 12:29:35 msell - * Valot ja äänijärjestelmän parantelua - * - * Revision 1.5 2002/05/17 23:13:30 msell - * Valot - * - * Revision 1.4 2002/05/16 18:41:16 msell - * Vektorifunctioita ja kamera - * - * Revision 1.3 2002/05/15 21:07:23 msell - * Äänisäätöä - * - * Revision 1.2 2002/05/15 15:21:00 msell - * Äänisäätöä - * - * Revision 1.1 2002/05/15 14:36:39 msell - * Yksinkertainen SDL-runko (Kääntyy toistaiseksi vain windowsissa). - * Mukana myös musiikinsoitto fmodilla. - * - * - * - * $Date: 2002/07/21 15:03:12 $ - * - */ - #include "main.h" #include @@ -124,125 +21,125 @@ int screenheight=768; int screenbpp; void exitProgram(int code){ - SDL_Quit(); - //uninitAudio(); - exit(code); + SDL_Quit(); + //uninitAudio(); + exit(code); } void changeResolution(int width, int height, bool fullscreen){ - int mode = SDL_OPENGL; - if (fullscreen) mode |= SDL_FULLSCREEN; - if (!SDL_SetVideoMode(width, height, screenbpp, mode)){ - fprintf(stderr,"Couldn't set %i*%i*%i opengl video mode: %s\n",screenwidth,screenheight,screenbpp,SDL_GetError()); - exitProgram(-1); - } + int mode = SDL_OPENGL; + if (fullscreen) mode |= SDL_FULLSCREEN; + if (!SDL_SetVideoMode(width, height, screenbpp, mode)){ + fprintf(stderr,"Couldn't set %i*%i*%i opengl video mode: %s\n",screenwidth,screenheight,screenbpp,SDL_GetError()); + exitProgram(-1); + } - setupOpengl(width, height); + setupOpengl(width, height); - screenwidth = width; - screenheight = height; + screenwidth = width; + screenheight = height; - if (fullscreen) SDL_ShowCursor(SDL_DISABLE); - else SDL_ShowCursor(SDL_ENABLE); - - initScenes(); + if (fullscreen) SDL_ShowCursor(SDL_DISABLE); + else SDL_ShowCursor(SDL_ENABLE); + + initScenes(); } bool keys[SDLK_LAST] = {false}; void handleKeydown(SDL_keysym *keysym){ - keys[keysym->sym] = true; + keys[keysym->sym] = true; } void handleKeyup(SDL_keysym *keysym){ - keys[keysym->sym] = false; + keys[keysym->sym] = false; } void processEvents(void){ - SDL_Event event; - while (SDL_PollEvent(&event)){ - switch (event.type){ - case SDL_KEYDOWN: - handleKeydown(&event.key.keysym); - break; - case SDL_KEYUP: - handleKeyup(&event.key.keysym); - break; - case SDL_VIDEORESIZE: - screenwidth=event.resize.w; - screenheight=event.resize.h; - setupOpengl(screenwidth,screenheight); - break; - case SDL_QUIT: - exitProgram(0); - break; - } - } + SDL_Event event; + while (SDL_PollEvent(&event)){ + switch (event.type){ + case SDL_KEYDOWN: + handleKeydown(&event.key.keysym); + break; + case SDL_KEYUP: + handleKeyup(&event.key.keysym); + break; + case SDL_VIDEORESIZE: + screenwidth=event.resize.w; + screenheight=event.resize.h; + setupOpengl(screenwidth,screenheight); + break; + case SDL_QUIT: + exitProgram(0); + break; + } + } } int getTime(void){ #ifdef WIN32 - return timeGetTime(); + return timeGetTime(); #else - return SDL_GetTicks(); + return SDL_GetTicks(); #endif } int main(int argc, char *argv[]){ - //printf("Initializing SDL.\n"); + //printf("Initializing SDL.\n"); - if ((SDL_Init(SDL_INIT_VIDEO)==-1)){ - printf("Could not initialize SDL: %s.\n",SDL_GetError()); - exitProgram(-1); - } + if ((SDL_Init(SDL_INIT_VIDEO)==-1)){ + printf("Could not initialize SDL: %s.\n",SDL_GetError()); + exitProgram(-1); + } - const SDL_VideoInfo *info=SDL_GetVideoInfo(); - if (!info){ - printf("Could not get video info with SDL: %s.\n",SDL_GetError()); - exitProgram(-1); - } - screenbpp=info->vfmt->BitsPerPixel; - SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5); - SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5); - SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5); - SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); - SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); + const SDL_VideoInfo *info=SDL_GetVideoInfo(); + if (!info){ + printf("Could not get video info with SDL: %s.\n",SDL_GetError()); + exitProgram(-1); + } + screenbpp=info->vfmt->BitsPerPixel; + SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5); + SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5); + SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5); + SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); + SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); - atexit(SDL_Quit); + atexit(SDL_Quit); - SDL_WM_SetCaption("BlockoFighter 2",NULL); + SDL_WM_SetCaption("BlockoFighter 2",NULL); - initAudio(); + initAudio(); - changeResolution(screenwidth, screenheight, false); + changeResolution(screenwidth, screenheight, false); - //printf("SDL initialized.\n"); + //printf("SDL initialized.\n"); - double calculatefps = 200.0; - int framecounter, oldframecounter = 0; - int currenttime; - int framesdrawn=0; - int skipframes; - int starttime = getTime(); + double calculatefps = 200.0; + int framecounter, oldframecounter = 0; + int currenttime; + int framesdrawn=0; + int skipframes; + int starttime = getTime(); - while (1){ - do{ - currenttime = getTime()-starttime; - framecounter = calculatefps*currenttime/1000.0; - } while (oldframecounter == framecounter); - skipframes = framecounter - oldframecounter; - for (; skipframes > 0; skipframes--){ - calculateFrame(++oldframecounter); - } - //calculateFrame(oldframecounter++); - processEvents(); - drawFrame(framecounter); - framesdrawn++; - } - return 0; -} \ No newline at end of file + while (1){ + do{ + currenttime = getTime()-starttime; + framecounter = calculatefps*currenttime/1000.0; + } while (oldframecounter == framecounter); + skipframes = framecounter - oldframecounter; + for (; skipframes > 0; skipframes--){ + calculateFrame(++oldframecounter); + } + //calculateFrame(oldframecounter++); + processEvents(); + drawFrame(framecounter); + framesdrawn++; + } + return 0; +} diff --git a/src/main.h b/src/main.h index 5660fac..3f3495c 100644 --- a/src/main.h +++ b/src/main.h @@ -1,54 +1,3 @@ -/* - * $Id: main.h,v 1.13 2002/07/19 20:33:28 msell Exp $ - * - * - * $Log: main.h,v $ - * Revision 1.13 2002/07/19 20:33:28 msell - * #pragma once -> #ifndef - * - * Revision 1.12 2002/07/19 20:06:32 msell - * Linux-porttausta - * - * Revision 1.11 2002/07/17 16:40:33 msell - * Resoluution vaihto - * - * Revision 1.10 2002/07/16 17:16:34 msell - * Fontit ja valikot - * - * Revision 1.9 2002/07/14 21:40:43 msell - * Conflictit pois, liikkumiset (hyppy, kävely, lyönti), uusi areena - * - * Revision 1.8 2002/07/14 21:22:39 jkaarlas - * skybox ja ukkojen säätö - * - * Revision 1.7 2002/07/08 22:53:38 msell - * Säätöä - * - * Revision 1.6 2002/06/17 19:58:08 msell - * #includeiden parantelua - * - * Revision 1.5 2002/06/16 01:04:58 jkaarlas - * tulipa säädettyä includejen kanssa. oon tod.näk. eri mieltä aamulla - * - * Revision 1.4 2002/06/04 16:28:32 msell - * #pragma once - * - * Revision 1.3 2002/05/17 12:30:26 msell - * no message - * - * Revision 1.2 2002/05/16 18:41:16 msell - * Vektorifunctioita ja kamera - * - * Revision 1.1 2002/05/15 14:36:39 msell - * Yksinkertainen SDL-runko (Kääntyy toistaiseksi vain windowsissa). - * Mukana myös musiikinsoitto fmodilla. - * - * - * - * $Date: 2002/07/19 20:33:28 $ - * - */ - #ifndef __MAIN_H_INCLUDED__ #define __MAIN_H_INCLUDED__ diff --git a/src/material.cpp b/src/material.cpp index c3fd441..6af5c9e 100644 --- a/src/material.cpp +++ b/src/material.cpp @@ -1,41 +1,3 @@ -/* - * $Id: material.cpp,v 1.10 2002/07/19 20:40:44 msell Exp $ - * - * - * $Log: material.cpp,v $ - * Revision 1.10 2002/07/19 20:40:44 msell - * Linux-porttausta - * - * Revision 1.9 2002/07/10 22:22:04 jkaarlas - * getColor - * - * Revision 1.8 2002/06/27 21:43:29 jkaarlas - * lisätty setTexture-funktio - * - * Revision 1.7 2002/06/27 00:08:04 msell - * Kimmotukset palloille myös pyöritettyihin mesheihin - * - * Revision 1.6 2002/06/20 00:21:01 jkaarlas - * materiaali- ja tekstuurihommia edistetty - * - * Revision 1.5 2002/06/19 22:45:29 jkaarlas - * nyt nämä menee järkevästi - * - * Revision 1.4 2002/06/17 20:49:05 msell - * free -> SDL_FreeSurface - * - * Revision 1.3 2002/06/16 01:04:58 jkaarlas - * tulipa säädettyä includejen kanssa. oon tod.näk. eri mieltä aamulla - * - * Revision 1.2 2002/06/03 23:06:38 msell - * no message - * - * - * - * $Date: 2002/07/19 20:40:44 $ - * - */ - #include "main.h" #include "material.h" @@ -43,7 +5,7 @@ #include "graphics.h" Material::Material(void){ - setColor(1, 1, 1, 1); + setColor(1, 1, 1, 1); this->texture = new Texture; } @@ -63,19 +25,19 @@ void Material::freeTexture(void){ } void Material::setColor(float red, float green, float blue, float alpha){ - color[0] = red; - color[1] = green; - color[2] = blue; - color[3] = alpha; + color[0] = red; + color[1] = green; + color[2] = blue; + color[3] = alpha; } const float* Material::getColor(void){ - return color; + return color; } void Material::enable(void){ enabled = true; - glColor4fv(color); + glColor4fv(color); this->texture->enable(); } diff --git a/src/material.h b/src/material.h index f1fc8ed..db58878 100644 --- a/src/material.h +++ b/src/material.h @@ -1,35 +1,3 @@ -/* - * $Id: material.h,v 1.8 2002/07/19 20:33:28 msell Exp $ - * - * - * $Log: material.h,v $ - * Revision 1.8 2002/07/19 20:33:28 msell - * #pragma once -> #ifndef - * - * Revision 1.7 2002/07/10 22:22:04 jkaarlas - * getColor - * - * Revision 1.6 2002/06/27 21:43:29 jkaarlas - * lisätty setTexture-funktio - * - * Revision 1.5 2002/06/20 00:21:01 jkaarlas - * materiaali- ja tekstuurihommia edistetty - * - * Revision 1.4 2002/06/19 22:45:29 jkaarlas - * nyt nämä menee järkevästi - * - * Revision 1.3 2002/06/04 16:28:32 msell - * #pragma once - * - * Revision 1.2 2002/06/03 23:06:38 msell - * no message - * - * - * - * $Date: 2002/07/19 20:33:28 $ - * - */ - #ifndef __MATERIAL_H_INCLUDED__ #define __MATERIAL_H_INCLUDED__ @@ -39,22 +7,22 @@ class Material{ private: Texture* texture; - float color[4]; + float color[4]; bool enabled; public: - Material(void); - bool loadTexture(char *path); + Material(void); + bool loadTexture(char *path); void freeTexture(void); - void setColor(float red, float green, float blue, float alpha); - const float* getColor(void); - void enable(void); + void setColor(float red, float green, float blue, float alpha); + const float* getColor(void); + void enable(void); void disable(void); bool isEnabled(void); Texture* getTexture(void); void setTexture(Texture* tex); - + }; #endif diff --git a/src/menu.cpp b/src/menu.cpp index a379071..e7b8c42 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -1,56 +1,3 @@ -/* - * $Id: menu.cpp,v 1.14 2002/07/22 01:14:14 msell Exp $ - * - * - * $Log: menu.cpp,v $ - * Revision 1.14 2002/07/22 01:14:14 msell - * Lopetussysteemi - * - * Revision 1.13 2002/07/21 22:50:39 msell - * no message - * - * Revision 1.12 2002/07/21 20:14:28 msell - * no message - * - * Revision 1.11 2002/07/21 16:37:00 msell - * no message - * - * Revision 1.10 2002/07/19 22:38:37 msell - * Pingviini - * - * Revision 1.9 2002/07/19 14:05:52 msell - * Damagetextuurit näkyy - * - * Revision 1.8 2002/07/19 12:28:29 msell - * 2D-mode - * - * Revision 1.7 2002/07/19 12:10:53 msell - * Hups - * - * Revision 1.6 2002/07/18 23:05:31 msell - * Partikkelit ja kakkospelaajan liike - * - * Revision 1.5 2002/07/17 22:45:54 msell - * Ääniä vähän - * - * Revision 1.4 2002/07/17 20:32:47 msell - * Detail-optio toimii - * - * Revision 1.3 2002/07/17 16:40:33 msell - * Resoluution vaihto - * - * Revision 1.2 2002/07/16 18:55:16 msell - * Äänet valikkoon - * - * Revision 1.1 2002/07/16 17:16:35 msell - * Fontit ja valikot - * - * - * - * $Date: 2002/07/22 01:14:14 $ - * - */ - #include "main.h" #include @@ -62,7 +9,7 @@ #include "object.h" #include "appearance.h" #include "sphere.h" -#include "vector.h" +#include "vector.h" #include "collision.h" #include "utils.h" #include "graphics.h" @@ -88,321 +35,321 @@ Sound *menumusic; bool menuinitialized = false; void initMenu(void){ - if (!menuinitialized){ - titleworld = new World(); - } + if (!menuinitialized){ + titleworld = new World(); + } - titlelight.setColor(1, 1, 1); - titlelight.setSpecular(1, 1, 1); - titlelight.setPosition(-0.5, BLOCKHEIGHT*16, 0.5); - titlelight.setAttenuation(0.0, 0.0, 0.01); + titlelight.setColor(1, 1, 1); + titlelight.setSpecular(1, 1, 1); + titlelight.setPosition(-0.5, BLOCKHEIGHT*16, 0.5); + titlelight.setAttenuation(0.0, 0.0, 0.01); - if (!menuinitialized){ - Object *lamp; - lamp = new Object(); - lamp->appearance = new LampAppearance(); - lamp->setPosition(-0.5, BLOCKHEIGHT*15.5, 0.5); - titleworld->addChild(lamp); + if (!menuinitialized){ + Object *lamp; + lamp = new Object(); + lamp->appearance = new LampAppearance(); + lamp->setPosition(-0.5, BLOCKHEIGHT*15.5, 0.5); + titleworld->addChild(lamp); - //Floor - BasicBlock *floorblock; + //Floor + BasicBlock *floorblock; - floorblock = new BasicBlock(33, 1, 5); - floorblock->setPosition(-0.5, -BLOCKHEIGHT/2.0 + BLOCKHEIGHT*(4*3+1), 0.5-5); - floorblock->setColor(0, 1, 0); - titleworld->addChild(floorblock); + floorblock = new BasicBlock(33, 1, 5); + floorblock->setPosition(-0.5, -BLOCKHEIGHT/2.0 + BLOCKHEIGHT*(4*3+1), 0.5-5); + floorblock->setColor(0, 1, 0); + titleworld->addChild(floorblock); - floorblock = new BasicBlock(41, 1, 10); - floorblock->setPosition(8.5-5, -BLOCKHEIGHT/2.0, 0.5-2.5); - floorblock->setColor(0, 1, 0); - titleworld->addChild(floorblock); + floorblock = new BasicBlock(41, 1, 10); + floorblock->setPosition(8.5-5, -BLOCKHEIGHT/2.0, 0.5-2.5); + floorblock->setColor(0, 1, 0); + titleworld->addChild(floorblock); - floorblock = new BasicBlock(1, 4*3, 1); - floorblock->setPosition(-14.5, BLOCKHEIGHT*4*3/2.0, 0.5-5); - floorblock->setColor(1, 0, 0); - titleworld->addChild(floorblock); + floorblock = new BasicBlock(1, 4*3, 1); + floorblock->setPosition(-14.5, BLOCKHEIGHT*4*3/2.0, 0.5-5); + floorblock->setColor(1, 0, 0); + titleworld->addChild(floorblock); - floorblock = new BasicBlock(1, 4*3, 1); - floorblock->setPosition(13.5, BLOCKHEIGHT*4*3/2.0, 0.5-5); - floorblock->setColor(1, 0, 0); - titleworld->addChild(floorblock); - - - - - //Letters - - //B - /*int Bsize = 8; - int Bwidth = 5; - int Bletter[8][4] = { - {0, 0, 4, 1}, - {0, 4, 3, 1}, - {0, 8, 4, 1}, - {0, 1, 1, 7}, - //{3, 1, 2, 1}, - {2, 3, 3, 1}, - {2, 5, 3, 1}, - //{3, 7, 2, 1}, - {4, 0, 1, 3}, - {4, 6, 1, 3}};*/ - int Bsize = 10; - int Bwidth = 5; - int Bletter[10][4] = { - {0, 0, 4, 1}, - {0, 4, 4, 1}, - {0, 8, 4, 1}, - {0, 1, 1, 7}, - {3, 1, 2, 1}, - {3, 3, 2, 1}, - {3, 5, 2, 1}, - {3, 7, 2, 1}, - {4, 2, 1, 1}, - {4, 6, 1, 1}}; - - //l - int lsize = 2; - int lwidth = 4; - int lletter[2][4] = { - {0, 0, 4, 1}, - {0, 1, 1, 4}}; - - //o - int osize = 4; - int owidth = 4; - int oletter[4][4] = { - {0, 0, 4, 1}, - {0, 4, 4, 1}, - {0, 1, 1, 3}, - {3, 1, 1, 3}}; - - //c - int csize = 5; - int cwidth = 4; - int cletter[5][4] = { - {0, 0, 4, 1}, - {0, 4, 4, 1}, - {0, 1, 1, 3}, - {3, 1, 1, 1}, - {3, 3, 1, 1}}; - /* {1, 0, 2, 1}, - {1, 4, 2, 1}, - {0, 1, 1, 3}, - {3, 1, 1, 1}, - {3, 3, 1, 1}};*/ - - //k - int ksize = 6; - int kwidth = 4; - int kletter[6][4] = { - {0, 0, 1, 5}, - {1, 2, 2, 1}, - {2, 1, 2, 1}, - {2, 3, 2, 1}, - {3, 0, 1, 1}, - {3, 4, 1, 1}}; - /* {0, 0, 1, 5}, - {1, 2, 1, 1}, - {2, 1, 1, 1}, - {2, 3, 1, 1}, - {3, 0, 1, 1}, - {3, 4, 1, 1}};*/ - - //F - int Fsize = 3; - int Fwidth = 3; - int Fletter[3][4] = { - {0, 0, 1, 7}, - {0, 4, 3, 1}, - {0, 7, 6, 1}}; - - //i - int isize = 1; - int iwidth = 1; - int iletter[1][4] = { - {0, 0, 1, 4}}; - - //g - int gsize = 5; - int gwidth = 4; - int gletter[5][4] = { - {0, 0, 4, 1}, - {0, 4, 4, 1}, - {0, 1, 1, 3}, - {3, 1, 1, 1}, - {2, 2, 2, 1}}; - - //h - int hsize = 3; - int hwidth = 1; - int hletter[3][4] = { - {0, 0, 1, 5}, - {3, 0, 1, 5}, - {0, 2, 4, 1}}; - - //t - int tsize = 2; - int twidth = 4; - int tletter[2][4] = { - {3, 0, 1, 6}, - {0, 6, 7, 1}}; - - //e - int esize = 5; - int ewidth = 4; - int eletter[5][4] = { - {0, 0, 4, 1}, - {0, 4, 4, 1}, - {0, 2, 3, 1}, - {0, 1, 1, 1}, - {0, 3, 1, 1}}; - - //r - int rsize = 6; - int rwidth = 4; - int rletter[6][4] = { - {0, 0, 1, 5}, - {0, 2, 3, 1}, - {0, 4, 3, 1}, - {2, 1, 2, 1}, - {3, 0, 1, 1}, - {2, 3, 2, 1}}; - /*int rsize = 5; - int rwidth = 4; - int rletter[5][4] = { - {0, 0, 1, 5}, - {0, 2, 3, 1}, - {0, 4, 3, 1}, - {3, 0, 1, 2}, - {3, 3, 1, 1}};*/ - - #define LETTERCOUNT 6 - int lettersizes[LETTERCOUNT] = { - Bsize, - lsize, - osize, - csize, - ksize, - osize - }; - int letterwidths[LETTERCOUNT] = { - Bwidth, - lwidth, - owidth, - cwidth, - kwidth, - owidth - }; - int *letters[LETTERCOUNT] = { - &Bletter[0][0], - &lletter[0][0], - &oletter[0][0], - &cletter[0][0], - &kletter[0][0], - &oletter[0][0] - }; - - #define LETTERCOUNT2 7 - int lettersizes2[LETTERCOUNT2] = { - Fsize, - isize, - gsize, - hsize, - tsize, - esize, - rsize - }; - int letterwidths2[LETTERCOUNT2] = { - Fwidth, - iwidth, - gwidth, - hwidth, - twidth, - ewidth, - rwidth - }; - int *letters2[LETTERCOUNT2] = { - &Fletter[0][0], - &iletter[0][0], - &gletter[0][0], - &hletter[0][0], - &tletter[0][0], - &eletter[0][0], - &rletter[0][0] - }; - BasicBlock *letterblock; - - float z = 0.5; - int i, j; - int dx = -15; - int dy = BLOCKHEIGHT*(4*3+1); - int dz = -5; - for (i = 0; i < LETTERCOUNT; i++){ - int size = lettersizes[i]; - int width = letterwidths[i]; - for (j = 0; j < size; j++){ - int x = letters[i][j*4+0]; - int y = letters[i][j*4+1]*3; - int w = letters[i][j*4+2]; - int h = letters[i][j*4+3]*3; - letterblock = new BasicBlock(w, h, 1); - letterblock->setPosition(dx+x+w/2.0, dy+BLOCKHEIGHT*(y+h/2.0), dz+z + randomf(0.1)); - letterblock->setColor(1, 0.5, 1); - titleworld->addChild(letterblock); - } - dx += width + 1; - } - dx = -5; - dy = 0; - dz = 0; - for (i = 0; i < LETTERCOUNT2; i++){ - int size = lettersizes2[i]; - int width = letterwidths2[i]; - for (j = 0; j < size; j++){ - int x = letters2[i][j*4+0]; - int y = letters2[i][j*4+1]*3; - int w = letters2[i][j*4+2]; - int h = letters2[i][j*4+3]*3; - letterblock = new BasicBlock(w, h, 1); - letterblock->setPosition(dx+x+w/2.0, dy+BLOCKHEIGHT*(y+h/2.0), dz+z + randomf(0.1)); - //float rotate[3] = {0, randomf(0.1), 0}; - //matrixCreateRotation(letterblock->rotation, rotate); - letterblock->setColor(1, 0.5, 1); - titleworld->addChild(letterblock); - } - dx += width + 1; - } + floorblock = new BasicBlock(1, 4*3, 1); + floorblock->setPosition(13.5, BLOCKHEIGHT*4*3/2.0, 0.5-5); + floorblock->setColor(1, 0, 0); + titleworld->addChild(floorblock); - Object *flower; - flower = new Object(); - flower->appearance = new FlowerAppearance(FLOWER_RED, FLOWER_WHITE, FLOWER_YELLOW); - flower->setPosition(-7.5, 0, 1.5); - titleworld->addChild(flower); + //Letters - flower = new Object(); - flower->appearance = new FlowerAppearance(FLOWER_YELLOW, FLOWER_RED, FLOWER_YELLOW); - flower->setPosition(-11.5, 0, -2.5); - titleworld->addChild(flower); + //B + /*int Bsize = 8; + int Bwidth = 5; + int Bletter[8][4] = { + {0, 0, 4, 1}, + {0, 4, 3, 1}, + {0, 8, 4, 1}, + {0, 1, 1, 7}, + //{3, 1, 2, 1}, + {2, 3, 3, 1}, + {2, 5, 3, 1}, + //{3, 7, 2, 1}, + {4, 0, 1, 3}, + {4, 6, 1, 3}};*/ + int Bsize = 10; + int Bwidth = 5; + int Bletter[10][4] = { + {0, 0, 4, 1}, + {0, 4, 4, 1}, + {0, 8, 4, 1}, + {0, 1, 1, 7}, + {3, 1, 2, 1}, + {3, 3, 2, 1}, + {3, 5, 2, 1}, + {3, 7, 2, 1}, + {4, 2, 1, 1}, + {4, 6, 1, 1}}; - flower = new Object(); - flower->appearance = new FlowerAppearance(FLOWER_WHITE, FLOWER_WHITE, FLOWER_RED); - flower->setPosition(-14.5, 0, 0.5); - titleworld->addChild(flower); + //l + int lsize = 2; + int lwidth = 4; + int lletter[2][4] = { + {0, 0, 4, 1}, + {0, 1, 1, 4}}; + + //o + int osize = 4; + int owidth = 4; + int oletter[4][4] = { + {0, 0, 4, 1}, + {0, 4, 4, 1}, + {0, 1, 1, 3}, + {3, 1, 1, 3}}; + + //c + int csize = 5; + int cwidth = 4; + int cletter[5][4] = { + {0, 0, 4, 1}, + {0, 4, 4, 1}, + {0, 1, 1, 3}, + {3, 1, 1, 1}, + {3, 3, 1, 1}}; + /* {1, 0, 2, 1}, + {1, 4, 2, 1}, + {0, 1, 1, 3}, + {3, 1, 1, 1}, + {3, 3, 1, 1}};*/ + + //k + int ksize = 6; + int kwidth = 4; + int kletter[6][4] = { + {0, 0, 1, 5}, + {1, 2, 2, 1}, + {2, 1, 2, 1}, + {2, 3, 2, 1}, + {3, 0, 1, 1}, + {3, 4, 1, 1}}; + /* {0, 0, 1, 5}, + {1, 2, 1, 1}, + {2, 1, 1, 1}, + {2, 3, 1, 1}, + {3, 0, 1, 1}, + {3, 4, 1, 1}};*/ + + //F + int Fsize = 3; + int Fwidth = 3; + int Fletter[3][4] = { + {0, 0, 1, 7}, + {0, 4, 3, 1}, + {0, 7, 6, 1}}; + + //i + int isize = 1; + int iwidth = 1; + int iletter[1][4] = { + {0, 0, 1, 4}}; + + //g + int gsize = 5; + int gwidth = 4; + int gletter[5][4] = { + {0, 0, 4, 1}, + {0, 4, 4, 1}, + {0, 1, 1, 3}, + {3, 1, 1, 1}, + {2, 2, 2, 1}}; + + //h + int hsize = 3; + int hwidth = 1; + int hletter[3][4] = { + {0, 0, 1, 5}, + {3, 0, 1, 5}, + {0, 2, 4, 1}}; + + //t + int tsize = 2; + int twidth = 4; + int tletter[2][4] = { + {3, 0, 1, 6}, + {0, 6, 7, 1}}; + + //e + int esize = 5; + int ewidth = 4; + int eletter[5][4] = { + {0, 0, 4, 1}, + {0, 4, 4, 1}, + {0, 2, 3, 1}, + {0, 1, 1, 1}, + {0, 3, 1, 1}}; + + //r + int rsize = 6; + int rwidth = 4; + int rletter[6][4] = { + {0, 0, 1, 5}, + {0, 2, 3, 1}, + {0, 4, 3, 1}, + {2, 1, 2, 1}, + {3, 0, 1, 1}, + {2, 3, 2, 1}}; + /*int rsize = 5; + int rwidth = 4; + int rletter[5][4] = { + {0, 0, 1, 5}, + {0, 2, 3, 1}, + {0, 4, 3, 1}, + {3, 0, 1, 2}, + {3, 3, 1, 1}};*/ + + #define LETTERCOUNT 6 + int lettersizes[LETTERCOUNT] = { + Bsize, + lsize, + osize, + csize, + ksize, + osize + }; + int letterwidths[LETTERCOUNT] = { + Bwidth, + lwidth, + owidth, + cwidth, + kwidth, + owidth + }; + int *letters[LETTERCOUNT] = { + &Bletter[0][0], + &lletter[0][0], + &oletter[0][0], + &cletter[0][0], + &kletter[0][0], + &oletter[0][0] + }; + + #define LETTERCOUNT2 7 + int lettersizes2[LETTERCOUNT2] = { + Fsize, + isize, + gsize, + hsize, + tsize, + esize, + rsize + }; + int letterwidths2[LETTERCOUNT2] = { + Fwidth, + iwidth, + gwidth, + hwidth, + twidth, + ewidth, + rwidth + }; + int *letters2[LETTERCOUNT2] = { + &Fletter[0][0], + &iletter[0][0], + &gletter[0][0], + &hletter[0][0], + &tletter[0][0], + &eletter[0][0], + &rletter[0][0] + }; + BasicBlock *letterblock; + + float z = 0.5; + int i, j; + int dx = -15; + int dy = BLOCKHEIGHT*(4*3+1); + int dz = -5; + for (i = 0; i < LETTERCOUNT; i++){ + int size = lettersizes[i]; + int width = letterwidths[i]; + for (j = 0; j < size; j++){ + int x = letters[i][j*4+0]; + int y = letters[i][j*4+1]*3; + int w = letters[i][j*4+2]; + int h = letters[i][j*4+3]*3; + letterblock = new BasicBlock(w, h, 1); + letterblock->setPosition(dx+x+w/2.0, dy+BLOCKHEIGHT*(y+h/2.0), dz+z + randomf(0.1)); + letterblock->setColor(1, 0.5, 1); + titleworld->addChild(letterblock); + } + dx += width + 1; + } + dx = -5; + dy = 0; + dz = 0; + for (i = 0; i < LETTERCOUNT2; i++){ + int size = lettersizes2[i]; + int width = letterwidths2[i]; + for (j = 0; j < size; j++){ + int x = letters2[i][j*4+0]; + int y = letters2[i][j*4+1]*3; + int w = letters2[i][j*4+2]; + int h = letters2[i][j*4+3]*3; + letterblock = new BasicBlock(w, h, 1); + letterblock->setPosition(dx+x+w/2.0, dy+BLOCKHEIGHT*(y+h/2.0), dz+z + randomf(0.1)); + //float rotate[3] = {0, randomf(0.1), 0}; + //matrixCreateRotation(letterblock->rotation, rotate); + letterblock->setColor(1, 0.5, 1); + titleworld->addChild(letterblock); + } + dx += width + 1; + } - changesound = new Sound(DATAPATH"menuchange.wav"); - selectsound = new Sound(DATAPATH"menuselect.wav"); - menumusic = new Sound(DATAPATH"menu.mp3", true); - } - - titleworld->prepare(); + Object *flower; - menuinitialized = true; + flower = new Object(); + flower->appearance = new FlowerAppearance(FLOWER_RED, FLOWER_WHITE, FLOWER_YELLOW); + flower->setPosition(-7.5, 0, 1.5); + titleworld->addChild(flower); + + flower = new Object(); + flower->appearance = new FlowerAppearance(FLOWER_YELLOW, FLOWER_RED, FLOWER_YELLOW); + flower->setPosition(-11.5, 0, -2.5); + titleworld->addChild(flower); + + flower = new Object(); + flower->appearance = new FlowerAppearance(FLOWER_WHITE, FLOWER_WHITE, FLOWER_RED); + flower->setPosition(-14.5, 0, 0.5); + titleworld->addChild(flower); + + + + changesound = new Sound(DATAPATH"menuchange.wav"); + selectsound = new Sound(DATAPATH"menuselect.wav"); + menumusic = new Sound(DATAPATH"menu.mp3", true); + } + + titleworld->prepare(); + + menuinitialized = true; } #define MODEMAIN 0 @@ -435,12 +382,12 @@ int detail = 2; #define RESOLUTIONCOUNT 6 int resolutions[RESOLUTIONCOUNT][2] = { - {640, 480}, - {800, 600}, - {1024, 768}, - {1280, 960}, - {1280, 1024}, - {1600, 1200} + {640, 480}, + {800, 600}, + {1024, 768}, + {1280, 960}, + {1280, 1024}, + {1600, 1200} }; #define DETAILCOUNT 4 @@ -449,17 +396,17 @@ char *details[DETAILCOUNT] = {"Off", "Low", "Medium", "High"}; int menurestartcounter = -1; void menuRestart(void){ - menurestartcounter = 0; + menurestartcounter = 0; } void menuMain(void){ - interpolator = 0.0; - menumode = MODEMAIN; - menuoption = MAINOPTIONS; - obx1 = bx1; - oby1 = by1; - obx2 = bx2; - oby2 = by2; + interpolator = 0.0; + menumode = MODEMAIN; + menuoption = MAINOPTIONS; + obx1 = bx1; + oby1 = by1; + obx2 = bx2; + oby2 = by2; } float menufade; @@ -469,432 +416,432 @@ int gamestart = 0; bool loading = true; void menuStartGame(void){ - menumusic->fadeOut(300); - gamestart = 200; - menurestartcounter = -1; + menumusic->fadeOut(300); + gamestart = 200; + menurestartcounter = -1; } void menuStartGame2(void){ - titlelight.setEnabled(false); - changeGameMode(FIGHTMODE); - startFight(); - menurestartcounter = -1; + titlelight.setEnabled(false); + changeGameMode(FIGHTMODE); + startFight(); + menurestartcounter = -1; } void menuOptions(void){ - interpolator = 0.0; - menumode = MODEOPTIONS; - menuoption = OPTIONSRESOLUTION; - obx1 = bx1; - oby1 = by1; - obx2 = bx2; - oby2 = by2; - oldresolution = resolution; - olddetail = detail; + interpolator = 0.0; + menumode = MODEOPTIONS; + menuoption = OPTIONSRESOLUTION; + obx1 = bx1; + oby1 = by1; + obx2 = bx2; + oby2 = by2; + oldresolution = resolution; + olddetail = detail; } int quitcounter = -1; void menuEscPressed(void){ - menurestartcounter = -1; - //menumusic->stop(); - menumusic->fadeOut(200); - quitcounter = 0; + menurestartcounter = -1; + //menumusic->stop(); + menumusic->fadeOut(200); + quitcounter = 0; } void menuQuit(void){ - exitProgram(0); + exitProgram(0); } void menuResolution(int dir){ - resolution += dir; - if (resolution < 0) resolution = 0; - if (resolution >= RESOLUTIONCOUNT) resolution = RESOLUTIONCOUNT-1; - //resolution = (resolution + RESOLUTIONCOUNT) % RESOLUTIONCOUNT; + resolution += dir; + if (resolution < 0) resolution = 0; + if (resolution >= RESOLUTIONCOUNT) resolution = RESOLUTIONCOUNT-1; + //resolution = (resolution + RESOLUTIONCOUNT) % RESOLUTIONCOUNT; } void calculateMenu(int framecount){ - if (framecount == 1){ - menumusic->setVolume(0); - menumusic->play(); - menumusic->fadeIn(300); - } - if (menurestartcounter != -1){ - menurestartcounter++; - if (menurestartcounter == 300){ - menumusic->play(); - menumusic->fadeIn(100); - menurestartcounter = -1; - } - } + if (framecount == 1){ + menumusic->setVolume(0); + menumusic->play(); + menumusic->fadeIn(300); + } + if (menurestartcounter != -1){ + menurestartcounter++; + if (menurestartcounter == 300){ + menumusic->play(); + menumusic->fadeIn(100); + menurestartcounter = -1; + } + } - menufade = -1; + menufade = -1; - titlelight.setEnabled(true); + titlelight.setEnabled(true); - if (framecount < 200){ - menufade = 1-framecount/200.0; - } else{ - loading = false; - } + if (framecount < 200){ + menufade = 1-framecount/200.0; + } else{ + loading = false; + } - if (gamestart > 0){ - gamestart--; - if (gamestart == 0){ - menuStartGame2(); - } - menufade = (200-gamestart)/200.0; - } + if (gamestart > 0){ + gamestart--; + if (gamestart == 0){ + menuStartGame2(); + } + menufade = (200-gamestart)/200.0; + } - if (quitcounter != -1){ - menufade = quitcounter/200.0; - quitcounter++; - if (quitcounter == 200) menuQuit(); - } + if (quitcounter != -1){ + menufade = quitcounter/200.0; + quitcounter++; + if (quitcounter == 200) menuQuit(); + } - float cameratarget[3] = {0, 0, 0}; - titlecamera.setPosition(sin(framecount*0.001)*2-8, sin(framecount*0.0033)*2+15, cos(framecount*0.001)*2+25); - titlecamera.setTarget(cameratarget); + float cameratarget[3] = {0, 0, 0}; + titlecamera.setPosition(sin(framecount*0.001)*2-8, sin(framecount*0.0033)*2+15, cos(framecount*0.001)*2+25); + titlecamera.setTarget(cameratarget); - titleworld->move(); + titleworld->move(); - xres = resolutions[resolution][0]; - yres = resolutions[resolution][1]; + xres = resolutions[resolution][0]; + yres = resolutions[resolution][1]; - switch(menumode){ - case MODEMAIN: - maxoption = 2; + switch(menumode){ + case MODEMAIN: + maxoption = 2; - bx1 = 0.03; - by1 = 0.49; - bx2 = 0.68; - by2 = 0.96; + bx1 = 0.03; + by1 = 0.49; + bx2 = 0.68; + by2 = 0.96; - break; - case MODEOPTIONS: - maxoption = 3; + break; + case MODEOPTIONS: + maxoption = 3; - bx1 = 0.1; - by1 = 0.3; - bx2 = 0.9; - by2 = 0.8; - break; - } + bx1 = 0.1; + by1 = 0.3; + bx2 = 0.9; + by2 = 0.8; + break; + } - if (interpolator < 1.0){ - interpolator += 0.02; - } else{ - interpolator = 1.0; - if (menufade == -1){ - if (keys[SDLK_DOWN]){ - if (!pressed){ - /*if (menuoption < maxoption){ - menuoption++; - changesound->play(); - }*/ - menuoption = (menuoption + 1)%(maxoption+1); - changesound->play(); - pressed = true; - } - } else if (keys[SDLK_UP]){ - if (!pressed){ - /*if (menuoption > 0){ - menuoption--; - changesound->play(); - }*/ - menuoption = (menuoption + maxoption)%(maxoption+1); - changesound->play(); - pressed = true; - } - } else if (keys[SDLK_LEFT]){ - if (!pressed){ - switch(menumode){ - case MODEOPTIONS: - switch(menuoption){ - case OPTIONSRESOLUTION: - menuResolution(-1); - break; - case OPTIONSDETAIL: - if (detail > 0) detail--; - break; - } - break; - } - selectsound->play(); - pressed = true; - } - } else if (keys[SDLK_RIGHT]){ - if (!pressed){ - switch(menumode){ - case MODEOPTIONS: - switch(menuoption){ - case OPTIONSRESOLUTION: - menuResolution(1); - break; - case OPTIONSDETAIL: - if (detail < DETAILCOUNT-1) detail++; - break; - } - break; - } - selectsound->play(); - pressed = true; - } - } else if (keys[SDLK_ESCAPE]){ - if (!pressed){ - switch(menumode){ - case MODEMAIN: - if (menuoption != MAINQUIT){ - menuoption = MAINQUIT; - changesound->play(); - } - else menuEscPressed(); - break; - case MODEOPTIONS: - selectsound->play(); - resolution = oldresolution; - detail = olddetail; - menuMain(); - break; - } - pressed = true; - } - } else if (keys[SDLK_RETURN]){ - if (!pressed){ - switch(menumode){ - case MODEMAIN: - switch(menuoption){ - case MAINSTART: - menuStartGame(); - break; - case MAINOPTIONS: - menuOptions(); - break; - case MAINQUIT: - menuEscPressed(); - break; - } - break; - case MODEOPTIONS: - switch(menuoption){ - case OPTIONSRESOLUTION: - if (resolution != oldresolution) changeResolution(xres, yres, fullscreen); - oldresolution = resolution; - break; - case OPTIONSFULLSCREEN: - fullscreen = !fullscreen; - changeResolution(xres, yres, fullscreen); - break; - case OPTIONSDETAIL: - setDetail(detail); - olddetail = detail; - break; - case OPTIONSRETURN: - if (resolution != oldresolution){ - changeResolution(xres, yres, fullscreen); - oldresolution = resolution; - } - if (detail != olddetail){ - setDetail(detail); - olddetail = detail; - } - menuMain(); - break; - } - break; - } - selectsound->play(); - pressed = true; - } - } else pressed = false; - } - } + if (interpolator < 1.0){ + interpolator += 0.02; + } else{ + interpolator = 1.0; + if (menufade == -1){ + if (keys[SDLK_DOWN]){ + if (!pressed){ + /*if (menuoption < maxoption){ + menuoption++; + changesound->play(); + }*/ + menuoption = (menuoption + 1)%(maxoption+1); + changesound->play(); + pressed = true; + } + } else if (keys[SDLK_UP]){ + if (!pressed){ + /*if (menuoption > 0){ + menuoption--; + changesound->play(); + }*/ + menuoption = (menuoption + maxoption)%(maxoption+1); + changesound->play(); + pressed = true; + } + } else if (keys[SDLK_LEFT]){ + if (!pressed){ + switch(menumode){ + case MODEOPTIONS: + switch(menuoption){ + case OPTIONSRESOLUTION: + menuResolution(-1); + break; + case OPTIONSDETAIL: + if (detail > 0) detail--; + break; + } + break; + } + selectsound->play(); + pressed = true; + } + } else if (keys[SDLK_RIGHT]){ + if (!pressed){ + switch(menumode){ + case MODEOPTIONS: + switch(menuoption){ + case OPTIONSRESOLUTION: + menuResolution(1); + break; + case OPTIONSDETAIL: + if (detail < DETAILCOUNT-1) detail++; + break; + } + break; + } + selectsound->play(); + pressed = true; + } + } else if (keys[SDLK_ESCAPE]){ + if (!pressed){ + switch(menumode){ + case MODEMAIN: + if (menuoption != MAINQUIT){ + menuoption = MAINQUIT; + changesound->play(); + } + else menuEscPressed(); + break; + case MODEOPTIONS: + selectsound->play(); + resolution = oldresolution; + detail = olddetail; + menuMain(); + break; + } + pressed = true; + } + } else if (keys[SDLK_RETURN]){ + if (!pressed){ + switch(menumode){ + case MODEMAIN: + switch(menuoption){ + case MAINSTART: + menuStartGame(); + break; + case MAINOPTIONS: + menuOptions(); + break; + case MAINQUIT: + menuEscPressed(); + break; + } + break; + case MODEOPTIONS: + switch(menuoption){ + case OPTIONSRESOLUTION: + if (resolution != oldresolution) changeResolution(xres, yres, fullscreen); + oldresolution = resolution; + break; + case OPTIONSFULLSCREEN: + fullscreen = !fullscreen; + changeResolution(xres, yres, fullscreen); + break; + case OPTIONSDETAIL: + setDetail(detail); + olddetail = detail; + break; + case OPTIONSRETURN: + if (resolution != oldresolution){ + changeResolution(xres, yres, fullscreen); + oldresolution = resolution; + } + if (detail != olddetail){ + setDetail(detail); + olddetail = detail; + } + menuMain(); + break; + } + break; + } + selectsound->play(); + pressed = true; + } + } else pressed = false; + } + } } void drawMenu(int framecount){ - //createSkyBox(0, -20, 0, 400, 200, 400); - createSkyBox(-200, -200, -200, 400, 400, 400); - glLoadIdentity(); - titlecamera.glUpdate(); + //createSkyBox(0, -20, 0, 400, 200, 400); + createSkyBox(-200, -200, -200, 400, 400, 400); + glLoadIdentity(); + titlecamera.glUpdate(); - updateLights(); - - - - titleworld->draw(); + updateLights(); - flaretexture->enable(); - titlelight.createFlare(); - flaretexture->disable(); + + titleworld->draw(); - /*//2D-view - glDisable(GL_LIGHTING); - glDisable(GL_CULL_FACE); - glDisable(GL_DEPTH_TEST); - glMatrixMode(GL_PROJECTION); - glPushMatrix(); - glLoadIdentity(); - gluOrtho2D(0, 1, 1, 0); - glMatrixMode(GL_MODELVIEW); - glPushMatrix(); - glLoadIdentity();*/ - enable2D(); - - glColor3f(1, 1, 1); - print(0.73, 0.55, - "Programming:\n" \ - " Miika Sell\n" \ - " Juha Kaarlas\n" \ - "\n" \ - "Graphics:\n" \ - " Miika Sell\n" \ - " Juha Kaarlas\n" \ - "\n" \ - "Musics:\n" \ - " Osmand" - , 0.03); - - print(0.35, 0.965, "http://blockofighter.kicks-ass.net/", 0.02); - - print(0.88, 0.96, "Version 2.0", 0.02); - - tuxtexture->enable(); - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glColor3f(1, 1, 1); - - float tuxx = 0.9; - float tuxy = 0.02; - float tuxw = 0.1*3/4; - float tuxh = 0.1; - glBegin(GL_QUADS); - glTexCoord2f(0, 0); - glVertex2f(tuxx, tuxy); - - glTexCoord2f(1, 0); - glVertex2f(tuxx+tuxw, tuxy); - - glTexCoord2f(1, 1); - glVertex2f(tuxx+tuxw, tuxy+tuxh); - - glTexCoord2f(0, 1); - glVertex2f(tuxx, tuxy+tuxh); - glEnd(); - tuxtexture->disable(); - - glColor3f(1, 1, 1); - print(0.88, 0.12, "supported", 0.02); + flaretexture->enable(); + titlelight.createFlare(); + flaretexture->disable(); - glEnable(GL_BLEND); - glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); - glColor4f(0, 0, 0, 0.5); - float x1, y1, x2, y2; - x1 = (1-interpolator)*obx1 + interpolator*bx1; - y1 = (1-interpolator)*oby1 + interpolator*by1; - x2 = (1-interpolator)*obx2 + interpolator*bx2; - y2 = (1-interpolator)*oby2 + interpolator*by2; - glBegin(GL_QUADS); - glVertex2f(x1, y1); - glVertex2f(x2, y1); - glVertex2f(x2, y2); - glVertex2f(x1, y2); - glEnd(); + /*//2D-view + glDisable(GL_LIGHTING); + glDisable(GL_CULL_FACE); + glDisable(GL_DEPTH_TEST); + glMatrixMode(GL_PROJECTION); + glPushMatrix(); + glLoadIdentity(); + gluOrtho2D(0, 1, 1, 0); + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + glLoadIdentity();*/ + enable2D(); - if (interpolator == 1.0){ - switch(menumode){ - case MODEMAIN: - glColor3f(1, 1, 1); - print(0.05, 0.5, "Start game", 0.1); - print(0.05, 0.65, "Options", 0.1); - print(0.05, 0.8, "Quit", 0.1); + glColor3f(1, 1, 1); + print(0.73, 0.55, + "Programming:\n" \ + " Miika Sell\n" \ + " Juha Kaarlas\n" \ + "\n" \ + "Graphics:\n" \ + " Miika Sell\n" \ + " Juha Kaarlas\n" \ + "\n" \ + "Musics:\n" \ + " Osmand" + , 0.03); - x1 = 0.04; - x2 = 0.67; - switch(menuoption){ - case 0: - y1 = 0.5; - y2 = 0.65; - break; - case 1: - y1 = 0.65; - y2 = 0.79; - break; - case 2: - y1 = 0.79; - y2 = 0.95; - break; - } - break; - case MODEOPTIONS: - glColor3f(1, 1, 1); - char resolutionstring[22]; - sprintf(resolutionstring, "Resolution: %ix%i", xres, yres); - print(0.12, 0.32, resolutionstring, 0.07); - print(0.12, 0.42, "Toggle fullscreen", 0.07); - char detailstring[22]; - sprintf(detailstring, "Detail: %s", details[detail]); - print(0.12, 0.52, detailstring, 0.07); - print(0.12, 0.68, "Save and return", 0.07); + print(0.35, 0.965, "http://blockofighter.kicks-ass.net/", 0.02); - x1 = 0.11; - x2 = 0.89; - switch(menuoption){ - case 0: - y1 = 0.32; - y2 = 0.42; - break; - case 1: - y1 = 0.42; - y2 = 0.52; - break; - case 2: - y1 = 0.52; - y2 = 0.62; - break; - case 3: - y1 = 0.68; - y2 = 0.78; - break; - } - break; - } + print(0.88, 0.96, "Version 2.0", 0.02); - glLineWidth(2); + tuxtexture->enable(); + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glColor3f(1, 1, 1); - glColor4f(sin(framecount*0.04)*0.4+0.6, sin(framecount*0.04)*0.4+0.6, sin(framecount*0.04)*0.4+0.6, 0.5); - glBegin(GL_LINE_LOOP); - glVertex2f(x1, y1); - glVertex2f(x2, y1); - glVertex2f(x2, y2); - glVertex2f(x1, y2); - glEnd(); - } + float tuxx = 0.9; + float tuxy = 0.02; + float tuxw = 0.1*3/4; + float tuxh = 0.1; + glBegin(GL_QUADS); + glTexCoord2f(0, 0); + glVertex2f(tuxx, tuxy); + + glTexCoord2f(1, 0); + glVertex2f(tuxx+tuxw, tuxy); + + glTexCoord2f(1, 1); + glVertex2f(tuxx+tuxw, tuxy+tuxh); + + glTexCoord2f(0, 1); + glVertex2f(tuxx, tuxy+tuxh); + glEnd(); + tuxtexture->disable(); + + glColor3f(1, 1, 1); + print(0.88, 0.12, "supported", 0.02); - if (menufade != -1){ - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glColor4f(0, 0, 0, menufade); - glBegin(GL_QUADS); - glVertex2f(0, 0); - glVertex2f(1, 0); - glVertex2f(1, 1); - glVertex2f(0, 1); - glEnd(); - if (loading){ - glColor4f(menufade, menufade, menufade, menufade); - print(0.08, 0.4, "Loading...", 0.2); - } - } + glEnable(GL_BLEND); + glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); + glColor4f(0, 0, 0, 0.5); + float x1, y1, x2, y2; + x1 = (1-interpolator)*obx1 + interpolator*bx1; + y1 = (1-interpolator)*oby1 + interpolator*by1; + x2 = (1-interpolator)*obx2 + interpolator*bx2; + y2 = (1-interpolator)*oby2 + interpolator*by2; + glBegin(GL_QUADS); + glVertex2f(x1, y1); + glVertex2f(x2, y1); + glVertex2f(x2, y2); + glVertex2f(x1, y2); + glEnd(); - disable2D(); - /*//Back to 3D-view - glPopMatrix(); - glMatrixMode(GL_PROJECTION); - glPopMatrix(); - glMatrixMode(GL_MODELVIEW);*/ + if (interpolator == 1.0){ + switch(menumode){ + case MODEMAIN: + glColor3f(1, 1, 1); + print(0.05, 0.5, "Start game", 0.1); + print(0.05, 0.65, "Options", 0.1); + print(0.05, 0.8, "Quit", 0.1); + + x1 = 0.04; + x2 = 0.67; + switch(menuoption){ + case 0: + y1 = 0.5; + y2 = 0.65; + break; + case 1: + y1 = 0.65; + y2 = 0.79; + break; + case 2: + y1 = 0.79; + y2 = 0.95; + break; + } + break; + case MODEOPTIONS: + glColor3f(1, 1, 1); + char resolutionstring[22]; + sprintf(resolutionstring, "Resolution: %ix%i", xres, yres); + print(0.12, 0.32, resolutionstring, 0.07); + print(0.12, 0.42, "Toggle fullscreen", 0.07); + char detailstring[22]; + sprintf(detailstring, "Detail: %s", details[detail]); + print(0.12, 0.52, detailstring, 0.07); + print(0.12, 0.68, "Save and return", 0.07); + + x1 = 0.11; + x2 = 0.89; + switch(menuoption){ + case 0: + y1 = 0.32; + y2 = 0.42; + break; + case 1: + y1 = 0.42; + y2 = 0.52; + break; + case 2: + y1 = 0.52; + y2 = 0.62; + break; + case 3: + y1 = 0.68; + y2 = 0.78; + break; + } + break; + } + + glLineWidth(2); + + glColor4f(sin(framecount*0.04)*0.4+0.6, sin(framecount*0.04)*0.4+0.6, sin(framecount*0.04)*0.4+0.6, 0.5); + glBegin(GL_LINE_LOOP); + glVertex2f(x1, y1); + glVertex2f(x2, y1); + glVertex2f(x2, y2); + glVertex2f(x1, y2); + glEnd(); + } + + + if (menufade != -1){ + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glColor4f(0, 0, 0, menufade); + glBegin(GL_QUADS); + glVertex2f(0, 0); + glVertex2f(1, 0); + glVertex2f(1, 1); + glVertex2f(0, 1); + glEnd(); + if (loading){ + glColor4f(menufade, menufade, menufade, menufade); + print(0.08, 0.4, "Loading...", 0.2); + } + } + + disable2D(); + /*//Back to 3D-view + glPopMatrix(); + glMatrixMode(GL_PROJECTION); + glPopMatrix(); + glMatrixMode(GL_MODELVIEW);*/ } diff --git a/src/menu.h b/src/menu.h index 93e07fa..8d8ef73 100644 --- a/src/menu.h +++ b/src/menu.h @@ -1,32 +1,3 @@ -/* - * $Id: menu.h,v 1.6 2002/07/21 22:50:39 msell Exp $ - * - * - * $Log: menu.h,v $ - * Revision 1.6 2002/07/21 22:50:39 msell - * no message - * - * Revision 1.5 2002/07/19 21:17:07 msell - * bugifixi - * - * Revision 1.4 2002/07/19 20:33:28 msell - * #pragma once -> #ifndef - * - * Revision 1.3 2002/07/19 20:06:32 msell - * Linux-porttausta - * - * Revision 1.2 2002/07/17 20:32:47 msell - * Detail-optio toimii - * - * Revision 1.1 2002/07/16 17:16:35 msell - * Fontit ja valikot - * - * - * - * $Date: 2002/07/21 22:50:39 $ - * - */ - #ifndef __MENU_H_INCLUDED__ #define __MENU_H_INCLUDED__ diff --git a/src/mesh.cpp b/src/mesh.cpp index af3dd9e..6f30542 100644 --- a/src/mesh.cpp +++ b/src/mesh.cpp @@ -1,57 +1,3 @@ -/* - * $Id: mesh.cpp,v 1.14 2002/07/19 20:08:28 msell Exp $ - * - * - * $Log: mesh.cpp,v $ - * Revision 1.14 2002/07/19 20:08:28 msell - * Linux-porttausta - * - * Revision 1.13 2002/07/15 15:22:08 msell - * Parantelua - * - * Revision 1.12 2002/07/14 21:40:43 msell - * Conflictit pois, liikkumiset (hyppy, kävely, lyönti), uusi areena - * - * Revision 1.11 2002/07/14 21:22:39 jkaarlas - * skybox ja ukkojen säätö - * - * Revision 1.10 2002/07/10 22:22:53 msell - * Cartoon-rendaus - * - * Revision 1.9 2002/07/10 22:10:32 jkaarlas - * skaalatut ja käännellyt ruumiinosat - * - * Revision 1.8 2002/07/10 17:13:44 msell - * Törmäystarkastelun parantelua - * - * Revision 1.7 2002/07/07 17:53:21 msell - * Legoukon alku - * - * Revision 1.6 2002/07/07 15:29:07 msell - * Törmäyksien parantelua - * - * Revision 1.5 2002/07/04 21:05:41 msell - * Se toimii!! =) - * Törmäystarkistukset siis - * - * Revision 1.4 2002/06/30 16:05:04 msell - * Törmäyksien parantelua, transformaatioita mukana - * - * Revision 1.3 2002/06/26 22:30:29 jkaarlas - * lisätty Vertexiin tekstuurikoordinaatit - * - * Revision 1.2 2002/06/24 14:12:15 msell - * Nyt toimii sphere -> mesh -törmäykset, ihan tosi - * - * Revision 1.1 2002/06/20 22:50:12 msell - * Meshit - * - * - * - * $Date: 2002/07/19 20:08:28 $ - * - */ - #include "main.h" #include "mesh.h" @@ -65,19 +11,19 @@ #include "glapi.h" Vertex::Vertex(void){ - vectorSet(position, 0, 0, 0); - vectorSet(normal, 0, 0, 0); + vectorSet(position, 0, 0, 0); + vectorSet(normal, 0, 0, 0); } Vertex::Vertex(float x, float y, float z){ - vectorSet(position, x, y, z); - vectorSet(normal, x, y, z); - vectorNormalize(normal); + vectorSet(position, x, y, z); + vectorSet(normal, x, y, z); + vectorNormalize(normal); } Vertex::Vertex(float x, float y, float z, float nx, float ny, float nz){ - vectorSet(position, x, y, z); - vectorSet(normal, nx, ny, nz); + vectorSet(position, x, y, z); + vectorSet(normal, nx, ny, nz); } void Vertex::setTexCoords(float u, float v){ @@ -86,173 +32,173 @@ void Vertex::setTexCoords(float u, float v){ } Polygon::Polygon(void){ - vertexcount = 0; - edgecount = 0; - smooth = false; - realsmooth = false; + vertexcount = 0; + edgecount = 0; + smooth = false; + realsmooth = false; } Mesh::Mesh(void){ - vertexcount = 0; - polygoncount = 0; - edgecount = 0; + vertexcount = 0; + polygoncount = 0; + edgecount = 0; } Mesh::~Mesh(void){ - delete [] polygons; - delete [] vertices; + delete [] polygons; + delete [] vertices; } void Mesh::createPlanes(void){ - int i; - for (i = 0; i < polygoncount; i++){ - class Polygon *polygon = &this->polygons[i]; - if (polygon->vertexcount >= 3){ - float v1[3], v2[3]; - vectorSub(v1, polygon->vertices[1]->position, - polygon->vertices[0]->position); - vectorSub(v2, polygon->vertices[2]->position, - polygon->vertices[0]->position); - vectorCross(polygon->planenormal, v1, v2); - vectorNormalize(polygon->planenormal); + int i; + for (i = 0; i < polygoncount; i++){ + class Polygon *polygon = &this->polygons[i]; + if (polygon->vertexcount >= 3){ + float v1[3], v2[3]; + vectorSub(v1, polygon->vertices[1]->position, + polygon->vertices[0]->position); + vectorSub(v2, polygon->vertices[2]->position, + polygon->vertices[0]->position); + vectorCross(polygon->planenormal, v1, v2); + vectorNormalize(polygon->planenormal); - polygon->planedistance = -vectorDot(polygon->vertices[0]->position, polygon->planenormal); - } - } + polygon->planedistance = -vectorDot(polygon->vertices[0]->position, polygon->planenormal); + } + } } void Mesh::createVertexnormals(void){ - int i, j, ii; - bool connect; - float normal[3]; - for (i = 0; i < vertexcount; i++){ - bool found = false; - vectorSet(normal, 0, 0, 0); - for (j = 0; j < polygoncount; j++){ - connect = false; - class Polygon *polygon = &polygons[j]; - for (ii = 0;ii < polygon->vertexcount; ii++){ - if (polygons[j].vertices[ii] == &(vertices[i])){ - connect = true; - } - } - if (connect){ - vectorAdd(normal, polygon->planenormal); - found = true; - } - } - if (found){ - vectorNormalize(vertices[i].normal, normal); - } - } - for (j = 0; j < polygoncount; j++){ - class Polygon *polygon = &polygons[j]; - if (!polygon->realsmooth) polygon->smooth = true; - } + int i, j, ii; + bool connect; + float normal[3]; + for (i = 0; i < vertexcount; i++){ + bool found = false; + vectorSet(normal, 0, 0, 0); + for (j = 0; j < polygoncount; j++){ + connect = false; + class Polygon *polygon = &polygons[j]; + for (ii = 0;ii < polygon->vertexcount; ii++){ + if (polygons[j].vertices[ii] == &(vertices[i])){ + connect = true; + } + } + if (connect){ + vectorAdd(normal, polygon->planenormal); + found = true; + } + } + if (found){ + vectorNormalize(vertices[i].normal, normal); + } + } + for (j = 0; j < polygoncount; j++){ + class Polygon *polygon = &polygons[j]; + if (!polygon->realsmooth) polygon->smooth = true; + } } void Mesh::createEdges(void){ - int maxedgecount = 0; - int i; - for (i = 0; i < polygoncount; i++){ - class Polygon *polygon = &polygons[i]; - maxedgecount += polygon->vertexcount; - } + int maxedgecount = 0; + int i; + for (i = 0; i < polygoncount; i++){ + class Polygon *polygon = &polygons[i]; + maxedgecount += polygon->vertexcount; + } - edgecount = 0; - int j, k; - Edge *edges = new Edge[maxedgecount]; - for (i = 0; i < polygoncount; i++){ - class Polygon *polygon = &polygons[i]; - polygon->edges = new Edge *[polygon->vertexcount]; - for (j = 1; j <= polygon->vertexcount; j++){ - Vertex *v1 = polygon->vertices[j-1]; - Vertex *v2 = polygon->vertices[j%polygon->vertexcount]; + edgecount = 0; + int j, k; + Edge *edges = new Edge[maxedgecount]; + for (i = 0; i < polygoncount; i++){ + class Polygon *polygon = &polygons[i]; + polygon->edges = new Edge *[polygon->vertexcount]; + for (j = 1; j <= polygon->vertexcount; j++){ + Vertex *v1 = polygon->vertices[j-1]; + Vertex *v2 = polygon->vertices[j%polygon->vertexcount]; - bool found = false; - for (k = 0; k < edgecount; k++){ - if (edges[k].v2 == v1 && edges[k].v1 == v2){ - found = true; - edges[k].p2 = polygon; - break; - } - } + bool found = false; + for (k = 0; k < edgecount; k++){ + if (edges[k].v2 == v1 && edges[k].v1 == v2){ + found = true; + edges[k].p2 = polygon; + break; + } + } - if (!found){ - edges[edgecount].v1 = v1; - edges[edgecount].v2 = v2; - edges[edgecount].p1 = polygon; - edges[edgecount].p2 = NULL; - edgecount++; - } - } - } + if (!found){ + edges[edgecount].v1 = v1; + edges[edgecount].v2 = v2; + edges[edgecount].p1 = polygon; + edges[edgecount].p2 = NULL; + edgecount++; + } + } + } - this->edges = new Edge[edgecount]; - //printf("%i\n", edgecount); - for (i = 0; i < edgecount; i++){ - this->edges[i].v1 = edges[i].v1; - this->edges[i].v2 = edges[i].v2; - this->edges[i].p1 = edges[i].p1; - this->edges[i].p2 = edges[i].p2; + this->edges = new Edge[edgecount]; + //printf("%i\n", edgecount); + for (i = 0; i < edgecount; i++){ + this->edges[i].v1 = edges[i].v1; + this->edges[i].v2 = edges[i].v2; + this->edges[i].p1 = edges[i].p1; + this->edges[i].p2 = edges[i].p2; - class Polygon *p; - p = edges[i].p1; - p->edges[p->edgecount++] = &this->edges[i]; - p = edges[i].p2; - p->edges[p->edgecount++] = &this->edges[i]; - //printf("%p, %p\n", edges[i].p1, edges[i].p2); - } - - delete[] edges; + class Polygon *p; + p = edges[i].p1; + p->edges[p->edgecount++] = &this->edges[i]; + p = edges[i].p2; + p->edges[p->edgecount++] = &this->edges[i]; + //printf("%p, %p\n", edges[i].p1, edges[i].p2); + } + + delete[] edges; } float Mesh::calculateScale(float targetLength, int axis){ - float min = 0.0; - float max = 0.0; + float min = 0.0; + float max = 0.0; - for (int i=0; i < this->vertexcount; i++){ - if (this->vertices->position[axis] > max){ - max = this->vertices->position[axis]; - } - if (this->vertices->position[axis] < min){ - min = this->vertices->position[axis]; - } - } - return fabs(targetLength / (max - min)); + for (int i=0; i < this->vertexcount; i++){ + if (this->vertices->position[axis] > max){ + max = this->vertices->position[axis]; + } + if (this->vertices->position[axis] < min){ + min = this->vertices->position[axis]; + } + } + return fabs(targetLength / (max - min)); } /* ei toimi kunnolla kaikille objekteille (kädet ok, jalat ja torso ei) */ void Mesh::scale(float targetLength, int axis){ - float newscale = this->calculateScale(targetLength, axis); - this->scale(newscale); + float newscale = this->calculateScale(targetLength, axis); + this->scale(newscale); } /* ei toimi kunnolla kaikille objekteille (kädet ok, jalat ja torso ei)*/ void Mesh::scale(float scale){ - for (int i=0; i < this->vertexcount; i++){ - this->vertices->position[0] *= scale; - this->vertices->position[1] *= scale; - this->vertices->position[2] *= scale; - } - this->createVertexnormals(); - this->createPlanes(); + for (int i=0; i < this->vertexcount; i++){ + this->vertices->position[0] *= scale; + this->vertices->position[1] *= scale; + this->vertices->position[2] *= scale; + } + this->createVertexnormals(); + this->createPlanes(); } MeshObject::MeshObject(Mesh *mesh){ - this->mesh = mesh; - this->appearance = new MeshAppearance(mesh); - this->geometry = new MeshShape(this); + this->mesh = mesh; + this->appearance = new MeshAppearance(mesh); + this->geometry = new MeshShape(this); } MeshAppearance::MeshAppearance(Mesh *mesh){ - this->mesh = mesh; + this->mesh = mesh; } @@ -262,41 +208,41 @@ void MeshAppearance::draw(void){ glColor4fv(this->material.getColor()); this->material.enable(); - int i, j; - - for (i = 0; i < mesh->polygoncount; i++){ - class Polygon *polygon = &mesh->polygons[i]; - - glBegin(GL_TRIANGLE_FAN); + int i, j; - if (!polygon->smooth) glNormal3fv(polygon->planenormal); + for (i = 0; i < mesh->polygoncount; i++){ + class Polygon *polygon = &mesh->polygons[i]; - for (j = 0; j < polygon->vertexcount; j++){ - Vertex *vertex = polygon->vertices[j]; + glBegin(GL_TRIANGLE_FAN); - if (polygon->smooth) glNormal3fv(vertex->normal); - glVertex3fv(vertex->position); + if (!polygon->smooth) glNormal3fv(polygon->planenormal); - } + for (j = 0; j < polygon->vertexcount; j++){ + Vertex *vertex = polygon->vertices[j]; + + if (polygon->smooth) glNormal3fv(vertex->normal); + glVertex3fv(vertex->position); + + } - glEnd(); - } + glEnd(); + } - glDisable(GL_DEPTH); - glDisable(GL_LIGHTING); + glDisable(GL_DEPTH); + glDisable(GL_LIGHTING); glLineWidth(5.0); - glBegin(GL_LINES); - for (i = 0; i < mesh->edgecount; i++){ - glColor3f(0, 0, 0); - glVertex3fv(mesh->edges[i].v1->position); - glVertex3fv(mesh->edges[i].v2->position); - } + glBegin(GL_LINES); + for (i = 0; i < mesh->edgecount; i++){ + glColor3f(0, 0, 0); + glVertex3fv(mesh->edges[i].v1->position); + glVertex3fv(mesh->edges[i].v2->position); + } - glEnd(); - glEnable(GL_LIGHTING); - glEnable(GL_DEPTH); + glEnd(); + glEnable(GL_LIGHTING); + glEnable(GL_DEPTH); this->material.disable(); @@ -309,125 +255,125 @@ void MeshAppearance::draw(void){ MeshShape::MeshShape(MeshObject *object) : Shape(object){ - mesh = object->mesh; + mesh = object->mesh; } MeshShape::MeshShape(Object *object, Mesh *mesh) : Shape(object){ - this->mesh = mesh; + this->mesh = mesh; } bool MeshShape::checkCollision(Object *target){ - return target->geometry->checkCollisionPeer(this); + return target->geometry->checkCollisionPeer(this); } float MeshShape::calculateMomentOfInertia(float *rotationvector){ - if (vectorDot(rotationvector, rotationvector) < EPSILON) return 0; - int i; - float j = 0; - for (i = 0; i < mesh->vertexcount; i++){ - float proj[3]; - vectorProject(proj, mesh->vertices[i].position, rotationvector); - vectorSub(proj, mesh->vertices[i].position, proj); - //float r = vectorLength(proj); - float r2 = vectorDot(proj, proj); - j += r2; - } - return j / i; + if (vectorDot(rotationvector, rotationvector) < EPSILON) return 0; + int i; + float j = 0; + for (i = 0; i < mesh->vertexcount; i++){ + float proj[3]; + vectorProject(proj, mesh->vertices[i].position, rotationvector); + vectorSub(proj, mesh->vertices[i].position, proj); + //float r = vectorLength(proj); + float r2 = vectorDot(proj, proj); + j += r2; + } + return j / i; } bool MeshShape::checkCollisionPeer(SphereShape *target){ - float position[3] = {0, 0, 0}; - target->object->transformPoint(position, position); - object->unTransformPoint(position, position); + float position[3] = {0, 0, 0}; + target->object->transformPoint(position, position); + object->unTransformPoint(position, position); - float normal[3]; - float contactpoint[3]; - float r = target->getRadius(); + float normal[3]; + float contactpoint[3]; + float r = target->getRadius(); - if (checkSphereMeshCollision(position, r, mesh, normal, contactpoint)){ - vectorScale(normal, -1); - object->transformVector(normal, normal); - object->transformPoint(contactpoint, contactpoint); + if (checkSphereMeshCollision(position, r, mesh, normal, contactpoint)){ + vectorScale(normal, -1); + object->transformVector(normal, normal); + object->transformPoint(contactpoint, contactpoint); - addCollision(object, target->object, normal, contactpoint); + addCollision(object, target->object, normal, contactpoint); - //vectorAdd(contactnormal, normal); + //vectorAdd(contactnormal, normal); - return true; - } + return true; + } - return false; + return false; } //extern Sound *shotsound; bool MeshShape::checkCollisionPeer(MeshShape *target){ - float normal[3]; - float contactpoint[3]; + float normal[3]; + float contactpoint[3]; - bool collided = false; + bool collided = false; - int i; + int i; - Mesh *sourcemesh, *targetmesh; - - sourcemesh = this->mesh; - targetmesh = target->mesh; - for (i = 0; i < sourcemesh->vertexcount; i++){ - Vertex *vertex = &sourcemesh->vertices[i]; - float vertexposition[3]; - object->transformPoint(vertexposition, vertex->position); - target->object->unTransformPoint(vertexposition, vertexposition); + Mesh *sourcemesh, *targetmesh; - if (checkPointMeshCollision(vertexposition, targetmesh, normal, contactpoint)){ - target->object->transformVector(normal, normal); - target->object->transformPoint(contactpoint, contactpoint); + sourcemesh = this->mesh; + targetmesh = target->mesh; + for (i = 0; i < sourcemesh->vertexcount; i++){ + Vertex *vertex = &sourcemesh->vertices[i]; + float vertexposition[3]; + object->transformPoint(vertexposition, vertex->position); + target->object->unTransformPoint(vertexposition, vertexposition); - if (vectorIsZero(contactpoint)){ - vectorSet(contactpoint, 0, 0, 0); - } - addCollision(object, target->object, normal, contactpoint); - collided = true; - } - } + if (checkPointMeshCollision(vertexposition, targetmesh, normal, contactpoint)){ + target->object->transformVector(normal, normal); + target->object->transformPoint(contactpoint, contactpoint); - sourcemesh = target->mesh; - targetmesh = this->mesh; - for (i = 0; i < sourcemesh->vertexcount; i++){ - Vertex *vertex = &sourcemesh->vertices[i]; - float vertexposition[3]; - target->object->transformPoint(vertexposition, vertex->position); - object->unTransformPoint(vertexposition, vertexposition); + if (vectorIsZero(contactpoint)){ + vectorSet(contactpoint, 0, 0, 0); + } + addCollision(object, target->object, normal, contactpoint); + collided = true; + } + } - if (checkPointMeshCollision(vertexposition, targetmesh, normal, contactpoint)){ - object->transformVector(normal, normal); - object->transformPoint(contactpoint, contactpoint); + sourcemesh = target->mesh; + targetmesh = this->mesh; + for (i = 0; i < sourcemesh->vertexcount; i++){ + Vertex *vertex = &sourcemesh->vertices[i]; + float vertexposition[3]; + target->object->transformPoint(vertexposition, vertex->position); + object->unTransformPoint(vertexposition, vertexposition); - addCollision(target->object, object, normal, contactpoint); - collided = true; - } - } + if (checkPointMeshCollision(vertexposition, targetmesh, normal, contactpoint)){ + object->transformVector(normal, normal); + object->transformPoint(contactpoint, contactpoint); - sourcemesh = this->mesh; - targetmesh = target->mesh; - for (i = 0; i < sourcemesh->edgecount; i++){ - Edge *edge = &sourcemesh->edges[i]; - float v1[3], v2[3]; - object->transformPoint(v1, edge->v1->position); - target->object->unTransformPoint(v1, v1); + addCollision(target->object, object, normal, contactpoint); + collided = true; + } + } - object->transformPoint(v2, edge->v2->position); - target->object->unTransformPoint(v2, v2); + sourcemesh = this->mesh; + targetmesh = target->mesh; + for (i = 0; i < sourcemesh->edgecount; i++){ + Edge *edge = &sourcemesh->edges[i]; + float v1[3], v2[3]; + object->transformPoint(v1, edge->v1->position); + target->object->unTransformPoint(v1, v1); - if (checkEdgeMeshCollision(v1, v2, targetmesh, normal, contactpoint)){ - target->object->transformVector(normal, normal); - target->object->transformPoint(contactpoint, contactpoint); + object->transformPoint(v2, edge->v2->position); + target->object->unTransformPoint(v2, v2); - addCollision(object, target->object, normal, contactpoint); - collided = true; - } - } + if (checkEdgeMeshCollision(v1, v2, targetmesh, normal, contactpoint)){ + target->object->transformVector(normal, normal); + target->object->transformPoint(contactpoint, contactpoint); - return collided; + addCollision(object, target->object, normal, contactpoint); + collided = true; + } + } + + return collided; } diff --git a/src/mesh.h b/src/mesh.h index 0ae56d9..7750fd2 100644 --- a/src/mesh.h +++ b/src/mesh.h @@ -1,51 +1,3 @@ -/* - * $Id: mesh.h,v 1.12 2002/07/19 20:33:28 msell Exp $ - * - * - * $Log: mesh.h,v $ - * Revision 1.12 2002/07/19 20:33:28 msell - * #pragma once -> #ifndef - * - * Revision 1.11 2002/07/19 20:08:28 msell - * Linux-porttausta - * - * Revision 1.10 2002/07/17 20:32:47 msell - * Detail-optio toimii - * - * Revision 1.9 2002/07/15 15:22:08 msell - * Parantelua - * - * Revision 1.8 2002/07/14 21:22:39 jkaarlas - * skybox ja ukkojen säätö - * - * Revision 1.7 2002/07/10 17:13:44 msell - * Törmäystarkastelun parantelua - * - * Revision 1.6 2002/07/07 17:53:21 msell - * Legoukon alku - * - * Revision 1.5 2002/07/04 21:05:41 msell - * Se toimii!! =) - * Törmäystarkistukset siis - * - * Revision 1.4 2002/06/30 16:05:04 msell - * Törmäyksien parantelua, transformaatioita mukana - * - * Revision 1.3 2002/06/26 22:30:29 jkaarlas - * lisätty Vertexiin tekstuurikoordinaatit - * - * Revision 1.2 2002/06/24 14:12:15 msell - * Nyt toimii sphere -> mesh -törmäykset, ihan tosi - * - * Revision 1.1 2002/06/20 22:50:12 msell - * Meshit - * - * - * - * $Date: 2002/07/19 20:33:28 $ - * - */ - #ifndef __MESH_H_INCLUDED__ #define __MESH_H_INCLUDED__ @@ -59,16 +11,16 @@ class Vertex{ public: - float position[3]; - float oldposition[3]; - float normal[3]; + float position[3]; + float oldposition[3]; + float normal[3]; float texcoords[2]; - Vertex(void); - Vertex(float x, float y, float z); - Vertex(float x, float y, float z, float nx, float ny, float nz); - - void setTexCoords(float u, float v); + Vertex(void); + Vertex(float x, float y, float z); + Vertex(float x, float y, float z, float nx, float ny, float nz); + + void setTexCoords(float u, float v); }; @@ -76,49 +28,49 @@ class Edge; class Polygon{ public: - float planenormal[3]; - float planedistance; - bool smooth; - bool realsmooth; + float planenormal[3]; + float planedistance; + bool smooth; + bool realsmooth; - int vertexcount; - Vertex **vertices; - int edgecount; - Edge **edges; + int vertexcount; + Vertex **vertices; + int edgecount; + Edge **edges; - Polygon(void); + Polygon(void); }; class Edge{ public: - Vertex *v1, *v2; - class Polygon *p1, *p2; + Vertex *v1, *v2; + class Polygon *p1, *p2; }; class Mesh{ public: - int vertexcount; - Vertex *vertices; + int vertexcount; + Vertex *vertices; - int polygoncount; - class Polygon *polygons; + int polygoncount; + class Polygon *polygons; - Edge *edges; - int edgecount; + Edge *edges; + int edgecount; - Mesh(void); - ~Mesh(void); + Mesh(void); + ~Mesh(void); - void createPlanes(void); - void createVertexnormals(void); - void createEdges(void); - float calculateScale(float targetLength, int axis); - void scale(float targetLength, int axis); + void createPlanes(void); + void createVertexnormals(void); + void createEdges(void); + float calculateScale(float targetLength, int axis); + void scale(float targetLength, int axis); void scale(float scale); }; @@ -126,21 +78,21 @@ public: class MeshObject : public Object{ public: - Mesh *mesh; + Mesh *mesh; - MeshObject(Mesh *mesh); + MeshObject(Mesh *mesh); }; class MeshAppearance : public Appearance{ private: - Mesh *mesh; + Mesh *mesh; public: - MeshAppearance(Mesh *mesh); + MeshAppearance(Mesh *mesh); - void draw(void); + void draw(void); }; @@ -149,20 +101,20 @@ public: class MeshShape : public Shape{ private: - Mesh *mesh; + Mesh *mesh; public: - MeshShape(MeshObject *meshobject); - MeshShape(Object *object, Mesh *mesh); + MeshShape(MeshObject *meshobject); + MeshShape(Object *object, Mesh *mesh); - float calculateMomentOfInertia(float *rotationvector); + float calculateMomentOfInertia(float *rotationvector); - bool checkCollision(Object *target); + bool checkCollision(Object *target); - bool checkCollisionPeer(SphereShape *target); - bool checkCollisionPeer(MeshShape *target); + bool checkCollisionPeer(SphereShape *target); + bool checkCollisionPeer(MeshShape *target); - friend class SphereShape; + friend class SphereShape; }; #endif diff --git a/src/object.cpp b/src/object.cpp index 497541b..f26f0a2 100644 --- a/src/object.cpp +++ b/src/object.cpp @@ -1,82 +1,3 @@ -/* - * $Id: object.cpp,v 1.22 2002/07/18 23:05:31 msell Exp $ - * - * - * $Log: object.cpp,v $ - * Revision 1.22 2002/07/18 23:05:31 msell - * Partikkelit ja kakkospelaajan liike - * - * Revision 1.21 2002/07/17 22:45:54 msell - * Ääniä vähän - * - * Revision 1.20 2002/07/15 15:22:08 msell - * Parantelua - * - * Revision 1.19 2002/07/14 21:40:43 msell - * Conflictit pois, liikkumiset (hyppy, kävely, lyönti), uusi areena - * - * Revision 1.18 2002/07/14 21:22:39 jkaarlas - * skybox ja ukkojen säätö - * - * Revision 1.17 2002/07/07 15:29:07 msell - * Törmäyksien parantelua - * - * Revision 1.16 2002/07/04 21:05:41 msell - * Se toimii!! =) - * Törmäystarkistukset siis - * - * Revision 1.15 2002/06/30 16:05:04 msell - * Törmäyksien parantelua, transformaatioita mukana - * - * Revision 1.14 2002/06/27 14:39:48 msell - * Toimiva maila :) - * Pyörivät kappaleet siis antaa liike-energiaa liikkuville kappaleille (ei toisin päin vielä) - * - * Revision 1.13 2002/06/27 00:08:04 msell - * Kimmotukset palloille myös pyöritettyihin mesheihin - * - * Revision 1.12 2002/06/24 14:12:15 msell - * Nyt toimii sphere -> mesh -törmäykset, ihan tosi - * - * Revision 1.11 2002/06/17 20:49:05 msell - * free -> SDL_FreeSurface - * - * Revision 1.10 2002/06/16 01:04:58 jkaarlas - * tulipa säädettyä includejen kanssa. oon tod.näk. eri mieltä aamulla - * - * Revision 1.9 2002/06/15 17:18:37 msell - * Toimiva törmäystarkastus kiinteille laatikoille - * - * Revision 1.8 2002/06/14 00:05:05 msell - * Törmäyssimulaatio kunnossa toivon mukaan - * - * Revision 1.7 2002/06/11 23:11:45 msell - * Törmäystarkistusta - * - * Revision 1.6 2002/06/07 21:16:51 msell - * Fysiikkaenginen alkua - * - * Revision 1.5 2002/06/05 18:39:05 msell - * Jotain pientä - * - * Revision 1.4 2002/06/05 15:00:41 msell - * Palikoihin lisää detailia, facet jaetaan halutun kokosiin osiin - * - * Revision 1.3 2002/06/03 23:20:43 msell - * no message - * - * Revision 1.2 2002/06/03 23:06:38 msell - * no message - * - * Revision 1.1 2002/06/02 16:57:37 msell - * Objektirakenteen pohja - * - * - * - * $Date: 2002/07/18 23:05:31 $ - * - */ - #include "main.h" #include @@ -89,204 +10,204 @@ #include "glapi.h" Object::Object(void){ - appearance = NULL; - geometry = NULL; - invmass = 0.0; - setPosition(0, 0, 0); - vectorSet(momentum, 0, 0, 0); + appearance = NULL; + geometry = NULL; + invmass = 0.0; + setPosition(0, 0, 0); + vectorSet(momentum, 0, 0, 0); - invmomentofinertia = 0.0; - matrixIdentity(rotation); - vectorSet(angularmomentum, 0, 0, 0); + invmomentofinertia = 0.0; + matrixIdentity(rotation); + vectorSet(angularmomentum, 0, 0, 0); - setCollisionGroup(COLLISIONGROUP_NONE); - gravity = false; + setCollisionGroup(COLLISIONGROUP_NONE); + gravity = false; } void Object::prepare(void){ - if (appearance != NULL) appearance->prepare(); + if (appearance != NULL) appearance->prepare(); } #define DT 0.01 void Object::move(void){ - moveStep(DT); + moveStep(DT); } void Object::moveStep(float dt){ - if (invmass == 0) return; + if (invmass == 0) return; - if (vectorDot(momentum, momentum) > 1.0e+5) vectorSet(momentum, 0, 0, 0); - if (vectorDot(angularmomentum, angularmomentum) > 1.0e+5) vectorSet(angularmomentum, 0, 0, 0); - calculateStateVariables(); + if (vectorDot(momentum, momentum) > 1.0e+5) vectorSet(momentum, 0, 0, 0); + if (vectorDot(angularmomentum, angularmomentum) > 1.0e+5) vectorSet(angularmomentum, 0, 0, 0); + calculateStateVariables(); - - float velocitydt[3]; - vectorScale(velocitydt, velocity, dt); - vectorAdd(position, velocitydt); - float rotationdt[9]; - if (vectorIsZero(angularmomentum)){ - matrixIdentity(rotationdt); - } else{ - float angularvelocitydt[3]; - vectorScale(angularvelocitydt, angularvelocity, dt); - matrixCreateRotation(rotationdt, angularvelocitydt); - } - matrixMultiply(rotation, rotation, rotationdt); + float velocitydt[3]; + vectorScale(velocitydt, velocity, dt); + vectorAdd(position, velocitydt); - vectorScale(angularmomentum, 0.99); + float rotationdt[9]; + if (vectorIsZero(angularmomentum)){ + matrixIdentity(rotationdt); + } else{ + float angularvelocitydt[3]; + vectorScale(angularvelocitydt, angularvelocity, dt); + matrixCreateRotation(rotationdt, angularvelocitydt); + } + matrixMultiply(rotation, rotation, rotationdt); + + vectorScale(angularmomentum, 0.99); } void Object::calculateStateVariables(void){ - getVelocity(velocity); + getVelocity(velocity); - if (vectorIsZero(angularmomentum)){ - invmomentofinertia = 0; - } else{ - invmomentofinertia = invmass * 1.0 / geometry->calculateMomentOfInertia(angularmomentum); - } + if (vectorIsZero(angularmomentum)){ + invmomentofinertia = 0; + } else{ + invmomentofinertia = invmass * 1.0 / geometry->calculateMomentOfInertia(angularmomentum); + } - vectorScale(angularvelocity, angularmomentum, invmomentofinertia); + vectorScale(angularvelocity, angularmomentum, invmomentofinertia); } void Object::setPosition(float x, float y, float z){ - position[0] = x; - position[1] = y; - position[2] = z; + position[0] = x; + position[1] = y; + position[2] = z; } void Object::getPosition(float *position){ - vectorCopy(position, this->position); + vectorCopy(position, this->position); } void Object::getVelocity(float *velocity){ - vectorCopy(velocity, momentum); - vectorScale(velocity, invmass); + vectorCopy(velocity, momentum); + vectorScale(velocity, invmass); } void Object::getVelocity(float *velocity, float *point){ - getVelocity(velocity); + getVelocity(velocity); - float tangentialvelocity[3]; - getTangentialVelocity(tangentialvelocity, point); - //float tv[3]; - //transformVector(tv, tangentialvelocity); - vectorAdd(velocity, tangentialvelocity); + float tangentialvelocity[3]; + getTangentialVelocity(tangentialvelocity, point); + //float tv[3]; + //transformVector(tv, tangentialvelocity); + vectorAdd(velocity, tangentialvelocity); } void Object::getTangentialVelocity(float *target, float *point){ - if (vectorIsZero(angularmomentum)){ - vectorSet(target, 0, 0, 0); - return; - } + if (vectorIsZero(angularmomentum)){ + vectorSet(target, 0, 0, 0); + return; + } - vectorCross(target, angularmomentum, point); - vectorScale(target, invmomentofinertia); + vectorCross(target, angularmomentum, point); + vectorScale(target, invmomentofinertia); } void Object::getMomentum(float *momentum){ - vectorCopy(momentum, this->momentum); + vectorCopy(momentum, this->momentum); } void Object::setMass(float mass){ - if (mass == 0) this->invmass = 0; - else this->invmass = 1.0 / mass; + if (mass == 0) this->invmass = 0; + else this->invmass = 1.0 / mass; } float Object::getMass(void){ - if (invmass == 0) return 0; - return 1.0 / invmass; + if (invmass == 0) return 0; + return 1.0 / invmass; } void Object::setCollisionGroup(int group){ - this->collisiongroup = group; + this->collisiongroup = group; } int Object::getCollisionGroup(void){ - return collisiongroup; + return collisiongroup; } void Object::addImpulse(float *impulse, float *contactpoint){ - if (invmass == 0) return; - float angularimpulse[3]; - vectorCross(angularimpulse, contactpoint, impulse); - vectorAdd(angularmomentum, angularimpulse); + if (invmass == 0) return; + float angularimpulse[3]; + vectorCross(angularimpulse, contactpoint, impulse); + vectorAdd(angularmomentum, angularimpulse); - vectorAdd(momentum, impulse); + vectorAdd(momentum, impulse); - float t1[3], t2[3]; - vectorAdd(t1, contactpoint, position); - vectorNormalize(t2, impulse); - vectorAdd(t2, t1); + float t1[3], t2[3]; + vectorAdd(t1, contactpoint, position); + vectorNormalize(t2, impulse); + vectorAdd(t2, t1); - //addGraphicsVector(t1, t2, vectorLength(impulse)); + //addGraphicsVector(t1, t2, vectorLength(impulse)); } void Object::addExternalForce(float *force){ - float impulse[3]; - vectorScale(impulse, force, DT); + float impulse[3]; + vectorScale(impulse, force, DT); - float contact[3] = {0, 0, 0}; - this->addImpulse(impulse, contact); + float contact[3] = {0, 0, 0}; + this->addImpulse(impulse, contact); } void Object::transformPoint(float *newpoint, float *oldpoint){ - vectorMatrixMultiply(newpoint, oldpoint, rotation); - vectorAdd(newpoint, position); + vectorMatrixMultiply(newpoint, oldpoint, rotation); + vectorAdd(newpoint, position); } void Object::unTransformPoint(float *newpoint, float *oldpoint){ - vectorSub(newpoint, oldpoint, position); - float rotmat[9]; - matrixTranspose(rotmat, rotation); - vectorMatrixMultiply(newpoint, newpoint, rotmat); + vectorSub(newpoint, oldpoint, position); + float rotmat[9]; + matrixTranspose(rotmat, rotation); + vectorMatrixMultiply(newpoint, newpoint, rotmat); } void Object::transformVector(float *newvector, float *oldvector){ - vectorMatrixMultiply(newvector, oldvector, rotation); + vectorMatrixMultiply(newvector, oldvector, rotation); } void Object::unTransformVector(float *newvector, float *oldvector){ - float rotmat[9]; - matrixTranspose(rotmat, rotation); - vectorMatrixMultiply(newvector, oldvector, rotmat); + float rotmat[9]; + matrixTranspose(rotmat, rotation); + vectorMatrixMultiply(newvector, oldvector, rotmat); } void Object::hitForce(float speed, float *speed2, Object *source){ - float tolerance = 1.0; - if (speed > tolerance){ - Sound *sound; - if (rand()&1) sound = softhitsound1; - else sound = softhitsound2; - float volume = (speed-tolerance)*2; - if (volume > 1) volume = 1; - sound->setVolume(volume); - sound->play(30 + random(70)); - } + float tolerance = 1.0; + if (speed > tolerance){ + Sound *sound; + if (rand()&1) sound = softhitsound1; + else sound = softhitsound2; + float volume = (speed-tolerance)*2; + if (volume > 1) volume = 1; + sound->setVolume(volume); + sound->play(30 + random(70)); + } } void Object::setGravity(bool enabled){ - gravity = enabled; + gravity = enabled; } void Object::draw(void){ - glPushMatrix(); - glTranslatef(position[0], position[1], position[2]); - - GLfloat glmatrix[16] = { - rotation[0], rotation[1], rotation[2], 0, - rotation[3], rotation[4], rotation[5], 0, - rotation[6], rotation[7], rotation[8], 0, - 0 , 0 , 0 , 1}; - glMultMatrixf(glmatrix); + glPushMatrix(); + glTranslatef(position[0], position[1], position[2]); - if (appearance != NULL) appearance->draw(); + GLfloat glmatrix[16] = { + rotation[0], rotation[1], rotation[2], 0, + rotation[3], rotation[4], rotation[5], 0, + rotation[6], rotation[7], rotation[8], 0, + 0 , 0 , 0 , 1}; + glMultMatrixf(glmatrix); - glPopMatrix(); + if (appearance != NULL) appearance->draw(); + + glPopMatrix(); } diff --git a/src/object.h b/src/object.h index abef27e..31f95be 100644 --- a/src/object.h +++ b/src/object.h @@ -1,76 +1,3 @@ -/* - * $Id: object.h,v 1.20 2002/07/19 20:33:28 msell Exp $ - * - * - * $Log: object.h,v $ - * Revision 1.20 2002/07/19 20:33:28 msell - * #pragma once -> #ifndef - * - * Revision 1.19 2002/07/18 23:05:31 msell - * Partikkelit ja kakkospelaajan liike - * - * Revision 1.18 2002/07/17 22:45:54 msell - * Ääniä vähän - * - * Revision 1.17 2002/07/14 21:40:43 msell - * Conflictit pois, liikkumiset (hyppy, kävely, lyönti), uusi areena - * - * Revision 1.16 2002/07/07 23:05:22 msell - * Osien liimaaminen toisiinsa (kesken) - * - * Revision 1.15 2002/07/04 21:05:41 msell - * Se toimii!! =) - * Törmäystarkistukset siis - * - * Revision 1.14 2002/06/30 16:05:04 msell - * Törmäyksien parantelua, transformaatioita mukana - * - * Revision 1.13 2002/06/27 14:39:48 msell - * Toimiva maila :) - * Pyörivät kappaleet siis antaa liike-energiaa liikkuville kappaleille (ei toisin päin vielä) - * - * Revision 1.12 2002/06/27 00:08:04 msell - * Kimmotukset palloille myös pyöritettyihin mesheihin - * - * Revision 1.11 2002/06/24 14:12:15 msell - * Nyt toimii sphere -> mesh -törmäykset, ihan tosi - * - * Revision 1.10 2002/06/15 22:56:37 msell - * Säätöä - * - * Revision 1.9 2002/06/14 00:05:05 msell - * Törmäyssimulaatio kunnossa toivon mukaan - * - * Revision 1.8 2002/06/11 23:11:45 msell - * Törmäystarkistusta - * - * Revision 1.7 2002/06/07 21:16:51 msell - * Fysiikkaenginen alkua - * - * Revision 1.6 2002/06/05 18:39:05 msell - * Jotain pientä - * - * Revision 1.5 2002/06/05 15:00:41 msell - * Palikoihin lisää detailia, facet jaetaan halutun kokosiin osiin - * - * Revision 1.4 2002/06/04 16:28:32 msell - * #pragma once - * - * Revision 1.3 2002/06/03 23:20:43 msell - * no message - * - * Revision 1.2 2002/06/03 23:06:38 msell - * no message - * - * Revision 1.1 2002/06/02 16:57:37 msell - * Objektirakenteen pohja - * - * - * - * $Date: 2002/07/19 20:33:28 $ - * - */ - #ifndef __OBJECT_H_INCLUDED__ #define __OBJECT_H_INCLUDED__ @@ -84,135 +11,135 @@ class Object; #include "appearance.h" struct objectlist{ - Object *object; - objectlist *next; + Object *object; + objectlist *next; }; class Object{ public: - float invmass; + float invmass; - /* Linear movement: - * position <-> paikka (x) - * velocity <-> nopeus (v) - * momentum <-> liikemäärä (p) - * force <-> voima (F) - * x' = v - * p' = F - * p = mv - * F = ma - * v' = a - */ + /* Linear movement: + * position <-> paikka (x) + * velocity <-> nopeus (v) + * momentum <-> liikemäärä (p) + * force <-> voima (F) + * x' = v + * p' = F + * p = mv + * F = ma + * v' = a + */ - float position[3]; - //derivative: velocity = momentum / mass + float position[3]; + //derivative: velocity = momentum / mass - float momentum[3];//, oldmomentum[3]; - //derivative: force + float momentum[3];//, oldmomentum[3]; + //derivative: force - //float force[3]; //Temporary properties - //float externalforce[3]; + //float force[3]; //Temporary properties + //float externalforce[3]; - /* Angular movement: - * rotation <-> orientaatio (R) - * angular velocity <-> kulmanopeus (w) - * angular momentum <-> pyörimisliikemäärä, vääntömomentti (L) - * torque <-> voiman momentti (M,T) - * moment of inertia <-> hitausmomentti (J,I) - * angular acceleration <-> kulmakiihtyvyys (a) - * L = J*w - * R' = Star(L) * R - * T = J*a - * w' = a - * L' = T - */ + /* Angular movement: + * rotation <-> orientaatio (R) + * angular velocity <-> kulmanopeus (w) + * angular momentum <-> pyörimisliikemäärä, vääntömomentti (L) + * torque <-> voiman momentti (M,T) + * moment of inertia <-> hitausmomentti (J,I) + * angular acceleration <-> kulmakiihtyvyys (a) + * L = J*w + * R' = Star(L) * R + * T = J*a + * w' = a + * L' = T + */ - float invmomentofinertia; + float invmomentofinertia; - float rotation[9]; - //derivative: StarOperation(angularvelocity) * rotation + float rotation[9]; + //derivative: StarOperation(angularvelocity) * rotation - float angularmomentum[3]; - //angular momentum = angular velocity * moment of inertia - //derivative: torque = angular acceleration * moment of inertia + float angularmomentum[3]; + //angular momentum = angular velocity * moment of inertia + //derivative: torque = angular acceleration * moment of inertia - //float torque[3]; //Temporary property + //float torque[3]; //Temporary property - void moveStep(float dt); - //void applyForces(float dt); + void moveStep(float dt); + //void applyForces(float dt); - void calculateStateVariables(void); + void calculateStateVariables(void); - int collisiongroup; + int collisiongroup; - void addImpulse(float *impulse, float *contactpoint); + void addImpulse(float *impulse, float *contactpoint); - Appearance *appearance; - Shape *geometry; + Appearance *appearance; + Shape *geometry; - bool gravity; + bool gravity; - Object(void); + Object(void); - virtual void prepare(void); - virtual void move(void); - virtual void draw(void); + virtual void prepare(void); + virtual void move(void); + virtual void draw(void); - void setPosition(float x, float y, float z); - void getPosition(float *position); + void setPosition(float x, float y, float z); + void getPosition(float *position); - //Gets velocity from object and return it in "velocity" - void getVelocity(float *velocity); + //Gets velocity from object and return it in "velocity" + void getVelocity(float *velocity); - //Gets velocity from object for point "point" with - //tangential speed and return it in "velocity" - void getVelocity(float *velocity, float *point); + //Gets velocity from object for point "point" with + //tangential speed and return it in "velocity" + void getVelocity(float *velocity, float *point); - void getTangentialVelocity(float *target, float *point); + void getTangentialVelocity(float *target, float *point); - void getMomentum(float *momentum); - //void getForce(float *force); - void setMass(float mass); - float getMass(void); - void setCollisionGroup(int group); - int getCollisionGroup(void); + void getMomentum(float *momentum); + //void getForce(float *force); + void setMass(float mass); + float getMass(void); + void setCollisionGroup(int group); + int getCollisionGroup(void); - void transformPoint(float *newpoint, float *oldpoint); - void unTransformPoint(float *newpoint, float *oldpoint); - void transformVector(float *newvector, float *oldvector); - void unTransformVector(float *newvector, float *oldvector); + void transformPoint(float *newpoint, float *oldpoint); + void unTransformPoint(float *newpoint, float *oldpoint); + void transformVector(float *newvector, float *oldvector); + void unTransformVector(float *newvector, float *oldvector); - void addExternalForce(float *force); + void addExternalForce(float *force); - void setGravity(bool enabled); + void setGravity(bool enabled); - virtual void hitForce(float speed, float *speed2, Object *source); - - + virtual void hitForce(float speed, float *speed2, Object *source); - friend class ObjectLink; - //friend void collide(Object *source, Object *target, float *normal, float *contactpoint); - friend bool checkCollisions(Object *object, float *contactnormal); + + + friend class ObjectLink; + //friend void collide(Object *source, Object *target, float *normal, float *contactpoint); + friend bool checkCollisions(Object *object, float *contactnormal); - //Temporary state variables - float velocity[3]; - float angularvelocity[3]; + //Temporary state variables + float velocity[3]; + float angularvelocity[3]; }; #endif diff --git a/src/objectfactory.cpp b/src/objectfactory.cpp index b53d67b..51c81f7 100644 --- a/src/objectfactory.cpp +++ b/src/objectfactory.cpp @@ -1,50 +1,3 @@ -/* - * $Id: objectfactory.cpp,v 1.12 2002/07/22 01:14:14 msell Exp $ - * - * - * $Log: objectfactory.cpp,v $ - * Revision 1.12 2002/07/22 01:14:14 msell - * Lopetussysteemi - * - * Revision 1.11 2002/07/15 20:32:35 msell - * Uudet valot ja ulkoasun parantelua - * - * Revision 1.10 2002/07/15 15:22:08 msell - * Parantelua - * - * Revision 1.9 2002/07/14 21:22:39 jkaarlas - * skybox ja ukkojen säätö - * - * Revision 1.8 2002/07/11 18:33:07 jkaarlas - * ascloaderi palauttaa nyt meshin - * - * Revision 1.7 2002/07/10 22:22:53 msell - * Cartoon-rendaus - * - * Revision 1.6 2002/07/10 22:07:23 jkaarlas - * skaalatut ja käännellyt ruumiinosat - * - * Revision 1.5 2002/07/09 19:54:35 msell - * intit floateiks asc-loaderista - * - * Revision 1.4 2002/06/26 22:30:02 jkaarlas - * lisätty asc-loaderi - * - * Revision 1.3 2002/06/24 14:12:15 msell - * Nyt toimii sphere -> mesh -törmäykset, ihan tosi - * - * Revision 1.2 2002/06/23 20:12:19 msell - * Parempi törmäystarkistus palloista mesheihin - * - * Revision 1.1 2002/06/20 22:50:12 msell - * Meshit - * - * - * - * $Date: 2002/07/22 01:14:14 $ - * - */ - #include "main.h" #include @@ -61,183 +14,183 @@ MeshObject *createPyramid(float width, float height){ - Mesh *mesh = new Mesh(); - mesh->vertexcount = 5; - mesh->vertices = new Vertex[5]; - vectorSet(mesh->vertices[0].position, width, 0, 0); - vectorSet(mesh->vertices[0].normal, 1, 0, 0); - vectorSet(mesh->vertices[1].position, -width, 0, 0); - vectorSet(mesh->vertices[1].normal, -1, 0, 0); - vectorSet(mesh->vertices[2].position, 0, 0, width); - vectorSet(mesh->vertices[2].normal, 0, 0, 1); - vectorSet(mesh->vertices[3].position, 0, 0, -width); - vectorSet(mesh->vertices[3].normal, 0, 0, -1); - vectorSet(mesh->vertices[4].position, 0, height, 0); - vectorSet(mesh->vertices[4].normal, 0, 1, 0); + Mesh *mesh = new Mesh(); + mesh->vertexcount = 5; + mesh->vertices = new Vertex[5]; + vectorSet(mesh->vertices[0].position, width, 0, 0); + vectorSet(mesh->vertices[0].normal, 1, 0, 0); + vectorSet(mesh->vertices[1].position, -width, 0, 0); + vectorSet(mesh->vertices[1].normal, -1, 0, 0); + vectorSet(mesh->vertices[2].position, 0, 0, width); + vectorSet(mesh->vertices[2].normal, 0, 0, 1); + vectorSet(mesh->vertices[3].position, 0, 0, -width); + vectorSet(mesh->vertices[3].normal, 0, 0, -1); + vectorSet(mesh->vertices[4].position, 0, height, 0); + vectorSet(mesh->vertices[4].normal, 0, 1, 0); - mesh->polygoncount = 5; - mesh->polygons = new class Polygon[5]; + mesh->polygoncount = 5; + mesh->polygons = new class Polygon[5]; - mesh->polygons[0].vertexcount = 3; - mesh->polygons[0].vertices = new Vertex *[3]; - mesh->polygons[0].vertices[0] = &mesh->vertices[4]; - mesh->polygons[0].vertices[1] = &mesh->vertices[0]; - mesh->polygons[0].vertices[2] = &mesh->vertices[3]; + mesh->polygons[0].vertexcount = 3; + mesh->polygons[0].vertices = new Vertex *[3]; + mesh->polygons[0].vertices[0] = &mesh->vertices[4]; + mesh->polygons[0].vertices[1] = &mesh->vertices[0]; + mesh->polygons[0].vertices[2] = &mesh->vertices[3]; - mesh->polygons[1].vertexcount = 3; - mesh->polygons[1].vertices = new Vertex *[3]; - mesh->polygons[1].vertices[0] = &mesh->vertices[4]; - mesh->polygons[1].vertices[1] = &mesh->vertices[3]; - mesh->polygons[1].vertices[2] = &mesh->vertices[1]; + mesh->polygons[1].vertexcount = 3; + mesh->polygons[1].vertices = new Vertex *[3]; + mesh->polygons[1].vertices[0] = &mesh->vertices[4]; + mesh->polygons[1].vertices[1] = &mesh->vertices[3]; + mesh->polygons[1].vertices[2] = &mesh->vertices[1]; - mesh->polygons[2].vertexcount = 3; - mesh->polygons[2].vertices = new Vertex *[3]; - mesh->polygons[2].vertices[0] = &mesh->vertices[4]; - mesh->polygons[2].vertices[1] = &mesh->vertices[1]; - mesh->polygons[2].vertices[2] = &mesh->vertices[2]; + mesh->polygons[2].vertexcount = 3; + mesh->polygons[2].vertices = new Vertex *[3]; + mesh->polygons[2].vertices[0] = &mesh->vertices[4]; + mesh->polygons[2].vertices[1] = &mesh->vertices[1]; + mesh->polygons[2].vertices[2] = &mesh->vertices[2]; - mesh->polygons[3].vertexcount = 3; - mesh->polygons[3].vertices = new Vertex *[3]; - mesh->polygons[3].vertices[0] = &mesh->vertices[4]; - mesh->polygons[3].vertices[1] = &mesh->vertices[2]; - mesh->polygons[3].vertices[2] = &mesh->vertices[0]; + mesh->polygons[3].vertexcount = 3; + mesh->polygons[3].vertices = new Vertex *[3]; + mesh->polygons[3].vertices[0] = &mesh->vertices[4]; + mesh->polygons[3].vertices[1] = &mesh->vertices[2]; + mesh->polygons[3].vertices[2] = &mesh->vertices[0]; - mesh->polygons[4].vertexcount = 4; - mesh->polygons[4].vertices = new Vertex *[4]; - mesh->polygons[4].vertices[0] = &mesh->vertices[0]; - mesh->polygons[4].vertices[1] = &mesh->vertices[2]; - mesh->polygons[4].vertices[2] = &mesh->vertices[1]; - mesh->polygons[4].vertices[3] = &mesh->vertices[3]; + mesh->polygons[4].vertexcount = 4; + mesh->polygons[4].vertices = new Vertex *[4]; + mesh->polygons[4].vertices[0] = &mesh->vertices[0]; + mesh->polygons[4].vertices[1] = &mesh->vertices[2]; + mesh->polygons[4].vertices[2] = &mesh->vertices[1]; + mesh->polygons[4].vertices[3] = &mesh->vertices[3]; - mesh->polygons[0].smooth = false; - mesh->polygons[1].smooth = false; - mesh->polygons[2].smooth = false; - mesh->polygons[3].smooth = false; - mesh->polygons[4].smooth = false; + mesh->polygons[0].smooth = false; + mesh->polygons[1].smooth = false; + mesh->polygons[2].smooth = false; + mesh->polygons[3].smooth = false; + mesh->polygons[4].smooth = false; - mesh->createPlanes(); + mesh->createPlanes(); - MeshObject *object = new MeshObject(mesh); - return object; + MeshObject *object = new MeshObject(mesh); + return object; } MeshObject *createSpherePool(float width, float height){ - int grid = 16; + int grid = 16; - Mesh *mesh = new Mesh(); - mesh->vertexcount = (grid+1)*(grid+1); - mesh->vertices = new Vertex[mesh->vertexcount]; + Mesh *mesh = new Mesh(); + mesh->vertexcount = (grid+1)*(grid+1); + mesh->vertices = new Vertex[mesh->vertexcount]; - int x, z; - for (z = 0; z < grid; z++){ - float pz = (2.0*z/(grid-1) - 1)*width; - for (x = 0; x < grid; x++){ - float px = (2.0*x/(grid-1) - 1)*width; + int x, z; + for (z = 0; z < grid; z++){ + float pz = (2.0*z/(grid-1) - 1)*width; + for (x = 0; x < grid; x++){ + float px = (2.0*x/(grid-1) - 1)*width; - //float py = randomf(1); - float l = sqrt(pz*pz + px*px)*1; - if (l > width) l = width; - l = l/width; - //l = l*l; - float py = height*(sin(PI*(1.5+l*2))+1)/2; - vectorSet(mesh->vertices[z * grid + x].position, px, py, pz); - } - } + //float py = randomf(1); + float l = sqrt(pz*pz + px*px)*1; + if (l > width) l = width; + l = l/width; + //l = l*l; + float py = height*(sin(PI*(1.5+l*2))+1)/2; + vectorSet(mesh->vertices[z * grid + x].position, px, py, pz); + } + } - mesh->polygoncount = (grid-1)*(grid-1); - mesh->polygons = new class Polygon[mesh->polygoncount]; - for (z = 0; z < grid-1; z++){ - for (x = 0; x < grid-1; x++){ - class Polygon *poly = &mesh->polygons[z * (grid-1) + x]; - poly->vertexcount = 4; - poly->vertices = new Vertex *[4]; + mesh->polygoncount = (grid-1)*(grid-1); + mesh->polygons = new class Polygon[mesh->polygoncount]; + for (z = 0; z < grid-1; z++){ + for (x = 0; x < grid-1; x++){ + class Polygon *poly = &mesh->polygons[z * (grid-1) + x]; + poly->vertexcount = 4; + poly->vertices = new Vertex *[4]; - poly->vertices[0] = &mesh->vertices[z * grid + x + 1]; - poly->vertices[1] = &mesh->vertices[z * grid + x ]; - poly->vertices[2] = &mesh->vertices[(z + 1) * grid + x]; - poly->vertices[3] = &mesh->vertices[(z + 1) * grid + x + 1]; + poly->vertices[0] = &mesh->vertices[z * grid + x + 1]; + poly->vertices[1] = &mesh->vertices[z * grid + x ]; + poly->vertices[2] = &mesh->vertices[(z + 1) * grid + x]; + poly->vertices[3] = &mesh->vertices[(z + 1) * grid + x + 1]; - poly->smooth = true; - } - } + poly->smooth = true; + } + } - mesh->createPlanes(); - mesh->createVertexnormals(); + mesh->createPlanes(); + mesh->createVertexnormals(); - MeshObject *object = new MeshObject(mesh); - return object; + MeshObject *object = new MeshObject(mesh); + return object; } Mesh *createBox(float x1, float x2, float y1, float y2, float z1, float z2){ - Mesh *mesh = new Mesh(); - mesh->vertexcount = 8; - mesh->vertices = new Vertex[8]; - vectorSet(mesh->vertices[0].position, x1, y1, z1); - vectorSet(mesh->vertices[1].position, x2, y1, z1); - vectorSet(mesh->vertices[2].position, x1, y2, z1); - vectorSet(mesh->vertices[3].position, x2, y2, z1); - vectorSet(mesh->vertices[4].position, x1, y1, z2); - vectorSet(mesh->vertices[5].position, x2, y1, z2); - vectorSet(mesh->vertices[6].position, x1, y2, z2); - vectorSet(mesh->vertices[7].position, x2, y2, z2); + Mesh *mesh = new Mesh(); + mesh->vertexcount = 8; + mesh->vertices = new Vertex[8]; + vectorSet(mesh->vertices[0].position, x1, y1, z1); + vectorSet(mesh->vertices[1].position, x2, y1, z1); + vectorSet(mesh->vertices[2].position, x1, y2, z1); + vectorSet(mesh->vertices[3].position, x2, y2, z1); + vectorSet(mesh->vertices[4].position, x1, y1, z2); + vectorSet(mesh->vertices[5].position, x2, y1, z2); + vectorSet(mesh->vertices[6].position, x1, y2, z2); + vectorSet(mesh->vertices[7].position, x2, y2, z2); - mesh->polygoncount = 6; - mesh->polygons = new class Polygon[6]; + mesh->polygoncount = 6; + mesh->polygons = new class Polygon[6]; - //Back - mesh->polygons[0].vertexcount = 4; - mesh->polygons[0].vertices = new Vertex *[4]; - mesh->polygons[0].vertices[0] = &mesh->vertices[0]; - mesh->polygons[0].vertices[1] = &mesh->vertices[2]; - mesh->polygons[0].vertices[2] = &mesh->vertices[3]; - mesh->polygons[0].vertices[3] = &mesh->vertices[1]; + //Back + mesh->polygons[0].vertexcount = 4; + mesh->polygons[0].vertices = new Vertex *[4]; + mesh->polygons[0].vertices[0] = &mesh->vertices[0]; + mesh->polygons[0].vertices[1] = &mesh->vertices[2]; + mesh->polygons[0].vertices[2] = &mesh->vertices[3]; + mesh->polygons[0].vertices[3] = &mesh->vertices[1]; - //Front - mesh->polygons[1].vertexcount = 4; - mesh->polygons[1].vertices = new Vertex *[4]; - mesh->polygons[1].vertices[0] = &mesh->vertices[4]; - mesh->polygons[1].vertices[1] = &mesh->vertices[5]; - mesh->polygons[1].vertices[2] = &mesh->vertices[7]; - mesh->polygons[1].vertices[3] = &mesh->vertices[6]; + //Front + mesh->polygons[1].vertexcount = 4; + mesh->polygons[1].vertices = new Vertex *[4]; + mesh->polygons[1].vertices[0] = &mesh->vertices[4]; + mesh->polygons[1].vertices[1] = &mesh->vertices[5]; + mesh->polygons[1].vertices[2] = &mesh->vertices[7]; + mesh->polygons[1].vertices[3] = &mesh->vertices[6]; - //Left - mesh->polygons[2].vertexcount = 4; - mesh->polygons[2].vertices = new Vertex *[4]; - mesh->polygons[2].vertices[0] = &mesh->vertices[0]; - mesh->polygons[2].vertices[1] = &mesh->vertices[4]; - mesh->polygons[2].vertices[2] = &mesh->vertices[6]; - mesh->polygons[2].vertices[3] = &mesh->vertices[2]; + //Left + mesh->polygons[2].vertexcount = 4; + mesh->polygons[2].vertices = new Vertex *[4]; + mesh->polygons[2].vertices[0] = &mesh->vertices[0]; + mesh->polygons[2].vertices[1] = &mesh->vertices[4]; + mesh->polygons[2].vertices[2] = &mesh->vertices[6]; + mesh->polygons[2].vertices[3] = &mesh->vertices[2]; - //Right - mesh->polygons[3].vertexcount = 4; - mesh->polygons[3].vertices = new Vertex *[4]; - mesh->polygons[3].vertices[0] = &mesh->vertices[1]; - mesh->polygons[3].vertices[1] = &mesh->vertices[3]; - mesh->polygons[3].vertices[2] = &mesh->vertices[7]; - mesh->polygons[3].vertices[3] = &mesh->vertices[5]; + //Right + mesh->polygons[3].vertexcount = 4; + mesh->polygons[3].vertices = new Vertex *[4]; + mesh->polygons[3].vertices[0] = &mesh->vertices[1]; + mesh->polygons[3].vertices[1] = &mesh->vertices[3]; + mesh->polygons[3].vertices[2] = &mesh->vertices[7]; + mesh->polygons[3].vertices[3] = &mesh->vertices[5]; - //Top - mesh->polygons[4].vertexcount = 4; - mesh->polygons[4].vertices = new Vertex *[4]; - mesh->polygons[4].vertices[0] = &mesh->vertices[2]; - mesh->polygons[4].vertices[1] = &mesh->vertices[6]; - mesh->polygons[4].vertices[2] = &mesh->vertices[7]; - mesh->polygons[4].vertices[3] = &mesh->vertices[3]; + //Top + mesh->polygons[4].vertexcount = 4; + mesh->polygons[4].vertices = new Vertex *[4]; + mesh->polygons[4].vertices[0] = &mesh->vertices[2]; + mesh->polygons[4].vertices[1] = &mesh->vertices[6]; + mesh->polygons[4].vertices[2] = &mesh->vertices[7]; + mesh->polygons[4].vertices[3] = &mesh->vertices[3]; - //Bottom - mesh->polygons[5].vertexcount = 4; - mesh->polygons[5].vertices = new Vertex *[4]; - mesh->polygons[5].vertices[0] = &mesh->vertices[0]; - mesh->polygons[5].vertices[1] = &mesh->vertices[1]; - mesh->polygons[5].vertices[2] = &mesh->vertices[5]; - mesh->polygons[5].vertices[3] = &mesh->vertices[4]; + //Bottom + mesh->polygons[5].vertexcount = 4; + mesh->polygons[5].vertices = new Vertex *[4]; + mesh->polygons[5].vertices[0] = &mesh->vertices[0]; + mesh->polygons[5].vertices[1] = &mesh->vertices[1]; + mesh->polygons[5].vertices[2] = &mesh->vertices[5]; + mesh->polygons[5].vertices[3] = &mesh->vertices[4]; - mesh->createPlanes(); - mesh->createEdges(); - //mesh->createVertexnormals(); + mesh->createPlanes(); + mesh->createEdges(); + //mesh->createVertexnormals(); - return mesh; + return mesh; } @@ -259,14 +212,14 @@ char* findStringEnd(char* data, char* findstring){ } Mesh* loadAscModel(char *filename, float scale){ - float zeroOffset[3] = {0.0, 0.0, 0.0}; - return loadAscModel(filename, scale, (float*)zeroOffset); + float zeroOffset[3] = {0.0, 0.0, 0.0}; + return loadAscModel(filename, scale, (float*)zeroOffset); } Mesh* loadAscModel(char *filename, float scale, float* offset){ - + Mesh* target = new Mesh(); - + FILE* file; float x, y, z; @@ -287,7 +240,7 @@ Mesh* loadAscModel(char *filename, float scale, float* offset){ target->polygoncount=getValueFromString(face); target->vertices = new Vertex[target->vertexcount]; target->polygons = new class Polygon[target->polygoncount]; - + int i; @@ -311,7 +264,7 @@ Mesh* loadAscModel(char *filename, float scale, float* offset){ } int vnum; face=findStringEnd(data,"Face list:"); - + for (i=0;ipolygoncount;i++){ face=findStringEnd(face,"Face"); @@ -320,25 +273,25 @@ Mesh* loadAscModel(char *filename, float scale, float* offset){ target->polygons[i].vertexcount = 3; target->polygons[i].vertices = new Vertex *[3]; target->polygons[i].vertices[0]=&(target->vertices[vnum]); - target->polygons[i].vertices[0]->setTexCoords(target->vertices[vnum].texcoords[0], + target->polygons[i].vertices[0]->setTexCoords(target->vertices[vnum].texcoords[0], target->vertices[vnum].texcoords[1]); face=findStringEnd(face,"B:"); vnum=getValueFromString(face); target->polygons[i].vertices[1]=&(target->vertices[vnum]); - target->polygons[i].vertices[1]->setTexCoords(target->vertices[vnum].texcoords[0], + target->polygons[i].vertices[1]->setTexCoords(target->vertices[vnum].texcoords[0], target->vertices[vnum].texcoords[1]); face=findStringEnd(face,"C:"); vnum=getValueFromString(face); target->polygons[i].vertices[2]=&(target->vertices[vnum]); - target->polygons[i].vertices[2]->setTexCoords(target->vertices[vnum].texcoords[0], + target->polygons[i].vertices[2]->setTexCoords(target->vertices[vnum].texcoords[0], target->vertices[vnum].texcoords[1]); char *face2=findStringEnd(face,"Nosmooth"); - char *face3=findStringEnd(face,"Smoothing"); - if (face2 > face && face2 < face3) target->polygons[i].realsmooth = true; + char *face3=findStringEnd(face,"Smoothing"); + if (face2 > face && face2 < face3) target->polygons[i].realsmooth = true; } free(data); data = NULL; - //target->createEdges(); + //target->createEdges(); target->createPlanes(); target->createVertexnormals(); //return new MeshObject(target); @@ -346,26 +299,26 @@ Mesh* loadAscModel(char *filename, float scale, float* offset){ } void drawTrophy(void){ - point2d points[14]; + point2d points[14]; - int width = 3; + int width = 3; - int i = 0; + int i = 0; - points[i].x = 0.0; points[i].y = 0.0; i++; - points[i].x = width; points[i].y = 0.0; i++; - points[i].x = width-2; points[i].y = 2.0; i++; - points[i].x = width-2; points[i].y = 3.0; i++; - points[i].x = width-1; points[i].y = 4.0; i++; - points[i].x = width-2; points[i].y = 5.0; i++; - points[i].x = width-2; points[i].y = 6.0; i++; - points[i].x = width-1; points[i].y = 8.0; i++; - points[i].x = width; points[i].y = 9.0; i++; - points[i].x = width+1; points[i].y = 11.0; i++; - points[i].x = width+2; points[i].y = 15.0; i++; - points[i].x = width+3; points[i].y = 21.0; i++; - points[i].x = width+2; points[i].y = 21.0; i++; - points[i].x = 0.0; points[i].y = 8.0; i++; + points[i].x = 0.0; points[i].y = 0.0; i++; + points[i].x = width; points[i].y = 0.0; i++; + points[i].x = width-2; points[i].y = 2.0; i++; + points[i].x = width-2; points[i].y = 3.0; i++; + points[i].x = width-1; points[i].y = 4.0; i++; + points[i].x = width-2; points[i].y = 5.0; i++; + points[i].x = width-2; points[i].y = 6.0; i++; + points[i].x = width-1; points[i].y = 8.0; i++; + points[i].x = width; points[i].y = 9.0; i++; + points[i].x = width+1; points[i].y = 11.0; i++; + points[i].x = width+2; points[i].y = 15.0; i++; + points[i].x = width+3; points[i].y = 21.0; i++; + points[i].x = width+2; points[i].y = 21.0; i++; + points[i].x = 0.0; points[i].y = 8.0; i++; - createLathedSurface(points, NULL, i, i*5, i*10); -} \ No newline at end of file + createLathedSurface(points, NULL, i, i*5, i*10); +} diff --git a/src/objectfactory.h b/src/objectfactory.h index e4edc0b..6d943fc 100644 --- a/src/objectfactory.h +++ b/src/objectfactory.h @@ -1,35 +1,3 @@ -/* - * $Id: objectfactory.h,v 1.7 2002/07/22 01:14:14 msell Exp $ - * - * - * $Log: objectfactory.h,v $ - * Revision 1.7 2002/07/22 01:14:14 msell - * Lopetussysteemi - * - * Revision 1.6 2002/07/19 20:33:28 msell - * #pragma once -> #ifndef - * - * Revision 1.5 2002/07/14 21:22:39 jkaarlas - * skybox ja ukkojen säätö - * - * Revision 1.4 2002/07/11 18:33:06 jkaarlas - * ascloaderi palauttaa nyt meshin - * - * Revision 1.3 2002/06/26 22:30:02 jkaarlas - * lisätty asc-loaderi - * - * Revision 1.2 2002/06/24 14:12:15 msell - * Nyt toimii sphere -> mesh -törmäykset, ihan tosi - * - * Revision 1.1 2002/06/20 22:50:12 msell - * Meshit - * - * - * - * $Date: 2002/07/22 01:14:14 $ - * - */ - #ifndef __OBJECTFACTORY_H_INCLUDED__ #define __OBJECTFACTORY_H_INCLUDED__ diff --git a/src/particle.cpp b/src/particle.cpp index 52b06cc..b15d754 100644 --- a/src/particle.cpp +++ b/src/particle.cpp @@ -1,17 +1,3 @@ -/* - * $Id: particle.cpp,v 1.1 2002/07/19 12:10:53 msell Exp $ - * - * - * $Log: particle.cpp,v $ - * Revision 1.1 2002/07/19 12:10:53 msell - * Hups - * - * - * - * $Date: 2002/07/19 12:10:53 $ - * - */ - #include "main.h" #include @@ -26,7 +12,7 @@ Particle::Particle(World *world, Mesh *mesh) : MeshObject(mesh){ - this->world = world; + this->world = world; } Contact *contact = new Contact(); @@ -34,132 +20,132 @@ Contact *contact = new Contact(); int bloodcount; void Particle::move(void){ - /*if (position[1] + momentum[1] < 0.5){ - currentparticle->velocity.x*=0.8; - currentparticle->velocity.y=fabs(currentparticle->velocity.y)*0.8; - currentparticle->velocity.z*=0.8; - currentparticle->bounces++; - } - currentparticle->position.x+=currentparticle->velocity.x; - currentparticle->position.y+=currentparticle->velocity.y; - currentparticle->position.z+=currentparticle->velocity.z; - currentparticle->angle.x+=currentparticle->velocity.x*50; - currentparticle->angle.y+=currentparticle->velocity.y*50; - currentparticle->angle.z+=currentparticle->velocity.z*50; - currentparticle->velocity.y-=0.003; - if (currentparticle->bounces==3) dieParticle(currentparticle);*/ - momentum[1] -= 0.02; - int i; - vectorSet(contact->normal, 0, 1, 0); - contact->object2 = NULL; - bool die = false; - for (i = 0; i < mesh->vertexcount; i++){ - float point[3]; - transformPoint(point, mesh->vertices[i].position); - if (point[1] < 0){ - contact->object1 = this; - vectorCopy(contact->position, point); - handleCollision(contact); - /*float impulse[3]; - getMomentum(impulse); - impulse[0] = 0; - impulse[1] = fabs(impulse[1]); - impulse[2] = 0; - vectorScale(impulse, 1.1); - addImpulse(impulse, point); - position[1] -= point[1]; - momentum[1] = impulse[1]*0.5;*/ - } - } - /*if (vectorLength(momentum) < 0.5) die = true; - if (die) removeBlood(id);*/ - lifetime++; - Object::move(); + /*if (position[1] + momentum[1] < 0.5){ + currentparticle->velocity.x*=0.8; + currentparticle->velocity.y=fabs(currentparticle->velocity.y)*0.8; + currentparticle->velocity.z*=0.8; + currentparticle->bounces++; + } + currentparticle->position.x+=currentparticle->velocity.x; + currentparticle->position.y+=currentparticle->velocity.y; + currentparticle->position.z+=currentparticle->velocity.z; + currentparticle->angle.x+=currentparticle->velocity.x*50; + currentparticle->angle.y+=currentparticle->velocity.y*50; + currentparticle->angle.z+=currentparticle->velocity.z*50; + currentparticle->velocity.y-=0.003; + if (currentparticle->bounces==3) dieParticle(currentparticle);*/ + momentum[1] -= 0.02; + int i; + vectorSet(contact->normal, 0, 1, 0); + contact->object2 = NULL; + bool die = false; + for (i = 0; i < mesh->vertexcount; i++){ + float point[3]; + transformPoint(point, mesh->vertices[i].position); + if (point[1] < 0){ + contact->object1 = this; + vectorCopy(contact->position, point); + handleCollision(contact); + /*float impulse[3]; + getMomentum(impulse); + impulse[0] = 0; + impulse[1] = fabs(impulse[1]); + impulse[2] = 0; + vectorScale(impulse, 1.1); + addImpulse(impulse, point); + position[1] -= point[1]; + momentum[1] = impulse[1]*0.5;*/ + } + } + /*if (vectorLength(momentum) < 0.5) die = true; + if (die) removeBlood(id);*/ + lifetime++; + Object::move(); - if (lifetime > 300) removeBlood(id); + if (lifetime > 300) removeBlood(id); } void Particle::hitForce(float speed, Object *source){ - /*bounces++; - if (bounces == 2){ - removeBlood(id); - }*/ + /*bounces++; + if (bounces == 2){ + removeBlood(id); + }*/ } void Particle::create(float *position, float *velocity){ - vectorCopy(this->position, position); - vectorCopy(this->momentum, velocity); - float rotate[3] = {randomf(2)-1, randomf(2)-1, randomf(2)-1}; - vectorCopy(this->angularmomentum, rotate); - bounces = 0; - lifetime = 0; - world->addParticle(this); + vectorCopy(this->position, position); + vectorCopy(this->momentum, velocity); + float rotate[3] = {randomf(2)-1, randomf(2)-1, randomf(2)-1}; + vectorCopy(this->angularmomentum, rotate); + bounces = 0; + lifetime = 0; + world->addParticle(this); } void Particle::destroy(void){ - world->removeParticle(this); + world->removeParticle(this); } Particle **bloodparticles; BloodAppearance::BloodAppearance(int *lifetime) : BasicBlockAppearance(1, 1, 1){ - this->lifetime = lifetime; - usematerial = false; + this->lifetime = lifetime; + usematerial = false; } void BloodAppearance::draw(void){ - glPushMatrix(); + glPushMatrix(); - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); - float alpha = 1-*lifetime*0.003; - if (alpha < 0) alpha = 0; + float alpha = 1-*lifetime*0.003; + if (alpha < 0) alpha = 0; - glColor4f(1, 0, 0, alpha);//1.0/(1+*lifetime*0.004)); + glColor4f(1, 0, 0, alpha);//1.0/(1+*lifetime*0.004)); - glScalef(0.5, 0.5, 0.5); - BasicBlockAppearance::draw(); + glScalef(0.5, 0.5, 0.5); + BasicBlockAppearance::draw(); - glDisable(GL_BLEND); + glDisable(GL_BLEND); - glPopMatrix(); + glPopMatrix(); } World *bloodworld; void initBloods(World *world){ - bloodcount = 0; - bloodparticles = new Particle *[MAXBLOOD]; - int i; - Mesh *bloodmesh = createBox(-0.5, 0.5, -0.5*BLOCKHEIGHT, 0.5*BLOCKHEIGHT, -0.5, 0.5); - for (i = 0; i < MAXBLOOD; i++){ - bloodparticles[i] = new Particle(world, bloodmesh); - bloodparticles[i]->appearance = new BloodAppearance(&(bloodparticles[i]->lifetime)); - bloodparticles[i]->setMass(1); - bloodparticles[i]->prepare(); - //bloodparticles[i]->setGravity(true); - //bloodparticles[i]->setCollisionGroup(COLLISIONGROUP_PARTICLE); - //bloodparticles[i]->id = i; - } - bloodworld = world; + bloodcount = 0; + bloodparticles = new Particle *[MAXBLOOD]; + int i; + Mesh *bloodmesh = createBox(-0.5, 0.5, -0.5*BLOCKHEIGHT, 0.5*BLOCKHEIGHT, -0.5, 0.5); + for (i = 0; i < MAXBLOOD; i++){ + bloodparticles[i] = new Particle(world, bloodmesh); + bloodparticles[i]->appearance = new BloodAppearance(&(bloodparticles[i]->lifetime)); + bloodparticles[i]->setMass(1); + bloodparticles[i]->prepare(); + //bloodparticles[i]->setGravity(true); + //bloodparticles[i]->setCollisionGroup(COLLISIONGROUP_PARTICLE); + //bloodparticles[i]->id = i; + } + bloodworld = world; } void createBlood(float *position, float *velocity){ - if (bloodcount < MAXBLOOD){ - Particle *currentparticle = bloodparticles[bloodcount]; - currentparticle->create(position, velocity); - currentparticle->id = bloodcount; - bloodcount++; - } + if (bloodcount < MAXBLOOD){ + Particle *currentparticle = bloodparticles[bloodcount]; + currentparticle->create(position, velocity); + currentparticle->id = bloodcount; + bloodcount++; + } } void removeBlood(int id){ - Particle *particle = bloodparticles[id]; - particle->destroy(); - bloodparticles[id] = bloodparticles[bloodcount-1]; - bloodparticles[id]->id = id; - bloodparticles[bloodcount-1] = particle; - bloodcount--; -} \ No newline at end of file + Particle *particle = bloodparticles[id]; + particle->destroy(); + bloodparticles[id] = bloodparticles[bloodcount-1]; + bloodparticles[id]->id = id; + bloodparticles[bloodcount-1] = particle; + bloodcount--; +} diff --git a/src/particle.h b/src/particle.h index 2dc22d6..66ce42a 100644 --- a/src/particle.h +++ b/src/particle.h @@ -1,20 +1,3 @@ -/* - * $Id: particle.h,v 1.2 2002/07/19 20:33:28 msell Exp $ - * - * - * $Log: particle.h,v $ - * Revision 1.2 2002/07/19 20:33:28 msell - * #pragma once -> #ifndef - * - * Revision 1.1 2002/07/19 12:10:53 msell - * Hups - * - * - * - * $Date: 2002/07/19 20:33:28 $ - * - */ - #ifndef __PARTICLE_H_INCLUDED__ #define __PARTICLE_H_INCLUDED__ @@ -27,26 +10,26 @@ class BloodAppearance; class Particle : public MeshObject{ private: - int bounces; - bool enabled; + int bounces; + bool enabled; - World *world; + World *world; - bool alive; + bool alive; public: - int lifetime; - int id; + int lifetime; + int id; - Particle(World *world, Mesh *mesh); + Particle(World *world, Mesh *mesh); - void move(void); + void move(void); - void hitForce(float speed, Object *source); + void hitForce(float speed, Object *source); - void create(float *position, float *velocity); - void destroy(void); + void create(float *position, float *velocity); + void destroy(void); }; @@ -57,12 +40,12 @@ public: class BloodAppearance : public BasicBlockAppearance{ private: - int *lifetime; + int *lifetime; public: - BloodAppearance(int *lifetime); + BloodAppearance(int *lifetime); - void draw(void); + void draw(void); }; void initBloods(World *world); diff --git a/src/run.cpp b/src/run.cpp index 7570a32..dcfc697 100644 --- a/src/run.cpp +++ b/src/run.cpp @@ -1,88 +1,3 @@ -/* - * $Id: run.cpp,v 1.24 2002/07/22 11:44:16 jkaarlas Exp $ - * - * - * $Log: run.cpp,v $ - * Revision 1.24 2002/07/22 11:44:16 jkaarlas - * naama - * - * Revision 1.23 2002/07/22 01:14:14 msell - * Lopetussysteemi - * - * Revision 1.22 2002/07/19 22:38:38 msell - * Pingviini - * - * Revision 1.21 2002/07/19 21:17:07 msell - * bugifixi - * - * Revision 1.20 2002/07/19 20:06:32 msell - * Linux-porttausta - * - * Revision 1.19 2002/07/19 19:46:07 msell - * Makefile - * - * Revision 1.18 2002/07/19 18:59:46 msell - * Alkuhommaa ja säätöä - * - * Revision 1.17 2002/07/19 14:05:52 msell - * Damagetextuurit näkyy - * - * Revision 1.16 2002/07/19 12:48:57 jkaarlas - * damagepää - * - * Revision 1.15 2002/07/19 12:42:44 msell - * Loading... - * - * Revision 1.14 2002/07/17 20:32:48 msell - * Detail-optio toimii - * - * Revision 1.13 2002/07/17 16:40:33 msell - * Resoluution vaihto - * - * Revision 1.12 2002/07/16 19:57:14 jkaarlas - * lisätty DATAPATH tiedostonimien eteen - * - * Revision 1.11 2002/07/16 17:16:35 msell - * Fontit ja valikot - * - * Revision 1.10 2002/07/04 21:05:41 msell - * Se toimii!! =) - * Törmäystarkistukset siis - * - * Revision 1.9 2002/06/17 20:49:05 msell - * free -> SDL_FreeSurface - * - * Revision 1.8 2002/06/17 19:58:08 msell - * #includeiden parantelua - * - * Revision 1.7 2002/06/16 01:04:58 jkaarlas - * tulipa säädettyä includejen kanssa. oon tod.näk. eri mieltä aamulla - * - * Revision 1.6 2002/06/02 16:57:37 msell - * Objektirakenteen pohja - * - * Revision 1.5 2002/05/18 12:29:35 msell - * Valot ja äänijärjestelmän parantelua - * - * Revision 1.4 2002/05/17 12:30:26 msell - * no message - * - * Revision 1.3 2002/05/16 18:41:16 msell - * Vektorifunctioita ja kamera - * - * Revision 1.2 2002/05/15 21:07:23 msell - * Äänisäätöä - * - * Revision 1.1 2002/05/15 14:36:39 msell - * Yksinkertainen SDL-runko (Kääntyy toistaiseksi vain windowsissa). - * Mukana myös musiikinsoitto fmodilla. - * - * - * - * $Date: 2002/07/22 11:44:16 $ - * - */ - #include "main.h" #include @@ -107,77 +22,77 @@ bool gameinitialized = false; void initFontTexture(void); void initScenes(void){ - knobgllist = glGenLists(1); - setDetail(detail); + knobgllist = glGenLists(1); + setDetail(detail); - - //Simple loading-screen - enable2D(); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - SDL_GL_SwapBuffers(); + //Simple loading-screen + enable2D(); - initFontTexture(); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + SDL_GL_SwapBuffers(); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - print(0.08, 0.4, "Loading...", 0.2); - SDL_GL_SwapBuffers(); + initFontTexture(); - disable2D(); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + print(0.08, 0.4, "Loading...", 0.2); + SDL_GL_SwapBuffers(); + + disable2D(); - SKYBOX = -1; - initTextures(); - initFight(); - initMenu(); - initEnd(); - changeGameMode(MENUMODE); - //changeGameMode(ENDMODE); - gameinitialized = true; + SKYBOX = -1; + initTextures(); + initFight(); + initMenu(); + initEnd(); + changeGameMode(MENUMODE); + //changeGameMode(ENDMODE); + gameinitialized = true; } void changeGameMode(int newmode){ - gamemode = newmode; - changed = true; + gamemode = newmode; + changed = true; } void calculateFrame(int framecount){ - switch(gamemode){ - case MENUMODE: - calculateMenu(framecount); - break; - case FIGHTMODE: - calculateFight(framecount); - break; - case ENDMODE: - calculateEnd(framecount); - break; - } - updateAudio(); - changed = false; + switch(gamemode){ + case MENUMODE: + calculateMenu(framecount); + break; + case FIGHTMODE: + calculateFight(framecount); + break; + case ENDMODE: + calculateEnd(framecount); + break; + } + updateAudio(); + changed = false; } void drawFrame(int framecount){ - if (changed) calculateFrame(framecount); + if (changed) calculateFrame(framecount); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - glMatrixMode(GL_MODELVIEW); - - switch(gamemode){ - case MENUMODE: - drawMenu(framecount); - break; - case FIGHTMODE: - drawFight(framecount); - break; - case ENDMODE: - drawEnd(framecount); - break; - } + glMatrixMode(GL_MODELVIEW); - SDL_GL_SwapBuffers(); + switch(gamemode){ + case MENUMODE: + drawMenu(framecount); + break; + case FIGHTMODE: + drawFight(framecount); + break; + case ENDMODE: + drawEnd(framecount); + break; + } + + SDL_GL_SwapBuffers(); } /*int SKY_FRONT_ID; @@ -204,95 +119,95 @@ Texture *tuxtexture; Texture *faceTexture; void initFontTexture(void){ - if (!texturesloaded){ - float trans[3] = {1, 0, 0}; - fonttexture = new Texture(); - fonttexture->loadImage(DATAPATH"font.png", trans); - } else{ - fonttexture->reload(); - } + if (!texturesloaded){ + float trans[3] = {1, 0, 0}; + fonttexture = new Texture(); + fonttexture->loadImage(DATAPATH"font.png", trans); + } else{ + fonttexture->reload(); + } } void initTextures(void){ - /*SKY_FRONT_ID = DRUID.loadTexture(SKYFRONT); - SKY_BACK_ID = DRUID.loadTexture(SKYBACK); - SKY_LEFT_ID = DRUID.loadTexture(SKYLEFT); - SKY_RIGHT_ID = DRUID.loadTexture(SKYRIGHT); - SKY_TOP_ID = DRUID.loadTexture(SKYTOP); - SKY_BOTTOM_ID = DRUID.loadTexture(SKYBOTTOM);*/ + /*SKY_FRONT_ID = DRUID.loadTexture(SKYFRONT); + SKY_BACK_ID = DRUID.loadTexture(SKYBACK); + SKY_LEFT_ID = DRUID.loadTexture(SKYLEFT); + SKY_RIGHT_ID = DRUID.loadTexture(SKYRIGHT); + SKY_TOP_ID = DRUID.loadTexture(SKYTOP); + SKY_BOTTOM_ID = DRUID.loadTexture(SKYBOTTOM);*/ - if (!texturesloaded){ - skyfronttexture = new Texture(); - skyfronttexture->loadImage(SKYFRONT); - skybacktexture = new Texture(); - skybacktexture->loadImage(SKYBACK); - skylefttexture = new Texture(); - skylefttexture->loadImage(SKYLEFT); - skyrighttexture = new Texture(); - skyrighttexture->loadImage(SKYRIGHT); - skytoptexture = new Texture(); - skytoptexture->loadImage(SKYTOP); - skybottomtexture = new Texture(); - skybottomtexture->loadImage(SKYBOTTOM); + if (!texturesloaded){ + skyfronttexture = new Texture(); + skyfronttexture->loadImage(SKYFRONT); + skybacktexture = new Texture(); + skybacktexture->loadImage(SKYBACK); + skylefttexture = new Texture(); + skylefttexture->loadImage(SKYLEFT); + skyrighttexture = new Texture(); + skyrighttexture->loadImage(SKYRIGHT); + skytoptexture = new Texture(); + skytoptexture->loadImage(SKYTOP); + skybottomtexture = new Texture(); + skybottomtexture->loadImage(SKYBOTTOM); - float something[3] = {1, 0, 0.5}; - damageHead = new Texture(); - damageHead->loadImage(DAMAGEHEAD, something); - damageTorso = new Texture(); - damageTorso->loadImage(DAMAGETORSO, something); - damageHand = new Texture(); - damageHand->loadImage(DAMAGEHAND, something); - damageLeg = new Texture(); - damageLeg->loadImage(DAMAGELEG, something); - faceTexture = new Texture(); - something[2] = 1; - faceTexture->loadImage(FACE, something); + float something[3] = {1, 0, 0.5}; + damageHead = new Texture(); + damageHead->loadImage(DAMAGEHEAD, something); + damageTorso = new Texture(); + damageTorso->loadImage(DAMAGETORSO, something); + damageHand = new Texture(); + damageHand->loadImage(DAMAGEHAND, something); + damageLeg = new Texture(); + damageLeg->loadImage(DAMAGELEG, something); + faceTexture = new Texture(); + something[2] = 1; + faceTexture->loadImage(FACE, something); - float zeros[3] = {0, 0, 0}; - flaretexture = new Texture(); - flaretexture->loadImage(DATAPATH"flare.png", zeros); - + float zeros[3] = {0, 0, 0}; + flaretexture = new Texture(); + flaretexture->loadImage(DATAPATH"flare.png", zeros); - float pink[3] = {1, 0, 1}; - tuxtexture = new Texture(); - tuxtexture->loadImage(DATAPATH"tux.png", pink); - } else{ - skyfronttexture->reload(); - skybacktexture->reload(); - skylefttexture->reload(); - skyrighttexture->reload(); - skytoptexture->reload(); - skybottomtexture->reload(); - damageHead->reload(); - damageTorso->reload(); - damageHand->reload(); - damageLeg->reload(); + float pink[3] = {1, 0, 1}; + tuxtexture = new Texture(); + tuxtexture->loadImage(DATAPATH"tux.png", pink); + } else{ + skyfronttexture->reload(); + skybacktexture->reload(); + skylefttexture->reload(); + skyrighttexture->reload(); + skytoptexture->reload(); + skybottomtexture->reload(); - flaretexture->reload(); + damageHead->reload(); + damageTorso->reload(); + damageHand->reload(); + damageLeg->reload(); - tuxtexture->reload(); - } - texturesloaded = true; + flaretexture->reload(); + + tuxtexture->reload(); + } + texturesloaded = true; } void setDetail(int detail){ - switch(detail){ - case 0: - knobdetail = 0; - break; - case 1: - knobdetail = 5; - break; - case 2: - knobdetail = 8; - break; - case 3: - knobdetail = 16; - break; - } - initKnob(); + switch(detail){ + case 0: + knobdetail = 0; + break; + case 1: + knobdetail = 5; + break; + case 2: + knobdetail = 8; + break; + case 3: + knobdetail = 16; + break; + } + initKnob(); } diff --git a/src/run.h b/src/run.h index 6abdf74..da160b7 100644 --- a/src/run.h +++ b/src/run.h @@ -1,42 +1,3 @@ -/* - * $Id: run.h,v 1.9 2002/07/22 01:14:14 msell Exp $ - * - * - * $Log: run.h,v $ - * Revision 1.9 2002/07/22 01:14:14 msell - * Lopetussysteemi - * - * Revision 1.8 2002/07/19 20:33:29 msell - * #pragma once -> #ifndef - * - * Revision 1.7 2002/07/17 20:32:48 msell - * Detail-optio toimii - * - * Revision 1.6 2002/07/16 17:16:35 msell - * Fontit ja valikot - * - * Revision 1.5 2002/06/04 16:28:32 msell - * #pragma once - * - * Revision 1.4 2002/06/02 16:57:37 msell - * Objektirakenteen pohja - * - * Revision 1.3 2002/05/17 12:30:26 msell - * no message - * - * Revision 1.2 2002/05/16 18:41:16 msell - * Vektorifunctioita ja kamera - * - * Revision 1.1 2002/05/15 14:36:39 msell - * Yksinkertainen SDL-runko (Kääntyy toistaiseksi vain windowsissa). - * Mukana myös musiikinsoitto fmodilla. - * - * - * - * $Date: 2002/07/22 01:14:14 $ - * - */ - #ifndef __RUN_H_INCLUDED__ #define __RUN_H_INCLUDED__ diff --git a/src/shape.cpp b/src/shape.cpp index 115aca1..04cb975 100644 --- a/src/shape.cpp +++ b/src/shape.cpp @@ -1,52 +1,18 @@ -/* - * $Id: shape.cpp,v 1.7 2002/07/04 21:05:41 msell Exp $ - * - * - * $Log: shape.cpp,v $ - * Revision 1.7 2002/07/04 21:05:41 msell - * Se toimii!! =) - * Törmäystarkistukset siis - * - * Revision 1.6 2002/06/30 16:05:04 msell - * Törmäyksien parantelua, transformaatioita mukana - * - * Revision 1.5 2002/06/24 14:12:15 msell - * Nyt toimii sphere -> mesh -törmäykset, ihan tosi - * - * Revision 1.4 2002/06/20 22:50:12 msell - * Meshit - * - * Revision 1.3 2002/06/15 17:18:37 msell - * Toimiva törmäystarkastus kiinteille laatikoille - * - * Revision 1.2 2002/06/14 00:05:05 msell - * Törmäyssimulaatio kunnossa toivon mukaan - * - * Revision 1.1 2002/06/11 23:11:45 msell - * Törmäystarkistusta - * - * - * - * - * $Date: 2002/07/04 21:05:41 $ - * - */ - #include "shape.h" Shape::Shape(Object *object){ - this->object = object; + this->object = object; } bool Shape::checkCollision(Object *target){ - return false; + return false; } bool Shape::checkCollisionPeer(Shape *target){ - return false; + return false; } bool Shape::checkCollisionPeer(SphereShape *target){ - return false; + return false; } bool Shape::checkCollisionPeer(MeshShape *target){ - return false; + return false; } diff --git a/src/shape.h b/src/shape.h index d0899f0..05619d1 100644 --- a/src/shape.h +++ b/src/shape.h @@ -1,51 +1,3 @@ -/* - * $Id: shape.h,v 1.12 2002/07/19 20:33:29 msell Exp $ - * - * - * $Log: shape.h,v $ - * Revision 1.12 2002/07/19 20:33:29 msell - * #pragma once -> #ifndef - * - * Revision 1.11 2002/07/04 21:05:41 msell - * Se toimii!! =) - * Törmäystarkistukset siis - * - * Revision 1.10 2002/06/30 16:05:04 msell - * Törmäyksien parantelua, transformaatioita mukana - * - * Revision 1.9 2002/06/24 14:12:15 msell - * Nyt toimii sphere -> mesh -törmäykset, ihan tosi - * - * Revision 1.8 2002/06/20 22:50:12 msell - * Meshit - * - * Revision 1.7 2002/06/15 17:18:37 msell - * Toimiva törmäystarkastus kiinteille laatikoille - * - * Revision 1.6 2002/06/14 00:05:05 msell - * Törmäyssimulaatio kunnossa toivon mukaan - * - * Revision 1.5 2002/06/11 23:11:45 msell - * Törmäystarkistusta - * - * Revision 1.4 2002/06/07 21:16:51 msell - * Fysiikkaenginen alkua - * - * Revision 1.3 2002/06/05 23:55:46 msell - * Pallo - * - * Revision 1.2 2002/06/04 16:28:32 msell - * #pragma once - * - * Revision 1.1 2002/06/02 16:57:37 msell - * Objektirakenteen pohja - * - * - * - * $Date: 2002/07/19 20:33:29 $ - * - */ - #ifndef __SHAPE_H_INCLUDED__ #define __SHAPE_H_INCLUDED__ @@ -60,19 +12,19 @@ class MeshShape; */ class Shape{ protected: - Object *object; + Object *object; public: - Shape(Object *object); + Shape(Object *object); - virtual float calculateMomentOfInertia(float *rotationvector) = 0; + virtual float calculateMomentOfInertia(float *rotationvector) = 0; - virtual bool checkCollision(Object *target); + virtual bool checkCollision(Object *target); - virtual bool checkCollisionPeer(Shape *target); - virtual bool checkCollisionPeer(SphereShape *target); - virtual bool checkCollisionPeer(MeshShape *target); + virtual bool checkCollisionPeer(Shape *target); + virtual bool checkCollisionPeer(SphereShape *target); + virtual bool checkCollisionPeer(MeshShape *target); }; #endif diff --git a/src/sphere.cpp b/src/sphere.cpp index c7114ca..6656471 100644 --- a/src/sphere.cpp +++ b/src/sphere.cpp @@ -1,73 +1,3 @@ -/* - * $Id: sphere.cpp,v 1.19 2002/07/19 18:59:46 msell Exp $ - * - * - * $Log: sphere.cpp,v $ - * Revision 1.19 2002/07/19 18:59:46 msell - * Alkuhommaa ja säätöä - * - * Revision 1.18 2002/07/07 17:53:21 msell - * Legoukon alku - * - * Revision 1.17 2002/07/04 21:05:41 msell - * Se toimii!! =) - * Törmäystarkistukset siis - * - * Revision 1.16 2002/06/30 16:05:04 msell - * Törmäyksien parantelua, transformaatioita mukana - * - * Revision 1.15 2002/06/27 14:39:48 msell - * Toimiva maila :) - * Pyörivät kappaleet siis antaa liike-energiaa liikkuville kappaleille (ei toisin päin vielä) - * - * Revision 1.14 2002/06/27 00:08:04 msell - * Kimmotukset palloille myös pyöritettyihin mesheihin - * - * Revision 1.13 2002/06/24 14:12:15 msell - * Nyt toimii sphere -> mesh -törmäykset, ihan tosi - * - * Revision 1.12 2002/06/23 20:12:19 msell - * Parempi törmäystarkistus palloista mesheihin - * - * Revision 1.11 2002/06/20 22:50:12 msell - * Meshit - * - * Revision 1.10 2002/06/20 00:21:19 jkaarlas - * materiaali- ja tekstuurihommia edistetty - * - * Revision 1.9 2002/06/17 20:49:05 msell - * free -> SDL_FreeSurface - * - * Revision 1.8 2002/06/16 01:04:58 jkaarlas - * tulipa säädettyä includejen kanssa. oon tod.näk. eri mieltä aamulla - * - * Revision 1.7 2002/06/15 17:18:37 msell - * Toimiva törmäystarkastus kiinteille laatikoille - * - * Revision 1.6 2002/06/14 00:26:17 msell - * 100 kimpoilevaa palloa ja vähän vaimennusta - * - * Revision 1.5 2002/06/14 00:05:05 msell - * Törmäyssimulaatio kunnossa toivon mukaan - * - * Revision 1.4 2002/06/11 23:23:03 msell - * Törmäystarkistusta - * - * Revision 1.3 2002/06/11 23:11:45 msell - * Törmäystarkistusta - * - * Revision 1.2 2002/06/07 21:16:51 msell - * Fysiikkaenginen alkua - * - * Revision 1.1 2002/06/05 23:55:46 msell - * Pallo - * - * - * - * $Date: 2002/07/19 18:59:46 $ - * - */ - #include "main.h" #include @@ -82,252 +12,252 @@ Sphere::Sphere(void){ - appearance = new SphereAppearance(); - Object::appearance = appearance; - geometry = new SphereShape(this); - Object::geometry = geometry; + appearance = new SphereAppearance(); + Object::appearance = appearance; + geometry = new SphereShape(this); + Object::geometry = geometry; } void Sphere::setRadius(float r){ - if (r < 0) r = -r; - this->r = r; - appearance->setRadius(r); - geometry->setRadius(r); + if (r < 0) r = -r; + this->r = r; + appearance->setRadius(r); + geometry->setRadius(r); } SphereAppearance::SphereAppearance(void){ - setRadius(1); + setRadius(1); } void SphereAppearance::setRadius(float r){ - if (r < 0) r = -r; - this->r = r; + if (r < 0) r = -r; + this->r = r; } void Sphere::setColor(float red, float green, float blue){ - appearance->getMaterial()->setColor(red, green, blue, 1); + appearance->getMaterial()->setColor(red, green, blue, 1); } void SphereAppearance::draw(void){ - material.enable(); - createSphere(r); + material.enable(); + createSphere(r); } SphereShape::SphereShape(Object *sphere) : Shape(sphere){ - setRadius(1); + setRadius(1); } void SphereShape::setRadius(float r){ - this->r = r; + this->r = r; } float SphereShape::getRadius(void){ - return r; + return r; } bool SphereShape::checkCollision(Object *target){ - return target->geometry->checkCollisionPeer(this); + return target->geometry->checkCollisionPeer(this); } float SphereShape::calculateMomentOfInertia(float *rotationvector){ - return 2.0/3.0*r*r; + return 2.0/3.0*r*r; } /*bool SphereShape::checkCollisionPeer(PlaneShape *target){ - float sourceposition[3], targetposition[3]; - object->getPosition(sourceposition); - target->object->getPosition(targetposition); - float height = target->height + targetposition[1]; + float sourceposition[3], targetposition[3]; + object->getPosition(sourceposition); + target->object->getPosition(targetposition); + float height = target->height + targetposition[1]; - if (sourceposition[1] - r < height){ - //shotsound->play(); - float normal[3] = {0, 1, 0}; + if (sourceposition[1] - r < height){ + //shotsound->play(); + float normal[3] = {0, 1, 0}; - float contactpoint[3] = {0, target->height, 0}; - collide(object, target->object, normal, contactpoint); - return true; - } + float contactpoint[3] = {0, target->height, 0}; + collide(object, target->object, normal, contactpoint); + return true; + } - return false; + return false; }*/ bool SphereShape::checkCollisionPeer(SphereShape *target){ - /*float sourceposition[3], targetposition[3]; - object->getPosition(sourceposition); - target->object->getPosition(targetposition); - float impact[3]; - vectorSub(impact, sourceposition, targetposition);*/ - float impact[3] = {0, 0, 0}; - object->transformPoint(impact, impact); - target->object->unTransformPoint(impact, impact); - float distance2 = vectorDot(impact, impact); + /*float sourceposition[3], targetposition[3]; + object->getPosition(sourceposition); + target->object->getPosition(targetposition); + float impact[3]; + vectorSub(impact, sourceposition, targetposition);*/ + float impact[3] = {0, 0, 0}; + object->transformPoint(impact, impact); + target->object->unTransformPoint(impact, impact); + float distance2 = vectorDot(impact, impact); - if (distance2 < (r + target->r)*(r + target->r)){ - /*float temp[3], temp2[3], temp3[3]; - object->getMomentum(temp2); - target->object->getMomentum(temp3); - vectorSub(temp, temp2, temp3); - shotsound->setVolume(1.0-1/(1+vectorLength(temp)*0.5)); - shotsound->play();*/ - float normal[3]; - vectorNormalize(normal, impact); + if (distance2 < (r + target->r)*(r + target->r)){ + /*float temp[3], temp2[3], temp3[3]; + object->getMomentum(temp2); + target->object->getMomentum(temp3); + vectorSub(temp, temp2, temp3); + shotsound->setVolume(1.0-1/(1+vectorLength(temp)*0.5)); + shotsound->play();*/ + float normal[3]; + vectorNormalize(normal, impact); - float contactpoint[3]; - vectorScale(contactpoint, normal, target->r); + float contactpoint[3]; + vectorScale(contactpoint, normal, target->r); - target->object->transformVector(normal, normal); - target->object->transformPoint(contactpoint, contactpoint); + target->object->transformVector(normal, normal); + target->object->transformPoint(contactpoint, contactpoint); - addCollision(object, target->object, normal, contactpoint); + addCollision(object, target->object, normal, contactpoint); - //vectorAdd(contactnormal, normal); - - return true; - } + //vectorAdd(contactnormal, normal); - return false; + return true; + } + + return false; } bool between(float x, float x1, float x2){ - if ((x >= x1 && x <=x2) || (x >= x2 && x <=x1)) return true; - return false; + if ((x >= x1 && x <=x2) || (x >= x2 && x <=x1)) return true; + return false; } /*bool SphereShape::checkCollisionPeer(BoxShape *target){ - float sourceposition[3], targetposition[3]; - object->getPosition(sourceposition); - target->object->getPosition(targetposition); - float x1 = target->x1 + targetposition[0]; - float x2 = target->x2 + targetposition[0]; - float y1 = target->y1 + targetposition[1]; - float y2 = target->y2 + targetposition[1]; - float z1 = target->z1 + targetposition[2]; - float z2 = target->z2 + targetposition[2]; - float points[3][2] = {{x1, x2}, {y1, y2}, {z1, z2}}; - float p[2], op1[2], op2[2]; - float c, oc1, oc2; - int i; - float normal[3]; - float *normal2[3]; - //Faces - for (i = 0; i < 3; i++){ - p[0] = points[i][0]; - p[1] = points[i][1]; - op1[0] = points[(i+1)%3][0]; - op1[1] = points[(i+1)%3][1]; - op2[0] = points[(i+2)%3][0]; - op2[1] = points[(i+2)%3][1]; - c = sourceposition[i]; - oc1 = sourceposition[(i+1)%3]; - oc2 = sourceposition[(i+2)%3]; - normal2[0] = &normal[i]; - normal2[1] = &normal[(i+1)%3]; - normal2[2] = &normal[(i+2)%3]; + float sourceposition[3], targetposition[3]; + object->getPosition(sourceposition); + target->object->getPosition(targetposition); + float x1 = target->x1 + targetposition[0]; + float x2 = target->x2 + targetposition[0]; + float y1 = target->y1 + targetposition[1]; + float y2 = target->y2 + targetposition[1]; + float z1 = target->z1 + targetposition[2]; + float z2 = target->z2 + targetposition[2]; + float points[3][2] = {{x1, x2}, {y1, y2}, {z1, z2}}; + float p[2], op1[2], op2[2]; + float c, oc1, oc2; + int i; + float normal[3]; + float *normal2[3]; + //Faces + for (i = 0; i < 3; i++){ + p[0] = points[i][0]; + p[1] = points[i][1]; + op1[0] = points[(i+1)%3][0]; + op1[1] = points[(i+1)%3][1]; + op2[0] = points[(i+2)%3][0]; + op2[1] = points[(i+2)%3][1]; + c = sourceposition[i]; + oc1 = sourceposition[(i+1)%3]; + oc2 = sourceposition[(i+2)%3]; + normal2[0] = &normal[i]; + normal2[1] = &normal[(i+1)%3]; + normal2[2] = &normal[(i+2)%3]; - if (between(oc1, op1[0], op1[1]) && - between(oc2, op2[0], op2[1])){ - if (c < p[0] && c+r > p[0]){ - *normal2[0] = -1; - *normal2[1] = 0; - *normal2[2] = 0; - collide(object, target->object, normal); - return true; - } - if (c > p[1] && c-r < p[1]){ - *normal2[0] = 1; - *normal2[1] = 0; - *normal2[2] = 0; - collide(object, target->object, normal); - return true; - } - } - } + if (between(oc1, op1[0], op1[1]) && + between(oc2, op2[0], op2[1])){ + if (c < p[0] && c+r > p[0]){ + *normal2[0] = -1; + *normal2[1] = 0; + *normal2[2] = 0; + collide(object, target->object, normal); + return true; + } + if (c > p[1] && c-r < p[1]){ + *normal2[0] = 1; + *normal2[1] = 0; + *normal2[2] = 0; + collide(object, target->object, normal); + return true; + } + } + } - //Edges - for (i = 0; i < 3; i++){ - p[0] = points[i][0]; - p[1] = points[i][1]; - op1[0] = points[(i+1)%3][0]; - op1[1] = points[(i+1)%3][1]; - op2[0] = points[(i+2)%3][0]; - op2[1] = points[(i+2)%3][1]; - c = sourceposition[i]; - oc1 = sourceposition[(i+1)%3]; - oc2 = sourceposition[(i+2)%3]; - normal2[0] = &normal[i]; - normal2[1] = &normal[(i+1)%3]; - normal2[2] = &normal[(i+2)%3]; - float edges[4][2] = { - {p[0], op1[0]}, - {p[1], op1[0]}, - {p[0], op1[1]}, - {p[1], op1[1]}}; + //Edges + for (i = 0; i < 3; i++){ + p[0] = points[i][0]; + p[1] = points[i][1]; + op1[0] = points[(i+1)%3][0]; + op1[1] = points[(i+1)%3][1]; + op2[0] = points[(i+2)%3][0]; + op2[1] = points[(i+2)%3][1]; + c = sourceposition[i]; + oc1 = sourceposition[(i+1)%3]; + oc2 = sourceposition[(i+2)%3]; + normal2[0] = &normal[i]; + normal2[1] = &normal[(i+1)%3]; + normal2[2] = &normal[(i+2)%3]; + float edges[4][2] = { + {p[0], op1[0]}, + {p[1], op1[0]}, + {p[0], op1[1]}, + {p[1], op1[1]}}; - if (between(oc2, op2[0], op2[1])){ - int j; - for (j = 0; j < 4; j++){ - float diff[2] = {c - edges[j][0], oc1 - edges[j][1]}; - if (diff[0]*diff[0] + diff[1]*diff[1] < r*r){ - *normal2[0] = diff[0]; - *normal2[1] = diff[1]; - *normal2[2] = 0; - vectorNormalize(normal); - collide(object, target->object, normal); - return true; - } - } - } - } + if (between(oc2, op2[0], op2[1])){ + int j; + for (j = 0; j < 4; j++){ + float diff[2] = {c - edges[j][0], oc1 - edges[j][1]}; + if (diff[0]*diff[0] + diff[1]*diff[1] < r*r){ + *normal2[0] = diff[0]; + *normal2[1] = diff[1]; + *normal2[2] = 0; + vectorNormalize(normal); + collide(object, target->object, normal); + return true; + } + } + } + } - //Corners - float corners[8][3] = { - {x1, y1, z1}, - {x1, y1, z2}, - {x1, y2, z1}, - {x1, y2, z2}, - {x2, y1, z1}, - {x2, y1, z2}, - {x2, y2, z1}, - {x2, y2, z2}}; - for (i = 0; i < 8; i++){ - float *corner = corners[i]; - float difference[3]; - vectorSub(difference, sourceposition, corner); - float length2 = vectorDot(difference, difference); - if (length2 < r*r){ - float normal[3]; - vectorNormalize(normal, difference); - collide(object, target->object, normal); - return true; - } - } + //Corners + float corners[8][3] = { + {x1, y1, z1}, + {x1, y1, z2}, + {x1, y2, z1}, + {x1, y2, z2}, + {x2, y1, z1}, + {x2, y1, z2}, + {x2, y2, z1}, + {x2, y2, z2}}; + for (i = 0; i < 8; i++){ + float *corner = corners[i]; + float difference[3]; + vectorSub(difference, sourceposition, corner); + float length2 = vectorDot(difference, difference); + if (length2 < r*r){ + float normal[3]; + vectorNormalize(normal, difference); + collide(object, target->object, normal); + return true; + } + } - return false; + return false; }*/ bool SphereShape::checkCollisionPeer(MeshShape *target){ - float position[3] = {0, 0, 0}; - object->transformPoint(position, position); - target->object->unTransformPoint(position, position); - Mesh *mesh = target->mesh; + float position[3] = {0, 0, 0}; + object->transformPoint(position, position); + target->object->unTransformPoint(position, position); + Mesh *mesh = target->mesh; - float normal[3]; - float contactpoint[3]; + float normal[3]; + float contactpoint[3]; - if (checkSphereMeshCollision(position, r, mesh, normal, contactpoint)){ - target->object->transformVector(normal, normal); - target->object->transformPoint(contactpoint, contactpoint); - - addCollision(object, target->object, normal, contactpoint); + if (checkSphereMeshCollision(position, r, mesh, normal, contactpoint)){ + target->object->transformVector(normal, normal); + target->object->transformPoint(contactpoint, contactpoint); - //vectorAdd(contactnormal, normal); + addCollision(object, target->object, normal, contactpoint); - return true; - } - return false; -} \ No newline at end of file + //vectorAdd(contactnormal, normal); + + return true; + } + return false; +} diff --git a/src/sphere.h b/src/sphere.h index fcfd0bb..7b33114 100644 --- a/src/sphere.h +++ b/src/sphere.h @@ -1,48 +1,3 @@ -/* - * $Id: sphere.h,v 1.11 2002/07/19 20:33:29 msell Exp $ - * - * - * $Log: sphere.h,v $ - * Revision 1.11 2002/07/19 20:33:29 msell - * #pragma once -> #ifndef - * - * Revision 1.10 2002/07/07 17:53:21 msell - * Legoukon alku - * - * Revision 1.9 2002/07/04 21:05:41 msell - * Se toimii!! =) - * Törmäystarkistukset siis - * - * Revision 1.8 2002/06/30 16:05:04 msell - * Törmäyksien parantelua, transformaatioita mukana - * - * Revision 1.7 2002/06/24 14:12:15 msell - * Nyt toimii sphere -> mesh -törmäykset, ihan tosi - * - * Revision 1.6 2002/06/20 22:50:12 msell - * Meshit - * - * Revision 1.5 2002/06/15 17:18:37 msell - * Toimiva törmäystarkastus kiinteille laatikoille - * - * Revision 1.4 2002/06/14 00:05:05 msell - * Törmäyssimulaatio kunnossa toivon mukaan - * - * Revision 1.3 2002/06/11 23:11:45 msell - * Törmäystarkistusta - * - * Revision 1.2 2002/06/07 21:16:51 msell - * Fysiikkaenginen alkua - * - * Revision 1.1 2002/06/05 23:55:46 msell - * Pallo - * - * - * - * $Date: 2002/07/19 20:33:29 $ - * - */ - #ifndef __SPHERE_H_INCLUDED__ #define __SPHERE_H_INCLUDED__ @@ -57,15 +12,15 @@ class SphereAppearance; class Sphere : public Object{ private: - float r; - SphereAppearance *appearance; - SphereShape *geometry; + float r; + SphereAppearance *appearance; + SphereShape *geometry; public: - Sphere(void); + Sphere(void); - void setRadius(float r); - void setColor(float red, float green, float blue); + void setRadius(float r); + void setColor(float red, float green, float blue); }; @@ -74,13 +29,13 @@ public: class SphereAppearance : public Appearance{ private: - float r; + float r; public: - SphereAppearance(void); - - void setRadius(float r); - void draw(void); + SphereAppearance(void); + + void setRadius(float r); + void draw(void); }; @@ -89,23 +44,23 @@ public: class SphereShape : public Shape{ private: - float r; + float r; public: - SphereShape(Object *sphere); + SphereShape(Object *sphere); - void setRadius(float r); - float getRadius(void); + void setRadius(float r); + float getRadius(void); - float calculateMomentOfInertia(float *rotationvector); + float calculateMomentOfInertia(float *rotationvector); - bool checkCollision(Object *target); + bool checkCollision(Object *target); - bool checkCollisionPeer(SphereShape *target); - bool checkCollisionPeer(MeshShape *target); + bool checkCollisionPeer(SphereShape *target); + bool checkCollisionPeer(MeshShape *target); - friend class Sphere; - friend class MeshShape; + friend class Sphere; + friend class MeshShape; }; #endif diff --git a/src/texture.cpp b/src/texture.cpp index 7d391da..e835106 100644 --- a/src/texture.cpp +++ b/src/texture.cpp @@ -1,33 +1,3 @@ -/* - * $Id: texture.cpp,v 1.7 2002/07/17 16:40:33 msell Exp $ - * - * - * $Log: texture.cpp,v $ - * Revision 1.7 2002/07/17 16:40:33 msell - * Resoluution vaihto - * - * Revision 1.6 2002/06/27 21:43:50 jkaarlas - * lisätty setId-funktio - * - * Revision 1.5 2002/06/20 15:27:48 jkaarlas - * bindtexture siirretty oikeaan paikkaan - * - * Revision 1.4 2002/06/20 00:21:01 jkaarlas - * materiaali- ja tekstuurihommia edistetty - * - * Revision 1.3 2002/06/19 22:45:29 jkaarlas - * nyt nämä menee järkevästi - * - * Revision 1.2 2002/06/15 22:04:01 jkaarlas - * tähänkin jotain sisältöä - * - * - * - * - * $Date: 2002/07/17 16:40:33 $ - * - */ - #include "texture.h" #include "graphics.h" @@ -56,9 +26,9 @@ Texture::Texture(int id){ } bool Texture::loadImage(char* path){ - format = GL_RGB; + format = GL_RGB; - texture = IMG_Load(path); + texture = IMG_Load(path); //texture = SDL_DisplayFormatAlpha(texture); @@ -69,18 +39,18 @@ bool Texture::loadImage(char* path){ } bool Texture::loadImage(char* path, float *trans){ - format = GL_RGBA; + format = GL_RGBA; - texture = IMG_Load(path); + texture = IMG_Load(path); - Uint32 colorKey = SDL_MapRGB(texture->format, - (Uint8)(trans[0] * 255), - (Uint8)(trans[1] * 255), + Uint32 colorKey = SDL_MapRGB(texture->format, + (Uint8)(trans[0] * 255), + (Uint8)(trans[1] * 255), (Uint8)(trans[2] * 255)); //SDL_SetAlpha(texture, 0, SDL_ALPHA_OPAQUE); SDL_SetColorKey(texture, SDL_SRCCOLORKEY, colorKey); - + //SDL_Surface* alphaSurface = SDL_DisplayFormatAlpha(texture); texture = SDL_DisplayFormatAlpha(texture); @@ -90,8 +60,8 @@ bool Texture::loadImage(char* path, float *trans){ } void Texture::reload(void){ - this->textureId = DRUID.loadTexture(texture, -1, format); - this->enable(); + this->textureId = DRUID.loadTexture(texture, -1, format); + this->enable(); } void Texture::disable(void){ diff --git a/src/texture.h b/src/texture.h index 3ee6e92..0ca77ac 100644 --- a/src/texture.h +++ b/src/texture.h @@ -1,32 +1,3 @@ -/* - * $Id: texture.h,v 1.8 2002/07/19 20:33:29 msell Exp $ - * - * - * $Log: texture.h,v $ - * Revision 1.8 2002/07/19 20:33:29 msell - * #pragma once -> #ifndef - * - * Revision 1.7 2002/07/17 16:40:33 msell - * Resoluution vaihto - * - * Revision 1.6 2002/06/27 21:43:50 jkaarlas - * lisätty setId-funktio - * - * Revision 1.5 2002/06/20 00:21:01 jkaarlas - * materiaali- ja tekstuurihommia edistetty - * - * Revision 1.4 2002/06/19 22:45:29 jkaarlas - * nyt nämä menee järkevästi - * - * Revision 1.3 2002/06/15 22:52:32 jkaarlas - * tekstuurimanageri ja työkalupakki - * - * - * - * $Date: 2002/07/19 20:33:29 $ - * - */ - #ifndef __TEXTURE_H_INCLUDED__ #define __TEXTURE_H_INCLUDED__ @@ -48,8 +19,8 @@ public: int getId(void); void setId(int id); bool isValidId(void); - void reload(void); - + void reload(void); + //int* getOGLTexture(void); //int* getModifiableOGLTexture(void); @@ -59,8 +30,8 @@ private: //int* modTexture; bool enabled; - SDL_Surface *texture; - int format; + SDL_Surface *texture; + int format; }; #endif diff --git a/src/utils.cpp b/src/utils.cpp index 934e67d..123e840 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -1,59 +1,39 @@ -/* - * $Id: utils.cpp,v 1.3 2002/07/14 21:40:43 msell Exp $ - * - * - * $Log: utils.cpp,v $ - * Revision 1.3 2002/07/14 21:40:43 msell - * Conflictit pois, liikkumiset (hyppy, kävely, lyönti), uusi areena - * - * Revision 1.2 2002/06/14 00:05:05 msell - * Törmäyssimulaatio kunnossa toivon mukaan - * - * Revision 1.1 2002/06/02 16:57:37 msell - * Objektirakenteen pohja - * - * - * - * $Date: 2002/07/14 21:40:43 $ - * - */ - #include void swapInt(int *a, int *b){ - int temp = *a; - *a = *b; - *b = temp; + int temp = *a; + *a = *b; + *b = temp; } void swapFloat(float *a, float *b){ - float temp = *a; - *a = *b; - *b = temp; + float temp = *a; + *a = *b; + *b = temp; } int random(int x){ - return rand() * x / RAND_MAX; + return rand() * x / RAND_MAX; } float randomf(float x){ - return rand() * x / RAND_MAX; + return rand() * x / RAND_MAX; } int smod(int val, int mod){ - if (val>=0) return val%mod; - int temp=-val/mod+1; - return (val+temp*mod)%mod; + if (val>=0) return val%mod; + int temp=-val/mod+1; + return (val+temp*mod)%mod; } double sdes(double val){ - if (val>=0) return val-(int)(val); - return val-(int)(val)+1; + if (val>=0) return val-(int)(val); + return val-(int)(val)+1; } double sfmod(double val, double mod){ - val-=(int)(val/mod)*mod; - if (val<0) val+=mod; - return val; + val-=(int)(val/mod)*mod; + if (val<0) val+=mod; + return val; } diff --git a/src/utils.h b/src/utils.h index 1503093..9d849a6 100644 --- a/src/utils.h +++ b/src/utils.h @@ -1,32 +1,3 @@ -/* - * $Id: utils.h,v 1.6 2002/07/19 20:33:29 msell Exp $ - * - * - * $Log: utils.h,v $ - * Revision 1.6 2002/07/19 20:33:29 msell - * #pragma once -> #ifndef - * - * Revision 1.5 2002/07/14 21:40:43 msell - * Conflictit pois, liikkumiset (hyppy, kävely, lyönti), uusi areena - * - * Revision 1.4 2002/06/14 00:05:05 msell - * Törmäyssimulaatio kunnossa toivon mukaan - * - * Revision 1.3 2002/06/04 16:28:32 msell - * #pragma once - * - * Revision 1.2 2002/06/03 23:06:38 msell - * no message - * - * Revision 1.1 2002/06/02 16:57:37 msell - * Objektirakenteen pohja - * - * - * - * $Date: 2002/07/19 20:33:29 $ - * - */ - #ifndef __UTILS_H_INCLUDED__ #define __UTILS_H_INCLUDED__ diff --git a/src/vector.cpp b/src/vector.cpp index ec429ff..7544c8e 100644 --- a/src/vector.cpp +++ b/src/vector.cpp @@ -1,37 +1,3 @@ -/* - * $Id: vector.cpp,v 1.7 2002/07/14 21:40:43 msell Exp $ - * - * - * $Log: vector.cpp,v $ - * Revision 1.7 2002/07/14 21:40:43 msell - * Conflictit pois, liikkumiset (hyppy, kävely, lyönti), uusi areena - * - * Revision 1.6 2002/07/04 21:05:41 msell - * Se toimii!! =) - * Törmäystarkistukset siis - * - * Revision 1.5 2002/06/27 00:08:04 msell - * Kimmotukset palloille myös pyöritettyihin mesheihin - * - * Revision 1.4 2002/06/23 20:12:19 msell - * Parempi törmäystarkistus palloista mesheihin - * - * Revision 1.3 2002/06/17 12:42:46 msell - * Hieman parempi törmäysmallinnus taas - * - * Revision 1.2 2002/06/11 23:23:03 msell - * Törmäystarkistusta - * - * Revision 1.1 2002/05/16 18:42:07 msell - * Vektorifunctioita ja kamera - * - * - * - * $Date: 2002/07/14 21:40:43 $ - * - */ - - #include #include "main.h" @@ -39,270 +5,270 @@ #include "utils.h" void vectorSet(float *target, float x, float y, float z){ - target[0] = x; - target[1] = y; - target[2] = z; + target[0] = x; + target[1] = y; + target[2] = z; } void vectorCopy(float *target, float *source){ - target[0] = source[0]; - target[1] = source[1]; - target[2] = source[2]; + target[0] = source[0]; + target[1] = source[1]; + target[2] = source[2]; } void vectorAdd(float *target, float *source1, float *source2){ - target[0] = source1[0] + source2[0]; - target[1] = source1[1] + source2[1]; - target[2] = source1[2] + source2[2]; + target[0] = source1[0] + source2[0]; + target[1] = source1[1] + source2[1]; + target[2] = source1[2] + source2[2]; } void vectorAdd(float *target, float *source){ - target[0] += source[0]; - target[1] += source[1]; - target[2] += source[2]; + target[0] += source[0]; + target[1] += source[1]; + target[2] += source[2]; } void vectorSub(float *target, float *source1, float *source2){ - target[0] = source1[0] - source2[0]; - target[1] = source1[1] - source2[1]; - target[2] = source1[2] - source2[2]; + target[0] = source1[0] - source2[0]; + target[1] = source1[1] - source2[1]; + target[2] = source1[2] - source2[2]; } void vectorSub(float *target, float *source){ - target[0] -= source[0]; - target[1] -= source[1]; - target[2] -= source[2]; + target[0] -= source[0]; + target[1] -= source[1]; + target[2] -= source[2]; } void vectorNegative(float *target, float *source){ - target[0] = -source[0]; - target[1] = -source[1]; - target[2] = -source[2]; + target[0] = -source[0]; + target[1] = -source[1]; + target[2] = -source[2]; } void vectorNegative(float *target){ - target[0] = -target[0]; - target[1] = -target[1]; - target[2] = -target[2]; + target[0] = -target[0]; + target[1] = -target[1]; + target[2] = -target[2]; } void vectorScale(float *target, float *source, float scale){ - target[0] = source[0] * scale; - target[1] = source[1] * scale; - target[2] = source[2] * scale; + target[0] = source[0] * scale; + target[1] = source[1] * scale; + target[2] = source[2] * scale; } void vectorScale(float *target, float scale){ - target[0] *= scale; - target[1] *= scale; - target[2] *= scale; + target[0] *= scale; + target[1] *= scale; + target[2] *= scale; } float vectorDot(float *source1, float *source2){ - return source1[0]*source2[0] + source1[1]*source2[1] + source1[2]*source2[2]; + return source1[0]*source2[0] + source1[1]*source2[1] + source1[2]*source2[2]; } float vectorNormalizedDot(float *source1, float *source2){ - return vectorDot(source1, source2) / (vectorLength(source1) * vectorLength(source2)); + return vectorDot(source1, source2) / (vectorLength(source1) * vectorLength(source2)); } float vectorLength(float *source){ - return sqrtf(vectorDot(source, source)); + return sqrtf(vectorDot(source, source)); } void vectorCross(float *target, float *source1, float *source2){ - target[0] = source1[1]*source2[2] - source1[2]*source2[1]; - target[1] = source1[2]*source2[0] - source1[0]*source2[2]; - target[2] = source1[0]*source2[1] - source1[1]*source2[0]; + target[0] = source1[1]*source2[2] - source1[2]*source2[1]; + target[1] = source1[2]*source2[0] - source1[0]*source2[2]; + target[2] = source1[0]*source2[1] - source1[1]*source2[0]; } void vectorNormalize(float *target, float *source){ - vectorScale(target, source, 1.0/vectorLength(source)); + vectorScale(target, source, 1.0/vectorLength(source)); } void vectorNormalize(float *target){ - vectorScale(target, 1.0/vectorLength(target)); + vectorScale(target, 1.0/vectorLength(target)); } void vectorReflect(float *target, float *source, float *normal){ - vectorCopy(target, normal); - vectorScale(target, -vectorDot(source, normal)*2); - vectorAdd(target, source); + vectorCopy(target, normal); + vectorScale(target, -vectorDot(source, normal)*2); + vectorAdd(target, source); } void vectorProject(float *target, float *source1, float *source2){ - vectorScale(target, source2, vectorDot(source1, source2) / vectorDot(source2, source2)); + vectorScale(target, source2, vectorDot(source1, source2) / vectorDot(source2, source2)); } bool vectorIsZero(float *vector){ - if (vector[0] == 0 && vector[1] == 0 && vector[2] == 0) return true; - //if (vectorDot(vector, vector) < 0.00001) return true; - else return false; + if (vector[0] == 0 && vector[1] == 0 && vector[2] == 0) return true; + //if (vectorDot(vector, vector) < 0.00001) return true; + else return false; } void vectorSaturate(float *target, float *source, float min, float max){ - float len = vectorLength(source); - if (len < min){ - len = min; - } else if (len > max){ - len = max; - } else{ - if (target != source) vectorCopy(target, source); - return; - } - vectorNormalize(target, source); - vectorScale(target, len); + float len = vectorLength(source); + if (len < min){ + len = min; + } else if (len > max){ + len = max; + } else{ + if (target != source) vectorCopy(target, source); + return; + } + vectorNormalize(target, source); + vectorScale(target, len); } void vectorSaturate(float *vector, float min, float max){ - vectorSaturate(vector, vector, min, max); + vectorSaturate(vector, vector, min, max); } void vectorMatrixMultiply(float *target, float *source, float *matrix){ - float source2[3]; - if (source == target){ - vectorCopy(source2, source); - source = source2; - } - int x; - for (x = 0; x < 3; x++){ - target[x] = source[0]*matrix[0+x] + - source[1]*matrix[3+x] + - source[2]*matrix[6+x]; - } + float source2[3]; + if (source == target){ + vectorCopy(source2, source); + source = source2; + } + int x; + for (x = 0; x < 3; x++){ + target[x] = source[0]*matrix[0+x] + + source[1]*matrix[3+x] + + source[2]*matrix[6+x]; + } } void matrixSet(float *matrix, - float x1, float y1, float z1, - float x2, float y2, float z2, - float x3, float y3, float z3){ - matrix[0] = x1; - matrix[1] = y1; - matrix[2] = z1; - matrix[3] = x2; - matrix[4] = y2; - matrix[5] = z2; - matrix[6] = x3; - matrix[7] = y3; - matrix[8] = z3; + float x1, float y1, float z1, + float x2, float y2, float z2, + float x3, float y3, float z3){ + matrix[0] = x1; + matrix[1] = y1; + matrix[2] = z1; + matrix[3] = x2; + matrix[4] = y2; + matrix[5] = z2; + matrix[6] = x3; + matrix[7] = y3; + matrix[8] = z3; } void matrixSet(float *matrix, float *r1, float *r2, float *r3){ - vectorCopy(&matrix[0], r1); - vectorCopy(&matrix[3], r2); - vectorCopy(&matrix[6], r3); + vectorCopy(&matrix[0], r1); + vectorCopy(&matrix[3], r2); + vectorCopy(&matrix[6], r3); } void matrixCopy(float *target, float *source){ - target[0] = source[0]; - target[1] = source[1]; - target[2] = source[2]; - target[3] = source[3]; - target[4] = source[4]; - target[5] = source[5]; - target[6] = source[6]; - target[7] = source[7]; - target[8] = source[8]; + target[0] = source[0]; + target[1] = source[1]; + target[2] = source[2]; + target[3] = source[3]; + target[4] = source[4]; + target[5] = source[5]; + target[6] = source[6]; + target[7] = source[7]; + target[8] = source[8]; } void matrixIdentity(float *matrix){ - matrixSet(matrix, 1, 0, 0, 0, 1, 0, 0, 0, 1); + matrixSet(matrix, 1, 0, 0, 0, 1, 0, 0, 0, 1); } void matrixAdd(float *target, float *source1, float *source2){ - target[0] = source1[0] + source2[0]; - target[1] = source1[1] + source2[1]; - target[2] = source1[2] + source2[2]; - target[3] = source1[3] + source2[3]; - target[4] = source1[4] + source2[4]; - target[5] = source1[5] + source2[5]; - target[6] = source1[6] + source2[6]; - target[7] = source1[7] + source2[7]; - target[8] = source1[8] + source2[8]; + target[0] = source1[0] + source2[0]; + target[1] = source1[1] + source2[1]; + target[2] = source1[2] + source2[2]; + target[3] = source1[3] + source2[3]; + target[4] = source1[4] + source2[4]; + target[5] = source1[5] + source2[5]; + target[6] = source1[6] + source2[6]; + target[7] = source1[7] + source2[7]; + target[8] = source1[8] + source2[8]; } void matrixAdd(float *target, float *source){ - target[0] += source[0]; - target[1] += source[1]; - target[2] += source[2]; - target[3] += source[3]; - target[4] += source[4]; - target[5] += source[5]; - target[6] += source[6]; - target[7] += source[7]; - target[8] += source[8]; + target[0] += source[0]; + target[1] += source[1]; + target[2] += source[2]; + target[3] += source[3]; + target[4] += source[4]; + target[5] += source[5]; + target[6] += source[6]; + target[7] += source[7]; + target[8] += source[8]; } void matrixMultiply(float *target, float *source1, float *source2){ - float target2[9]; - float *oldtarget = target; - bool copy = false; - if (source1 == target || source2 == target){ - copy = true; - target = target2; - } - int x, y; - for (y = 0; y < 3; y++){ - for (x = 0; x < 3; x++){ - *target = source1[y*3+0]*source2[x] + - source1[y*3+1]*source2[3+x] + - source1[y*3+2]*source2[6+x]; - target++; - } - } - if (copy){ - matrixCopy(oldtarget, target2); - } + float target2[9]; + float *oldtarget = target; + bool copy = false; + if (source1 == target || source2 == target){ + copy = true; + target = target2; + } + int x, y; + for (y = 0; y < 3; y++){ + for (x = 0; x < 3; x++){ + *target = source1[y*3+0]*source2[x] + + source1[y*3+1]*source2[3+x] + + source1[y*3+2]*source2[6+x]; + target++; + } + } + if (copy){ + matrixCopy(oldtarget, target2); + } } /*void matrixMultiply(float *target, float *source){ - matrixMultiply(target, source, source); + matrixMultiply(target, source, source); }*/ /*void matrixRotate(float *matrix, float *vector){ - float rotmat[9]; - createRotationMatrix(rotmat, vector); - matrixMultiply(matrix, matrix, rotmat); + float rotmat[9]; + createRotationMatrix(rotmat, vector); + matrixMultiply(matrix, matrix, rotmat); }*/ void matrixCreateRotation(float *matrix, float *vector){ - float angle = vectorLength(vector); - float n[3]; - vectorNormalize(n, vector); + float angle = vectorLength(vector); + float n[3]; + vectorNormalize(n, vector); - float c = cos(angle); - float s = sin(angle); - float t = 1 - c; + float c = cos(angle); + float s = sin(angle); + float t = 1 - c; - float x = n[0]; - float y = n[1]; - float z = n[2]; + float x = n[0]; + float y = n[1]; + float z = n[2]; - matrixSet(matrix, - t*x*x + c, t*y*x + s*z, t*z*x - s*y, - t*x*y - s*z, t*y*y + c, t*z*y + s*x, - t*x*z + s*y, t*y*z - s*x, t*z*z + c); + matrixSet(matrix, + t*x*x + c, t*y*x + s*z, t*z*x - s*y, + t*x*y - s*z, t*y*y + c, t*z*y + s*x, + t*x*z + s*y, t*y*z - s*x, t*z*z + c); } void matrixTranspose(float *target, float *source){ - target[0] = source[0]; target[1] = source[3]; target[2] = source[6]; - target[3] = source[1]; target[4] = source[4]; target[5] = source[7]; - target[6] = source[2]; target[7] = source[5]; target[8] = source[8]; + target[0] = source[0]; target[1] = source[3]; target[2] = source[6]; + target[3] = source[1]; target[4] = source[4]; target[5] = source[7]; + target[6] = source[2]; target[7] = source[5]; target[8] = source[8]; } /*void rotatePointAroundVector(float *target, float *point, float *vector){ - float angle = vectorLength(vector); - float n[3]; - vectorNormalize(n, vector); + float angle = vectorLength(vector); + float n[3]; + vectorNormalize(n, vector); - float c = cos(angle); - float s = sin(angle); - float t = 1 - c; + float c = cos(angle); + float s = sin(angle); + float t = 1 - c; - //r' = r*c + n*(n . r)*t + (r x n)*s + //r' = r*c + n*(n . r)*t + (r x n)*s }*/ diff --git a/src/vector.h b/src/vector.h index 406ca2c..bc53d1d 100644 --- a/src/vector.h +++ b/src/vector.h @@ -1,38 +1,3 @@ -/* - * $Id: vector.h,v 1.8 2002/07/19 20:33:29 msell Exp $ - * - * - * $Log: vector.h,v $ - * Revision 1.8 2002/07/19 20:33:29 msell - * #pragma once -> #ifndef - * - * Revision 1.7 2002/07/14 21:40:43 msell - * Conflictit pois, liikkumiset (hyppy, kävely, lyönti), uusi areena - * - * Revision 1.6 2002/06/27 00:08:04 msell - * Kimmotukset palloille myös pyöritettyihin mesheihin - * - * Revision 1.5 2002/06/23 20:12:19 msell - * Parempi törmäystarkistus palloista mesheihin - * - * Revision 1.4 2002/06/17 12:42:46 msell - * Hieman parempi törmäysmallinnus taas - * - * Revision 1.3 2002/06/11 23:23:03 msell - * Törmäystarkistusta - * - * Revision 1.2 2002/06/04 16:28:32 msell - * #pragma once - * - * Revision 1.1 2002/05/16 18:42:07 msell - * Vektorifunctioita ja kamera - * - * - * - * $Date: 2002/07/19 20:33:29 $ - * - */ - #ifndef __VECTOR_H_INCLUDED__ #define __VECTOR_H_INCLUDED__ @@ -67,9 +32,9 @@ void vectorMatrixMultiply(float *target, float *source, float *matrix); void matrixSet(float *matrix, - float x1, float y1, float z1, - float x2, float y2, float z2, - float x3, float y3, float z3); + float x1, float y1, float z1, + float x2, float y2, float z2, + float x3, float y3, float z3); void matrixSet(float *matrix, float *r1, float *r2, float *r3); void matrixCopy(float *target, float *source); void matrixIdentity(float *matrix); diff --git a/src/world.cpp b/src/world.cpp index 4d60169..8b54595 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -1,42 +1,3 @@ -/* - * $Id: world.cpp,v 1.9 2002/07/18 23:05:31 msell Exp $ - * - * - * $Log: world.cpp,v $ - * Revision 1.9 2002/07/18 23:05:31 msell - * Partikkelit ja kakkospelaajan liike - * - * Revision 1.8 2002/07/15 20:32:36 msell - * Uudet valot ja ulkoasun parantelua - * - * Revision 1.7 2002/07/15 15:22:08 msell - * Parantelua - * - * Revision 1.6 2002/07/14 21:40:43 msell - * Conflictit pois, liikkumiset (hyppy, kävely, lyönti), uusi areena - * - * Revision 1.5 2002/07/10 17:13:44 msell - * Törmäystarkastelun parantelua - * - * Revision 1.4 2002/07/08 18:28:47 msell - * Törmäystä ja ukkoja - * - * Revision 1.3 2002/07/07 23:05:22 msell - * Osien liimaaminen toisiinsa (kesken) - * - * Revision 1.2 2002/07/07 15:29:07 msell - * Törmäyksien parantelua - * - * Revision 1.1 2002/07/04 21:05:41 msell - * Se toimii!! =) - * Törmäystarkistukset siis - * - * - * - * $Date: 2002/07/18 23:05:31 $ - * - */ - #include "world.h" #include "object.h" @@ -44,207 +5,207 @@ #include "vector.h" World::World(void){ - childlist = NULL; - linklist = NULL; - maxparticles = 500; - particles = new Particle *[maxparticles]; - particlecount = 0; + childlist = NULL; + linklist = NULL; + maxparticles = 500; + particles = new Particle *[maxparticles]; + particlecount = 0; } void World::prepare(void){ - objectlist *node = childlist; - childcount = 0; - while (node != NULL){ - Object *child = node->object; - child->prepare(); - node = node->next; - childcount++; - } + objectlist *node = childlist; + childcount = 0; + while (node != NULL){ + Object *child = node->object; + child->prepare(); + node = node->next; + childcount++; + } - childs = new Object *[childcount]; - node = childlist; - int i = 0; - while (node != NULL){ - Object *child = node->object; - childs[i] = child; - node = node->next; - i++; - } + childs = new Object *[childcount]; + node = childlist; + int i = 0; + while (node != NULL){ + Object *child = node->object; + childs[i] = child; + node = node->next; + i++; + } - contacts = new Contact[MAXCONTACTS];//childcount*childcount]; + contacts = new Contact[MAXCONTACTS];//childcount*childcount]; } #define GRAVITY 9.81 //#define GRAVITY 15 void World::move(void){ - int i, j; + int i, j; - //Gravity - float gravity[3]; - vectorSet(gravity, 0, 0, 0); - for (i = 0; i < childcount; i++){ - Object *object = childs[i]; - if (object->gravity){ - gravity[1] = -object->getMass()*GRAVITY; - object->addExternalForce(gravity); - } - } + //Gravity + float gravity[3]; + vectorSet(gravity, 0, 0, 0); + for (i = 0; i < childcount; i++){ + Object *object = childs[i]; + if (object->gravity){ + gravity[1] = -object->getMass()*GRAVITY; + object->addExternalForce(gravity); + } + } - /*for (i = 0; i < particlecount; i++){ - Particle *object = particles[i]; - if (object->gravity){ - gravity[1] = -object->getMass()*GRAVITY; - object->addExternalForce(gravity); - } - }*/ + /*for (i = 0; i < particlecount; i++){ + Particle *object = particles[i]; + if (object->gravity){ + gravity[1] = -object->getMass()*GRAVITY; + object->addExternalForce(gravity); + } + }*/ - //Collisions - contactcount = 0; + //Collisions + contactcount = 0; - for (i = 0; i < childcount; i++){ - Object *object1 = childs[i]; - int group1 = object1->getCollisionGroup(); - for (j = i+1; j < childcount; j++){ - Object *object2 = childs[j]; - int group2 = object2->getCollisionGroup(); + for (i = 0; i < childcount; i++){ + Object *object1 = childs[i]; + int group1 = object1->getCollisionGroup(); + for (j = i+1; j < childcount; j++){ + Object *object2 = childs[j]; + int group2 = object2->getCollisionGroup(); - if (isCollisionLink(group1, group2)){ - object2->geometry->checkCollision(object1); - } - } - } + if (isCollisionLink(group1, group2)){ + object2->geometry->checkCollision(object1); + } + } + } - /*for (i = 0; i < particlecount; i++){ - Particle *object1 = particles[i]; - int group1 = object1->getCollisionGroup(); - for (j = 0; j < childcount; j++){ - Object *object2 = childs[j]; - int group2 = object2->getCollisionGroup(); + /*for (i = 0; i < particlecount; i++){ + Particle *object1 = particles[i]; + int group1 = object1->getCollisionGroup(); + for (j = 0; j < childcount; j++){ + Object *object2 = childs[j]; + int group2 = object2->getCollisionGroup(); - if (isCollisionLink(group1, group2)){ - object2->geometry->checkCollision(object1); - } - } - }*/ + if (isCollisionLink(group1, group2)){ + object2->geometry->checkCollision(object1); + } + } + }*/ - //printf("Contacts: %i\n", contactcount); - - - bool contactresponse; - - j = 0; - do{ - contactresponse = false; - - //Links between objects - objectlinklist *node = linklist; - while (node != NULL){ - ObjectLink *link = node->link; - if (handleLink(link)) contactresponse = true; - node = node->next; - } - - //Collision contact - for (i = 0; i < contactcount; i++){ - Contact *contact = &contacts[i]; - if (handleCollision(contact)) contactresponse = true; - } - - j++; - } while (contactresponse && j < 10); - - /*j = 0; - do{ - contactresponse = false; - - //Collision contact - for (i = 0; i < contactcount; i++){ - Contact *contact = &contacts[i]; - if (handleCollision(contact)) contactresponse = true; - } - - j++; - } while (contactresponse && j < 10);*/ - - /*j = 0; - do{ - contactresponse = false; - - //Links between objects - objectlinklist *node = linklist; - while (node != NULL){ - ObjectLink *link = node->link; - if (handleLink(link)) contactresponse = true; - node = node->next; - } - - j++; - } while (contactresponse && j < 3);*/ + //printf("Contacts: %i\n", contactcount); - for (i = 0; i < childcount; i++){ - childs[i]->move(); - } - for (i = 0; i < particlecount; i++){ - particles[i]->move(); - } + bool contactresponse; + + j = 0; + do{ + contactresponse = false; + + //Links between objects + objectlinklist *node = linklist; + while (node != NULL){ + ObjectLink *link = node->link; + if (handleLink(link)) contactresponse = true; + node = node->next; + } + + //Collision contact + for (i = 0; i < contactcount; i++){ + Contact *contact = &contacts[i]; + if (handleCollision(contact)) contactresponse = true; + } + + j++; + } while (contactresponse && j < 10); + + /*j = 0; + do{ + contactresponse = false; + + //Collision contact + for (i = 0; i < contactcount; i++){ + Contact *contact = &contacts[i]; + if (handleCollision(contact)) contactresponse = true; + } + + j++; + } while (contactresponse && j < 10);*/ + + /*j = 0; + do{ + contactresponse = false; + + //Links between objects + objectlinklist *node = linklist; + while (node != NULL){ + ObjectLink *link = node->link; + if (handleLink(link)) contactresponse = true; + node = node->next; + } + + j++; + } while (contactresponse && j < 3);*/ + + + for (i = 0; i < childcount; i++){ + childs[i]->move(); + } + for (i = 0; i < particlecount; i++){ + particles[i]->move(); + } } void World::draw(void){ - int i; - for (i = 0; i < childcount; i++) childs[i]->draw(); - for (i = 0; i < particlecount; i++) particles[i]->draw(); + int i; + for (i = 0; i < childcount; i++) childs[i]->draw(); + for (i = 0; i < particlecount; i++) particles[i]->draw(); } void World::addChild(Object *child){ - objectlist *node = new objectlist; - node->object = child; - node->next = childlist; - childlist = node; + objectlist *node = new objectlist; + node->object = child; + node->next = childlist; + childlist = node; } void World::addParticle(Particle *particle){ - if (particlecount < maxparticles){ - particles[particlecount++] = particle; - } + if (particlecount < maxparticles){ + particles[particlecount++] = particle; + } } void World::removeParticle(Particle *particle){ - int i; - for (i = 0; i < particlecount; i++){ - if (particles[i] == particle){ - particles[i] = particles[particlecount-1]; - particlecount--; - break; - } - } + int i; + for (i = 0; i < particlecount; i++){ + if (particles[i] == particle){ + particles[i] = particles[particlecount-1]; + particlecount--; + break; + } + } } ObjectLink *World::addLink(Object *object1, Object *object2, float *point){ - ObjectLink *link = new ObjectLink(); - link->object1 = object1; - link->object2 = object2; - if (point != NULL){ - object1->unTransformPoint(link->point1, point); - object2->unTransformPoint(link->point2, point); - link->enabled = true; - } else{ - link->enabled = false; - } - objectlinklist *node = new objectlinklist; - node->link = link; - node->next = linklist; - linklist = node; - return link; + ObjectLink *link = new ObjectLink(); + link->object1 = object1; + link->object2 = object2; + if (point != NULL){ + object1->unTransformPoint(link->point1, point); + object2->unTransformPoint(link->point2, point); + link->enabled = true; + } else{ + link->enabled = false; + } + objectlinklist *node = new objectlinklist; + node->link = link; + node->next = linklist; + linklist = node; + return link; } void World::renewLink(ObjectLink *link, float *point){ - link->object1->unTransformPoint(link->point1, point); - link->object2->unTransformPoint(link->point2, point); - link->enabled = true; + link->object1->unTransformPoint(link->point1, point); + link->object2->unTransformPoint(link->point2, point); + link->enabled = true; } diff --git a/src/world.h b/src/world.h index 484705c..f657587 100644 --- a/src/world.h +++ b/src/world.h @@ -1,33 +1,3 @@ -/* - * $Id: world.h,v 1.6 2002/07/19 20:33:29 msell Exp $ - * - * - * $Log: world.h,v $ - * Revision 1.6 2002/07/19 20:33:29 msell - * #pragma once -> #ifndef - * - * Revision 1.5 2002/07/18 23:05:31 msell - * Partikkelit ja kakkospelaajan liike - * - * Revision 1.4 2002/07/15 15:22:08 msell - * Parantelua - * - * Revision 1.3 2002/07/10 17:13:44 msell - * Törmäystarkastelun parantelua - * - * Revision 1.2 2002/07/07 23:05:22 msell - * Osien liimaaminen toisiinsa (kesken) - * - * Revision 1.1 2002/07/04 21:05:41 msell - * Se toimii!! =) - * Törmäystarkistukset siis - * - * - * - * $Date: 2002/07/19 20:33:29 $ - * - */ - #ifndef __WORLD_H_INCLUDED__ #define __WORLD_H_INCLUDED__ @@ -39,47 +9,47 @@ class ObjectLink; class ObjectLink{ public: - Object *object1, *object2; - float point1[3], point2[3]; - bool enabled; + Object *object1, *object2; + float point1[3], point2[3]; + bool enabled; }; struct objectlinklist{ - ObjectLink *link; - objectlinklist *next; + ObjectLink *link; + objectlinklist *next; }; #define MAXCONTACTS 100 class World{ private: - objectlist *childlist; + objectlist *childlist; - int childcount; - Object **childs; + int childcount; + Object **childs; - int particlecount; - int maxparticles; - Particle **particles; + int particlecount; + int maxparticles; + Particle **particles; - objectlinklist *linklist; + objectlinklist *linklist; public: - World(void); + World(void); - void prepare(void); - void move(void); - void draw(void); + void prepare(void); + void move(void); + void draw(void); - void addChild(Object *child); + void addChild(Object *child); - void addParticle(Particle *particle); - void removeParticle(Particle *particle); - - //Point is world-relative - ObjectLink *addLink(Object *object1, Object *object2, float *point); - void renewLink(ObjectLink *link, float *point); + void addParticle(Particle *particle); + void removeParticle(Particle *particle); + + //Point is world-relative + ObjectLink *addLink(Object *object1, Object *object2, float *point); + void renewLink(ObjectLink *link, float *point); }; #endif