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
* 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;
point2d *h1, *h2;
point2d *derivates;
if (pointderivates == NULL) derivates = new point2d[count];
else derivates = pointderivates;
//Derivaatta pisteessä i on (points[i+1]-points[i-1])/2 alkua ja loppua lukuunottamatta
if (pointderivates == NULL)
derivates = new point2d[count];
else
derivates = pointderivates;
// Derivaatta pisteessä i on (points[i+1]-points[i-1])/2 alkua ja loppua
// lukuunottamatta
for (i = 0; i < count; i++) {
if (pointderivates == NULL || (derivates[i].x == 0 && derivates[i].y == 0)){
if (i == 0) h1 = &points[0];
else h1 = &points[i-1];
if (i == count-1) h2 = &points[count-1];
else h2 = &points[i+1];
if (pointderivates == NULL ||
(derivates[i].x == 0 && derivates[i].y == 0)) {
if (i == 0)
h1 = &points[0];
else
h1 = &points[i - 1];
if (i == count - 1)
h2 = &points[count - 1];
else
h2 = &points[i + 1];
float dx, dy;
dx = (h2->x - h1->x);
dy = (h2->y - h1->y);
@ -69,7 +78,8 @@ void createLathedSurface(point2d *points, point2d *pointderivates, int count, in
t = sif - si;
i1 = si;
i2 = si + 1;
if (i2 >= count) i2 = count-1;
if (i2 >= count)
i2 = count - 1;
p1 = &points[i1];
p2 = &points[i2];
d1 = &derivates[i1];
@ -152,13 +162,11 @@ void createSphere(float r, int slices, int stacks){
#define DEFAULTSLICES 20
#define DEFAULTSTACKS 10
void createSphere(float r){
createSphere(r, DEFAULTSLICES, DEFAULTSTACKS);
}
void createSphere(float r) { createSphere(r, DEFAULTSLICES, DEFAULTSTACKS); }
bool solvePointInTriangle(float *position, float *normal,
Vertex *v1, Vertex *v2, Vertex *v3,
float *t, float *u, float *v){
bool solvePointInTriangle(float *position, float *normal, Vertex *v1,
Vertex *v2, Vertex *v3, float *t, float *u,
float *v) {
float edge1[3], edge2[3], tvec[3], pvec[3], qvec[3];
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
det = vectorDot(edge1, pvec);
if (det > -EPSILON && det < EPSILON) return false;
if (det > -EPSILON && det < EPSILON)
return false;
inv_det = 1.0 / det;
// calculate distance from vert0 to ray origin
@ -180,14 +189,16 @@ bool solvePointInTriangle(float *position, float *normal,
// calculate U parameter and test bounds
*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
vectorCross(qvec, tvec, edge1);
// calculate V parameter and test bounds
*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
*t = vectorDot(edge2, qvec) * inv_det;
@ -195,14 +206,11 @@ bool solvePointInTriangle(float *position, float *normal,
return true;
}
float distanceFromPlane(float point[3], float normal[3], float 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);
glClear(GL_DEPTH_BUFFER_BIT);
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) {
glCallList(SKYBOX);
}
else{
} else {
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);
// glBindTexture(GL_TEXTURE_2D, SKY_BACK_ID);
skybacktexture->enable();
glBegin(GL_QUADS);
glColor4f(1, 1, 1, 1.0);
glTexCoord2f(1-d, 1-d); glVertex3f(x + w, y, z);
glTexCoord2f(1-d, 0+d); 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);
glTexCoord2f(1 - d, 1 - d);
glVertex3f(x + w, y, z);
glTexCoord2f(1 - d, 0 + d);
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();
// glBindTexture(GL_TEXTURE_2D, SKY_FRONT_ID);
skyfronttexture->enable();
glBegin(GL_QUADS);
glColor4f(1, 1, 1, 1.0);
glTexCoord2f(1-d, 1-d); glVertex3f(x, y, z + l);
glTexCoord2f(1-d, 0+d); 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);
glTexCoord2f(1 - d, 1 - d);
glVertex3f(x, y, z + l);
glTexCoord2f(1 - d, 0 + d);
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();
// glBindTexture(GL_TEXTURE_2D, SKY_TOP_ID);
skytoptexture->enable();
glBegin(GL_QUADS);
glColor4f(1, 1, 1, 1.0);
glTexCoord2f(0+d, 0+d); glVertex3f(x + w, y + h, z + l);
glTexCoord2f(1-d, 0+d); 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(0 + d, 0 + d);
glVertex3f(x + w, y + h, z + l);
glTexCoord2f(1 - d, 0 + d);
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, 1.0f); glVertex3f(x + w, 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);*/
glEnd();
// glBindTexture(GL_TEXTURE_2D, SKY_BOTTOM_ID);
skybottomtexture->enable();
glBegin(GL_QUADS);
glColor4f(1, 1, 1, 1.0);
glTexCoord2f(1-d, 0+d); glVertex3f(x, y, z);
glTexCoord2f(1-d, 1-d); 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);
glTexCoord2f(1 - d, 0 + d);
glVertex3f(x, y, z);
glTexCoord2f(1 - d, 1 - d);
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();
// glBindTexture(GL_TEXTURE_2D, SKY_LEFT_ID);
skylefttexture->enable();
glBegin(GL_QUADS);
glColor4f(1, 1, 1, 1.0);
glTexCoord2f(1-d, 0+d); glVertex3f(x, y + h, z);
glTexCoord2f(0+d, 0+d); 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);
glTexCoord2f(1 - d, 0 + d);
glVertex3f(x, y + h, z);
glTexCoord2f(0 + d, 0 + d);
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();
@ -318,11 +332,14 @@ void createSkyBox(float x, float y, float z, float w, float h, float l)
glBegin(GL_QUADS);
glColor4f(1, 1, 1, 1.0);
glTexCoord2f(0+d, 1-d); glVertex3f(x + w, y, z);
glTexCoord2f(1-d, 1-d); 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);
glTexCoord2f(0 + d, 1 - d);
glVertex3f(x + w, y, z);
glTexCoord2f(1 - d, 1 - d);
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();
glEndList();

View file

@ -4,8 +4,6 @@
#include "main.h"
#include "texture.h"
#define SKYFRONT DATAPATH "tback.png"
#define SKYBACK DATAPATH "tfront.png"
#define SKYLEFT DATAPATH "tleft.png"
@ -13,7 +11,6 @@
#define SKYTOP DATAPATH "ttop.png"
#define SKYBOTTOM DATAPATH "tbottom.png"
#define DAMAGEHEAD DATAPATH "damagehead.png"
#define DAMAGETORSO DATAPATH "damagetorso.png"
#define DAMAGEHAND DATAPATH "damagehand.png"
@ -22,13 +19,9 @@
extern int SKYBOX;
typedef struct{
float x,y;
} point2d;
typedef struct { float x, y; } point2d;
typedef struct{
float x,y,z;
} point3d;
typedef struct { float x, y, z; } point3d;
extern Texture *flaretexture;
extern Texture *skyfronttexture;
@ -40,7 +33,8 @@ extern Texture *skybottomtexture;
extern Texture *damageHead;
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);
@ -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);
// MUST be called in pairs, enable pushes and disable pops
void enable2D(void);
void disable2D(void);
#endif

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -31,17 +31,18 @@ public:
extern Contact *contacts;
extern int contactcount;
// Contact point is world-relative and must be transformed
// into coordinate system of both objects
void addCollision(Object *source, Object *target,
float *normal, float *contactpoint);
void addCollision(Object *source, Object *target, float *normal,
float *contactpoint);
bool handleCollision(Contact *contact);
bool handleLink(ObjectLink *link);
bool checkSphereMeshCollision(float *sphereposition, float r, 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);
bool checkSphereMeshCollision(float *sphereposition, float r, 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

View file

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

View file

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

View file

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

View file

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

View file

@ -35,23 +35,26 @@ void drawChar(float x, float y, char ch, float size){
}
float letterwidth[256] = {
1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
0.5, 0.2, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.45, 0.2, 0.5,
0.6, 0.5, 0.6, 0.6, 0.65, 0.65, 0.6, 0.65, 0.6, 0.6, 0.2, 1.0, 1.0, 1.0, 1.0, 0.5,
1.0, 0.7, 0.6, 0.7, 0.7, 0.65, 0.6, 0.7, 0.8, 0.6, 0.7, 0.7, 0.6, 0.9, 0.85, 0.8,
0.6, 0.9, 0.7, 0.7, 0.7, 0.7, 0.7, 1.0, 0.8, 0.7, 0.8, 1.0, 1.0, 1.0, 1.0, 1.0,
1.0, 0.6, 0.6, 0.6, 0.6, 0.6, 0.5, 0.6, 0.6, 0.2, 0.4, 0.6, 0.2, 0.8, 0.5, 0.55,
0.55, 0.55, 0.5, 0.55, 0.55, 0.55, 0.6, 0.8, 0.6, 0.6, 0.6, 1.0, 1.0, 1.0, 1.0, 1.0,
1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0
};
1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.5, 0.2, 1.0, 1.0, 1.0, 1.0, 1.0,
1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.45, 0.2, 0.5, 0.6, 0.5, 0.6, 0.6,
0.65, 0.65, 0.6, 0.65, 0.6, 0.6, 0.2, 1.0, 1.0, 1.0, 1.0, 0.5, 1.0,
0.7, 0.6, 0.7, 0.7, 0.65, 0.6, 0.7, 0.8, 0.6, 0.7, 0.7, 0.6, 0.9,
0.85, 0.8, 0.6, 0.9, 0.7, 0.7, 0.7, 0.7, 0.7, 1.0, 0.8, 0.7, 0.8,
1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.6, 0.6, 0.6, 0.6, 0.6, 0.5, 0.6,
0.6, 0.2, 0.4, 0.6, 0.2, 0.8, 0.5, 0.55, 0.55, 0.55, 0.5, 0.55, 0.55,
0.55, 0.6, 0.8, 0.6, 0.6, 0.6, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0};
void print(float x, float y, char *text, float size) {
int i;
@ -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);
#endif

