1
0
Fork 0

Apply clang llvm formatting

This commit is contained in:
Michaël Lemaire 2015-06-03 14:29:34 +02:00
parent 9d2084b6b5
commit 371731a73b
54 changed files with 6062 additions and 6171 deletions

View file

@ -24,19 +24,28 @@ int SKYBOX = -1;
* pyörähdyskappaletta. Muulloin pisteet lasketaan kuutiollisella * pyörähdyskappaletta. Muulloin pisteet lasketaan kuutiollisella
* interpoloinnilla annettujen pisteiden välillä. * interpoloinnilla annettujen pisteiden välillä.
*/ */
void createLathedSurface(point2d *points, point2d *pointderivates, int count, int slices, int stacks){ void createLathedSurface(point2d *points, point2d *pointderivates, int count,
int slices, int stacks) {
int i, j; int i, j;
point2d *h1, *h2; point2d *h1, *h2;
point2d *derivates; point2d *derivates;
if (pointderivates == NULL) derivates = new point2d[count]; if (pointderivates == NULL)
else derivates = pointderivates; derivates = new point2d[count];
//Derivaatta pisteessä i on (points[i+1]-points[i-1])/2 alkua ja loppua lukuunottamatta else
derivates = pointderivates;
// Derivaatta pisteessä i on (points[i+1]-points[i-1])/2 alkua ja loppua
// lukuunottamatta
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
if (pointderivates == NULL || (derivates[i].x == 0 && derivates[i].y == 0)){ if (pointderivates == NULL ||
if (i == 0) h1 = &points[0]; (derivates[i].x == 0 && derivates[i].y == 0)) {
else h1 = &points[i-1]; if (i == 0)
if (i == count-1) h2 = &points[count-1]; h1 = &points[0];
else h2 = &points[i+1]; else
h1 = &points[i - 1];
if (i == count - 1)
h2 = &points[count - 1];
else
h2 = &points[i + 1];
float dx, dy; float dx, dy;
dx = (h2->x - h1->x); dx = (h2->x - h1->x);
dy = (h2->y - h1->y); dy = (h2->y - h1->y);
@ -69,7 +78,8 @@ void createLathedSurface(point2d *points, point2d *pointderivates, int count, in
t = sif - si; t = sif - si;
i1 = si; i1 = si;
i2 = si + 1; i2 = si + 1;
if (i2 >= count) i2 = count-1; if (i2 >= count)
i2 = count - 1;
p1 = &points[i1]; p1 = &points[i1];
p2 = &points[i2]; p2 = &points[i2];
d1 = &derivates[i1]; d1 = &derivates[i1];
@ -152,13 +162,11 @@ void createSphere(float r, int slices, int stacks){
#define DEFAULTSLICES 20 #define DEFAULTSLICES 20
#define DEFAULTSTACKS 10 #define DEFAULTSTACKS 10
void createSphere(float r){ void createSphere(float r) { createSphere(r, DEFAULTSLICES, DEFAULTSTACKS); }
createSphere(r, DEFAULTSLICES, DEFAULTSTACKS);
}
bool solvePointInTriangle(float *position, float *normal, bool solvePointInTriangle(float *position, float *normal, Vertex *v1,
Vertex *v1, Vertex *v2, Vertex *v3, Vertex *v2, Vertex *v3, float *t, float *u,
float *t, float *u, float *v){ float *v) {
float edge1[3], edge2[3], tvec[3], pvec[3], qvec[3]; float edge1[3], edge2[3], tvec[3], pvec[3], qvec[3];
float det, inv_det; float det, inv_det;
@ -172,7 +180,8 @@ bool solvePointInTriangle(float *position, float *normal,
// if determinant is near zero, ray lies in plane of triangle // if determinant is near zero, ray lies in plane of triangle
det = vectorDot(edge1, pvec); det = vectorDot(edge1, pvec);
if (det > -EPSILON && det < EPSILON) return false; if (det > -EPSILON && det < EPSILON)
return false;
inv_det = 1.0 / det; inv_det = 1.0 / det;
// calculate distance from vert0 to ray origin // calculate distance from vert0 to ray origin
@ -180,14 +189,16 @@ bool solvePointInTriangle(float *position, float *normal,
// calculate U parameter and test bounds // calculate U parameter and test bounds
*u = vectorDot(tvec, pvec) * inv_det; *u = vectorDot(tvec, pvec) * inv_det;
if (*u < 0.0 || *u > 1.0) return false; if (*u < 0.0 || *u > 1.0)
return false;
// prepare to test V parameter // prepare to test V parameter
vectorCross(qvec, tvec, edge1); vectorCross(qvec, tvec, edge1);
// calculate V parameter and test bounds // calculate V parameter and test bounds
*v = vectorDot(normal, qvec) * inv_det; *v = vectorDot(normal, qvec) * inv_det;
if (*v < 0.0 || *u + *v > 1.0) return false; if (*v < 0.0 || *u + *v > 1.0)
return false;
// calculate t, ray intersects triangle // calculate t, ray intersects triangle
*t = vectorDot(edge2, qvec) * inv_det; *t = vectorDot(edge2, qvec) * inv_det;
@ -195,14 +206,11 @@ bool solvePointInTriangle(float *position, float *normal,
return true; return true;
} }
float distanceFromPlane(float point[3], float normal[3], float distance) { float distanceFromPlane(float point[3], float normal[3], float distance) {
return vectorDot(point, normal) + distance; return vectorDot(point, normal) + distance;
} }
void createSkyBox(float x, float y, float z, float w, float h, float l) {
void createSkyBox(float x, float y, float z, float w, float h, float l)
{
glEnable(GL_TEXTURE_2D); glEnable(GL_TEXTURE_2D);
glClear(GL_DEPTH_BUFFER_BIT); glClear(GL_DEPTH_BUFFER_BIT);
glDisable(GL_DEPTH_TEST); glDisable(GL_DEPTH_TEST);
@ -221,8 +229,7 @@ void createSkyBox(float x, float y, float z, float w, float h, float l)
if (SKYBOX > 0) { if (SKYBOX > 0) {
glCallList(SKYBOX); glCallList(SKYBOX);
} } else {
else{
SKYBOX = glGenLists(1); SKYBOX = glGenLists(1);
@ -232,84 +239,91 @@ void createSkyBox(float x, float y, float z, float w, float h, float l)
glNewList(SKYBOX, GL_COMPILE_AND_EXECUTE); glNewList(SKYBOX, GL_COMPILE_AND_EXECUTE);
// glBindTexture(GL_TEXTURE_2D, SKY_BACK_ID); // glBindTexture(GL_TEXTURE_2D, SKY_BACK_ID);
skybacktexture->enable(); skybacktexture->enable();
glBegin(GL_QUADS); glBegin(GL_QUADS);
glColor4f(1, 1, 1, 1.0); glColor4f(1, 1, 1, 1.0);
glTexCoord2f(1-d, 1-d); glVertex3f(x + w, y, z); glTexCoord2f(1 - d, 1 - d);
glTexCoord2f(1-d, 0+d); glVertex3f(x + w, y + h, z); glVertex3f(x + w, y, z);
glTexCoord2f(0+d, 0+d); glVertex3f(x, y + h, z); glTexCoord2f(1 - d, 0 + d);
glTexCoord2f(0+d, 1-d); glVertex3f(x, y, z); glVertex3f(x + w, y + h, z);
glTexCoord2f(0 + d, 0 + d);
glVertex3f(x, y + h, z);
glTexCoord2f(0 + d, 1 - d);
glVertex3f(x, y, z);
glEnd(); glEnd();
// glBindTexture(GL_TEXTURE_2D, SKY_FRONT_ID); // glBindTexture(GL_TEXTURE_2D, SKY_FRONT_ID);
skyfronttexture->enable(); skyfronttexture->enable();
glBegin(GL_QUADS); glBegin(GL_QUADS);
glColor4f(1, 1, 1, 1.0); glColor4f(1, 1, 1, 1.0);
glTexCoord2f(1-d, 1-d); glVertex3f(x, y, z + l); glTexCoord2f(1 - d, 1 - d);
glTexCoord2f(1-d, 0+d); glVertex3f(x, y + h, z + l); glVertex3f(x, y, z + l);
glTexCoord2f(0+d, 0+d); glVertex3f(x + w, y + h, z + l); glTexCoord2f(1 - d, 0 + d);
glTexCoord2f(0+d, 1-d); glVertex3f(x + w, y, z + l); glVertex3f(x, y + h, z + l);
glTexCoord2f(0 + d, 0 + d);
glVertex3f(x + w, y + h, z + l);
glTexCoord2f(0 + d, 1 - d);
glVertex3f(x + w, y, z + l);
glEnd(); glEnd();
// glBindTexture(GL_TEXTURE_2D, SKY_TOP_ID); // glBindTexture(GL_TEXTURE_2D, SKY_TOP_ID);
skytoptexture->enable(); skytoptexture->enable();
glBegin(GL_QUADS); glBegin(GL_QUADS);
glColor4f(1, 1, 1, 1.0); glColor4f(1, 1, 1, 1.0);
glTexCoord2f(0+d, 0+d); glVertex3f(x + w, y + h, z + l); glTexCoord2f(0 + d, 0 + d);
glTexCoord2f(1-d, 0+d); glVertex3f(x + w, y + h, z); glVertex3f(x + w, y + h, z + l);
glTexCoord2f(1-d, 1-d); glVertex3f(x, y + h, z); glTexCoord2f(1 - d, 0 + d);
glTexCoord2f(0+d, 1-d); glVertex3f(x, y + h, z + l); glVertex3f(x + w, y + h, z);
glTexCoord2f(1 - d, 1 - d);
glVertex3f(x, y + h, z);
glTexCoord2f(0 + d, 1 - d);
glVertex3f(x, y + h, z + l);
/*glTexCoord2f(1.0f, 0+d); glVertex3f(x + w, y + h, z); /*glTexCoord2f(1.0f, 0+d); glVertex3f(x + w, y + h, z);
glTexCoord2f(1.0f, 1.0f); glVertex3f(x + w, y + h, z + l); glTexCoord2f(1.0f, 1.0f); glVertex3f(x + w, y + h, z + l);
glTexCoord2f(0+d, 1.0f); glVertex3f(x, y + h, z + l); glTexCoord2f(0+d, 1.0f); glVertex3f(x, y + h, z + l);
glTexCoord2f(0+d, 0+d); glVertex3f(x, y + h, z);*/ glTexCoord2f(0+d, 0+d); glVertex3f(x, y + h, z);*/
glEnd(); glEnd();
// glBindTexture(GL_TEXTURE_2D, SKY_BOTTOM_ID); // glBindTexture(GL_TEXTURE_2D, SKY_BOTTOM_ID);
skybottomtexture->enable(); skybottomtexture->enable();
glBegin(GL_QUADS); glBegin(GL_QUADS);
glColor4f(1, 1, 1, 1.0); glColor4f(1, 1, 1, 1.0);
glTexCoord2f(1-d, 0+d); glVertex3f(x, y, z); glTexCoord2f(1 - d, 0 + d);
glTexCoord2f(1-d, 1-d); glVertex3f(x + w, y, z); glVertex3f(x, y, z);
glTexCoord2f(0+d, 1-d); glVertex3f(x + w, y, z + l); glTexCoord2f(1 - d, 1 - d);
glTexCoord2f(0+d, 0+d); glVertex3f(x, y, z + l); glVertex3f(x + w, y, z);
glTexCoord2f(0 + d, 1 - d);
glVertex3f(x + w, y, z + l);
glTexCoord2f(0 + d, 0 + d);
glVertex3f(x, y, z + l);
glEnd(); glEnd();
// glBindTexture(GL_TEXTURE_2D, SKY_LEFT_ID); // glBindTexture(GL_TEXTURE_2D, SKY_LEFT_ID);
skylefttexture->enable(); skylefttexture->enable();
glBegin(GL_QUADS); glBegin(GL_QUADS);
glColor4f(1, 1, 1, 1.0); glColor4f(1, 1, 1, 1.0);
glTexCoord2f(1-d, 0+d); glVertex3f(x, y + h, z); glTexCoord2f(1 - d, 0 + d);
glTexCoord2f(0+d, 0+d); glVertex3f(x, y + h, z + l); glVertex3f(x, y + h, z);
glTexCoord2f(0+d, 1-d); glVertex3f(x, y, z + l); glTexCoord2f(0 + d, 0 + d);
glTexCoord2f(1-d, 1-d); glVertex3f(x, y, z); glVertex3f(x, y + h, z + l);
glTexCoord2f(0 + d, 1 - d);
glVertex3f(x, y, z + l);
glTexCoord2f(1 - d, 1 - d);
glVertex3f(x, y, z);
glEnd(); glEnd();
@ -318,11 +332,14 @@ void createSkyBox(float x, float y, float z, float w, float h, float l)
glBegin(GL_QUADS); glBegin(GL_QUADS);
glColor4f(1, 1, 1, 1.0); glColor4f(1, 1, 1, 1.0);
glTexCoord2f(0+d, 1-d); glVertex3f(x + w, y, z); glTexCoord2f(0 + d, 1 - d);
glTexCoord2f(1-d, 1-d); glVertex3f(x + w, y, z + l); glVertex3f(x + w, y, z);
glTexCoord2f(1-d, 0+d); glVertex3f(x + w, y + h, z + l); glTexCoord2f(1 - d, 1 - d);
glTexCoord2f(0+d, 0+d); glVertex3f(x + w, y + h, z); glVertex3f(x + w, y, z + l);
glTexCoord2f(1 - d, 0 + d);
glVertex3f(x + w, y + h, z + l);
glTexCoord2f(0 + d, 0 + d);
glVertex3f(x + w, y + h, z);
glEnd(); glEnd();
glEndList(); glEndList();

View file

@ -4,8 +4,6 @@
#include "main.h" #include "main.h"
#include "texture.h" #include "texture.h"
#define SKYFRONT DATAPATH "tback.png" #define SKYFRONT DATAPATH "tback.png"
#define SKYBACK DATAPATH "tfront.png" #define SKYBACK DATAPATH "tfront.png"
#define SKYLEFT DATAPATH "tleft.png" #define SKYLEFT DATAPATH "tleft.png"
@ -13,7 +11,6 @@
#define SKYTOP DATAPATH "ttop.png" #define SKYTOP DATAPATH "ttop.png"
#define SKYBOTTOM DATAPATH "tbottom.png" #define SKYBOTTOM DATAPATH "tbottom.png"
#define DAMAGEHEAD DATAPATH "damagehead.png" #define DAMAGEHEAD DATAPATH "damagehead.png"
#define DAMAGETORSO DATAPATH "damagetorso.png" #define DAMAGETORSO DATAPATH "damagetorso.png"
#define DAMAGEHAND DATAPATH "damagehand.png" #define DAMAGEHAND DATAPATH "damagehand.png"
@ -22,13 +19,9 @@
extern int SKYBOX; extern int SKYBOX;
typedef struct{ typedef struct { float x, y; } point2d;
float x,y;
} point2d;
typedef struct{ typedef struct { float x, y, z; } point3d;
float x,y,z;
} point3d;
extern Texture *flaretexture; extern Texture *flaretexture;
extern Texture *skyfronttexture; extern Texture *skyfronttexture;
@ -40,7 +33,8 @@ extern Texture *skybottomtexture;
extern Texture *damageHead; extern Texture *damageHead;
extern Texture *faceTexture; extern Texture *faceTexture;
void createLathedSurface(point2d *points, point2d *pointderivates, int count, int slices, int stacks); void createLathedSurface(point2d *points, point2d *pointderivates, int count,
int slices, int stacks);
void createSphere(float r, int slices, int stacks); void createSphere(float r, int slices, int stacks);
void createSphere(float r); void createSphere(float r);
@ -48,10 +42,8 @@ float distanceFromPlane(float point[3], float normal[3], float distance);
void createSkyBox(float x, float y, float z, float w, float h, float l); void createSkyBox(float x, float y, float z, float w, float h, float l);
// MUST be called in pairs, enable pushes and disable pops // MUST be called in pairs, enable pushes and disable pops
void enable2D(void); void enable2D(void);
void disable2D(void); void disable2D(void);
#endif #endif

View file

@ -1,24 +1,20 @@
#include "main.h" #include "main.h"
#include "appearance.h" #include "appearance.h"
#include "utils.h" #include "utils.h"
#include "3dutils.h" #include "3dutils.h"
#include "glapi.h" #include "glapi.h"
Appearance::Appearance(void){ Appearance::Appearance(void) {}
}
void Appearance::prepare(void){
}
void Appearance::prepare(void) {}
/*BoxAppearance::BoxAppearance(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){ BoxAppearance::setDimension(float x1, float x2, float y1, float y2, float z1,
float z2){
if (x1 > x2) swapFloat(&x1, &x2); if (x1 > x2) swapFloat(&x1, &x2);
if (y1 > y2) swapFloat(&y1, &y2); if (y1 > y2) swapFloat(&y1, &y2);
if (z1 > z2) swapFloat(&z1, &z2); if (z1 > z2) swapFloat(&z1, &z2);
@ -77,21 +73,11 @@ void BoxAppearance::draw(void){
this->material.disable(); this->material.disable();
}*/ }*/
Material *Appearance::getMaterial(void) { return &this->material; }
Material* Appearance::getMaterial(void){ void Appearance::setMaterial(Material matsku) { material = matsku; }
return &this->material;
}
void Appearance::setMaterial(Material matsku){ MultiAppearance::MultiAppearance(void) { appearances = NULL; }
material = matsku;
}
MultiAppearance::MultiAppearance(void){
appearances = NULL;
}
void MultiAppearance::addAppearance(Appearance *appearance) { void MultiAppearance::addAppearance(Appearance *appearance) {
appearancelist *node = new appearancelist; appearancelist *node = new appearancelist;

View file

@ -22,7 +22,6 @@ public:
virtual void draw(void) = 0; virtual void draw(void) = 0;
}; };
struct appearancelist { struct appearancelist {
Appearance *data; Appearance *data;
appearancelist *next; appearancelist *next;
@ -41,4 +40,3 @@ public:
}; };
#endif #endif

View file

@ -5,12 +5,10 @@
#include "audio.h" #include "audio.h"
#define SOUND_FADENONE 0 #define SOUND_FADENONE 0
#define SOUND_FADEIN 1 #define SOUND_FADEIN 1
#define SOUND_FADEOUT 2 #define SOUND_FADEOUT 2
struct soundlist { struct soundlist {
Sound *sound; Sound *sound;
soundlist *next; soundlist *next;
@ -18,7 +16,6 @@ struct soundlist{
soundlist *allsounds = NULL; soundlist *allsounds = NULL;
Sound::Sound(Sound *source) { Sound::Sound(Sound *source) {
memcpy(this, source, sizeof(Sound)); memcpy(this, source, sizeof(Sound));
soundlist *node = new soundlist; soundlist *node = new soundlist;
@ -32,9 +29,7 @@ Sound::Sound(char *filename){
// printf("%s: %p, %p, %p, %p\n", filename, this, stream, sample, module); // printf("%s: %p, %p, %p, %p\n", filename, this, stream, sample, module);
} }
Sound::Sound(char *filename, int type){ Sound::Sound(char *filename, int type) { load(filename, type, false); }
load(filename, type, false);
}
Sound::Sound(char *filename, bool loops) { Sound::Sound(char *filename, bool loops) {
load(filename, SOUNDTYPE_AUTODETECT, loops); load(filename, SOUNDTYPE_AUTODETECT, loops);
@ -48,30 +43,31 @@ Sound::Sound(char *filename, int type, bool loops){
bool endsWith(char *str1, char *str2) { bool endsWith(char *str1, char *str2) {
char *str3 = str1 + strlen(str1) - strlen(str2); char *str3 = str1 + strlen(str1) - strlen(str2);
#ifdef WIN32 #ifdef WIN32
if (stricmp(str3, str2)) return false; if (stricmp(str3, str2))
return false;
#else #else
if (strcasecmp(str3, str2)) return false; if (strcasecmp(str3, str2))
return false;
#endif #endif
else return true; else
return true;
} }
void Sound::load(char *filename, int type, bool loops) { void Sound::load(char *filename, int type, bool loops) {
this->filename = filename; this->filename = filename;
if (type == SOUNDTYPE_AUTODETECT) { if (type == SOUNDTYPE_AUTODETECT) {
if (endsWith(filename, "mp3") || if (endsWith(filename, "mp3") || endsWith(filename, "mp2") ||
endsWith(filename, "mp2") || endsWith(filename, "ogg"))
endsWith(filename, "ogg")) type = SOUNDTYPE_STREAM; type = SOUNDTYPE_STREAM;
if (endsWith(filename, "wav") || if (endsWith(filename, "wav") || endsWith(filename, "raw"))
endsWith(filename, "raw")) type = SOUNDTYPE_SAMPLE; type = SOUNDTYPE_SAMPLE;
if (endsWith(filename, "s3m") || if (endsWith(filename, "s3m") || endsWith(filename, "xm") ||
endsWith(filename, "xm") || endsWith(filename, "it") || endsWith(filename, "mid") ||
endsWith(filename, "it") || endsWith(filename, "rmi") || endsWith(filename, "sgr") ||
endsWith(filename, "mid") || endsWith(filename, "mod"))
endsWith(filename, "rmi") || type = SOUNDTYPE_MODULE;
endsWith(filename, "sgr") ||
endsWith(filename, "mod")) type = SOUNDTYPE_MODULE;
} }
#ifdef AUDIO_FMOD #ifdef AUDIO_FMOD
sample = NULL; sample = NULL;
@ -108,10 +104,11 @@ void Sound::load(char *filename, int type, bool loops){
setVolume(1.0); setVolume(1.0);
} }
bool Sound::play() { bool Sound::play() {
//printf("Playing %s: %p, %p, %p, %p\n", filename, this, stream, sample, module); // printf("Playing %s: %p, %p, %p, %p\n", filename, this, stream, sample,
if (minduration > 0) return false; // module);
if (minduration > 0)
return false;
running = true; running = true;
finished = false; finished = false;
fademode = SOUND_FADENONE; fademode = SOUND_FADENONE;
@ -137,7 +134,8 @@ bool Sound::play(){
} }
void Sound::play(int minduration) { void Sound::play(int minduration) {
if (play()) this->minduration = minduration; if (play())
this->minduration = minduration;
} }
void Sound::stop() { void Sound::stop() {
@ -167,7 +165,8 @@ void Sound::setVolume(float volume){
} }
#ifdef AUDIO_FMOD #ifdef AUDIO_FMOD
signed char streamendcallback(FSOUND_STREAM *stream, void *buff, int len, int param){ signed char streamendcallback(FSOUND_STREAM *stream, void *buff, int len,
int param) {
Sound *sound = (Sound *)param; Sound *sound = (Sound *)param;
sound->setFinished(); sound->setFinished();
return true; return true;
@ -186,20 +185,18 @@ void Sound::setStopCallback(STOPCALLBACK callback){
#endif #endif
} }
void Sound::setFinished(void) { finished = true; }
void Sound::setFinished(void){
finished = true;
}
bool Sound::isFinished(void) { bool Sound::isFinished(void) {
#ifdef AUDIO_FMOD #ifdef AUDIO_FMOD
if (type == SOUNDTYPE_MODULE) { if (type == SOUNDTYPE_MODULE) {
if (FMUSIC_IsFinished(module)) return true; if (FMUSIC_IsFinished(module))
return true;
} else if (type == SOUNDTYPE_SAMPLE) { } else if (type == SOUNDTYPE_SAMPLE) {
// NOT SUPPORTED // NOT SUPPORTED
} else if (type == SOUNDTYPE_STREAM) { } else if (type == SOUNDTYPE_STREAM) {
if (finished) return true; if (finished)
return true;
} }
#endif #endif
return false; return false;
@ -209,13 +206,15 @@ void Sound::update(void){
if (running) { if (running) {
if (isFinished()) { if (isFinished()) {
running = false; running = false;
if (stopcallback != NULL) stopcallback(this); if (stopcallback != NULL)
stopcallback(this);
} else { } else {
if (fademode == SOUND_FADEIN) { if (fademode == SOUND_FADEIN) {
if (fadepos < fadetarget) { if (fadepos < fadetarget) {
fadepos++; fadepos++;
setVolume((float)fadepos / fadetarget); setVolume((float)fadepos / fadetarget);
} else fademode = SOUND_FADENONE; } else
fademode = SOUND_FADENONE;
} }
if (fademode == SOUND_FADEOUT) { if (fademode == SOUND_FADEOUT) {
if (fadepos < fadetarget) { if (fadepos < fadetarget) {
@ -228,7 +227,8 @@ void Sound::update(void){
} }
} }
} }
if (minduration > 0) minduration--; if (minduration > 0)
minduration--;
} }
void Sound::fadeIn(int length) { void Sound::fadeIn(int length) {
@ -247,7 +247,6 @@ void Sound::fadeOut(int length){
fademode = SOUND_FADEOUT; fademode = SOUND_FADEOUT;
} }
void initAudio(void) { void initAudio(void) {
#ifdef AUDIO_FMOD #ifdef AUDIO_FMOD
FSOUND_Init(44100, 32, 0); FSOUND_Init(44100, 32, 0);

View file

@ -1,12 +1,10 @@
#ifndef __AUDIO_H_INCLUDED__ #ifndef __AUDIO_H_INCLUDED__
#define __AUDIO_H_INCLUDED__ #define __AUDIO_H_INCLUDED__
#ifdef AUDIO_FMOD #ifdef AUDIO_FMOD
#include <fmod.h> #include <fmod.h>
#endif #endif
class Sound; class Sound;
typedef void (*STOPCALLBACK)(Sound *sound); typedef void (*STOPCALLBACK)(Sound *sound);
@ -69,4 +67,3 @@ void uninitAudio(void);
void updateAudio(void); void updateAudio(void);
#endif #endif

View file

@ -30,17 +30,11 @@ void Camera::getPosition(float *position){
vectorCopy(position, this->position); vectorCopy(position, this->position);
} }
void Camera::setTarget(float target[3]){ void Camera::setTarget(float target[3]) { vectorCopy(this->target, target); }
vectorCopy(this->target, target);
}
void Camera::getTarget(float *target){ void Camera::getTarget(float *target) { vectorCopy(target, this->target); }
vectorCopy(target, this->target);
}
void Camera::setUp(float up[3]){ void Camera::setUp(float up[3]) { vectorCopy(this->up, up); }
vectorCopy(this->up, up);
}
void Camera::getMatrix(float *matrix) { void Camera::getMatrix(float *matrix) {
vectorCopy(&matrix[0], &this->matrix[0]); vectorCopy(&matrix[0], &this->matrix[0]);
@ -75,9 +69,8 @@ void Camera::moveForward(float amount){
void Camera::glUpdate(void) { void Camera::glUpdate(void) {
// glLoadIdentity(); // glLoadIdentity();
gluLookAt(position[0], position[1], position[2], gluLookAt(position[0], position[1], position[2], target[0], target[1],
target[0], target[1], target[2], target[2], up[0], up[1], up[2]);
up[0], up[1], up[2]);
} }
void Camera::calculateMatrix(void) { void Camera::calculateMatrix(void) {

View file

@ -29,4 +29,3 @@ public:
}; };
#endif #endif

View file

@ -9,7 +9,6 @@
#include "world.h" #include "world.h"
#include "audio.h" #include "audio.h"
// objectlist *collisionlists[32]; // objectlist *collisionlists[32];
unsigned int collisionlinks[32]; unsigned int collisionlinks[32];
@ -33,21 +32,24 @@ void initCollisions(void){
void addCollisionLink(int source, int target) { void addCollisionLink(int source, int target) {
collisionlinks[source] |= (1 << target); collisionlinks[source] |= (1 << target);
if (source != target) collisionlinks[target] |= (1<<source); if (source != target)
collisionlinks[target] |= (1 << source);
} }
void removeCollisionLink(int source, int target) { void removeCollisionLink(int source, int target) {
collisionlinks[source] &= ~(1 << target); collisionlinks[source] &= ~(1 << target);
if (source != target) collisionlinks[target] &= ~(1<<source); if (source != target)
collisionlinks[target] &= ~(1 << source);
} }
bool isCollisionLink(int source, int target) { bool isCollisionLink(int source, int target) {
if (collisionlinks[source] & (1<<target)) return true; if (collisionlinks[source] & (1 << target))
return true;
return false; return false;
} }
void addCollision(Object *source, Object *target, void addCollision(Object *source, Object *target, float *normal,
float *normal, float *contactpoint){ float *contactpoint) {
if (contactcount == MAXCONTACTS) { if (contactcount == MAXCONTACTS) {
printf("Too many contacts!\n"); printf("Too many contacts!\n");
return; return;
@ -88,15 +90,17 @@ bool handleCollision(Contact *contact){
// if (fabs(dot) < EPSILON) return false; // if (fabs(dot) < EPSILON) return false;
// if (dot > -1.0e-5 && dot < 1.0e-5) return false; // if (dot > -1.0e-5 && dot < 1.0e-5) return false;
// if (dot >= 0) return false; // if (dot >= 0) return false;
if (dot > -1.0e-5) return false; if (dot > -1.0e-5)
return false;
float invmass1; float invmass1;
invmass1 = source->invmass; invmass1 = source->invmass;
float invmass2; float invmass2;
if (target == NULL) invmass2 = 0; if (target == NULL)
else invmass2 = target->invmass; invmass2 = 0;
else
invmass2 = target->invmass;
float t1; float t1;
if (source->invmomentofinertia == 0) { if (source->invmomentofinertia == 0) {
@ -133,18 +137,17 @@ bool handleCollision(Contact *contact){
float impulse[3]; float impulse[3];
vectorScale(impulse, normal, impulsesize); vectorScale(impulse, normal, impulsesize);
float friction[3]; float friction[3];
vectorScale(friction, normal, vectorDot(deltavelocity, normal)); vectorScale(friction, normal, vectorDot(deltavelocity, normal));
vectorAdd(friction, deltavelocity); vectorAdd(friction, deltavelocity);
vectorNormalize(friction); vectorNormalize(friction);
float frictionsize = 10 * KINETICFRICTION * dot / denominator; float frictionsize = 10 * KINETICFRICTION * dot / denominator;
float maxfrictionsize = 0.1 * vectorLength(deltavelocity); float maxfrictionsize = 0.1 * vectorLength(deltavelocity);
if (frictionsize < -maxfrictionsize) frictionsize = -maxfrictionsize; if (frictionsize < -maxfrictionsize)
frictionsize = -maxfrictionsize;
vectorScale(friction, -frictionsize); vectorScale(friction, -frictionsize);
vectorAdd(impulse, friction); vectorAdd(impulse, friction);
if (target != NULL) { if (target != NULL) {
target->addImpulse(impulse, targetcontactpoint); target->addImpulse(impulse, targetcontactpoint);
target->calculateStateVariables(); target->calculateStateVariables();
@ -169,7 +172,6 @@ bool handleCollision(Contact *contact){
if (k > 0) */ target->hitForce(speed, speed2, source); if (k > 0) */ target->hitForce(speed, speed2, source);
} }
vectorScale(impulse, -1); vectorScale(impulse, -1);
source->addImpulse(impulse, sourcecontactpoint); source->addImpulse(impulse, sourcecontactpoint);
source->calculateStateVariables(); source->calculateStateVariables();
@ -191,13 +193,12 @@ bool handleCollision(Contact *contact){
if (k > 0) */ source->hitForce(speed, speed2, target); if (k > 0) */ source->hitForce(speed, speed2, target);
} }
return true; return true;
} }
bool handleLink(ObjectLink *link) { bool handleLink(ObjectLink *link) {
if (!link->enabled) return false; if (!link->enabled)
return false;
Object *source = link->object1; Object *source = link->object1;
Object *target = link->object2; Object *target = link->object2;
@ -213,7 +214,8 @@ bool handleLink(ObjectLink *link){
float strength = vectorDot(diff, diff); float strength = vectorDot(diff, diff);
if (strength < 1.0e-5) return false; if (strength < 1.0e-5)
return false;
float sourcevelocity[3], targetvelocity[3]; float sourcevelocity[3], targetvelocity[3];
float sourcecontactpoint[3], targetcontactpoint[3]; float sourcecontactpoint[3], targetcontactpoint[3];
@ -233,7 +235,6 @@ bool handleLink(ObjectLink *link){
// if (dot >= 0) return false; // if (dot >= 0) return false;
// if (dot > -1.0e-5) return false; // if (dot > -1.0e-5) return false;
float invmass1 = source->invmass; float invmass1 = source->invmass;
float invmass2 = target->invmass; float invmass2 = target->invmass;
@ -270,7 +271,6 @@ bool handleLink(ObjectLink *link){
float impulse[3]; float impulse[3];
vectorScale(impulse, normal, impulsesize); vectorScale(impulse, normal, impulsesize);
target->addImpulse(impulse, targetcontactpoint); target->addImpulse(impulse, targetcontactpoint);
target->calculateStateVariables(); target->calculateStateVariables();
@ -278,7 +278,6 @@ bool handleLink(ObjectLink *link){
source->addImpulse(impulse, sourcecontactpoint); source->addImpulse(impulse, sourcecontactpoint);
source->calculateStateVariables(); source->calculateStateVariables();
return true; return true;
} }
@ -341,7 +340,8 @@ bool checkCollisions(Object *object, float *contactnormal){
} }
}*/ }*/
void collide(Object *source, Object *target, float *normal, float *contactpoint){ void collide(Object *source, Object *target, float *normal,
float *contactpoint) {
/* float momentum[3]; /* float momentum[3];
source->getMomentum(momentum); source->getMomentum(momentum);
@ -378,7 +378,8 @@ void collide(Object *source, Object *target, float *normal, float *contactpoint)
vectorCross(w1, v1, sourcecontactpoint); vectorCross(w1, v1, sourcecontactpoint);
t1 = vectorDot(normal, w1); t1 = vectorDot(normal, w1);
} }
//printf("S: %f, %f, %f\n", sourcecontactpoint[0], source->momentofinertia, v1); //printf("S: %f, %f, %f\n", sourcecontactpoint[0],
source->momentofinertia, v1);
float t2; float t2;
if (target->momentofinertia == 0){ if (target->momentofinertia == 0){
@ -391,19 +392,22 @@ void collide(Object *source, Object *target, float *normal, float *contactpoint)
vectorCross(w2, v2, targetcontactpoint); vectorCross(w2, v2, targetcontactpoint);
t2 = vectorDot(normal, w2); t2 = vectorDot(normal, w2);
} }
//printf("T: %f, %f, %f\n", targetcontactpoint[0], target->momentofinertia, v2); //printf("T: %f, %f, %f\n", targetcontactpoint[0],
target->momentofinertia, v2);
float divisor; float divisor;
divisor = massinverse1 + massinverse2;// + t1 + t2; 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]; float impulse[3];
vectorScale(impulse, normal, impulsesize); vectorScale(impulse, normal, impulsesize);
//collide(sourcevelocity, targetvelocity, sourcemass, targetmass, normal, impulse); //collide(sourcevelocity, targetvelocity, sourcemass, targetmass, normal,
impulse);
//vectorAdd(source->momentum, impulse); //vectorAdd(source->momentum, impulse);
@ -417,9 +421,8 @@ void collide(Object *source, Object *target, float *normal, float *contactpoint)
//source->addForce(force, sourcecontactpoint);*/ //source->addForce(force, sourcecontactpoint);*/
} }
bool checkSphereMeshCollision(float *sphereposition, float r, Mesh *mesh,
float *normal, float *contactpoint) {
bool checkSphereMeshCollision(float *sphereposition, float r, Mesh *mesh, float *normal, float *contactpoint){
float linenormal[3]; float linenormal[3];
float pointnormal[3]; float pointnormal[3];
float maxdist = 0; float maxdist = 0;
@ -432,7 +435,8 @@ bool checkSphereMeshCollision(float *sphereposition, float r, Mesh *mesh, float
for (i = 0; i < mesh->polygoncount; i++) { for (i = 0; i < mesh->polygoncount; i++) {
class Polygon *polygon = &mesh->polygons[i]; class Polygon *polygon = &mesh->polygons[i];
float dist = distanceFromPlane(sphereposition, polygon->planenormal, polygon->planedistance); float dist = distanceFromPlane(sphereposition, polygon->planenormal,
polygon->planedistance);
if (dist < r && dist > -r) { if (dist < r && dist > -r) {
bool directcollision = true; bool directcollision = true;
for (j = 0; j < polygon->vertexcount; j++) { for (j = 0; j < polygon->vertexcount; j++) {
@ -465,7 +469,8 @@ bool checkSphereMeshCollision(float *sphereposition, float r, Mesh *mesh, float
float l2 = vectorDot(projorth, projorth); float l2 = vectorDot(projorth, projorth);
if (l2 < r * r) { if (l2 < r * r) {
vectorNormalize(linenormal, projorth); vectorNormalize(linenormal, projorth);
if (dist < 0) vectorScale(linenormal, -1); if (dist < 0)
vectorScale(linenormal, -1);
linecollision = true; linecollision = true;
} }
} }
@ -477,7 +482,8 @@ bool checkSphereMeshCollision(float *sphereposition, float r, Mesh *mesh, float
float l3 = vectorDot(pointdiff, pointdiff); float l3 = vectorDot(pointdiff, pointdiff);
if (l3 < r * r) { if (l3 < r * r) {
vectorScale(pointnormal, pointdiff, 1.0 / sqrt(l3)); vectorScale(pointnormal, pointdiff, 1.0 / sqrt(l3));
if (dist < 0) vectorScale(pointnormal, -1); if (dist < 0)
vectorScale(pointnormal, -1);
pointcollision = true; pointcollision = true;
} }
} }
@ -509,11 +515,8 @@ bool checkSphereMeshCollision(float *sphereposition, float r, Mesh *mesh, float
return true; return true;
} }
bool checkPointMeshCollision(float *position, Mesh *mesh, float *normal,
float *contactpoint) {
bool checkPointMeshCollision(float *position, Mesh *mesh, float *normal, float *contactpoint){
float maxdist = 0; float maxdist = 0;
bool planecollision = false; bool planecollision = false;
@ -522,7 +525,8 @@ bool checkPointMeshCollision(float *position, Mesh *mesh, float *normal, float *
for (i = 0; i < mesh->polygoncount; i++) { for (i = 0; i < mesh->polygoncount; i++) {
class Polygon *polygon = &mesh->polygons[i]; class Polygon *polygon = &mesh->polygons[i];
float dist = distanceFromPlane(position, polygon->planenormal, polygon->planedistance); float dist = distanceFromPlane(position, polygon->planenormal,
polygon->planedistance);
if (dist < 0) { if (dist < 0) {
bool directcollision = true; bool directcollision = true;
/*for (j = 0; j < polygon->vertexcount; j++){ /*for (j = 0; j < polygon->vertexcount; j++){
@ -574,13 +578,16 @@ struct tracehit{
Polygon *polygon; Polygon *polygon;
}; };
bool tracePlane(tracehit *result, float *origin, float *ray, class Polygon *polygon){ bool tracePlane(tracehit *result, float *origin, float *ray,
class Polygon *polygon) {
float *normal = polygon->planenormal; float *normal = polygon->planenormal;
float D = polygon->planedistance; float D = polygon->planedistance;
float denominator = vectorDot(normal, ray); float denominator = vectorDot(normal, ray);
if (denominator == 0) { if (denominator == 0) {
if (vectorDot(normal, origin) > 0) result->t = 1000000; if (vectorDot(normal, origin) > 0)
else result->t = -1000000; result->t = 1000000;
else
result->t = -1000000;
result->polygon = polygon; result->polygon = polygon;
return true; return true;
} }
@ -601,7 +608,8 @@ Edge *findSharingEdge(class Polygon *p1, class Polygon *p2){
for (i = 0; i < p1->vertexcount; i++) { for (i = 0; i < p1->vertexcount; i++) {
// printf("%p\n", p1->edges[i]); // printf("%p\n", p1->edges[i]);
for (j = 0; j < p2->vertexcount; j++) { for (j = 0; j < p2->vertexcount; j++) {
if (p1->edges[i] == p2->edges[j]) return p1->edges[i]; if (p1->edges[i] == p2->edges[j])
return p1->edges[i];
} }
} }
return NULL; return NULL;
@ -625,9 +633,12 @@ Polygon *findNearestPolygon(class Polygon *polygon, float *point){
for (i = 0; i < polygon->edgecount; i++) { for (i = 0; i < polygon->edgecount; i++) {
Edge *edge = polygon->edges[i]; Edge *edge = polygon->edges[i];
Polygon *polygon2 = edge->p1; Polygon *polygon2 = edge->p1;
if (polygon2 == polygon) polygon2 = edge->p2; if (polygon2 == polygon)
float newdist = distanceFromPlane(point, polygon2->planenormal, polygon2->planedistance); polygon2 = edge->p2;
if (newdist > 0) return NULL; float newdist = distanceFromPlane(point, polygon2->planenormal,
polygon2->planedistance);
if (newdist > 0)
return NULL;
if (mindist == 0 || newdist > mindist) { if (mindist == 0 || newdist > mindist) {
mindist = newdist; mindist = newdist;
nearestpolygon = polygon2; nearestpolygon = polygon2;
@ -636,7 +647,8 @@ Polygon *findNearestPolygon(class Polygon *polygon, float *point){
return nearestpolygon; return nearestpolygon;
} }
bool checkEdgeMeshCollision(float *p1, float *p2, Mesh *mesh, float *normal, float *contactpoint){ bool checkEdgeMeshCollision(float *p1, float *p2, Mesh *mesh, float *normal,
float *contactpoint) {
float ray[3]; float ray[3];
vectorSub(ray, p2, p1); vectorSub(ray, p2, p1);
@ -656,7 +668,8 @@ bool checkEdgeMeshCollision(float *p1, float *p2, Mesh *mesh, float *normal, flo
} }
} }
if (hitcount < 2) return false; if (hitcount < 2)
return false;
for (i = 1; i < hitcount; i++) { for (i = 1; i < hitcount; i++) {
for (j = i; j > 0; j--) { for (j = i; j > 0; j--) {
@ -667,26 +680,30 @@ bool checkEdgeMeshCollision(float *p1, float *p2, Mesh *mesh, float *normal, flo
class Polygon *tempp = hits[j].polygon; class Polygon *tempp = hits[j].polygon;
hits[j].polygon = hits[j - 1].polygon; hits[j].polygon = hits[j - 1].polygon;
hits[j - 1].polygon = tempp; hits[j - 1].polygon = tempp;
} else break; } else
break;
} }
} }
int negative = -1, positive = -1; int negative = -1, positive = -1;
for (i = 0; i < hitcount; i++) { for (i = 0; i < hitcount; i++) {
float t = hits[i].t; float t = hits[i].t;
class Polygon *polygon = hits[i].polygon; 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 && positive == -1)
if (dot < 0) negative = i; 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++){ /*for (i = 0; i < hitcount; i++){
float t = hits[i].t; float t = hits[i].t;
@ -698,7 +715,8 @@ bool checkEdgeMeshCollision(float *p1, float *p2, Mesh *mesh, float *normal, flo
} }
printf("\n");*/ 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);
@ -751,7 +769,6 @@ bool checkEdgeMeshCollision(float *p1, float *p2, Mesh *mesh, float *normal, flo
} }
} }
// shotsound->play(); // shotsound->play();
return true; return true;
} }

View file

@ -31,17 +31,18 @@ public:
extern Contact *contacts; extern Contact *contacts;
extern int contactcount; extern int contactcount;
// Contact point is world-relative and must be transformed // Contact point is world-relative and must be transformed
// into coordinate system of both objects // into coordinate system of both objects
void addCollision(Object *source, Object *target, void addCollision(Object *source, Object *target, float *normal,
float *normal, float *contactpoint); float *contactpoint);
bool handleCollision(Contact *contact); bool handleCollision(Contact *contact);
bool handleLink(ObjectLink *link); bool handleLink(ObjectLink *link);
bool checkSphereMeshCollision(float *sphereposition, float r, Mesh *mesh, float *normal, float *contactpoint); bool checkSphereMeshCollision(float *sphereposition, float r, Mesh *mesh,
bool checkPointMeshCollision(float *position, Mesh *mesh, float *normal, float *contactpoint); float *normal, float *contactpoint);
bool checkEdgeMeshCollision(float *p1, float *p2, Mesh *mesh, float *normal, float *contactpoint); bool checkPointMeshCollision(float *position, Mesh *mesh, float *normal,
float *contactpoint);
bool checkEdgeMeshCollision(float *p1, float *p2, Mesh *mesh, float *normal,
float *contactpoint);
#endif #endif

View file

@ -77,11 +77,15 @@ void calculateEnd(int framecount){
float target[3] = {0, 13, 0}; float target[3] = {0, 13, 0};
endcamera.setTarget(target); 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(10 + sin(framecount * 0.002) * 2,
//endcamera.setPosition(sin(framecount*0.01)*25, sin(framecount*0.007)*6+20, cos(framecount*0.01)*25); 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(40, 20, 0);
endlight.setPosition(-sin(framecount*0.007)*10, 15, cos(framecount*0.007)*2+22); endlight.setPosition(-sin(framecount * 0.007) * 10, 15,
cos(framecount * 0.007) * 2 + 22);
if (keys[SDLK_ESCAPE]) { if (keys[SDLK_ESCAPE]) {
stopEnding(); stopEnding();
@ -119,14 +123,14 @@ void drawEnd(int framecount){
winner->leftleg->draw(); winner->leftleg->draw();
winner->rightleg->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 == PLAYER1)
if (winner->side == PLAYER2) print(0.05, 0.05, "Player 2 is\nthe winner", 0.09); 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) { if (endfade != -1) {
glEnable(GL_BLEND); glEnable(GL_BLEND);

View file

@ -6,11 +6,9 @@
#include "texture.h" #include "texture.h"
#include "audio.h" #include "audio.h"
void initEnd(void); void initEnd(void);
void endRestart(void); void endRestart(void);
void calculateEnd(int framecount); void calculateEnd(int framecount);
void drawEnd(int framecount); void drawEnd(int framecount);
#endif #endif

View file

@ -75,14 +75,12 @@ void initFight(void){
arenaworld = new World(); arenaworld = new World();
// arenalight.setEnabled(true); // arenalight.setEnabled(true);
/*arenalight.setPosition(0, 10, 0); /*arenalight.setPosition(0, 10, 0);
Object *lamp = new Object(); Object *lamp = new Object();
lamp->appearance = new LampAppearance(); lamp->appearance = new LampAppearance();
lamp->setPosition(0, 10, 0); lamp->setPosition(0, 10, 0);
arenaworld->addChild(lamp);*/ arenaworld->addChild(lamp);*/
} }
light1.setColor(1, 1, 1); light1.setColor(1, 1, 1);
@ -105,31 +103,33 @@ void initFight(void){
light4.setPosition(ARENASIZE - 0.5, 5, ARENASIZE - 0.5); light4.setPosition(ARENASIZE - 0.5, 5, ARENASIZE - 0.5);
light4.setAttenuation(0.2, 0.0, 0.02); light4.setAttenuation(0.2, 0.0, 0.02);
if (!fightinitialized) { if (!fightinitialized) {
Object *lamp; Object *lamp;
lamp = new Object(); lamp = new Object();
lamp->appearance = new LampAppearance(); lamp->appearance = new LampAppearance();
lamp->setPosition(-ARENASIZE+0.5, (ARENAHEIGHT+0.5)*BLOCKHEIGHT, -ARENASIZE+0.5); lamp->setPosition(-ARENASIZE + 0.5, (ARENAHEIGHT + 0.5) * BLOCKHEIGHT,
-ARENASIZE + 0.5);
arenaworld->addChild(lamp); arenaworld->addChild(lamp);
lamp = new Object(); lamp = new Object();
lamp->appearance = new LampAppearance(); lamp->appearance = new LampAppearance();
lamp->setPosition(ARENASIZE-0.5, (ARENAHEIGHT+0.5)*BLOCKHEIGHT, -ARENASIZE+0.5); lamp->setPosition(ARENASIZE - 0.5, (ARENAHEIGHT + 0.5) * BLOCKHEIGHT,
-ARENASIZE + 0.5);
arenaworld->addChild(lamp); arenaworld->addChild(lamp);
lamp = new Object(); lamp = new Object();
lamp->appearance = new LampAppearance(); lamp->appearance = new LampAppearance();
lamp->setPosition(-ARENASIZE+0.5, (ARENAHEIGHT+0.5)*BLOCKHEIGHT, ARENASIZE-0.5); lamp->setPosition(-ARENASIZE + 0.5, (ARENAHEIGHT + 0.5) * BLOCKHEIGHT,
ARENASIZE - 0.5);
arenaworld->addChild(lamp); arenaworld->addChild(lamp);
lamp = new Object(); lamp = new Object();
lamp->appearance = new LampAppearance(); lamp->appearance = new LampAppearance();
lamp->setPosition(ARENASIZE-0.5, (ARENAHEIGHT+0.5)*BLOCKHEIGHT, ARENASIZE-0.5); lamp->setPosition(ARENASIZE - 0.5, (ARENAHEIGHT + 0.5) * BLOCKHEIGHT,
ARENASIZE - 0.5);
arenaworld->addChild(lamp); arenaworld->addChild(lamp);
// Floor // Floor
BasicBlock *floorblock; BasicBlock *floorblock;
floorblock = new BasicBlock(ARENASIZE * 2, 3, ARENASIZE * 2); floorblock = new BasicBlock(ARENASIZE * 2, 3, ARENASIZE * 2);
@ -138,35 +138,37 @@ void initFight(void){
floorblock->setCollisionGroup(COLLISIONGROUP_ARENA); floorblock->setCollisionGroup(COLLISIONGROUP_ARENA);
arenaworld->addChild(floorblock); arenaworld->addChild(floorblock);
// Corners // Corners
BasicBlock *arenacorner; BasicBlock *arenacorner;
arenacorner = new BasicBlock(1, ARENAHEIGHT, 1); arenacorner = new BasicBlock(1, ARENAHEIGHT, 1);
arenacorner->setColor(1, 0, 0); arenacorner->setColor(1, 0, 0);
// arenacorner->setCollisionGroup(COLLISIONGROUP_ARENA); // arenacorner->setCollisionGroup(COLLISIONGROUP_ARENA);
arenacorner->setPosition(ARENASIZE-0.5, BLOCKHEIGHT*ARENAHEIGHT/2.0, ARENASIZE-0.5); arenacorner->setPosition(ARENASIZE - 0.5, BLOCKHEIGHT * ARENAHEIGHT / 2.0,
ARENASIZE - 0.5);
arenaworld->addChild(arenacorner); arenaworld->addChild(arenacorner);
arenacorner = new BasicBlock(1, ARENAHEIGHT, 1); arenacorner = new BasicBlock(1, ARENAHEIGHT, 1);
arenacorner->setColor(1, 0, 0); arenacorner->setColor(1, 0, 0);
// arenacorner->setCollisionGroup(COLLISIONGROUP_ARENA); // arenacorner->setCollisionGroup(COLLISIONGROUP_ARENA);
arenacorner->setPosition(-ARENASIZE+0.5, BLOCKHEIGHT*ARENAHEIGHT/2.0, ARENASIZE-0.5); arenacorner->setPosition(-ARENASIZE + 0.5, BLOCKHEIGHT * ARENAHEIGHT / 2.0,
ARENASIZE - 0.5);
arenaworld->addChild(arenacorner); arenaworld->addChild(arenacorner);
arenacorner = new BasicBlock(1, ARENAHEIGHT, 1); arenacorner = new BasicBlock(1, ARENAHEIGHT, 1);
arenacorner->setColor(1, 0, 0); arenacorner->setColor(1, 0, 0);
// arenacorner->setCollisionGroup(COLLISIONGROUP_ARENA); // arenacorner->setCollisionGroup(COLLISIONGROUP_ARENA);
arenacorner->setPosition(ARENASIZE-0.5, BLOCKHEIGHT*ARENAHEIGHT/2.0, -ARENASIZE+0.5); arenacorner->setPosition(ARENASIZE - 0.5, BLOCKHEIGHT * ARENAHEIGHT / 2.0,
-ARENASIZE + 0.5);
arenaworld->addChild(arenacorner); arenaworld->addChild(arenacorner);
arenacorner = new BasicBlock(1, ARENAHEIGHT, 1); arenacorner = new BasicBlock(1, ARENAHEIGHT, 1);
arenacorner->setColor(1, 0, 0); arenacorner->setColor(1, 0, 0);
// arenacorner->setCollisionGroup(COLLISIONGROUP_ARENA); // arenacorner->setCollisionGroup(COLLISIONGROUP_ARENA);
arenacorner->setPosition(-ARENASIZE+0.5, BLOCKHEIGHT*ARENAHEIGHT/2.0, -ARENASIZE+0.5); arenacorner->setPosition(-ARENASIZE + 0.5, BLOCKHEIGHT * ARENAHEIGHT / 2.0,
-ARENASIZE + 0.5);
arenaworld->addChild(arenacorner); arenaworld->addChild(arenacorner);
//"Ropes" //"Ropes"
MeshObject *arenaline; MeshObject *arenaline;
Mesh *linegeometry; Mesh *linegeometry;
@ -174,7 +176,9 @@ void initFight(void){
BasicBlockAppearance *line; BasicBlockAppearance *line;
int geometryheight = BLOCKHEIGHT * ARENAHEIGHT; int geometryheight = BLOCKHEIGHT * ARENAHEIGHT;
linegeometry = createBox(-0.5, 0.5, -geometryheight/2, geometryheight/2-BLOCKHEIGHT, -ARENASIZE, ARENASIZE); linegeometry =
createBox(-0.5, 0.5, -geometryheight / 2,
geometryheight / 2 - BLOCKHEIGHT, -ARENASIZE, ARENASIZE);
arenaline = new MeshObject(linegeometry); arenaline = new MeshObject(linegeometry);
lineappearance = new MultiAppearance(); lineappearance = new MultiAppearance();
line = new BasicBlockAppearance(1, 1, ARENASIZE * 2); line = new BasicBlockAppearance(1, 1, ARENASIZE * 2);
@ -188,13 +192,14 @@ void initFight(void){
line = new BasicBlockAppearance(1, 1, ARENASIZE * 2); line = new BasicBlockAppearance(1, 1, ARENASIZE * 2);
vectorSet(line->displacement, 0, BLOCKHEIGHT * 3.5, 0); vectorSet(line->displacement, 0, BLOCKHEIGHT * 3.5, 0);
line->material.setColor(1, 0, 0, 1); line->material.setColor(1, 0, 0, 1);
lineappearance->addAppearance(line), lineappearance->addAppearance(line), arenaline->appearance = lineappearance;
arenaline->appearance = lineappearance;
arenaline->setCollisionGroup(COLLISIONGROUP_ARENA); arenaline->setCollisionGroup(COLLISIONGROUP_ARENA);
arenaline->setPosition(-ARENASIZE + 0.5, geometryheight / 2, 0); arenaline->setPosition(-ARENASIZE + 0.5, geometryheight / 2, 0);
arenaworld->addChild(arenaline); arenaworld->addChild(arenaline);
linegeometry = createBox(-0.5, 0.5, -geometryheight/2, geometryheight/2-BLOCKHEIGHT, -ARENASIZE, ARENASIZE); linegeometry =
createBox(-0.5, 0.5, -geometryheight / 2,
geometryheight / 2 - BLOCKHEIGHT, -ARENASIZE, ARENASIZE);
arenaline = new MeshObject(linegeometry); arenaline = new MeshObject(linegeometry);
lineappearance = new MultiAppearance(); lineappearance = new MultiAppearance();
line = new BasicBlockAppearance(1, 1, ARENASIZE * 2); line = new BasicBlockAppearance(1, 1, ARENASIZE * 2);
@ -208,13 +213,13 @@ void initFight(void){
line = new BasicBlockAppearance(1, 1, ARENASIZE * 2); line = new BasicBlockAppearance(1, 1, ARENASIZE * 2);
vectorSet(line->displacement, 0, BLOCKHEIGHT * 3.5, 0); vectorSet(line->displacement, 0, BLOCKHEIGHT * 3.5, 0);
line->material.setColor(1, 0, 0, 1); line->material.setColor(1, 0, 0, 1);
lineappearance->addAppearance(line), lineappearance->addAppearance(line), arenaline->appearance = lineappearance;
arenaline->appearance = lineappearance;
arenaline->setCollisionGroup(COLLISIONGROUP_ARENA); arenaline->setCollisionGroup(COLLISIONGROUP_ARENA);
arenaline->setPosition(ARENASIZE - 0.5, geometryheight / 2, 0); arenaline->setPosition(ARENASIZE - 0.5, geometryheight / 2, 0);
arenaworld->addChild(arenaline); arenaworld->addChild(arenaline);
linegeometry = createBox(-ARENASIZE, ARENASIZE, -geometryheight/2, geometryheight/2-BLOCKHEIGHT, -0.5, 0.5); linegeometry = createBox(-ARENASIZE, ARENASIZE, -geometryheight / 2,
geometryheight / 2 - BLOCKHEIGHT, -0.5, 0.5);
arenaline = new MeshObject(linegeometry); arenaline = new MeshObject(linegeometry);
lineappearance = new MultiAppearance(); lineappearance = new MultiAppearance();
line = new BasicBlockAppearance(ARENASIZE * 2, 1, 1); line = new BasicBlockAppearance(ARENASIZE * 2, 1, 1);
@ -228,13 +233,13 @@ void initFight(void){
line = new BasicBlockAppearance(ARENASIZE * 2, 1, 1); line = new BasicBlockAppearance(ARENASIZE * 2, 1, 1);
vectorSet(line->displacement, 0, BLOCKHEIGHT * 3.5, 0); vectorSet(line->displacement, 0, BLOCKHEIGHT * 3.5, 0);
line->material.setColor(1, 0, 0, 1); line->material.setColor(1, 0, 0, 1);
lineappearance->addAppearance(line), lineappearance->addAppearance(line), arenaline->appearance = lineappearance;
arenaline->appearance = lineappearance;
arenaline->setCollisionGroup(COLLISIONGROUP_ARENA); arenaline->setCollisionGroup(COLLISIONGROUP_ARENA);
arenaline->setPosition(0, geometryheight / 2, -ARENASIZE + 0.5); arenaline->setPosition(0, geometryheight / 2, -ARENASIZE + 0.5);
arenaworld->addChild(arenaline); arenaworld->addChild(arenaline);
linegeometry = createBox(-ARENASIZE, ARENASIZE, -geometryheight/2, geometryheight/2-BLOCKHEIGHT, -0.5, 0.5); linegeometry = createBox(-ARENASIZE, ARENASIZE, -geometryheight / 2,
geometryheight / 2 - BLOCKHEIGHT, -0.5, 0.5);
arenaline = new MeshObject(linegeometry); arenaline = new MeshObject(linegeometry);
lineappearance = new MultiAppearance(); lineappearance = new MultiAppearance();
line = new BasicBlockAppearance(ARENASIZE * 2, 1, 1); line = new BasicBlockAppearance(ARENASIZE * 2, 1, 1);
@ -248,8 +253,7 @@ void initFight(void){
line = new BasicBlockAppearance(ARENASIZE * 2, 1, 1); line = new BasicBlockAppearance(ARENASIZE * 2, 1, 1);
vectorSet(line->displacement, 0, BLOCKHEIGHT * 3.5, 0); vectorSet(line->displacement, 0, BLOCKHEIGHT * 3.5, 0);
line->material.setColor(1, 0, 0, 1); line->material.setColor(1, 0, 0, 1);
lineappearance->addAppearance(line), lineappearance->addAppearance(line), arenaline->appearance = lineappearance;
arenaline->appearance = lineappearance;
arenaline->setCollisionGroup(COLLISIONGROUP_ARENA); arenaline->setCollisionGroup(COLLISIONGROUP_ARENA);
arenaline->setPosition(0, geometryheight / 2, ARENASIZE - 0.5); arenaline->setPosition(0, geometryheight / 2, ARENASIZE - 0.5);
arenaworld->addChild(arenaline); arenaworld->addChild(arenaline);
@ -271,10 +275,8 @@ void initFight(void){
man1->addOpponent(man2); man1->addOpponent(man2);
man2->addOpponent(man1); man2->addOpponent(man1);
initBloods(arenaworld); initBloods(arenaworld);
hitsound1 = new Sound(DATAPATH "hit1.wav"); hitsound1 = new Sound(DATAPATH "hit1.wav");
softhitsound1 = new Sound(DATAPATH "hitsoft1.wav"); softhitsound1 = new Sound(DATAPATH "hitsoft1.wav");
softhitsound2 = new Sound(DATAPATH "hitsoft2.wav"); softhitsound2 = new Sound(DATAPATH "hitsoft2.wav");
@ -356,7 +358,6 @@ SDLKey player2backward = SDLK_s;
SDLKey player2jump = SDLK_LSHIFT; SDLKey player2jump = SDLK_LSHIFT;
SDLKey player2hit = SDLK_LCTRL; SDLKey player2hit = SDLK_LCTRL;
void stopGame(void) { void stopGame(void) {
light1.setEnabled(false); light1.setEnabled(false);
light2.setEnabled(false); light2.setEnabled(false);
@ -367,9 +368,7 @@ void stopGame(void){
menuRestart(); menuRestart();
} }
void endGame(void){ void endGame(void) { trophycounter = 0; }
trophycounter = 0;
}
void endGame2(void) { void endGame2(void) {
light1.setEnabled(false); light1.setEnabled(false);
@ -402,8 +401,10 @@ void calculateFight(int framecount){
if (endcounter == VICTORY) { if (endcounter == VICTORY) {
victorysound->play(); victorysound->play();
if (winner == man1) points1++; if (winner == man1)
if (winner == man2) points2++; points1++;
if (winner == man2)
points2++;
} }
if (endcounter >= ENDFADE && endcounter <= STARTOVER) { if (endcounter >= ENDFADE && endcounter <= STARTOVER) {
fightfade = (endcounter - ENDFADE) / (STARTOVER - ENDFADE); fightfade = (endcounter - ENDFADE) / (STARTOVER - ENDFADE);
@ -418,11 +419,13 @@ void calculateFight(int framecount){
endcounter = 0; endcounter = 0;
} }
} }
if (dead) endcounter++; if (dead)
endcounter++;
if (trophycounter != -1) { if (trophycounter != -1) {
fightfade = (float)trophycounter / TROPHYFADE; fightfade = (float)trophycounter / TROPHYFADE;
trophycounter++; trophycounter++;
if (trophycounter == TROPHYFADE) endGame2(); if (trophycounter == TROPHYFADE)
endGame2();
} }
/*if (framecount % 10 == 0){ /*if (framecount % 10 == 0){
@ -434,7 +437,9 @@ void calculateFight(int framecount){
// light2.setPosition(sin(framecount*0.017)*6, 2, cos(framecount*0.027)*5); // 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); // 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(sin(framecount * 0.0005) * 20,
sin(framecount * 0.0013) * 5 + 15,
cos(framecount * 0.0005) * 20);
// camera.setPosition(8, 5, 5); // camera.setPosition(8, 5, 5);
@ -447,30 +452,40 @@ void calculateFight(int framecount){
if (startcounter >= FIGHT) { if (startcounter >= FIGHT) {
if (man1->isAlive()) { if (man1->isAlive()) {
if (keys[player1left]) man1->turn(5); if (keys[player1left])
if (keys[player1right]) man1->turn(-5); man1->turn(5);
if (keys[player1forward]) man1->walk(0.03); if (keys[player1right])
if (keys[player1backward]) man1->walk(-0.03); man1->turn(-5);
if (keys[player1jump]) man1->jump(); if (keys[player1forward])
if (keys[player1hit]) man1->hit(); 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 (man2->isAlive()) {
if (keys[player2left]) man2->turn(5); if (keys[player2left])
if (keys[player2right]) man2->turn(-5); man2->turn(5);
if (keys[player2forward]) man2->walk(0.03); if (keys[player2right])
if (keys[player2backward]) man2->walk(-0.03); man2->turn(-5);
if (keys[player2jump]) man2->jump(); if (keys[player2forward])
if (keys[player2hit]) man2->hit(); 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]) { if (keys[SDLK_ESCAPE]) {
stopGame(); stopGame();
} }
arenaworld->move(); arenaworld->move();
} }
@ -493,7 +508,6 @@ void drawDamageMeters(void){
glDisable(GL_TEXTURE_2D); glDisable(GL_TEXTURE_2D);
glColor3f(1, 1, 0); glColor3f(1, 1, 0);
char pointstring[5]; char pointstring[5];
@ -515,7 +529,6 @@ void drawFight(int framecount){
createSkyBox(0, 10, 0, 50, 20, 50); createSkyBox(0, 10, 0, 50, 20, 50);
light1.setEnabled(true); light1.setEnabled(true);
light2.setEnabled(true); light2.setEnabled(true);
light3.setEnabled(true); light3.setEnabled(true);
@ -527,7 +540,6 @@ void drawFight(int framecount){
drawDamageMeters(); drawDamageMeters();
flaretexture->enable(); flaretexture->enable();
light1.createFlare(); light1.createFlare();
light2.createFlare(); light2.createFlare();
@ -535,7 +547,6 @@ void drawFight(int framecount){
light4.createFlare(); light4.createFlare();
flaretexture->disable(); flaretexture->disable();
enable2D(); enable2D();
if (fightfade != -1) { if (fightfade != -1) {
@ -591,7 +602,6 @@ void drawFight(int framecount){
disable2D(); disable2D();
glDisable(GL_BLEND); glDisable(GL_BLEND);
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
} }

View file

@ -25,4 +25,3 @@ void handleKeydownFight(SDLKey key);
void addGraphicsVector(float *p1, float *p2, float size); void addGraphicsVector(float *p1, float *p2, float size);
#endif #endif

View file

@ -35,23 +35,26 @@ void drawChar(float x, float y, char ch, float size){
} }
float letterwidth[256] = { 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, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 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, 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,
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, 1.0, 1.0, 1.0, 1.0, 1.0, 0.45, 0.2, 0.5, 0.6, 0.5, 0.6, 0.6,
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.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.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, 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,
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.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,
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, 0.6, 0.6, 0.6, 0.6, 0.6, 0.5, 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, 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,
1.0, 1.0, 1.0, 1.0, 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.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, 1.0, 1.0, 1.0 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
}; 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 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) { void print(float x, float y, char *text, float size) {
int i; int i;
@ -69,5 +72,3 @@ void print(float x, float y, char *text, float size){
} }
} }
} }

View file

@ -10,4 +10,3 @@ void drawChar(float x, float y, char ch, float size = 0.05);
void print(float x, float y, char *text, float size = 0.05); void print(float x, float y, char *text, float size = 0.05);
#endif #endif

View file

@ -20,7 +20,8 @@ void setupOpengl(int width, int height){
glEnable(GL_COLOR_MATERIAL); glEnable(GL_COLOR_MATERIAL);
//Enables lighting with zero initial lights. Lights are created with Light-class // Enables lighting with zero initial lights. Lights are created with
// Light-class
glEnable(GL_LIGHTING); glEnable(GL_LIGHTING);
glDisable(GL_LIGHT0); glDisable(GL_LIGHT0);
@ -45,8 +46,6 @@ void setupOpengl(int width, int height){
glMaterialfv(GL_BACK, GL_DIFFUSE, zero); glMaterialfv(GL_BACK, GL_DIFFUSE, zero);
glMaterialfv(GL_BACK, GL_SPECULAR, zero); glMaterialfv(GL_BACK, GL_SPECULAR, zero);
glViewport(0, 0, width, height); glViewport(0, 0, width, height);
glDepthFunc(GL_LEQUAL); glDepthFunc(GL_LEQUAL);
@ -59,6 +58,5 @@ void setupOpengl(int width, int height){
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);
} }

View file

@ -6,5 +6,3 @@
void setupOpengl(int width, int height); void setupOpengl(int width, int height);
#endif #endif

View file

@ -3,12 +3,9 @@
GraphicsDruid *GraphicsDruid::instance = 0; GraphicsDruid *GraphicsDruid::instance = 0;
GraphicsDruid::GraphicsDruid(void){ GraphicsDruid::GraphicsDruid(void) { this->reserved = 0; }
this->reserved = 0;
}
GraphicsDruid::~GraphicsDruid(void){ GraphicsDruid::~GraphicsDruid(void) {}
}
void GraphicsDruid::init(void) { void GraphicsDruid::init(void) {
instance->textureCount = 0; instance->textureCount = 0;
@ -51,14 +48,16 @@ int GraphicsDruid::loadTexture(SDL_Surface *texture, int id, int format){
// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);//_MIPMAP_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
GL_LINEAR); //_MIPMAP_NEAREST);
// glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); // 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_S, GL_CLAMP);
// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
// printf("w: %i, h: %i, format: %i, RGBA: %i, pixels: %p\n", // printf("w: %i, h: %i, format: %i, RGBA: %i, pixels: %p\n",
// texture->w, texture->h, format, GL_RGBA, texture->pixels); // texture->w, texture->h, format, GL_RGBA, texture->pixels);
//printf("Pitch: %i, Bpp: %i\n", texture->pitch, texture->format->BytesPerPixel); // printf("Pitch: %i, Bpp: %i\n", texture->pitch,
// texture->format->BytesPerPixel);
/*gluBuild2DMipmaps(GL_TEXTURE_2D, /*gluBuild2DMipmaps(GL_TEXTURE_2D,
4, 4,
@ -82,11 +81,14 @@ int GraphicsDruid::loadTexture(SDL_Surface *texture, int id, int format){
} }
h = 1; h = 1;
for (;i > 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); // glTexImage2D(GL_TEXTURE_2D, 0, texture->format->BytesPerPixel, w, h, 0,
// format, GL_UNSIGNED_BYTE, texture->pixels);
if (texture->format->BytesPerPixel == 3) { if (texture->format->BytesPerPixel == 3) {
glTexImage2D(GL_TEXTURE_2D, 0, 3, w, h, 0, GL_RGB, 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) { } 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, 4, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE,
texture->pixels);
} }
// SDL_FreeSurface(texture); // SDL_FreeSurface(texture);
// SDL_FreeSurface(alphaSurface); // SDL_FreeSurface(alphaSurface);
@ -106,7 +108,6 @@ int GraphicsDruid::loadTexture(char* path, int id){
} }
int textureID = getNewTextureID(id); int textureID = getNewTextureID(id);
// register texture in OpenGL // register texture in OpenGL
glBindTexture(GL_TEXTURE_2D, textureID); glBindTexture(GL_TEXTURE_2D, textureID);
@ -114,7 +115,8 @@ int GraphicsDruid::loadTexture(char* path, int id){
// NOTE : Making some assumptions about texture parameters // NOTE : Making some assumptions about texture parameters
// glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // 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_MIN_FILTER,
// GL_LINEAR_MIPMAP_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 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_MIN_FILTER, GL_LINEAR);
@ -124,7 +126,8 @@ int GraphicsDruid::loadTexture(char* path, int id){
// printf("w: %i, h: %i, RGBA: %i, pixels: %p\n", // printf("w: %i, h: %i, RGBA: %i, pixels: %p\n",
// texture->w, texture->h, GL_RGBA, texture->pixels); // texture->w, texture->h, GL_RGBA, texture->pixels);
//printf("Pitch: %i, Bpp: %i\n", texture->pitch, texture->format->BytesPerPixel); // printf("Pitch: %i, Bpp: %i\n", texture->pitch,
// texture->format->BytesPerPixel);
if (texture->format->BytesPerPixel == 3) { if (texture->format->BytesPerPixel == 3) {
/*gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, /*gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB,
@ -132,15 +135,16 @@ int GraphicsDruid::loadTexture(char* path, int id){
texture->h, texture->h,
GL_RGB, GL_UNSIGNED_BYTE, GL_RGB, GL_UNSIGNED_BYTE,
texture->pixels);*/ texture->pixels);*/
glTexImage2D(GL_TEXTURE_2D, 0, 3, texture->w, texture->h, 0, 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){ } else if (texture->format->BytesPerPixel == 4) {
/*gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, /*gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA,
texture->w, texture->w,
texture->h, texture->h,
GL_RGBA, GL_UNSIGNED_BYTE, GL_RGBA, GL_UNSIGNED_BYTE,
texture->pixels);*/ texture->pixels);*/
glTexImage2D(GL_TEXTURE_2D, 0, 4, texture->w, texture->h, 0, 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);
} }
/* /*
@ -169,11 +173,9 @@ int GraphicsDruid::loadTranspTexture(char* path, float* transpColor, int id){
return -1; return -1;
} }
Uint32 colorKey =
Uint32 colorKey = SDL_MapRGB(texture->format, SDL_MapRGB(texture->format, (Uint8)(transpColor[0] * 255),
(Uint8)(transpColor[0] * 255), (Uint8)(transpColor[1] * 255), (Uint8)(transpColor[2] * 255));
(Uint8)(transpColor[1] * 255),
(Uint8)(transpColor[2] * 255));
// SDL_SetAlpha(texture, 0, SDL_ALPHA_OPAQUE); // SDL_SetAlpha(texture, 0, SDL_ALPHA_OPAQUE);
SDL_SetColorKey(texture, SDL_SRCCOLORKEY, colorKey); SDL_SetColorKey(texture, SDL_SRCCOLORKEY, colorKey);
@ -200,8 +202,7 @@ int GraphicsDruid::getNewTextureID(int id){
if (id == -1) { if (id == -1) {
glGenTextures(1, &newId); glGenTextures(1, &newId);
} } else
else
newId = id; newId = id;
int index = 0; int index = 0;
@ -211,17 +212,17 @@ int GraphicsDruid::getNewTextureID(int id){
// out of space, make more // out of space, make more
if (index >= instance->reserved) { if (index >= instance->reserved) {
instance->idArray = (int*) realloc(instance->idArray, (instance->reserved + ID_ARRAY_GROW)*sizeof(int)); 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++) for (int i = instance->reserved + 1; i < instance->reserved + ID_ARRAY_GROW;
i++)
instance->idArray[i] = -1; instance->idArray[i] = -1;
instance->reserved += ID_ARRAY_GROW; instance->reserved += ID_ARRAY_GROW;
} } else
else
instance->idArray[index] = newId; instance->idArray[index] = newId;
instance->textureCount++; instance->textureCount++;
return newId; return newId;
} }
@ -233,4 +234,3 @@ void GraphicsDruid::freeTexture(int id){
glDeleteTextures(1, &helpInt); glDeleteTextures(1, &helpInt);
} }
} }

View file

@ -21,12 +21,9 @@ typedef struct jpeg_pixel{
Uint8 blue; Uint8 blue;
} jpeg_pixel; } jpeg_pixel;
class GraphicsDruid { class GraphicsDruid {
private: private:
static GraphicsDruid *instance; static GraphicsDruid *instance;
int *idArray; int *idArray;
int textureCount; int textureCount;
@ -39,7 +36,6 @@ private:
static void destroy(void); static void destroy(void);
public: public:
static GraphicsDruid &getInstance(void); 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 loadTexture(char *path, int id = -1);
@ -47,8 +43,6 @@ public:
void freeTexture(int id); void freeTexture(int id);
void freeAll(void); void freeAll(void);
int getNewTextureID(int id); int getNewTextureID(int id);
}; };
#endif #endif

View file

@ -9,7 +9,10 @@
#include "vector.h" #include "vector.h"
#include "glapi.h" #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)){ 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); appearance = new BasicBlockAppearance(width, height, depth);
// geometry = new MeshShape(this); // geometry = new MeshShape(this);
} }
@ -18,8 +21,6 @@ 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) { BasicBlockAppearance::BasicBlockAppearance(int width, int height, int depth) {
this->width = width; this->width = width;
this->height = height; this->height = height;
@ -32,11 +33,11 @@ BasicBlockAppearance::BasicBlockAppearance(int width, int height, int depth){
void BasicBlockAppearance::prepare() { void BasicBlockAppearance::prepare() {
glNewList(gllist, GL_COMPILE); glNewList(gllist, GL_COMPILE);
float width = this->width; float width = this->width;
float height = this->height * BLOCKHEIGHT; float height = this->height * BLOCKHEIGHT;
if (usematerial) material.enable(); if (usematerial)
material.enable();
{ // Block { // Block
// Front Face // Front Face
glPushMatrix(); glPushMatrix();
@ -94,7 +95,8 @@ void BasicBlockAppearance::prepare(){
} }
glPopMatrix(); glPopMatrix();
if (usematerial) material.disable(); if (usematerial)
material.disable();
glEndList(); glEndList();
} }
@ -106,7 +108,6 @@ void BasicBlockAppearance::draw(){
// prepare(); // prepare();
} }
#define BLOCKDETAILGRID 1 #define BLOCKDETAILGRID 1
void drawDetailRectangle(float width, float height) { void drawDetailRectangle(float width, float height) {
@ -116,10 +117,12 @@ void drawDetailRectangle(float width, float height){
for (y = 0; y < height; y += BLOCKDETAILGRID) { for (y = 0; y < height; y += BLOCKDETAILGRID) {
y2 = y + BLOCKDETAILGRID; y2 = y + BLOCKDETAILGRID;
if (y2 > height) y2 = height; if (y2 > height)
y2 = height;
for (x = 0; x < width; x += BLOCKDETAILGRID) { for (x = 0; x < width; x += BLOCKDETAILGRID) {
x2 = x + BLOCKDETAILGRID; x2 = x + BLOCKDETAILGRID;
if (x2 > width) x2 = width; if (x2 > width)
x2 = width;
glTexCoord2f(x / width, y / height); glTexCoord2f(x / width, y / height);
glVertex3f(x, y, 0); glVertex3f(x, y, 0);
@ -182,16 +185,10 @@ void createKnob(int knobsegments){
glCallList(knobgllist); glCallList(knobgllist);
} }
float knobroundness = 0.05; float knobroundness = 0.05;
float pillarroundness = 0.03; float pillarroundness = 0.03;
HeadAppearance::HeadAppearance(void){ HeadAppearance::HeadAppearance(void) { gllist = glGenLists(1); }
gllist = glGenLists(1);
}
void HeadAppearance::prepare(void) { void HeadAppearance::prepare(void) {
glNewList(gllist, GL_COMPILE); glNewList(gllist, GL_COMPILE);
@ -202,25 +199,39 @@ void HeadAppearance::prepare(void){
point2d headpoints[14]; point2d headpoints[14];
headpoints[0].x=0.0; headpoints[0].y=BLOCKHEIGHT*(0); headpoints[0].x = 0.0;
headpoints[1].x=0.4; headpoints[1].y=BLOCKHEIGHT*(0); headpoints[0].y = BLOCKHEIGHT * (0);
headpoints[2].x=0.45; headpoints[2].y=BLOCKHEIGHT*(0.35); headpoints[1].x = 0.4;
headpoints[3].x=0.55; headpoints[3].y=BLOCKHEIGHT*(0.5); headpoints[1].y = BLOCKHEIGHT * (0);
headpoints[4].x=0.62*1.0; headpoints[4].y=BLOCKHEIGHT*(0.65); headpoints[2].x = 0.45;
headpoints[5].x=0.65*1.0; headpoints[5].y=BLOCKHEIGHT*(1); headpoints[2].y = BLOCKHEIGHT * (0.35);
headpoints[6].x=0.65*1.0; headpoints[6].y=BLOCKHEIGHT*(1.75); headpoints[3].x = 0.55;
headpoints[7].x=0.65*1.0; headpoints[7].y=BLOCKHEIGHT*(2.35); headpoints[3].y = BLOCKHEIGHT * (0.5);
headpoints[8].x=0.62*1.0; headpoints[8].y=BLOCKHEIGHT*(2.60); headpoints[4].x = 0.62 * 1.0;
headpoints[9].x=0.55*1.0; headpoints[9].y=BLOCKHEIGHT*(2.80); headpoints[4].y = BLOCKHEIGHT * (0.65);
headpoints[10].x=0.4; headpoints[10].y=BLOCKHEIGHT*(2.95); headpoints[5].x = 0.65 * 1.0;
headpoints[11].x=0.3; headpoints[11].y=BLOCKHEIGHT*3.5-pillarroundness; headpoints[5].y = BLOCKHEIGHT * (1);
headpoints[12].x=0.3-pillarroundness; headpoints[12].y=BLOCKHEIGHT*3.5; headpoints[6].x = 0.65 * 1.0;
headpoints[13].x=0; headpoints[13].y=BLOCKHEIGHT*3.5; headpoints[6].y = BLOCKHEIGHT * (1.75);
headpoints[11].x=0; headpoints[11].y=BLOCKHEIGHT*3.0; 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;
glColor4f(0.8, 0.8, 0.0, 1.0); glColor4f(0.8, 0.8, 0.0, 1.0);
faceTexture->enable(); faceTexture->enable();
glBlendFunc(GL_ONE, GL_SRC_ALPHA); glBlendFunc(GL_ONE, GL_SRC_ALPHA);
createLathedSurface(headpoints, NULL, 12, 16, 24); createLathedSurface(headpoints, NULL, 12, 16, 24);
@ -235,13 +246,7 @@ void HeadAppearance::prepare(void){
glEndList(); glEndList();
} }
void HeadAppearance::draw(void){ void HeadAppearance::draw(void) { glCallList(gllist); }
glCallList(gllist);
}
FlowerAppearance::FlowerAppearance(int color1, int color2, int color3) { FlowerAppearance::FlowerAppearance(int color1, int color2, int color3) {
gllist = glGenLists(1); gllist = glGenLists(1);
@ -255,30 +260,45 @@ void FlowerAppearance::prepare(void){
glPushMatrix(); 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]; point2d basepoints[8];
basepoints[0].x=0.4; basepoints[0].y=0; basepoints[0].x = 0.4;
basepoints[1].x=0.4; basepoints[1].y=BLOCKHEIGHT*1.5-pillarroundness; basepoints[0].y = 0;
basepoints[2].x=0.4-pillarroundness; basepoints[2].y=BLOCKHEIGHT*1.5; basepoints[1].x = 0.4;
basepoints[3].x=0.3+pillarroundness; basepoints[3].y=BLOCKHEIGHT*1.5; basepoints[1].y = BLOCKHEIGHT * 1.5 - pillarroundness;
basepoints[4].x=0.3; basepoints[4].y=BLOCKHEIGHT*1.5+pillarroundness; basepoints[2].x = 0.4 - pillarroundness;
basepoints[5].x=0.3; basepoints[5].y=BLOCKHEIGHT*2.0-pillarroundness; basepoints[2].y = BLOCKHEIGHT * 1.5;
basepoints[6].x=0.3-pillarroundness; basepoints[6].y=BLOCKHEIGHT*2.0; basepoints[3].x = 0.3 + pillarroundness;
basepoints[7].x=0; basepoints[7].y=BLOCKHEIGHT*2.0; 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]; point2d basederivates[8];
basederivates[0].x=0; basederivates[0].y=basepoints[1].y-basepoints[0].y; basederivates[0].x = 0;
basederivates[1].x=0; basederivates[1].y=basepoints[2].y-basepoints[1].y; basederivates[0].y = basepoints[1].y - basepoints[0].y;
basederivates[2].x=basepoints[2].x-basepoints[1].x; basederivates[2].y=0; basederivates[1].x = 0;
basederivates[3].x=basepoints[4].x-basepoints[3].x; basederivates[3].y=0; basederivates[1].y = basepoints[2].y - basepoints[1].y;
basederivates[4].x=0; basederivates[4].y=basepoints[4].y-basepoints[3].y; basederivates[2].x = basepoints[2].x - basepoints[1].x;
basederivates[5].x=0; basederivates[5].y=basepoints[6].y-basepoints[5].y; basederivates[2].y = 0;
basederivates[6].x=basepoints[6].x-basepoints[5].x; basederivates[6].y=0; basederivates[3].x = basepoints[4].x - basepoints[3].x;
basederivates[7].x=basepoints[7].x-basepoints[6].x; basederivates[7].y=0; 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);
@ -295,13 +315,19 @@ void FlowerAppearance::prepare(void){
float r, g, b; float r, g, b;
switch (colors[i]) { switch (colors[i]) {
case FLOWER_RED: case FLOWER_RED:
r=1.0; g=0.0; b=0.0; r = 1.0;
g = 0.0;
b = 0.0;
break; break;
case FLOWER_YELLOW: case FLOWER_YELLOW:
r=1.0; g=1.0; b=0.0; r = 1.0;
g = 1.0;
b = 0.0;
break; break;
case FLOWER_WHITE: case FLOWER_WHITE:
r=1.0; g=1.0; b=1.0; r = 1.0;
g = 1.0;
b = 1.0;
break; break;
} }
@ -342,17 +368,9 @@ void FlowerAppearance::prepare(void){
glEndList(); glEndList();
} }
void FlowerAppearance::draw(void){ void FlowerAppearance::draw(void) { glCallList(gllist); }
glCallList(gllist);
}
LampAppearance::LampAppearance(void) { gllist = glGenLists(1); }
LampAppearance::LampAppearance(void){
gllist = glGenLists(1);
}
void LampAppearance::prepare(void) { void LampAppearance::prepare(void) {
glNewList(gllist, GL_COMPILE); glNewList(gllist, GL_COMPILE);
@ -366,17 +384,28 @@ void LampAppearance::prepare(void){
glDisable(GL_LIGHTING); glDisable(GL_LIGHTING);
point2d lightpoints[11]; point2d lightpoints[11];
lightpoints[0].x=0.4; lightpoints[0].y=BLOCKHEIGHT*(0); lightpoints[0].x = 0.4;
lightpoints[1].x=0.55; lightpoints[1].y=BLOCKHEIGHT*(0); lightpoints[0].y = BLOCKHEIGHT * (0);
lightpoints[2].x=0.62; lightpoints[2].y=BLOCKHEIGHT*(0+0.15); lightpoints[1].x = 0.55;
lightpoints[3].x=0.65; lightpoints[3].y=BLOCKHEIGHT*(0+0.5); lightpoints[1].y = BLOCKHEIGHT * (0);
lightpoints[4].x=0.68; lightpoints[4].y=BLOCKHEIGHT*(0+1.25); lightpoints[2].x = 0.62;
lightpoints[5].x=0.65; lightpoints[5].y=BLOCKHEIGHT*(0+2); lightpoints[2].y = BLOCKHEIGHT * (0 + 0.15);
lightpoints[6].x=0.62; lightpoints[6].y=BLOCKHEIGHT*(0+2.35); lightpoints[3].x = 0.65;
lightpoints[7].x=0.55; lightpoints[7].y=BLOCKHEIGHT*(0+2.5); lightpoints[3].y = BLOCKHEIGHT * (0 + 0.5);
lightpoints[8].x=0.4; lightpoints[8].y=BLOCKHEIGHT*(0+2.5); lightpoints[4].x = 0.68;
lightpoints[9].x=0.4; lightpoints[9].y=BLOCKHEIGHT*(0+3); lightpoints[4].y = BLOCKHEIGHT * (0 + 1.25);
lightpoints[10].x=0.0; lightpoints[10].y=BLOCKHEIGHT*(0+3); 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); glColor4f(0.8, 0.8, 0.8, 0.5);
glEnable(GL_BLEND); glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
@ -392,7 +421,6 @@ void LampAppearance::prepare(void){
glVertex3f(0, -100, 0); glVertex3f(0, -100, 0);
glEnd();*/ glEnd();*/
/*float screencoords[3] /*float screencoords[3]
getPointCoordinates(0,lighty,0); getPointCoordinates(0,lighty,0);
@ -438,13 +466,9 @@ void LampAppearance::prepare(void){
glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);
glLoadIdentity();*/ glLoadIdentity();*/
glPopMatrix(); glPopMatrix();
glEndList(); glEndList();
} }
void LampAppearance::draw(void){ void LampAppearance::draw(void) { glCallList(gllist); }
glCallList(gllist);
}

View file

@ -18,7 +18,6 @@ public:
void setColor(float red, float green, float blue); void setColor(float red, float green, float blue);
}; };
class BasicBlockAppearance : public Appearance { class BasicBlockAppearance : public Appearance {
private: private:
int width, height, depth; int width, height, depth;
@ -43,8 +42,6 @@ extern int knobdetail;
void initKnob(void); void initKnob(void);
void createKnob(int knobsegments = -1); void createKnob(int knobsegments = -1);
class HeadAppearance : public Appearance { class HeadAppearance : public Appearance {
private: private:
int gllist; int gllist;
@ -56,8 +53,6 @@ public:
void draw(void); void draw(void);
}; };
#define FLOWER_RED 1 #define FLOWER_RED 1
#define FLOWER_YELLOW 2 #define FLOWER_YELLOW 2
#define FLOWER_WHITE 3 #define FLOWER_WHITE 3
@ -74,8 +69,6 @@ public:
void draw(void); void draw(void);
}; };
class LampAppearance : public Appearance { class LampAppearance : public Appearance {
private: private:
int gllist; int gllist;
@ -87,5 +80,4 @@ public:
void draw(void); void draw(void);
}; };
#endif #endif

View file

@ -15,9 +15,6 @@
#include "fight.h" #include "fight.h"
#include "glapi.h" #include "glapi.h"
BodyPart::BodyPart(Legoman *parent, float strength) { BodyPart::BodyPart(Legoman *parent, float strength) {
this->parent = parent; this->parent = parent;
this->strength = strength; this->strength = strength;
@ -35,7 +32,8 @@ void BodyPart::reset(void){
} }
void BodyPart::move(void) { void BodyPart::move(void) {
if (immortal > 0) immortal--; if (immortal > 0)
immortal--;
Object::move(); Object::move();
} }
@ -46,7 +44,8 @@ void BodyPart::hitForce(float speed, float *speed2, Object *source){
Sound *sound; Sound *sound;
sound = hitsound1; sound = hitsound1;
float volume = (speed - tolerance) * 0.4; float volume = (speed - tolerance) * 0.4;
if (volume > 1) volume = 1; if (volume > 1)
volume = 1;
volume = 1; volume = 1;
sound->setVolume(volume); sound->setVolume(volume);
sound->play(30 + random(120)); sound->play(30 + random(120));
@ -70,22 +69,25 @@ void BodyPart::hitForce(float speed, float *speed2, Object *source){
} }
void BodyPart::makeDamage(float amount) { void BodyPart::makeDamage(float amount) {
if (strength == 0) return; if (strength == 0)
if (energy == 0) return; return;
if (!parent->opponent->isAlive()) return; if (energy == 0)
if (immortal > 0) return; return;
if (!parent->opponent->isAlive())
return;
if (immortal > 0)
return;
energy -= amount / strength; energy -= amount / strength;
if (energy < 0) energy = 0; if (energy < 0)
energy = 0;
if (energy == 0) { if (energy == 0) {
parent->releasePart(this); parent->releasePart(this);
} }
immortal = 30; immortal = 30;
} }
Sensor::Sensor() {}
Sensor::Sensor(){
}
void Sensor::attach(Object *object, float *relativeposition) { void Sensor::attach(Object *object, float *relativeposition) {
vectorCopy(this->relativeposition, relativeposition); vectorCopy(this->relativeposition, relativeposition);
@ -113,13 +115,9 @@ void Sensor::update(void){
// 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){ void Sensor::getPosition(float *target) { vectorCopy(target, position); }
vectorCopy(target, position);
}
void Sensor::getVelocity(float *target){ void Sensor::getVelocity(float *target) { vectorCopy(target, velocity); }
vectorCopy(target, velocity);
}
void Sensor::getAcceleration(float *target) { void Sensor::getAcceleration(float *target) {
vectorCopy(target, acceleration); vectorCopy(target, acceleration);
@ -161,18 +159,21 @@ Legoman::Legoman(int side){
} }
// Legs // Legs
Mesh* geomLegMesh = createBox(-0.45, 0.45, -BLOCKHEIGHT*LEGHEIGHT/2.0, BLOCKHEIGHT*LEGHEIGHT/2.0, -0.5, 0.5); Mesh *geomLegMesh = createBox(-0.45, 0.45, -BLOCKHEIGHT * LEGHEIGHT / 2.0,
BLOCKHEIGHT * LEGHEIGHT / 2.0, -0.5, 0.5);
float tmpScale = 1.0; float tmpScale = 1.0;
// Left leg // Left leg
{ {
leftleg = new BodyPart(this, 8); leftleg = new BodyPart(this, 8);
Mesh* leftLegMesh = loadAscModel((char*)LEFTLEGASC, MODELSCALE, leftLegOffset); Mesh *leftLegMesh =
loadAscModel((char *)LEFTLEGASC, MODELSCALE, leftLegOffset);
MeshShape *leftLegGeom = new MeshShape(leftleg, geomLegMesh); MeshShape *leftLegGeom = new MeshShape(leftleg, geomLegMesh);
leftleg->geometry = leftLegGeom; leftleg->geometry = leftLegGeom;
leftleg->appearance = new MeshAppearance(leftLegMesh); leftleg->appearance = new MeshAppearance(leftLegMesh);
// leftleg->appearance = new MeshAppearance(geomLegMesh); // leftleg->appearance = new MeshAppearance(geomLegMesh);
leftleg->appearance->material.setColor(legcolor[0], legcolor[1], legcolor[2], 1); leftleg->appearance->material.setColor(legcolor[0], legcolor[1],
legcolor[2], 1);
vectorSet(leftleg->position, -0.6, BLOCKHEIGHT * (LEGHEIGHT / 2.0), 0); vectorSet(leftleg->position, -0.6, BLOCKHEIGHT * (LEGHEIGHT / 2.0), 0);
leftleg->setGravity(true); leftleg->setGravity(true);
leftleg->setMass(LEGHEIGHT / 3.0); leftleg->setMass(LEGHEIGHT / 3.0);
@ -182,19 +183,20 @@ Legoman::Legoman(int side){
// Right leg // Right leg
{ {
rightleg = new BodyPart(this, 8); rightleg = new BodyPart(this, 8);
Mesh* rightLegMesh = loadAscModel((char*)RIGHTLEGASC, MODELSCALE, rightLegOffset); Mesh *rightLegMesh =
loadAscModel((char *)RIGHTLEGASC, MODELSCALE, rightLegOffset);
MeshShape *rightLegGeom = new MeshShape(rightleg, geomLegMesh); MeshShape *rightLegGeom = new MeshShape(rightleg, geomLegMesh);
rightleg->geometry = rightLegGeom; rightleg->geometry = rightLegGeom;
rightleg->appearance = new MeshAppearance(rightLegMesh); rightleg->appearance = new MeshAppearance(rightLegMesh);
// rightleg->appearance = new MeshAppearance(geomLegMesh); // rightleg->appearance = new MeshAppearance(geomLegMesh);
rightleg->appearance->material.setColor(legcolor[0], legcolor[1], legcolor[2], 1); rightleg->appearance->material.setColor(legcolor[0], legcolor[1],
legcolor[2], 1);
vectorSet(rightleg->position, 0.6, BLOCKHEIGHT * (LEGHEIGHT / 2.0), 0); vectorSet(rightleg->position, 0.6, BLOCKHEIGHT * (LEGHEIGHT / 2.0), 0);
rightleg->setGravity(true); rightleg->setGravity(true);
rightleg->setMass(LEGHEIGHT / 3.0); rightleg->setMass(LEGHEIGHT / 3.0);
rightleg->setCollisionGroup(collisiongroup); rightleg->setCollisionGroup(collisiongroup);
} }
// Waist // Waist
{ {
waist = new BodyPart(this, 0); waist = new BodyPart(this, 0);
@ -202,49 +204,56 @@ Legoman::Legoman(int side){
MeshAppearance *waistappearance = new MeshAppearance(waistMesh); 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); Mesh *waistGeomMesh = createBox(-1 + 0.1, 1 - 0.1, 0,
BLOCKHEIGHT * WAISTHEIGHT / 2.0, 0.1, 0.4);
MeshShape *waistgeometry = new MeshShape(waist, waistGeomMesh); MeshShape *waistgeometry = new MeshShape(waist, waistGeomMesh);
waist->geometry = waistgeometry; waist->geometry = waistgeometry;
waist->appearance = waistappearance; waist->appearance = waistappearance;
// waist->appearance = new MeshAppearance(waistGeomMesh); // waist->appearance = new MeshAppearance(waistGeomMesh);
vectorSet(waist->position, 0, BLOCKHEIGHT*(LEGHEIGHT + WAISTHEIGHT/2.0), 0); vectorSet(waist->position, 0, BLOCKHEIGHT * (LEGHEIGHT + WAISTHEIGHT / 2.0),
0);
waist->setGravity(true); waist->setGravity(true);
waist->setMass(2 * WAISTHEIGHT / 3.0); waist->setMass(2 * WAISTHEIGHT / 3.0);
waist->setCollisionGroup(collisiongroup); waist->setCollisionGroup(collisiongroup);
} }
// Torso // Torso
{ {
torso = new BodyPart(this, 4); torso = new BodyPart(this, 4);
Mesh *torsoMesh = loadAscModel((char *)TORSOASC, TORSOSCALE); Mesh *torsoMesh = loadAscModel((char *)TORSOASC, TORSOSCALE);
// int i; // int i;
//for (i = 0; i < torsoMesh->polygoncount; i++) torsoMesh->polygons[i].smooth = false; // for (i = 0; i < torsoMesh->polygoncount; i++)
// torsoMesh->polygons[i].smooth = false;
MeshAppearance *torsoAppearance = new MeshAppearance(torsoMesh); MeshAppearance *torsoAppearance = new MeshAppearance(torsoMesh);
torsoAppearance->material.setColor(torsocolor[0], torsocolor[1], torsocolor[2], 1); torsoAppearance->material.setColor(torsocolor[0], torsocolor[1],
Mesh *torsoGeomMesh = createBox(-1, 1, -BLOCKHEIGHT*TORSOHEIGHT/2.0, BLOCKHEIGHT*TORSOHEIGHT/2.0, -0.5, 0.5); 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); MeshShape *torsogeometry = new MeshShape(torso, torsoGeomMesh);
torso->geometry = torsogeometry; torso->geometry = torsogeometry;
torso->appearance = torsoAppearance; torso->appearance = torsoAppearance;
// torso->appearance = new MeshAppearance(torsoGeomMesh); // torso->appearance = new MeshAppearance(torsoGeomMesh);
vectorSet(torso->position, 0, BLOCKHEIGHT*(LEGHEIGHT + WAISTHEIGHT + TORSOHEIGHT/2.0), 0); vectorSet(torso->position, 0,
BLOCKHEIGHT * (LEGHEIGHT + WAISTHEIGHT + TORSOHEIGHT / 2.0), 0);
torso->setGravity(true); torso->setGravity(true);
torso->setMass(2 * TORSOHEIGHT / 3.0); torso->setMass(2 * TORSOHEIGHT / 3.0);
torso->setCollisionGroup(collisiongroup); torso->setCollisionGroup(collisiongroup);
} }
// Hands // Hands
//Mesh *handMeshGeom = createBox(-0.4, 0.4, -BLOCKHEIGHT*HANDHEIGHT/2.0, BLOCKHEIGHT*HANDHEIGHT/2.0, -0.5, 0.5); // Mesh *handMeshGeom = createBox(-0.4, 0.4, -BLOCKHEIGHT*HANDHEIGHT/2.0,
Mesh *handMeshGeom = createBox(-0.2, 0.2, -BLOCKHEIGHT*HANDHEIGHT/2.0, BLOCKHEIGHT*HANDHEIGHT/2.0, -0.5, 0.5); // 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 // Left hand
{ {
lefthand = new BodyPart(this, 5); lefthand = new BodyPart(this, 5);
Mesh* leftHandMesh = loadAscModel((char*)LEFTARMASC, MODELSCALE, leftHandOffset); Mesh *leftHandMesh =
Mesh* leftPalmMesh = loadAscModel((char*)LEFTPALMASC, MODELSCALE, leftPalmOffset); loadAscModel((char *)LEFTARMASC, MODELSCALE, leftHandOffset);
Mesh *leftPalmMesh =
loadAscModel((char *)LEFTPALMASC, MODELSCALE, leftPalmOffset);
MultiAppearance *a = new MultiAppearance(); MultiAppearance *a = new MultiAppearance();
Appearance *arm = new MeshAppearance(leftHandMesh); Appearance *arm = new MeshAppearance(leftHandMesh);
Appearance *palm = new MeshAppearance(leftPalmMesh); Appearance *palm = new MeshAppearance(leftPalmMesh);
@ -257,7 +266,10 @@ Legoman::Legoman(int side){
lefthand->appearance = a; // new MeshAppearance(leftHandMesh); lefthand->appearance = a; // new MeshAppearance(leftHandMesh);
// lefthand->appearance = new MeshAppearance(handMeshGeom); // lefthand->appearance = new MeshAppearance(handMeshGeom);
// lefthand->appearance->material.setColor(1, 0, 0, 1); // lefthand->appearance->material.setColor(1, 0, 0, 1);
vectorSet(lefthand->position, -1.3, BLOCKHEIGHT*(LEGHEIGHT + WAISTHEIGHT + TORSOHEIGHT - HANDHEIGHT/2.0), 0); vectorSet(lefthand->position, -1.3,
BLOCKHEIGHT *
(LEGHEIGHT + WAISTHEIGHT + TORSOHEIGHT - HANDHEIGHT / 2.0),
0);
lefthand->setGravity(true); lefthand->setGravity(true);
lefthand->setMass(HANDHEIGHT / 3.0); lefthand->setMass(HANDHEIGHT / 3.0);
lefthand->setCollisionGroup(collisiongrouphand); lefthand->setCollisionGroup(collisiongrouphand);
@ -266,8 +278,10 @@ Legoman::Legoman(int side){
// Right hand // Right hand
{ {
righthand = new BodyPart(this, 5); righthand = new BodyPart(this, 5);
Mesh* rightHandMesh = loadAscModel((char*)RIGHTARMASC, MODELSCALE, rightHandOffset); Mesh *rightHandMesh =
Mesh* rightPalmMesh = loadAscModel((char*)RIGHTPALMASC, MODELSCALE, rightPalmOffset); loadAscModel((char *)RIGHTARMASC, MODELSCALE, rightHandOffset);
Mesh *rightPalmMesh =
loadAscModel((char *)RIGHTPALMASC, MODELSCALE, rightPalmOffset);
MultiAppearance *a = new MultiAppearance(); MultiAppearance *a = new MultiAppearance();
Appearance *arm = new MeshAppearance(rightHandMesh); Appearance *arm = new MeshAppearance(rightHandMesh);
arm->material.setColor(torsocolor[0], torsocolor[1], torsocolor[2], 1); arm->material.setColor(torsocolor[0], torsocolor[1], torsocolor[2], 1);
@ -279,13 +293,15 @@ Legoman::Legoman(int side){
righthand->geometry = righthandgeometry; righthand->geometry = righthandgeometry;
righthand->appearance = a; righthand->appearance = a;
// righthand->appearance = new MeshAppearance(handMeshGeom); // righthand->appearance = new MeshAppearance(handMeshGeom);
vectorSet(righthand->position, 1.3, BLOCKHEIGHT*(LEGHEIGHT + WAISTHEIGHT + TORSOHEIGHT - HANDHEIGHT/2.0), 0); vectorSet(righthand->position, 1.3,
BLOCKHEIGHT *
(LEGHEIGHT + WAISTHEIGHT + TORSOHEIGHT - HANDHEIGHT / 2.0),
0);
righthand->setGravity(true); righthand->setGravity(true);
righthand->setMass(HANDHEIGHT / 3.0); righthand->setMass(HANDHEIGHT / 3.0);
righthand->setCollisionGroup(collisiongrouphand); righthand->setCollisionGroup(collisiongrouphand);
} }
// Head // Head
{ {
head = new BodyPart(this, 2); head = new BodyPart(this, 2);
@ -298,40 +314,34 @@ Legoman::Legoman(int side){
headgeometry->setRadius(r); headgeometry->setRadius(r);
head->geometry = headgeometry; head->geometry = headgeometry;
head->appearance = headappearance; head->appearance = headappearance;
vectorSet(head->position, 0, BLOCKHEIGHT*(LEGHEIGHT + WAISTHEIGHT + TORSOHEIGHT + HEADHEIGHT/2 + 0.5), 0); vectorSet(head->position, 0,
BLOCKHEIGHT * (LEGHEIGHT + WAISTHEIGHT + TORSOHEIGHT +
HEADHEIGHT / 2 + 0.5),
0);
head->setGravity(true); head->setGravity(true);
head->setMass(4.0 / 3 * PI * r * r * r); head->setMass(4.0 / 3 * PI * r * r * r);
head->setCollisionGroup(collisiongroup); head->setCollisionGroup(collisiongroup);
} }
headsensor = new Sensor(); headsensor = new Sensor();
torsosensor = 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);
headvisual = new DamageVisual(head, damageHead, false, lefthandvisual =
-0.5, -2, 0.5, -1); new DamageVisual(lefthand, damageHand, true, 0.4, -1, 0.9, 0);
torsovisual = new DamageVisual(torso, damageTorso, false, righthandvisual =
-0.5, -1, 0.5, 0); new DamageVisual(righthand, damageHand, true, -0.4, -1, -0.9, 0);
lefthandvisual = new DamageVisual(lefthand, damageHand, true, leftlegvisual = new DamageVisual(leftleg, damageLeg, true, 0, 0, 0.5, 1);
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);
rightlegvisual = new DamageVisual(rightleg, damageLeg, true, -0, 0, -0.5, 1);
harmfulobjects = NULL; harmfulobjects = NULL;
walkphase = 0; walkphase = 0;
jumpphase = 0; jumpphase = 0;
hitside = 0; hitside = 0;
@ -342,7 +352,6 @@ Legoman::Legoman(int side){
void Legoman::insertToWorld(World *world) { void Legoman::insertToWorld(World *world) {
this->world = world; this->world = world;
world->addChild(rightleg); world->addChild(rightleg);
world->addChild(leftleg); world->addChild(leftleg);
world->addChild(waist); world->addChild(waist);
@ -352,36 +361,42 @@ void Legoman::insertToWorld(World *world){
world->addChild(head); world->addChild(head);
float linkpoint[3]; float linkpoint[3];
vectorSet(linkpoint, 0, BLOCKHEIGHT*(LEGHEIGHT + WAISTHEIGHT + TORSOHEIGHT + HEADHEIGHT), 0); vectorSet(linkpoint, 0,
BLOCKHEIGHT * (LEGHEIGHT + WAISTHEIGHT + TORSOHEIGHT + HEADHEIGHT),
0);
headlinks[0] = world->addLink(head, torso, linkpoint); headlinks[0] = world->addLink(head, torso, linkpoint);
vectorSet(linkpoint, 0, BLOCKHEIGHT*(LEGHEIGHT + WAISTHEIGHT + TORSOHEIGHT), 0); vectorSet(linkpoint, 0, BLOCKHEIGHT * (LEGHEIGHT + WAISTHEIGHT + TORSOHEIGHT),
0);
headlinks[1] = world->addLink(head, torso, linkpoint); headlinks[1] = world->addLink(head, torso, linkpoint);
vectorSet(linkpoint, 0, BLOCKHEIGHT*(LEGHEIGHT + WAISTHEIGHT + TORSOHEIGHT + HEADHEIGHT*0.5), 1); vectorSet(linkpoint, 0, BLOCKHEIGHT * (LEGHEIGHT + WAISTHEIGHT + TORSOHEIGHT +
HEADHEIGHT * 0.5),
1);
headlinks[2] = world->addLink(head, torso, linkpoint); headlinks[2] = world->addLink(head, torso, linkpoint);
head->attached = true; head->attached = true;
vectorSet(linkpoint, -1,
vectorSet(linkpoint, -1, BLOCKHEIGHT*(LEGHEIGHT + WAISTHEIGHT + TORSOHEIGHT) - 0.5, 0); BLOCKHEIGHT * (LEGHEIGHT + WAISTHEIGHT + TORSOHEIGHT) - 0.5, 0);
lefthandlinks[0] = world->addLink(torso, lefthand, linkpoint); lefthandlinks[0] = world->addLink(torso, lefthand, linkpoint);
vectorSet(linkpoint, -2, BLOCKHEIGHT*(LEGHEIGHT + WAISTHEIGHT + TORSOHEIGHT) - 0.5, 0); vectorSet(linkpoint, -2,
BLOCKHEIGHT * (LEGHEIGHT + WAISTHEIGHT + TORSOHEIGHT) - 0.5, 0);
lefthandlinks[1] = world->addLink(torso, lefthand, linkpoint); lefthandlinks[1] = world->addLink(torso, lefthand, linkpoint);
lefthand->attached = true; lefthand->attached = true;
vectorSet(linkpoint, 1,
vectorSet(linkpoint, 1, BLOCKHEIGHT*(LEGHEIGHT + WAISTHEIGHT + TORSOHEIGHT) - 0.5, 0); BLOCKHEIGHT * (LEGHEIGHT + WAISTHEIGHT + TORSOHEIGHT) - 0.5, 0);
righthandlinks[0] = world->addLink(torso, righthand, linkpoint); righthandlinks[0] = world->addLink(torso, righthand, linkpoint);
vectorSet(linkpoint, 2, BLOCKHEIGHT*(LEGHEIGHT + WAISTHEIGHT + TORSOHEIGHT) - 0.5, 0); vectorSet(linkpoint, 2,
BLOCKHEIGHT * (LEGHEIGHT + WAISTHEIGHT + TORSOHEIGHT) - 0.5, 0);
righthandlinks[1] = world->addLink(torso, righthand, linkpoint); righthandlinks[1] = world->addLink(torso, righthand, linkpoint);
righthand->attached = true; righthand->attached = true;
vectorSet(linkpoint, -1, BLOCKHEIGHT * (LEGHEIGHT + WAISTHEIGHT), -0.5); vectorSet(linkpoint, -1, BLOCKHEIGHT * (LEGHEIGHT + WAISTHEIGHT), -0.5);
world->addLink(torso, waist, linkpoint); world->addLink(torso, waist, linkpoint);
@ -396,7 +411,6 @@ void Legoman::insertToWorld(World *world){
waist->attached = true; waist->attached = true;
vectorSet(linkpoint, -1, BLOCKHEIGHT * (LEGHEIGHT + WAISTHEIGHT) - 0.5, 0); vectorSet(linkpoint, -1, BLOCKHEIGHT * (LEGHEIGHT + WAISTHEIGHT) - 0.5, 0);
leftleglinks[0] = world->addLink(waist, leftleg, linkpoint); leftleglinks[0] = world->addLink(waist, leftleg, linkpoint);
@ -407,7 +421,6 @@ void Legoman::insertToWorld(World *world){
leftleg->attached = true; leftleg->attached = true;
vectorSet(linkpoint, 0, BLOCKHEIGHT * (LEGHEIGHT + WAISTHEIGHT) - 0.5, 0); vectorSet(linkpoint, 0, BLOCKHEIGHT * (LEGHEIGHT + WAISTHEIGHT) - 0.5, 0);
rightleglinks[0] = world->addLink(waist, rightleg, linkpoint); rightleglinks[0] = world->addLink(waist, rightleg, linkpoint);
@ -418,7 +431,6 @@ void Legoman::insertToWorld(World *world){
rightleg->attached = true; rightleg->attached = true;
leftleglinks[2] = world->addLink(waist, leftleg, NULL); leftleglinks[2] = world->addLink(waist, leftleg, NULL);
leftleglink = leftleglinks[2]; leftleglink = leftleglinks[2];
leftleglink->enabled = false; leftleglink->enabled = false;
@ -465,11 +477,22 @@ void Legoman::heal(void){
head->reset(); head->reset();
vectorSet(leftleg->position, -0.6, BLOCKHEIGHT * (LEGHEIGHT / 2.0), 0); vectorSet(leftleg->position, -0.6, BLOCKHEIGHT * (LEGHEIGHT / 2.0), 0);
vectorSet(rightleg->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(waist->position, 0, BLOCKHEIGHT * (LEGHEIGHT + WAISTHEIGHT / 2.0),
vectorSet(torso->position, 0, BLOCKHEIGHT*(LEGHEIGHT + WAISTHEIGHT + TORSOHEIGHT/2.0), 0); 0);
vectorSet(lefthand->position, -1.3, BLOCKHEIGHT*(LEGHEIGHT + WAISTHEIGHT + TORSOHEIGHT - HANDHEIGHT/2.0), 0); vectorSet(torso->position, 0,
vectorSet(righthand->position, 1.3, BLOCKHEIGHT*(LEGHEIGHT + WAISTHEIGHT + TORSOHEIGHT - HANDHEIGHT/2.0), 0); BLOCKHEIGHT * (LEGHEIGHT + WAISTHEIGHT + TORSOHEIGHT / 2.0), 0);
vectorSet(head->position, 0, BLOCKHEIGHT*(LEGHEIGHT + WAISTHEIGHT + TORSOHEIGHT + HEADHEIGHT/2 + 0.5), 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); headsensor->attach(head);
torsosensor->attach(torso); torsosensor->attach(torso);
@ -521,7 +544,8 @@ void Legoman::addHarmfulObject(Object *object){
bool Legoman::isHarmfulObject(Object *object) { bool Legoman::isHarmfulObject(Object *object) {
objectlist *node = harmfulobjects; objectlist *node = harmfulobjects;
while (node != NULL) { while (node != NULL) {
if (node->object == object) return true; if (node->object == object)
return true;
node = node->next; node = node->next;
} }
return false; return false;
@ -529,11 +553,16 @@ bool Legoman::isHarmfulObject(Object *object){
float Legoman::getInvMass(void) { float Legoman::getInvMass(void) {
float mass = torso->getMass() + waist->getMass(); float mass = torso->getMass() + waist->getMass();
if (head->attached) mass += head->getMass(); if (head->attached)
if (lefthand->attached) mass += lefthand->getMass(); mass += head->getMass();
if (righthand->attached) mass += righthand->getMass(); if (lefthand->attached)
if (leftleg->attached) mass += leftleg->getMass(); mass += lefthand->getMass();
if (rightleg->attached) mass += rightleg->getMass(); if (righthand->attached)
mass += righthand->getMass();
if (leftleg->attached)
mass += leftleg->getMass();
if (rightleg->attached)
mass += rightleg->getMass();
return 1.0 / mass; return 1.0 / mass;
} }
@ -576,7 +605,8 @@ void Legoman::move(float *movement){
#define BALANCEANGLE (PI / 12) #define BALANCEANGLE (PI / 12)
void Legoman::balance(void) { void Legoman::balance(void) {
if (!alive || !head->attached) return; if (!alive || !head->attached)
return;
float headpos[3], torsopos[3]; float headpos[3], torsopos[3];
headsensor->getPosition(headpos); headsensor->getPosition(headpos);
@ -631,10 +661,12 @@ void Legoman::update(void){
}*/ }*/
if (torso->momentum[1] < 0 && isOnGround()) { if (torso->momentum[1] < 0 && isOnGround()) {
jumpphase--; jumpphase--;
if (jumpphase == 0) jumpenabled = true; if (jumpphase == 0)
jumpenabled = true;
} }
if (hitside < 10) hitside += 2; if (hitside < 10)
hitside += 2;
// hitside = -hitside; // hitside = -hitside;
/*if (hitside > 0){ /*if (hitside > 0){
hitside = -hitside; hitside = -hitside;
@ -662,16 +694,20 @@ void Legoman::updateLegs(void){
// Left leg // Left leg
angle = sfmod(walkphase * LEGSPEED, PI); angle = sfmod(walkphase * LEGSPEED, PI);
if (angle > PI/4) angle = PI/2 - angle; if (angle > PI / 4)
if (angle < -PI/4) angle = -PI/2 - angle; angle = PI / 2 - angle;
if (angle < -PI / 4)
angle = -PI / 2 - angle;
vectorSet(temp, 0, -cos(angle), -sin(angle)); vectorSet(temp, 0, -cos(angle), -sin(angle));
vectorAdd(temp, lll->point1); vectorAdd(temp, lll->point1);
vectorCopy(leftleglink->point1, temp); vectorCopy(leftleglink->point1, temp);
// Right leg // Right leg
angle = sfmod(walkphase * LEGSPEED + PI / 2, PI); angle = sfmod(walkphase * LEGSPEED + PI / 2, PI);
if (angle > PI/4) angle = PI/2 - angle; if (angle > PI / 4)
if (angle < -PI/4) angle = -PI/2 - angle; angle = PI / 2 - angle;
if (angle < -PI / 4)
angle = -PI / 2 - angle;
vectorSet(temp, 0, -cos(angle), -sin(angle)); vectorSet(temp, 0, -cos(angle), -sin(angle));
vectorAdd(temp, rll->point1); vectorAdd(temp, rll->point1);
vectorCopy(rightleglink->point1, temp); vectorCopy(rightleglink->point1, temp);
@ -681,14 +717,17 @@ void Legoman::walk(float amount){
walkdelay = 20; walkdelay = 20;
float sign; float sign;
if (amount > 0) sign = 1; if (amount > 0)
else sign = -1; sign = 1;
else
sign = -1;
walkphase += sign; walkphase += sign;
updateLegs(); updateLegs();
if (!isStanding()) return; if (!isStanding())
return;
float movement[3]; float movement[3];
float xdir[3], ydir[3], zdir[3]; float xdir[3], ydir[3], zdir[3];
@ -734,7 +773,6 @@ void Legoman::walk(float amount){
vectorScale(movement, torso->invmass * waist->getMass()); vectorScale(movement, torso->invmass * waist->getMass());
vectorCopy(waist->momentum, movement); vectorCopy(waist->momentum, movement);
/*float speed = vectorDot(oldmomentum, movement); /*float speed = vectorDot(oldmomentum, movement);
float speedadd = 1; float speedadd = 1;
float maxspeed = 5; float maxspeed = 5;
@ -823,7 +861,8 @@ void Legoman::turn(float amount){
} }
void Legoman::hit(void) { void Legoman::hit(void) {
if (!lefthand->attached && !righthand->attached) return; if (!lefthand->attached && !righthand->attached)
return;
/*float leftdot = vectorDot(&lefthand->rotation[3], &torso->rotation[6]); /*float leftdot = vectorDot(&lefthand->rotation[3], &torso->rotation[6]);
float rightdot = vectorDot(&righthand->rotation[3], &torso->rotation[6]); float rightdot = vectorDot(&righthand->rotation[3], &torso->rotation[6]);
if (leftdot < rightdot){ if (leftdot < rightdot){
@ -832,11 +871,15 @@ void Legoman::hit(void){
hitside = RIGHTHAND; hitside = RIGHTHAND;
}*/ }*/
if (hitside >= 10) hitside -= 9; if (hitside >= 10)
else hitside -= 2; hitside -= 9;
else
hitside -= 2;
if ((hitside & 1) && !lefthand->attached) hitside++; if ((hitside & 1) && !lefthand->attached)
if (!(hitside & 1) && !righthand->attached) hitside++; hitside++;
if (!(hitside & 1) && !righthand->attached)
hitside++;
float axis[3]; float axis[3];
if (hitside & 1) { if (hitside & 1) {
@ -849,11 +892,13 @@ void Legoman::hit(void){
} }
void Legoman::jump(void) { void Legoman::jump(void) {
if (!leftleg->attached && !rightleg->attached) return; if (!leftleg->attached && !rightleg->attached)
return;
if (jumpenabled) { // == 0 && isOnGround()){ if (jumpenabled) { // == 0 && isOnGround()){
float r = BLOCKHEIGHT * HEADHEIGHT / 2; float r = BLOCKHEIGHT * HEADHEIGHT / 2;
float strength = (2*LEGHEIGHT + 2*WAISTHEIGHT + 2*TORSOHEIGHT float strength = (2 * LEGHEIGHT + 2 * WAISTHEIGHT + 2 * TORSOHEIGHT +
+ 2*HANDHEIGHT + 4.0*PI*r*r*r)/3.0*getInvMass(); 2 * HANDHEIGHT + 4.0 * PI * r * r * r) /
3.0 * getInvMass();
float jumpvector[3] = {0, 100.0 / strength, 0}; float jumpvector[3] = {0, 100.0 / strength, 0};
// vectorCopy(torso->momentum, jumpvector); // vectorCopy(torso->momentum, jumpvector);
@ -875,15 +920,18 @@ void Legoman::jump(void){
bool Legoman::isOnGround(void) { bool Legoman::isOnGround(void) {
// if (!isStanding()) return false; // if (!isStanding()) return false;
float wh = waist->position[1]; float wh = waist->position[1];
if (wh > WAISTHEIGHT + 1.5) return false; if (wh > WAISTHEIGHT + 1.5)
if (fabs(torso->momentum[1]) > 10) return false; return false;
if (fabs(torso->momentum[1]) > 10)
return false;
// if (fabs(head->momentum[1]) > 10) return false; // if (fabs(head->momentum[1]) > 10) return false;
// if (fabs(waist->momentum[1]) > 3) return false; // if (fabs(waist->momentum[1]) > 3) return false;
return true; return true;
} }
bool Legoman::isStanding(void) { bool Legoman::isStanding(void) {
if (!leftleg->attached && !rightleg->attached) return false; if (!leftleg->attached && !rightleg->attached)
return false;
float headpos[3], torsopos[3]; float headpos[3], torsopos[3];
headsensor->getPosition(headpos); headsensor->getPosition(headpos);
torsosensor->getPosition(torsopos); torsosensor->getPosition(torsopos);
@ -892,14 +940,19 @@ bool Legoman::isStanding(void){
float posdifflen = vectorLength(posdiff); float posdifflen = vectorLength(posdiff);
float angle = acos(posdiff[1] / posdifflen); float angle = acos(posdiff[1] / posdifflen);
if (angle < BALANCEANGLE) return true; if (angle < BALANCEANGLE)
else return false; return true;
else
return false;
} }
void Legoman::fallOff(void) { void Legoman::fallOff(void) {
if (dead) return; if (dead)
if (rand()&1) fallsound1->play(); return;
else fallsound2->play(); if (rand() & 1)
fallsound1->play();
else
fallsound2->play();
die(); die();
head->energy = 0; head->energy = 0;
torso->energy = 0; torso->energy = 0;
@ -911,7 +964,8 @@ void Legoman::fallOff(void){
} }
void Legoman::releasePart(BodyPart *part) { void Legoman::releasePart(BodyPart *part) {
if (dead) return; if (dead)
return;
if (part == head) { if (part == head) {
headlinks[0]->enabled = false; headlinks[0]->enabled = false;
headlinks[1]->enabled = false; headlinks[1]->enabled = false;
@ -944,25 +998,23 @@ void Legoman::releasePart(BodyPart *part){
} else if (part == torso) { } else if (part == torso) {
die(); die();
} }
if (!lefthand->attached && !righthand->attached && if (!lefthand->attached && !righthand->attached && !leftleg->attached &&
!leftleg->attached && !rightleg->attached) die(); !rightleg->attached)
die();
} }
void Legoman::die(void) { void Legoman::die(void) {
if (dead) return; if (dead)
return;
alive = false; alive = false;
lll->enabled = false; lll->enabled = false;
rll->enabled = false; rll->enabled = false;
gameOver(this); gameOver(this);
} }
bool Legoman::isAlive(void){ bool Legoman::isAlive(void) { return alive; }
return alive;
}
Legoman *Legoman::getOpponent(void){ Legoman *Legoman::getOpponent(void) { return opponent; }
return opponent;
}
void Legoman::drawVisuals(void) { void Legoman::drawVisuals(void) {
headvisual->draw(); headvisual->draw();
@ -973,8 +1025,6 @@ void Legoman::drawVisuals(void){
rightlegvisual->draw(); rightlegvisual->draw();
} }
DamageVisual::DamageVisual(BodyPart *object, Texture *texture, bool mirror, DamageVisual::DamageVisual(BodyPart *object, Texture *texture, bool mirror,
float x1, float y1, float x2, float y2) { float x1, float y1, float x2, float y2) {
this->object = object; this->object = object;
@ -1003,8 +1053,10 @@ void DamageVisual::draw(void){
texture->enable(); texture->enable();
glBegin(GL_QUADS); glBegin(GL_QUADS);
if (energy > 0) glColor3f(1-energy, energy, 0); if (energy > 0)
else glColor3f(0.3, 0.3, 0.3); glColor3f(1 - energy, energy, 0);
else
glColor3f(0.3, 0.3, 0.3);
glTexCoord2f(tx1, ty1); glTexCoord2f(tx1, ty1);
glVertex2f(x1, y1); glVertex2f(x1, y1);

View file

@ -23,7 +23,6 @@ class DamageVisual;
#define LEFTHAND 4 #define LEFTHAND 4
#define RIGHTHAND 8 #define RIGHTHAND 8
const char LEFTLEGASC[] = DATAPATH "blockolegscaled.asc"; const char LEFTLEGASC[] = DATAPATH "blockolegscaled.asc";
const char RIGHTLEGASC[] = DATAPATH "blockolegscaled.asc"; const char RIGHTLEGASC[] = DATAPATH "blockolegscaled.asc";
const char WAISTASC[] = DATAPATH "blockowaistscaled.asc"; const char WAISTASC[] = DATAPATH "blockowaistscaled.asc";
@ -33,11 +32,9 @@ const char RIGHTARMASC[] = DATAPATH"rightarm.asc";
const char LEFTPALMASC[] = DATAPATH "leftpalm.asc"; const char LEFTPALMASC[] = DATAPATH "leftpalm.asc";
const char RIGHTPALMASC[] = DATAPATH "rightpalm.asc"; const char RIGHTPALMASC[] = DATAPATH "rightpalm.asc";
#define MODELSCALE 0.12 #define MODELSCALE 0.12
#define TORSOSCALE 0.115 #define TORSOSCALE 0.115
class BodyPart : public Object { class BodyPart : public Object {
private: private:
float energy; float energy;
@ -171,14 +168,11 @@ public:
friend void drawEnd(int framecount); friend void drawEnd(int framecount);
}; };
extern Texture *damageHead; extern Texture *damageHead;
extern Texture *damageTorso; extern Texture *damageTorso;
extern Texture *damageHand; extern Texture *damageHand;
extern Texture *damageLeg; extern Texture *damageLeg;
class DamageVisual { class DamageVisual {
private: private:
BodyPart *object; BodyPart *object;
@ -187,11 +181,10 @@ private:
Texture *texture; Texture *texture;
public: public:
DamageVisual(BodyPart *object, Texture *texture, bool mirror, DamageVisual(BodyPart *object, Texture *texture, bool mirror, float x1,
float x1, float y1, float x2, float y2); float y1, float x2, float y2);
void draw(void); void draw(void);
}; };
#endif #endif

View file

@ -61,17 +61,16 @@ void Light::setAttenuation(float constant, float linear, float quadratic){
void Light::setEnabled(bool enabled) { void Light::setEnabled(bool enabled) {
this->enabled = enabled; this->enabled = enabled;
if (enabled) glEnable(glnum); if (enabled)
else glDisable(glnum); glEnable(glnum);
else
glDisable(glnum);
} }
void Light::glUpdate(void){ void Light::glUpdate(void) { glLightfv(glnum, GL_POSITION, position); }
glLightfv(glnum, GL_POSITION, position);
}
extern Camera camera; extern Camera camera;
void Light::createFlare(void) { void Light::createFlare(void) {
glPushMatrix(); glPushMatrix();
@ -109,7 +108,6 @@ void Light::createFlare(void){
float zd=(staticlightpositions[lightnumber].z-cameraposition.z)*cz; float zd=(staticlightpositions[lightnumber].z-cameraposition.z)*cz;
float distance=xd+yd+zd;*/ float distance=xd+yd+zd;*/
float screencoords[3]; float screencoords[3];
/*GLint viewport[4]; /*GLint viewport[4];
glGetIntegerv(GL_VIEWPORT, viewport); glGetIntegerv(GL_VIEWPORT, viewport);
@ -122,7 +120,8 @@ void Light::createFlare(void){
glGetDoublev(GL_PROJECTION_MATRIX, projectionm); glGetDoublev(GL_PROJECTION_MATRIX, projectionm);
GLdouble wx, wy, wz; GLdouble wx, wy, wz;
if (gluProject(0, 0, 0, modelviewm, projectionm, viewport, &wx, &wy, &wz) == GL_FALSE){ if (gluProject(0, 0, 0, modelviewm, projectionm, viewport, &wx, &wy, &wz) ==
GL_FALSE) {
printf("Failure\n"); printf("Failure\n");
} }
@ -130,7 +129,6 @@ void Light::createFlare(void){
screencoords[1] = (float)(2 * wy - height) / height; screencoords[1] = (float)(2 * wy - height) / height;
screencoords[2] = wz; screencoords[2] = wz;
// getPointCoordinates(screencoords); // getPointCoordinates(screencoords);
// point3d screencoords = getPointCoordinates(0, 0, 0); // point3d screencoords = getPointCoordinates(0, 0, 0);
@ -147,7 +145,8 @@ void Light::createFlare(void){
glMatrixMode(GL_PROJECTION); glMatrixMode(GL_PROJECTION);
glPushMatrix(); glPushMatrix();
glLoadIdentity(); glLoadIdentity();
float sizey = 6.0/distance * 1.0;//staticlightflarebrightnesses[lightnumber]; float sizey =
6.0 / distance * 1.0; // staticlightflarebrightnesses[lightnumber];
float sizex = sizey * height / width; float sizex = sizey * height / width;
if (distance > 0.5) { if (distance > 0.5) {
@ -177,7 +176,8 @@ void Light::createFlare(void){
glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);
glLoadIdentity(); glLoadIdentity();
if (lightingenabled) glEnable(GL_LIGHTING); if (lightingenabled)
glEnable(GL_LIGHTING);
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
glPopMatrix(); glPopMatrix();

View file

@ -27,4 +27,3 @@ public:
void updateLights(void); void updateLights(void);
#endif #endif

View file

@ -28,9 +28,11 @@ void exitProgram(int code){
void changeResolution(int width, int height, bool fullscreen) { void changeResolution(int width, int height, bool fullscreen) {
int mode = SDL_OPENGL; int mode = SDL_OPENGL;
if (fullscreen) mode |= SDL_FULLSCREEN; if (fullscreen)
mode |= SDL_FULLSCREEN;
if (!SDL_SetVideoMode(width, height, screenbpp, mode)) { 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()); fprintf(stderr, "Couldn't set %i*%i*%i opengl video mode: %s\n",
screenwidth, screenheight, screenbpp, SDL_GetError());
exitProgram(-1); exitProgram(-1);
} }
@ -39,23 +41,19 @@ void changeResolution(int width, int height, bool fullscreen){
screenwidth = width; screenwidth = width;
screenheight = height; screenheight = height;
if (fullscreen) SDL_ShowCursor(SDL_DISABLE); if (fullscreen)
else SDL_ShowCursor(SDL_ENABLE); SDL_ShowCursor(SDL_DISABLE);
else
SDL_ShowCursor(SDL_ENABLE);
initScenes(); initScenes();
} }
bool keys[SDLK_LAST] = {false}; bool keys[SDLK_LAST] = {false};
void handleKeydown(SDL_keysym *keysym){ void handleKeydown(SDL_keysym *keysym) { keys[keysym->sym] = true; }
keys[keysym->sym] = true;
}
void handleKeyup(SDL_keysym *keysym) { keys[keysym->sym] = false; }
void handleKeyup(SDL_keysym *keysym){
keys[keysym->sym] = false;
}
void processEvents(void) { void processEvents(void) {
SDL_Event event; SDL_Event event;
@ -107,7 +105,6 @@ int main(int argc, char *argv[]){
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); 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);
@ -118,8 +115,6 @@ int main(int argc, char *argv[]){
// printf("SDL initialized.\n"); // printf("SDL initialized.\n");
double calculatefps = 200.0; double calculatefps = 200.0;
int framecounter, oldframecounter = 0; int framecounter, oldframecounter = 0;
int currenttime; int currenttime;

View file

@ -1,10 +1,11 @@
#ifndef __MAIN_H_INCLUDED__ #ifndef __MAIN_H_INCLUDED__
#define __MAIN_H_INCLUDED__ #define __MAIN_H_INCLUDED__
#ifdef WIN32 #ifdef WIN32
#pragma warning(disable:4244) //Disable: conversion from 'double' to 'double', possible loss of data #pragma warning(disable : 4244) // Disable: conversion from 'double' to
#pragma warning(disable:4305) //Disable: truncation from 'const double' to 'double' // 'double', possible loss of data
#pragma warning( \
disable : 4305) // Disable: truncation from 'const double' to 'double'
#endif #endif
#include <SDL.h> #include <SDL.h>
@ -18,10 +19,10 @@ extern int screenwidth, screenheight;
extern int debugcounter; extern int debugcounter;
#ifdef DEBUG #ifdef DEBUG
#define DP printf("%s: %i (Debug counter: %i)\n",__FILE__,__LINE__,debugcounter++); #define DP \
printf("%s: %i (Debug counter: %i)\n", __FILE__, __LINE__, debugcounter++);
#else #else
#define DP #define DP
#endif #endif
#endif #endif

View file

@ -20,9 +20,7 @@ bool Material::loadTexture(char *path){
return false; return false;
} }
void Material::freeTexture(void){ void Material::freeTexture(void) { this->texture->~Texture(); }
this->texture->~Texture();
}
void Material::setColor(float red, float green, float blue, float alpha) { void Material::setColor(float red, float green, float blue, float alpha) {
color[0] = red; color[0] = red;
@ -31,9 +29,7 @@ void Material::setColor(float red, float green, float blue, float alpha){
color[3] = alpha; color[3] = alpha;
} }
const float* Material::getColor(void){ const float *Material::getColor(void) { return color; }
return color;
}
void Material::enable(void) { void Material::enable(void) {
enabled = true; enabled = true;
@ -46,13 +42,9 @@ void Material::disable(void){
this->texture->disable(); this->texture->disable();
} }
bool Material::isEnabled(void){ bool Material::isEnabled(void) { return enabled; }
return enabled;
}
Texture* Material::getTexture(void){ Texture *Material::getTexture(void) { return this->texture; }
return this->texture;
}
void Material::setTexture(Texture *tex) { void Material::setTexture(Texture *tex) {
// this->texture->~Texture; // this->texture->~Texture;

View file

@ -22,8 +22,6 @@ public:
bool isEnabled(void); bool isEnabled(void);
Texture *getTexture(void); Texture *getTexture(void);
void setTexture(Texture *tex); void setTexture(Texture *tex);
}; };
#endif #endif

View file

@ -51,12 +51,12 @@ void initMenu(void){
lamp->setPosition(-0.5, BLOCKHEIGHT * 15.5, 0.5); lamp->setPosition(-0.5, BLOCKHEIGHT * 15.5, 0.5);
titleworld->addChild(lamp); titleworld->addChild(lamp);
// Floor // Floor
BasicBlock *floorblock; BasicBlock *floorblock;
floorblock = new BasicBlock(33, 1, 5); floorblock = new BasicBlock(33, 1, 5);
floorblock->setPosition(-0.5, -BLOCKHEIGHT/2.0 + BLOCKHEIGHT*(4*3+1), 0.5-5); floorblock->setPosition(
-0.5, -BLOCKHEIGHT / 2.0 + BLOCKHEIGHT * (4 * 3 + 1), 0.5 - 5);
floorblock->setColor(0, 1, 0); floorblock->setColor(0, 1, 0);
titleworld->addChild(floorblock); titleworld->addChild(floorblock);
@ -75,9 +75,6 @@ void initMenu(void){
floorblock->setColor(1, 0, 0); floorblock->setColor(1, 0, 0);
titleworld->addChild(floorblock); titleworld->addChild(floorblock);
// Letters // Letters
// B // B
@ -96,8 +93,7 @@ void initMenu(void){
{4, 6, 1, 3}};*/ {4, 6, 1, 3}};*/
int Bsize = 10; int Bsize = 10;
int Bwidth = 5; int Bwidth = 5;
int Bletter[10][4] = { int Bletter[10][4] = {{0, 0, 4, 1},
{0, 0, 4, 1},
{0, 4, 4, 1}, {0, 4, 4, 1},
{0, 8, 4, 1}, {0, 8, 4, 1},
{0, 1, 1, 7}, {0, 1, 1, 7},
@ -111,28 +107,19 @@ void initMenu(void){
// l // l
int lsize = 2; int lsize = 2;
int lwidth = 4; int lwidth = 4;
int lletter[2][4] = { int lletter[2][4] = {{0, 0, 4, 1}, {0, 1, 1, 4}};
{0, 0, 4, 1},
{0, 1, 1, 4}};
// o // o
int osize = 4; int osize = 4;
int owidth = 4; int owidth = 4;
int oletter[4][4] = { int oletter[4][4] = {
{0, 0, 4, 1}, {0, 0, 4, 1}, {0, 4, 4, 1}, {0, 1, 1, 3}, {3, 1, 1, 3}};
{0, 4, 4, 1},
{0, 1, 1, 3},
{3, 1, 1, 3}};
// c // c
int csize = 5; int csize = 5;
int cwidth = 4; int cwidth = 4;
int cletter[5][4] = { int cletter[5][4] = {
{0, 0, 4, 1}, {0, 0, 4, 1}, {0, 4, 4, 1}, {0, 1, 1, 3}, {3, 1, 1, 1}, {3, 3, 1, 1}};
{0, 4, 4, 1},
{0, 1, 1, 3},
{3, 1, 1, 1},
{3, 3, 1, 1}};
/* {1, 0, 2, 1}, /* {1, 0, 2, 1},
{1, 4, 2, 1}, {1, 4, 2, 1},
{0, 1, 1, 3}, {0, 1, 1, 3},
@ -142,8 +129,7 @@ void initMenu(void){
// k // k
int ksize = 6; int ksize = 6;
int kwidth = 4; int kwidth = 4;
int kletter[6][4] = { int kletter[6][4] = {{0, 0, 1, 5},
{0, 0, 1, 5},
{1, 2, 2, 1}, {1, 2, 2, 1},
{2, 1, 2, 1}, {2, 1, 2, 1},
{2, 3, 2, 1}, {2, 3, 2, 1},
@ -159,57 +145,39 @@ void initMenu(void){
// F // F
int Fsize = 3; int Fsize = 3;
int Fwidth = 3; int Fwidth = 3;
int Fletter[3][4] = { int Fletter[3][4] = {{0, 0, 1, 7}, {0, 4, 3, 1}, {0, 7, 6, 1}};
{0, 0, 1, 7},
{0, 4, 3, 1},
{0, 7, 6, 1}};
// i // i
int isize = 1; int isize = 1;
int iwidth = 1; int iwidth = 1;
int iletter[1][4] = { int iletter[1][4] = {{0, 0, 1, 4}};
{0, 0, 1, 4}};
// g // g
int gsize = 5; int gsize = 5;
int gwidth = 4; int gwidth = 4;
int gletter[5][4] = { int gletter[5][4] = {
{0, 0, 4, 1}, {0, 0, 4, 1}, {0, 4, 4, 1}, {0, 1, 1, 3}, {3, 1, 1, 1}, {2, 2, 2, 1}};
{0, 4, 4, 1},
{0, 1, 1, 3},
{3, 1, 1, 1},
{2, 2, 2, 1}};
// h // h
int hsize = 3; int hsize = 3;
int hwidth = 1; int hwidth = 1;
int hletter[3][4] = { int hletter[3][4] = {{0, 0, 1, 5}, {3, 0, 1, 5}, {0, 2, 4, 1}};
{0, 0, 1, 5},
{3, 0, 1, 5},
{0, 2, 4, 1}};
// t // t
int tsize = 2; int tsize = 2;
int twidth = 4; int twidth = 4;
int tletter[2][4] = { int tletter[2][4] = {{3, 0, 1, 6}, {0, 6, 7, 1}};
{3, 0, 1, 6},
{0, 6, 7, 1}};
// e // e
int esize = 5; int esize = 5;
int ewidth = 4; int ewidth = 4;
int eletter[5][4] = { int eletter[5][4] = {
{0, 0, 4, 1}, {0, 0, 4, 1}, {0, 4, 4, 1}, {0, 2, 3, 1}, {0, 1, 1, 1}, {0, 3, 1, 1}};
{0, 4, 4, 1},
{0, 2, 3, 1},
{0, 1, 1, 1},
{0, 3, 1, 1}};
// r // r
int rsize = 6; int rsize = 6;
int rwidth = 4; int rwidth = 4;
int rletter[6][4] = { int rletter[6][4] = {{0, 0, 1, 5},
{0, 0, 1, 5},
{0, 2, 3, 1}, {0, 2, 3, 1},
{0, 4, 3, 1}, {0, 4, 3, 1},
{2, 1, 2, 1}, {2, 1, 2, 1},
@ -225,59 +193,21 @@ void initMenu(void){
{3, 3, 1, 1}};*/ {3, 3, 1, 1}};*/
#define LETTERCOUNT 6 #define LETTERCOUNT 6
int lettersizes[LETTERCOUNT] = { int lettersizes[LETTERCOUNT] = {Bsize, lsize, osize, csize, ksize, osize};
Bsize, int letterwidths[LETTERCOUNT] = {Bwidth, lwidth, owidth,
lsize, cwidth, kwidth, owidth};
osize, int *letters[LETTERCOUNT] = {&Bletter[0][0], &lletter[0][0],
csize, &oletter[0][0], &cletter[0][0],
ksize, &kletter[0][0], &oletter[0][0]};
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 #define LETTERCOUNT2 7
int lettersizes2[LETTERCOUNT2] = { int lettersizes2[LETTERCOUNT2] = {Fsize, isize, gsize, hsize,
Fsize, tsize, esize, rsize};
isize, int letterwidths2[LETTERCOUNT2] = {Fwidth, iwidth, gwidth, hwidth,
gsize, twidth, ewidth, rwidth};
hsize,
tsize,
esize,
rsize
};
int letterwidths2[LETTERCOUNT2] = {
Fwidth,
iwidth,
gwidth,
hwidth,
twidth,
ewidth,
rwidth
};
int *letters2[LETTERCOUNT2] = { int *letters2[LETTERCOUNT2] = {
&Fletter[0][0], &Fletter[0][0], &iletter[0][0], &gletter[0][0], &hletter[0][0],
&iletter[0][0], &tletter[0][0], &eletter[0][0], &rletter[0][0]};
&gletter[0][0],
&hletter[0][0],
&tletter[0][0],
&eletter[0][0],
&rletter[0][0]
};
BasicBlock *letterblock; BasicBlock *letterblock;
float z = 0.5; float z = 0.5;
@ -294,7 +224,9 @@ void initMenu(void){
int w = letters[i][j * 4 + 2]; int w = letters[i][j * 4 + 2];
int h = letters[i][j * 4 + 3] * 3; int h = letters[i][j * 4 + 3] * 3;
letterblock = new BasicBlock(w, h, 1); 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->setPosition(dx + x + w / 2.0,
dy + BLOCKHEIGHT * (y + h / 2.0),
dz + z + randomf(0.1));
letterblock->setColor(1, 0.5, 1); letterblock->setColor(1, 0.5, 1);
titleworld->addChild(letterblock); titleworld->addChild(letterblock);
} }
@ -312,7 +244,9 @@ void initMenu(void){
int w = letters2[i][j * 4 + 2]; int w = letters2[i][j * 4 + 2];
int h = letters2[i][j * 4 + 3] * 3; int h = letters2[i][j * 4 + 3] * 3;
letterblock = new BasicBlock(w, h, 1); 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->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}; // float rotate[3] = {0, randomf(0.1), 0};
// matrixCreateRotation(letterblock->rotation, rotate); // matrixCreateRotation(letterblock->rotation, rotate);
letterblock->setColor(1, 0.5, 1); letterblock->setColor(1, 0.5, 1);
@ -321,27 +255,26 @@ void initMenu(void){
dx += width + 1; dx += width + 1;
} }
Object *flower; Object *flower;
flower = new Object(); flower = new Object();
flower->appearance = new FlowerAppearance(FLOWER_RED, FLOWER_WHITE, FLOWER_YELLOW); flower->appearance =
new FlowerAppearance(FLOWER_RED, FLOWER_WHITE, FLOWER_YELLOW);
flower->setPosition(-7.5, 0, 1.5); flower->setPosition(-7.5, 0, 1.5);
titleworld->addChild(flower); titleworld->addChild(flower);
flower = new Object(); flower = new Object();
flower->appearance = new FlowerAppearance(FLOWER_YELLOW, FLOWER_RED, FLOWER_YELLOW); flower->appearance =
new FlowerAppearance(FLOWER_YELLOW, FLOWER_RED, FLOWER_YELLOW);
flower->setPosition(-11.5, 0, -2.5); flower->setPosition(-11.5, 0, -2.5);
titleworld->addChild(flower); titleworld->addChild(flower);
flower = new Object(); flower = new Object();
flower->appearance = new FlowerAppearance(FLOWER_WHITE, FLOWER_WHITE, FLOWER_RED); flower->appearance =
new FlowerAppearance(FLOWER_WHITE, FLOWER_WHITE, FLOWER_RED);
flower->setPosition(-14.5, 0, 0.5); flower->setPosition(-14.5, 0, 0.5);
titleworld->addChild(flower); titleworld->addChild(flower);
changesound = new Sound(DATAPATH "menuchange.wav"); changesound = new Sound(DATAPATH "menuchange.wav");
selectsound = new Sound(DATAPATH "menuselect.wav"); selectsound = new Sound(DATAPATH "menuselect.wav");
menumusic = new Sound(DATAPATH "menu.mp3", true); menumusic = new Sound(DATAPATH "menu.mp3", true);
@ -381,23 +314,19 @@ int olddetail;
int detail = 2; int detail = 2;
#define RESOLUTIONCOUNT 6 #define RESOLUTIONCOUNT 6
int resolutions[RESOLUTIONCOUNT][2] = { int resolutions[RESOLUTIONCOUNT][2] = {{640, 480},
{640, 480},
{800, 600}, {800, 600},
{1024, 768}, {1024, 768},
{1280, 960}, {1280, 960},
{1280, 1024}, {1280, 1024},
{1600, 1200} {1600, 1200}};
};
#define DETAILCOUNT 4 #define DETAILCOUNT 4
char *details[DETAILCOUNT] = {"Off", "Low", "Medium", "High"}; char *details[DETAILCOUNT] = {"Off", "Low", "Medium", "High"};
int menurestartcounter = -1; int menurestartcounter = -1;
void menuRestart(void){ void menuRestart(void) { menurestartcounter = 0; }
menurestartcounter = 0;
}
void menuMain(void) { void menuMain(void) {
interpolator = 0.0; interpolator = 0.0;
@ -449,15 +378,14 @@ void menuEscPressed(void){
quitcounter = 0; quitcounter = 0;
} }
void menuQuit(void){ void menuQuit(void) { exitProgram(0); }
exitProgram(0);
}
void menuResolution(int dir) { void menuResolution(int dir) {
resolution += dir; resolution += dir;
if (resolution < 0) resolution = 0; if (resolution < 0)
if (resolution >= RESOLUTIONCOUNT) resolution = RESOLUTIONCOUNT-1; resolution = 0;
if (resolution >= RESOLUTIONCOUNT)
resolution = RESOLUTIONCOUNT - 1;
// resolution = (resolution + RESOLUTIONCOUNT) % RESOLUTIONCOUNT; // resolution = (resolution + RESOLUTIONCOUNT) % RESOLUTIONCOUNT;
} }
@ -476,7 +404,6 @@ void calculateMenu(int framecount){
} }
} }
menufade = -1; menufade = -1;
titlelight.setEnabled(true); titlelight.setEnabled(true);
@ -498,11 +425,14 @@ void calculateMenu(int framecount){
if (quitcounter != -1) { if (quitcounter != -1) {
menufade = quitcounter / 200.0; menufade = quitcounter / 200.0;
quitcounter++; quitcounter++;
if (quitcounter == 200) menuQuit(); if (quitcounter == 200)
menuQuit();
} }
float cameratarget[3] = {0, 0, 0}; 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.setPosition(sin(framecount * 0.001) * 2 - 8,
sin(framecount * 0.0033) * 2 + 15,
cos(framecount * 0.001) * 2 + 25);
titlecamera.setTarget(cameratarget); titlecamera.setTarget(cameratarget);
titleworld->move(); titleworld->move();
@ -564,7 +494,8 @@ void calculateMenu(int framecount){
menuResolution(-1); menuResolution(-1);
break; break;
case OPTIONSDETAIL: case OPTIONSDETAIL:
if (detail > 0) detail--; if (detail > 0)
detail--;
break; break;
} }
break; break;
@ -581,7 +512,8 @@ void calculateMenu(int framecount){
menuResolution(1); menuResolution(1);
break; break;
case OPTIONSDETAIL: case OPTIONSDETAIL:
if (detail < DETAILCOUNT-1) detail++; if (detail < DETAILCOUNT - 1)
detail++;
break; break;
} }
break; break;
@ -596,8 +528,8 @@ void calculateMenu(int framecount){
if (menuoption != MAINQUIT) { if (menuoption != MAINQUIT) {
menuoption = MAINQUIT; menuoption = MAINQUIT;
changesound->play(); changesound->play();
} } else
else menuEscPressed(); menuEscPressed();
break; break;
case MODEOPTIONS: case MODEOPTIONS:
selectsound->play(); selectsound->play();
@ -627,7 +559,8 @@ void calculateMenu(int framecount){
case MODEOPTIONS: case MODEOPTIONS:
switch (menuoption) { switch (menuoption) {
case OPTIONSRESOLUTION: case OPTIONSRESOLUTION:
if (resolution != oldresolution) changeResolution(xres, yres, fullscreen); if (resolution != oldresolution)
changeResolution(xres, yres, fullscreen);
oldresolution = resolution; oldresolution = resolution;
break; break;
case OPTIONSFULLSCREEN: case OPTIONSFULLSCREEN:
@ -655,7 +588,8 @@ void calculateMenu(int framecount){
selectsound->play(); selectsound->play();
pressed = true; pressed = true;
} }
} else pressed = false; } else
pressed = false;
} }
} }
} }
@ -668,16 +602,12 @@ void drawMenu(int framecount){
updateLights(); updateLights();
titleworld->draw(); titleworld->draw();
flaretexture->enable(); flaretexture->enable();
titlelight.createFlare(); titlelight.createFlare();
flaretexture->disable(); flaretexture->disable();
/*//2D-view /*//2D-view
glDisable(GL_LIGHTING); glDisable(GL_LIGHTING);
glDisable(GL_CULL_FACE); glDisable(GL_CULL_FACE);
@ -692,18 +622,17 @@ void drawMenu(int framecount){
enable2D(); enable2D();
glColor3f(1, 1, 1); glColor3f(1, 1, 1);
print(0.73, 0.55, print(0.73, 0.55, "Programming:\n"
"Programming:\n" \ " Miika Sell\n"
" Miika Sell\n" \ " Juha Kaarlas\n"
" Juha Kaarlas\n" \ "\n"
"\n" \ "Graphics:\n"
"Graphics:\n" \ " Miika Sell\n"
" Miika Sell\n" \ " Juha Kaarlas\n"
" Juha Kaarlas\n" \ "\n"
"\n" \ "Musics:\n"
"Musics:\n" \ " Osmand",
" Osmand" 0.03);
, 0.03);
print(0.35, 0.965, "http://blockofighter.kicks-ass.net/", 0.02); print(0.35, 0.965, "http://blockofighter.kicks-ass.net/", 0.02);
@ -736,7 +665,6 @@ void drawMenu(int framecount){
glColor3f(1, 1, 1); glColor3f(1, 1, 1);
print(0.88, 0.12, "supported", 0.02); print(0.88, 0.12, "supported", 0.02);
glEnable(GL_BLEND); glEnable(GL_BLEND);
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
glColor4f(0, 0, 0, 0.5); glColor4f(0, 0, 0, 0.5);
@ -813,7 +741,9 @@ void drawMenu(int framecount){
glLineWidth(2); 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); 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); glBegin(GL_LINE_LOOP);
glVertex2f(x1, y1); glVertex2f(x1, y1);
glVertex2f(x2, y1); glVertex2f(x2, y1);
@ -822,7 +752,6 @@ void drawMenu(int framecount){
glEnd(); glEnd();
} }
if (menufade != -1) { if (menufade != -1) {
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glColor4f(0, 0, 0, menufade); glColor4f(0, 0, 0, menufade);

View file

@ -16,4 +16,3 @@ void drawMenu(int framecount);
void menuRestart(void); void menuRestart(void);
#endif #endif

View file

@ -38,8 +38,6 @@ Polygon::Polygon(void){
realsmooth = false; realsmooth = false;
} }
Mesh::Mesh(void) { Mesh::Mesh(void) {
vertexcount = 0; vertexcount = 0;
polygoncount = 0; polygoncount = 0;
@ -64,7 +62,8 @@ void Mesh::createPlanes(void){
vectorCross(polygon->planenormal, v1, v2); vectorCross(polygon->planenormal, v1, v2);
vectorNormalize(polygon->planenormal); vectorNormalize(polygon->planenormal);
polygon->planedistance = -vectorDot(polygon->vertices[0]->position, polygon->planenormal); polygon->planedistance =
-vectorDot(polygon->vertices[0]->position, polygon->planenormal);
} }
} }
} }
@ -95,7 +94,8 @@ void Mesh::createVertexnormals(void){
} }
for (j = 0; j < polygoncount; j++) { for (j = 0; j < polygoncount; j++) {
class Polygon *polygon = &polygons[j]; class Polygon *polygon = &polygons[j];
if (!polygon->realsmooth) polygon->smooth = true; if (!polygon->realsmooth)
polygon->smooth = true;
} }
} }
@ -155,7 +155,6 @@ void Mesh::createEdges(void){
delete[] edges; delete[] edges;
} }
float Mesh::calculateScale(float targetLength, int axis) { float Mesh::calculateScale(float targetLength, int axis) {
float min = 0.0; float min = 0.0;
@ -195,13 +194,7 @@ MeshObject::MeshObject(Mesh *mesh){
this->geometry = new MeshShape(this); this->geometry = new MeshShape(this);
} }
MeshAppearance::MeshAppearance(Mesh *mesh) { this->mesh = mesh; }
MeshAppearance::MeshAppearance(Mesh *mesh){
this->mesh = mesh;
}
void MeshAppearance::draw(void) { void MeshAppearance::draw(void) {
// glDisable(GL_CULL_FACE); // glDisable(GL_CULL_FACE);
@ -215,21 +208,20 @@ void MeshAppearance::draw(void){
glBegin(GL_TRIANGLE_FAN); glBegin(GL_TRIANGLE_FAN);
if (!polygon->smooth) glNormal3fv(polygon->planenormal); if (!polygon->smooth)
glNormal3fv(polygon->planenormal);
for (j = 0; j < polygon->vertexcount; j++) { for (j = 0; j < polygon->vertexcount; j++) {
Vertex *vertex = polygon->vertices[j]; Vertex *vertex = polygon->vertices[j];
if (polygon->smooth) glNormal3fv(vertex->normal); if (polygon->smooth)
glNormal3fv(vertex->normal);
glVertex3fv(vertex->position); glVertex3fv(vertex->position);
} }
glEnd(); glEnd();
} }
glDisable(GL_DEPTH); glDisable(GL_DEPTH);
glDisable(GL_LIGHTING); glDisable(GL_LIGHTING);
glLineWidth(5.0); glLineWidth(5.0);
@ -244,16 +236,10 @@ void MeshAppearance::draw(void){
glEnable(GL_LIGHTING); glEnable(GL_LIGHTING);
glEnable(GL_DEPTH); glEnable(GL_DEPTH);
this->material.disable(); this->material.disable();
// glEnable(GL_CULL_FACE); // glEnable(GL_CULL_FACE);
} }
MeshShape::MeshShape(MeshObject *object) : Shape(object) { MeshShape::MeshShape(MeshObject *object) : Shape(object) {
mesh = object->mesh; mesh = object->mesh;
} }
@ -267,7 +253,8 @@ bool MeshShape::checkCollision(Object *target){
} }
float MeshShape::calculateMomentOfInertia(float *rotationvector) { float MeshShape::calculateMomentOfInertia(float *rotationvector) {
if (vectorDot(rotationvector, rotationvector) < EPSILON) return 0; if (vectorDot(rotationvector, rotationvector) < EPSILON)
return 0;
int i; int i;
float j = 0; float j = 0;
for (i = 0; i < mesh->vertexcount; i++) { for (i = 0; i < mesh->vertexcount; i++) {
@ -325,7 +312,8 @@ bool MeshShape::checkCollisionPeer(MeshShape *target){
object->transformPoint(vertexposition, vertex->position); object->transformPoint(vertexposition, vertex->position);
target->object->unTransformPoint(vertexposition, vertexposition); target->object->unTransformPoint(vertexposition, vertexposition);
if (checkPointMeshCollision(vertexposition, targetmesh, normal, contactpoint)){ if (checkPointMeshCollision(vertexposition, targetmesh, normal,
contactpoint)) {
target->object->transformVector(normal, normal); target->object->transformVector(normal, normal);
target->object->transformPoint(contactpoint, contactpoint); target->object->transformPoint(contactpoint, contactpoint);
@ -345,7 +333,8 @@ bool MeshShape::checkCollisionPeer(MeshShape *target){
target->object->transformPoint(vertexposition, vertex->position); target->object->transformPoint(vertexposition, vertex->position);
object->unTransformPoint(vertexposition, vertexposition); object->unTransformPoint(vertexposition, vertexposition);
if (checkPointMeshCollision(vertexposition, targetmesh, normal, contactpoint)){ if (checkPointMeshCollision(vertexposition, targetmesh, normal,
contactpoint)) {
object->transformVector(normal, normal); object->transformVector(normal, normal);
object->transformPoint(contactpoint, contactpoint); object->transformPoint(contactpoint, contactpoint);
@ -376,4 +365,3 @@ bool MeshShape::checkCollisionPeer(MeshShape *target){
return collided; return collided;
} }

View file

@ -3,12 +3,10 @@
#include "object.h" #include "object.h"
#define X_AXIS 0 #define X_AXIS 0
#define Y_AXIS 1 #define Y_AXIS 1
#define Z_AXIS 2 #define Z_AXIS 2
class Vertex { class Vertex {
public: public:
float position[3]; float position[3];
@ -23,7 +21,6 @@ public:
void setTexCoords(float u, float v); void setTexCoords(float u, float v);
}; };
class Edge; class Edge;
class Polygon { class Polygon {
@ -41,16 +38,12 @@ public:
Polygon(void); Polygon(void);
}; };
class Edge { class Edge {
public: public:
Vertex *v1, *v2; Vertex *v1, *v2;
class Polygon *p1, *p2; class Polygon *p1, *p2;
}; };
class Mesh { class Mesh {
public: public:
int vertexcount; int vertexcount;
@ -62,7 +55,6 @@ public:
Edge *edges; Edge *edges;
int edgecount; int edgecount;
Mesh(void); Mesh(void);
~Mesh(void); ~Mesh(void);
@ -74,8 +66,6 @@ public:
void scale(float scale); void scale(float scale);
}; };
class MeshObject : public Object { class MeshObject : public Object {
public: public:
Mesh *mesh; Mesh *mesh;
@ -83,8 +73,6 @@ public:
MeshObject(Mesh *mesh); MeshObject(Mesh *mesh);
}; };
class MeshAppearance : public Appearance { class MeshAppearance : public Appearance {
private: private:
Mesh *mesh; Mesh *mesh;
@ -95,8 +83,6 @@ public:
void draw(void); void draw(void);
}; };
// Geometry of sphere // Geometry of sphere
class MeshShape : public Shape { class MeshShape : public Shape {
@ -118,4 +104,3 @@ public:
}; };
#endif #endif

View file

@ -25,24 +25,24 @@ Object::Object(void){
} }
void Object::prepare(void) { void Object::prepare(void) {
if (appearance != NULL) appearance->prepare(); if (appearance != NULL)
appearance->prepare();
} }
#define DT 0.01 #define DT 0.01
void Object::move(void){ void Object::move(void) { moveStep(DT); }
moveStep(DT);
}
void Object::moveStep(float dt) { void Object::moveStep(float dt) {
if (invmass == 0) return; if (invmass == 0)
return;
if (vectorDot(momentum, momentum) > 1.0e+5)
if (vectorDot(momentum, momentum) > 1.0e+5) vectorSet(momentum, 0, 0, 0); vectorSet(momentum, 0, 0, 0);
if (vectorDot(angularmomentum, angularmomentum) > 1.0e+5) vectorSet(angularmomentum, 0, 0, 0); if (vectorDot(angularmomentum, angularmomentum) > 1.0e+5)
vectorSet(angularmomentum, 0, 0, 0);
calculateStateVariables(); calculateStateVariables();
float velocitydt[3]; float velocitydt[3];
vectorScale(velocitydt, velocity, dt); vectorScale(velocitydt, velocity, dt);
vectorAdd(position, velocitydt); vectorAdd(position, velocitydt);
@ -66,7 +66,8 @@ void Object::calculateStateVariables(void){
if (vectorIsZero(angularmomentum)) { if (vectorIsZero(angularmomentum)) {
invmomentofinertia = 0; invmomentofinertia = 0;
} else { } else {
invmomentofinertia = invmass * 1.0 / geometry->calculateMomentOfInertia(angularmomentum); invmomentofinertia =
invmass * 1.0 / geometry->calculateMomentOfInertia(angularmomentum);
} }
vectorScale(angularvelocity, angularmomentum, invmomentofinertia); vectorScale(angularvelocity, angularmomentum, invmomentofinertia);
@ -112,25 +113,25 @@ void Object::getMomentum(float *momentum){
} }
void Object::setMass(float mass) { void Object::setMass(float mass) {
if (mass == 0) this->invmass = 0; if (mass == 0)
else this->invmass = 1.0 / mass; this->invmass = 0;
else
this->invmass = 1.0 / mass;
} }
float Object::getMass(void) { float Object::getMass(void) {
if (invmass == 0) return 0; if (invmass == 0)
return 0;
return 1.0 / invmass; return 1.0 / invmass;
} }
void Object::setCollisionGroup(int group){ void Object::setCollisionGroup(int group) { this->collisiongroup = group; }
this->collisiongroup = group;
}
int Object::getCollisionGroup(void){ int Object::getCollisionGroup(void) { return collisiongroup; }
return collisiongroup;
}
void Object::addImpulse(float *impulse, float *contactpoint) { void Object::addImpulse(float *impulse, float *contactpoint) {
if (invmass == 0) return; if (invmass == 0)
return;
float angularimpulse[3]; float angularimpulse[3];
vectorCross(angularimpulse, contactpoint, impulse); vectorCross(angularimpulse, contactpoint, impulse);
vectorAdd(angularmomentum, angularimpulse); vectorAdd(angularmomentum, angularimpulse);
@ -175,39 +176,36 @@ void Object::unTransformVector(float *newvector, float *oldvector){
vectorMatrixMultiply(newvector, oldvector, rotmat); vectorMatrixMultiply(newvector, oldvector, rotmat);
} }
void Object::hitForce(float speed, float *speed2, Object *source) { void Object::hitForce(float speed, float *speed2, Object *source) {
float tolerance = 1.0; float tolerance = 1.0;
if (speed > tolerance) { if (speed > tolerance) {
Sound *sound; Sound *sound;
if (rand()&1) sound = softhitsound1; if (rand() & 1)
else sound = softhitsound2; sound = softhitsound1;
else
sound = softhitsound2;
float volume = (speed - tolerance) * 2; float volume = (speed - tolerance) * 2;
if (volume > 1) volume = 1; if (volume > 1)
volume = 1;
sound->setVolume(volume); sound->setVolume(volume);
sound->play(30 + random(70)); sound->play(30 + random(70));
} }
} }
void Object::setGravity(bool enabled) { gravity = enabled; }
void Object::setGravity(bool enabled){
gravity = enabled;
}
void Object::draw(void) { void Object::draw(void) {
glPushMatrix(); glPushMatrix();
glTranslatef(position[0], position[1], position[2]); glTranslatef(position[0], position[1], position[2]);
GLfloat glmatrix[16] = { GLfloat glmatrix[16] = {rotation[0], rotation[1], rotation[2], 0,
rotation[0], rotation[1], rotation[2], 0,
rotation[3], rotation[4], rotation[5], 0, rotation[3], rotation[4], rotation[5], 0,
rotation[6], rotation[7], rotation[8], 0, rotation[6], rotation[7], rotation[8], 0,
0, 0, 0, 1}; 0, 0, 0, 1};
glMultMatrixf(glmatrix); glMultMatrixf(glmatrix);
if (appearance != NULL) appearance->draw(); if (appearance != NULL)
appearance->draw();
glPopMatrix(); glPopMatrix();
} }

View file

@ -40,7 +40,6 @@ public:
// float force[3]; //Temporary properties // float force[3]; //Temporary properties
// float externalforce[3]; // float externalforce[3];
/* Angular movement: /* Angular movement:
* rotation <-> orientaatio (R) * rotation <-> orientaatio (R)
* angular velocity <-> kulmanopeus (w) * angular velocity <-> kulmanopeus (w)
@ -66,7 +65,6 @@ public:
// float torque[3]; //Temporary property // float torque[3]; //Temporary property
void moveStep(float dt); void moveStep(float dt);
// void applyForces(float dt); // void applyForces(float dt);
@ -81,8 +79,6 @@ public:
bool gravity; bool gravity;
Object(void); Object(void);
virtual void prepare(void); virtual void prepare(void);
@ -117,30 +113,16 @@ public:
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 class ObjectLink;
//friend void collide(Object *source, Object *target, float *normal, float *contactpoint); // friend void collide(Object *source, Object *target, float *normal, float
// *contactpoint);
friend bool checkCollisions(Object *object, float *contactnormal); friend bool checkCollisions(Object *object, float *contactnormal);
// Temporary state variables // Temporary state variables
float velocity[3]; float velocity[3];
float angularvelocity[3]; float angularvelocity[3];
}; };
#endif #endif

View file

@ -12,7 +12,6 @@
#include "objectfactory.h" #include "objectfactory.h"
#include "glapi.h" #include "glapi.h"
MeshObject *createPyramid(float width, float height) { MeshObject *createPyramid(float width, float height) {
Mesh *mesh = new Mesh(); Mesh *mesh = new Mesh();
mesh->vertexcount = 5; mesh->vertexcount = 5;
@ -89,7 +88,8 @@ MeshObject *createSpherePool(float width, float height){
// float py = randomf(1); // float py = randomf(1);
float l = sqrt(pz * pz + px * px) * 1; float l = sqrt(pz * pz + px * px) * 1;
if (l > width) l = width; if (l > width)
l = width;
l = l / width; l = l / width;
// l = l*l; // l = l*l;
float py = height * (sin(PI * (1.5 + l * 2)) + 1) / 2; float py = height * (sin(PI * (1.5 + l * 2)) + 1) / 2;
@ -114,7 +114,6 @@ MeshObject *createSpherePool(float width, float height){
} }
} }
mesh->createPlanes(); mesh->createPlanes();
mesh->createVertexnormals(); mesh->createVertexnormals();
@ -193,14 +192,15 @@ Mesh *createBox(float x1, float x2, float y1, float y2, float z1, float z2){
return mesh; return mesh;
} }
float getValueFromString(char *data) { float getValueFromString(char *data) {
while(*data==' ') data++; while (*data == ' ')
data++;
char *enddata = data; char *enddata = data;
// char oldchar; // char oldchar;
do { do {
enddata++; enddata++;
if ((*enddata<'0' || *enddata>'9') && (*enddata!='.')) *enddata=0; if ((*enddata < '0' || *enddata > '9') && (*enddata != '.'))
*enddata = 0;
} while (*enddata != 0); } while (*enddata != 0);
float ret = atof(data); float ret = atof(data);
*enddata = ' '; *enddata = ' ';
@ -220,7 +220,6 @@ Mesh* loadAscModel(char *filename, float scale, float* offset){
Mesh *target = new Mesh(); Mesh *target = new Mesh();
FILE *file; FILE *file;
float x, y, z; float x, y, z;
@ -241,7 +240,6 @@ Mesh* loadAscModel(char *filename, float scale, float* offset){
target->vertices = new Vertex[target->vertexcount]; target->vertices = new Vertex[target->vertexcount];
target->polygons = new class Polygon[target->polygoncount]; target->polygons = new class Polygon[target->polygoncount];
int i; int i;
vert = findStringEnd(data, "Vertex list:"); vert = findStringEnd(data, "Vertex list:");
@ -254,7 +252,8 @@ Mesh* loadAscModel(char *filename, float scale, float* offset){
y = getValueFromString(vert) * scale; y = getValueFromString(vert) * scale;
vert = findStringEnd(vert, "Z:"); vert = findStringEnd(vert, "Z:");
z = getValueFromString(vert) * scale; z = getValueFromString(vert) * scale;
vectorSet(target->vertices[i].position, x + offset[0], y + offset[1] , z + offset[2]); vectorSet(target->vertices[i].position, x + offset[0], y + offset[1],
z + offset[2]);
// recycle variables for texture coordinates // recycle variables for texture coordinates
vert = findStringEnd(vert, "U:"); vert = findStringEnd(vert, "U:");
x = getValueFromString(vert); x = getValueFromString(vert);
@ -265,7 +264,6 @@ Mesh* loadAscModel(char *filename, float scale, float* offset){
int vnum; int vnum;
face = findStringEnd(data, "Face list:"); face = findStringEnd(data, "Face list:");
for (i = 0; i < target->polygoncount; i++) { for (i = 0; i < target->polygoncount; i++) {
face = findStringEnd(face, "Face"); face = findStringEnd(face, "Face");
face = findStringEnd(face, "A:"); face = findStringEnd(face, "A:");
@ -273,21 +271,25 @@ Mesh* loadAscModel(char *filename, float scale, float* offset){
target->polygons[i].vertexcount = 3; target->polygons[i].vertexcount = 3;
target->polygons[i].vertices = new Vertex *[3]; target->polygons[i].vertices = new Vertex *[3];
target->polygons[i].vertices[0] = &(target->vertices[vnum]); 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]); target->vertices[vnum].texcoords[1]);
face = findStringEnd(face, "B:"); face = findStringEnd(face, "B:");
vnum = getValueFromString(face); vnum = getValueFromString(face);
target->polygons[i].vertices[1] = &(target->vertices[vnum]); 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]); target->vertices[vnum].texcoords[1]);
face = findStringEnd(face, "C:"); face = findStringEnd(face, "C:");
vnum = getValueFromString(face); vnum = getValueFromString(face);
target->polygons[i].vertices[2] = &(target->vertices[vnum]); 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]); target->vertices[vnum].texcoords[1]);
char *face2 = findStringEnd(face, "Nosmooth"); char *face2 = findStringEnd(face, "Nosmooth");
char *face3 = findStringEnd(face, "Smoothing"); char *face3 = findStringEnd(face, "Smoothing");
if (face2 > face && face2 < face3) target->polygons[i].realsmooth = true; if (face2 > face && face2 < face3)
target->polygons[i].realsmooth = true;
} }
free(data); free(data);
data = NULL; data = NULL;
@ -305,20 +307,48 @@ void drawTrophy(void){
int i = 0; int i = 0;
points[i].x = 0.0; points[i].y = 0.0; i++; points[i].x = 0.0;
points[i].x = width; points[i].y = 0.0; i++; points[i].y = 0.0;
points[i].x = width-2; points[i].y = 2.0; i++; i++;
points[i].x = width-2; points[i].y = 3.0; i++; points[i].x = width;
points[i].x = width-1; points[i].y = 4.0; i++; points[i].y = 0.0;
points[i].x = width-2; points[i].y = 5.0; i++; i++;
points[i].x = width-2; points[i].y = 6.0; i++; points[i].x = width - 2;
points[i].x = width-1; points[i].y = 8.0; i++; points[i].y = 2.0;
points[i].x = width; points[i].y = 9.0; i++; i++;
points[i].x = width+1; points[i].y = 11.0; i++; points[i].x = width - 2;
points[i].x = width+2; points[i].y = 15.0; i++; points[i].y = 3.0;
points[i].x = width+3; points[i].y = 21.0; i++; i++;
points[i].x = width+2; points[i].y = 21.0; i++; points[i].x = width - 1;
points[i].x = 0.0; points[i].y = 8.0; i++; 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); createLathedSurface(points, NULL, i, i * 5, i * 10);
} }

View file

@ -6,11 +6,9 @@
MeshObject *createPyramid(float width, float height); MeshObject *createPyramid(float width, float height);
MeshObject *createSpherePool(float width, float height); MeshObject *createSpherePool(float width, float height);
Mesh *createBox(float x1, float x2, float y1, float y2, float z1, float z2); Mesh *createBox(float x1, float x2, float y1, float y2, float z1, float z2);
Mesh *loadAscModel(char *filename, float scale, float *offset); Mesh *loadAscModel(char *filename, float scale, float *offset);
Mesh *loadAscModel(char *filename, float scale); Mesh *loadAscModel(char *filename, float scale);
void drawTrophy(void); void drawTrophy(void);
#endif #endif

View file

@ -10,7 +10,6 @@
#include "collision.h" #include "collision.h"
#include "glapi.h" #include "glapi.h"
Particle::Particle(World *world, Mesh *mesh) : MeshObject(mesh) { Particle::Particle(World *world, Mesh *mesh) : MeshObject(mesh) {
this->world = world; this->world = world;
} }
@ -62,7 +61,8 @@ void Particle::move(void){
lifetime++; lifetime++;
Object::move(); Object::move();
if (lifetime > 300) removeBlood(id); if (lifetime > 300)
removeBlood(id);
} }
void Particle::hitForce(float speed, Object *source) { void Particle::hitForce(float speed, Object *source) {
@ -82,14 +82,12 @@ void Particle::create(float *position, float *velocity){
world->addParticle(this); world->addParticle(this);
} }
void Particle::destroy(void){ void Particle::destroy(void) { world->removeParticle(this); }
world->removeParticle(this);
}
Particle **bloodparticles; Particle **bloodparticles;
BloodAppearance::BloodAppearance(int *lifetime) : BasicBlockAppearance(1, 1, 1){ BloodAppearance::BloodAppearance(int *lifetime)
: BasicBlockAppearance(1, 1, 1) {
this->lifetime = lifetime; this->lifetime = lifetime;
usematerial = false; usematerial = false;
} }
@ -101,7 +99,8 @@ void BloodAppearance::draw(void){
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
float alpha = 1 - *lifetime * 0.003; float alpha = 1 - *lifetime * 0.003;
if (alpha < 0) alpha = 0; 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));
@ -119,10 +118,12 @@ void initBloods(World *world){
bloodcount = 0; bloodcount = 0;
bloodparticles = new Particle *[MAXBLOOD]; bloodparticles = new Particle *[MAXBLOOD];
int i; int i;
Mesh *bloodmesh = createBox(-0.5, 0.5, -0.5*BLOCKHEIGHT, 0.5*BLOCKHEIGHT, -0.5, 0.5); Mesh *bloodmesh =
createBox(-0.5, 0.5, -0.5 * BLOCKHEIGHT, 0.5 * BLOCKHEIGHT, -0.5, 0.5);
for (i = 0; i < MAXBLOOD; i++) { for (i = 0; i < MAXBLOOD; i++) {
bloodparticles[i] = new Particle(world, bloodmesh); bloodparticles[i] = new Particle(world, bloodmesh);
bloodparticles[i]->appearance = new BloodAppearance(&(bloodparticles[i]->lifetime)); bloodparticles[i]->appearance =
new BloodAppearance(&(bloodparticles[i]->lifetime));
bloodparticles[i]->setMass(1); bloodparticles[i]->setMass(1);
bloodparticles[i]->prepare(); bloodparticles[i]->prepare();
// bloodparticles[i]->setGravity(true); // bloodparticles[i]->setGravity(true);

View file

@ -27,17 +27,12 @@ public:
void hitForce(float speed, Object *source); void hitForce(float speed, Object *source);
void create(float *position, float *velocity); void create(float *position, float *velocity);
void destroy(void); void destroy(void);
}; };
#define MAXBLOOD 500 #define MAXBLOOD 500
class BloodAppearance : public BasicBlockAppearance { class BloodAppearance : public BasicBlockAppearance {
private: private:
int *lifetime; int *lifetime;
@ -53,4 +48,3 @@ void createBlood(float *position, float *velocity);
void removeBlood(int id); void removeBlood(int id);
#endif #endif

View file

@ -25,7 +25,6 @@ void initScenes(void){
knobgllist = glGenLists(1); knobgllist = glGenLists(1);
setDetail(detail); setDetail(detail);
// Simple loading-screen // Simple loading-screen
enable2D(); enable2D();
@ -40,8 +39,6 @@ void initScenes(void){
disable2D(); disable2D();
SKYBOX = -1; SKYBOX = -1;
initTextures(); initTextures();
initFight(); initFight();
@ -74,7 +71,8 @@ void calculateFrame(int framecount){
} }
void drawFrame(int framecount) { 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);
@ -150,7 +148,6 @@ void initTextures(void){
skybottomtexture = new Texture(); skybottomtexture = new Texture();
skybottomtexture->loadImage(SKYBOTTOM); skybottomtexture->loadImage(SKYBOTTOM);
float something[3] = {1, 0, 0.5}; float something[3] = {1, 0, 0.5};
damageHead = new Texture(); damageHead = new Texture();
damageHead->loadImage(DAMAGEHEAD, something); damageHead->loadImage(DAMAGEHEAD, something);
@ -168,7 +165,6 @@ void initTextures(void){
flaretexture = new Texture(); flaretexture = new Texture();
flaretexture->loadImage(DATAPATH "flare.png", zeros); flaretexture->loadImage(DATAPATH "flare.png", zeros);
float pink[3] = {1, 0, 1}; float pink[3] = {1, 0, 1};
tuxtexture = new Texture(); tuxtexture = new Texture();
tuxtexture->loadImage(DATAPATH "tux.png", pink); tuxtexture->loadImage(DATAPATH "tux.png", pink);
@ -209,5 +205,3 @@ void setDetail(int detail){
} }
initKnob(); initKnob();
} }

View file

@ -13,4 +13,3 @@ void initTextures(void);
void setDetail(int detail); void setDetail(int detail);
#endif #endif

View file

@ -1,18 +1,8 @@
#include "shape.h" #include "shape.h"
Shape::Shape(Object *object){ Shape::Shape(Object *object) { this->object = object; }
this->object = object;
}
bool Shape::checkCollision(Object *target){ bool Shape::checkCollision(Object *target) { return false; }
return false; bool Shape::checkCollisionPeer(Shape *target) { return false; }
} bool Shape::checkCollisionPeer(SphereShape *target) { return false; }
bool Shape::checkCollisionPeer(Shape *target){ bool Shape::checkCollisionPeer(MeshShape *target) { return false; }
return false;
}
bool Shape::checkCollisionPeer(SphereShape *target){
return false;
}
bool Shape::checkCollisionPeer(MeshShape *target){
return false;
}

View file

@ -17,7 +17,6 @@ protected:
public: 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);
@ -28,4 +27,3 @@ public:
}; };
#endif #endif

View file

@ -10,7 +10,6 @@
#include "collision.h" #include "collision.h"
#include "glapi.h" #include "glapi.h"
Sphere::Sphere(void) { Sphere::Sphere(void) {
appearance = new SphereAppearance(); appearance = new SphereAppearance();
Object::appearance = appearance; Object::appearance = appearance;
@ -19,18 +18,18 @@ Sphere::Sphere(void){
} }
void Sphere::setRadius(float r) { void Sphere::setRadius(float r) {
if (r < 0) r = -r; if (r < 0)
r = -r;
this->r = r; this->r = r;
appearance->setRadius(r); appearance->setRadius(r);
geometry->setRadius(r); geometry->setRadius(r);
} }
SphereAppearance::SphereAppearance(void){ SphereAppearance::SphereAppearance(void) { setRadius(1); }
setRadius(1);
}
void SphereAppearance::setRadius(float r) { void SphereAppearance::setRadius(float r) {
if (r < 0) r = -r; if (r < 0)
r = -r;
this->r = r; this->r = r;
} }
@ -43,20 +42,11 @@ void SphereAppearance::draw(void){
createSphere(r); createSphere(r);
} }
SphereShape::SphereShape(Object *sphere) : Shape(sphere) { setRadius(1); }
void SphereShape::setRadius(float r) { this->r = r; }
float SphereShape::getRadius(void) { return r; }
SphereShape::SphereShape(Object *sphere) : Shape(sphere){
setRadius(1);
}
void SphereShape::setRadius(float r){
this->r = r;
}
float SphereShape::getRadius(void){
return r;
}
bool SphereShape::checkCollision(Object *target) { bool SphereShape::checkCollision(Object *target) {
return target->geometry->checkCollisionPeer(this); return target->geometry->checkCollisionPeer(this);
@ -122,7 +112,8 @@ bool SphereShape::checkCollisionPeer(SphereShape *target){
} }
bool between(float x, float x1, float x2) { bool between(float x, float x1, float x2) {
if ((x >= x1 && x <=x2) || (x >= x2 && x <=x1)) return true; if ((x >= x1 && x <= x2) || (x >= x2 && x <= x1))
return true;
return false; return false;
} }
@ -238,8 +229,6 @@ bool between(float x, float x1, float x2){
return false; return false;
}*/ }*/
bool SphereShape::checkCollisionPeer(MeshShape *target) { bool SphereShape::checkCollisionPeer(MeshShape *target) {
float position[3] = {0, 0, 0}; float position[3] = {0, 0, 0};
object->transformPoint(position, position); object->transformPoint(position, position);

View file

@ -5,7 +5,6 @@
#include "material.h" #include "material.h"
#include "mesh.h" #include "mesh.h"
class SphereAppearance; class SphereAppearance;
// Object for sphere // Object for sphere
@ -23,8 +22,6 @@ public:
void setColor(float red, float green, float blue); void setColor(float red, float green, float blue);
}; };
// Appearance of sphere // Appearance of sphere
class SphereAppearance : public Appearance { class SphereAppearance : public Appearance {
@ -38,8 +35,6 @@ public:
void draw(void); void draw(void);
}; };
// Geometry of sphere // Geometry of sphere
class SphereShape : public Shape { class SphereShape : public Shape {
@ -64,4 +59,3 @@ public:
}; };
#endif #endif

View file

@ -18,8 +18,7 @@ Texture::Texture(int id){
if (id > -1) { if (id > -1) {
this->textureId = id; this->textureId = id;
this->enabled = false; this->enabled = false;
} } else {
else{
this->textureId = -1; this->textureId = -1;
this->enabled = false; this->enabled = false;
} }
@ -43,10 +42,9 @@ bool Texture::loadImage(char* path, float *trans){
texture = IMG_Load(path); texture = IMG_Load(path);
Uint32 colorKey = SDL_MapRGB(texture->format, Uint32 colorKey =
(Uint8)(trans[0] * 255), SDL_MapRGB(texture->format, (Uint8)(trans[0] * 255),
(Uint8)(trans[1] * 255), (Uint8)(trans[1] * 255), (Uint8)(trans[2] * 255));
(Uint8)(trans[2] * 255));
// SDL_SetAlpha(texture, 0, SDL_ALPHA_OPAQUE); // SDL_SetAlpha(texture, 0, SDL_ALPHA_OPAQUE);
SDL_SetColorKey(texture, SDL_SRCCOLORKEY, colorKey); SDL_SetColorKey(texture, SDL_SRCCOLORKEY, colorKey);
@ -77,13 +75,9 @@ void Texture::enable(void){
} }
} }
bool Texture::isEnabled(void){ bool Texture::isEnabled(void) { return this->enabled; }
return this->enabled;
}
int Texture::getId(void){ int Texture::getId(void) { return this->textureId; }
return this->textureId;
}
void Texture::setId(int id) { void Texture::setId(int id) {
if (id > -1) { if (id > -1) {
@ -92,6 +86,4 @@ void Texture::setId(int id){
} }
} }
bool Texture::isValidId(void){ bool Texture::isValidId(void) { return (this->textureId > -1); }
return (this->textureId > -1);
}

View file

@ -6,7 +6,6 @@
class Texture { class Texture {
public: public:
Texture(void); Texture(void);
Texture(int id); Texture(int id);
~Texture(void); ~Texture(void);
@ -25,7 +24,6 @@ public:
// int* getModifiableOGLTexture(void); // int* getModifiableOGLTexture(void);
private: private:
int textureId; int textureId;
// int* modTexture; // int* modTexture;
bool enabled; bool enabled;
@ -35,4 +33,3 @@ private:
}; };
#endif #endif

View file

@ -12,28 +12,26 @@ void swapFloat(float *a, float *b){
*b = temp; *b = temp;
} }
int random(int x){ int random(int x) { return rand() * x / RAND_MAX; }
return rand() * x / RAND_MAX;
}
float randomf(float x){ float randomf(float x) { return rand() * x / RAND_MAX; }
return rand() * x / RAND_MAX;
}
int smod(int val, int mod) { int smod(int val, int mod) {
if (val>=0) return val%mod; if (val >= 0)
return val % mod;
int temp = -val / mod + 1; int temp = -val / mod + 1;
return (val + temp * mod) % mod; return (val + temp * mod) % mod;
} }
double sdes(double val) { double sdes(double val) {
if (val>=0) return val-(int)(val); if (val >= 0)
return val - (int)(val);
return val - (int)(val) + 1; return val - (int)(val) + 1;
} }
double sfmod(double val, double mod) { double sfmod(double val, double mod) {
val -= (int)(val / mod) * mod; val -= (int)(val / mod) * mod;
if (val<0) val+=mod; if (val < 0)
val += mod;
return val; return val;
} }

View file

@ -1,7 +1,6 @@
#ifndef __UTILS_H_INCLUDED__ #ifndef __UTILS_H_INCLUDED__
#define __UTILS_H_INCLUDED__ #define __UTILS_H_INCLUDED__
#define PI 3.14159265358979323846 #define PI 3.14159265358979323846
void swapInt(int *a, int *b); void swapInt(int *a, int *b);
@ -13,4 +12,3 @@ double sdes(double val);
double sfmod(double val, double mod); double sfmod(double val, double mod);
#endif #endif

View file

@ -65,16 +65,16 @@ void vectorScale(float *target, float scale){
} }
float vectorDot(float *source1, float *source2) { 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) { 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){ float vectorLength(float *source) { return sqrtf(vectorDot(source, source)); }
return sqrtf(vectorDot(source, source));
}
void vectorCross(float *target, float *source1, float *source2) { void vectorCross(float *target, float *source1, float *source2) {
target[0] = source1[1] * source2[2] - source1[2] * source2[1]; target[0] = source1[1] * source2[2] - source1[2] * source2[1];
@ -97,13 +97,16 @@ void vectorReflect(float *target, float *source, float *normal){
} }
void vectorProject(float *target, float *source1, float *source2) { 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) { bool vectorIsZero(float *vector) {
if (vector[0] == 0 && vector[1] == 0 && vector[2] == 0) return true; if (vector[0] == 0 && vector[1] == 0 && vector[2] == 0)
return true;
// if (vectorDot(vector, vector) < 0.00001) return true; // if (vectorDot(vector, vector) < 0.00001) return true;
else return false; else
return false;
} }
void vectorSaturate(float *target, float *source, float min, float max) { void vectorSaturate(float *target, float *source, float min, float max) {
@ -113,7 +116,8 @@ void vectorSaturate(float *target, float *source, float min, float max){
} else if (len > max) { } else if (len > max) {
len = max; len = max;
} else { } else {
if (target != source) vectorCopy(target, source); if (target != source)
vectorCopy(target, source);
return; return;
} }
vectorNormalize(target, source); vectorNormalize(target, source);
@ -132,18 +136,13 @@ void vectorMatrixMultiply(float *target, float *source, float *matrix){
} }
int x; int x;
for (x = 0; x < 3; x++) { for (x = 0; x < 3; x++) {
target[x] = source[0]*matrix[0+x] + target[x] = source[0] * matrix[0 + x] + source[1] * matrix[3 + x] +
source[1]*matrix[3+x] +
source[2] * matrix[6 + 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) {
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[0] = x1;
matrix[1] = y1; matrix[1] = y1;
matrix[2] = z1; matrix[2] = z1;
@ -246,20 +245,23 @@ void matrixCreateRotation(float *matrix, float *vector){
float y = n[1]; float y = n[1];
float z = n[2]; float z = n[2];
matrixSet(matrix, matrixSet(matrix, t * x * x + c, t * y * x + s * z, t * z * x - s * y,
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 * 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); t * x * z + s * y, t * y * z - s * x, t * z * z + c);
} }
void matrixTranspose(float *target, float *source) { void matrixTranspose(float *target, float *source) {
target[0] = source[0]; target[1] = source[3]; target[2] = source[6]; target[0] = source[0];
target[3] = source[1]; target[4] = source[4]; target[5] = source[7]; target[1] = source[3];
target[6] = source[2]; target[7] = source[5]; target[8] = source[8]; 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){ /*void rotatePointAroundVector(float *target, float *point, float *vector){
float angle = vectorLength(vector); float angle = vectorLength(vector);
float n[3]; float n[3];
@ -271,4 +273,3 @@ void matrixTranspose(float *target, float *source){
//r' = r*c + n*(n . r)*t + (r x n)*s //r' = r*c + n*(n . r)*t + (r x n)*s
}*/ }*/

View file

@ -29,12 +29,8 @@ void vectorProject(float *target, float *source1, float *source2);
void vectorMatrixMultiply(float *target, float *source, float *matrix); 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);
void matrixSet(float *matrix,
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 matrixSet(float *matrix, float *r1, float *r2, float *r3);
void matrixCopy(float *target, float *source); void matrixCopy(float *target, float *source);
void matrixIdentity(float *matrix); void matrixIdentity(float *matrix);
@ -47,4 +43,3 @@ void matrixCreateRotation(float *matrix, float *vector);
void matrixTranspose(float *target, float *source); void matrixTranspose(float *target, float *source);
#endif #endif

View file

@ -41,7 +41,6 @@ void World::prepare(void){
void World::move(void) { void World::move(void) {
int i, j; int i, j;
// Gravity // Gravity
float gravity[3]; float gravity[3];
vectorSet(gravity, 0, 0, 0); vectorSet(gravity, 0, 0, 0);
@ -61,7 +60,6 @@ void World::move(void){
} }
}*/ }*/
// Collisions // Collisions
contactcount = 0; contactcount = 0;
@ -93,7 +91,6 @@ void World::move(void){
// printf("Contacts: %i\n", contactcount); // printf("Contacts: %i\n", contactcount);
bool contactresponse; bool contactresponse;
j = 0; j = 0;
@ -104,14 +101,16 @@ void World::move(void){
objectlinklist *node = linklist; objectlinklist *node = linklist;
while (node != NULL) { while (node != NULL) {
ObjectLink *link = node->link; ObjectLink *link = node->link;
if (handleLink(link)) contactresponse = true; if (handleLink(link))
contactresponse = true;
node = node->next; node = node->next;
} }
// Collision contact // Collision contact
for (i = 0; i < contactcount; i++) { for (i = 0; i < contactcount; i++) {
Contact *contact = &contacts[i]; Contact *contact = &contacts[i];
if (handleCollision(contact)) contactresponse = true; if (handleCollision(contact))
contactresponse = true;
} }
j++; j++;
@ -145,7 +144,6 @@ void World::move(void){
j++; j++;
} while (contactresponse && j < 3);*/ } while (contactresponse && j < 3);*/
for (i = 0; i < childcount; i++) { for (i = 0; i < childcount; i++) {
childs[i]->move(); childs[i]->move();
} }
@ -156,8 +154,10 @@ void World::move(void){
void World::draw(void) { void World::draw(void) {
int i; int i;
for (i = 0; i < childcount; i++) childs[i]->draw(); for (i = 0; i < childcount; i++)
for (i = 0; i < particlecount; i++) particles[i]->draw(); childs[i]->draw();
for (i = 0; i < particlecount; i++)
particles[i]->draw();
} }
void World::addChild(Object *child) { void World::addChild(Object *child) {
@ -207,5 +207,3 @@ void World::renewLink(ObjectLink *link, float *point){
link->object2->unTransformPoint(link->point2, point); link->object2->unTransformPoint(link->point2, point);
link->enabled = true; link->enabled = true;
} }

View file

@ -28,13 +28,12 @@ private:
int childcount; int childcount;
Object **childs; Object **childs;
int particlecount; int particlecount;
int maxparticles; int maxparticles;
Particle **particles; Particle **particles;
objectlinklist *linklist; objectlinklist *linklist;
public: public:
World(void); World(void);
@ -53,4 +52,3 @@ public:
}; };
#endif #endif