View file

@ -20,7 +20,8 @@ void setupOpengl(int width, int height){
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);
glDisable(GL_LIGHT0);
@ -45,8 +46,6 @@ void setupOpengl(int width, int height){
glMaterialfv(GL_BACK, GL_DIFFUSE, zero);
glMaterialfv(GL_BACK, GL_SPECULAR, zero);
glViewport(0, 0, width, height);
glDepthFunc(GL_LEQUAL);
@ -59,6 +58,5 @@ void setupOpengl(int width, int height){
gluPerspective(60.0, ratio, 1.0, 1024.0);
// glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
}

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,10 +1,11 @@
#ifndef __MAIN_H_INCLUDED__
#define __MAIN_H_INCLUDED__
#ifdef WIN32
#pragma warning(disable:4244) //Disable: conversion from 'double' to 'double', possible loss of data
#pragma warning(disable:4305) //Disable: truncation from 'const double' to 'double'
#pragma warning(disable : 4244) // Disable: conversion from 'double' to
// 'double', possible loss of data
#pragma warning( \
disable : 4305) // Disable: truncation from 'const double' to 'double'
#endif
#include <SDL.h>
@ -18,10 +19,10 @@ extern int screenwidth, screenheight;
extern int debugcounter;
#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
#define DP
#endif
#endif

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -6,11 +6,9 @@
MeshObject *createPyramid(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 *loadAscModel(char *filename, float scale, float *offset);
Mesh *loadAscModel(char *filename, float scale);
void drawTrophy(void);
#endif

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -17,7 +17,6 @@ protected:
public:
Shape(Object *object);
virtual float calculateMomentOfInertia(float *rotationvector) = 0;
virtual bool checkCollision(Object *target);
@ -28,4 +27,3 @@ public:
};
#endif

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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