PDA

View Full Version : Yes, Collision detection, but with a twist ;p



Spock
01-16-2009, 09:45 AM
Hello forum!

I have been trying to get collision detection working, but atm I cant even structure a full algorithm!

This is very basic type of detection, 2D world, with even 1 bounding box ( well, Ill expand this when I have time, and understanding!). The game is tile based, but Im using BSP trees for collision detection.

Now heres the real twist.

In order to cut down on algorithms and time, for each level, the drawing space is redefined as 0 - mapWidth, 0 - mapHeight, though one can only view a 20x20 region, and scale down to make sure tile sizes remain as I want them to :).

Heres the basic code, that I think should do the job of creating the corret drawing space:



void globNewDimesion( float globfMaxX, float globfMaxY )
{
/* set up graphix mode to correlate to map... */
glMatrixMode( GL_PROJECTION );
glPushMatrix();

glLoadIdentity();
glOrtho( 0.0f, 0.0f, globfMaxX, globfMaxY, -1.0f, 1.0f );

glMatrixMode( GL_MODELVIEW );
glPushMatrix();

glScalef( 0.2f, 0.2f, 1.0f );
}


And the camera is kept on the player with a simple glTranslatef.

This means that tile map co-ords should directly correspond to player position, and images dont have constraints :D

However, I have now become utterly confused in how to implement collision detection. I've checked out <http://eternallyconfuzzled.com/tuts/datastructures/jsw_tut_bst1.aspx>, a very nice tutorial on bsp trees in general..

So, to get down to the point. How do I implement collision detection?!

I honestly dont even know where to start :'(

Thank you...

EDIT:

Also, heres info about how objects and what not are defined in my game.



struct
{
int number;
GLsizei globuiWidth;
GLsizei globuiHeight;
} globWindow;

typedef struct {
int destructable;
GLuint textureID[2];
} Tile;

typedef struct {
unsigned int lifeTime;
int actionID; /* What does this powerup do? */
int actionValue; /* And by how much does it do it? */
GLuint textureID;
} Powerup;

typedef struct {
int weaponType;
int bulletID;
int soundID;
unsigned int ammo;
float range;
char* name;
GLuint textureID[2];
} Weapon;

typedef struct {
unsigned int damage;
float range;
GLuint textureID;
} Bullet;

typedef struct {
float boundsX[2];
float boundsY[2];
unsigned int botSFX[2];
char botTaunt[9][40]; /* Path to 8 taunt recordings */
GLuint textureID[9];
} Bot; //Player is the `special' bot 0.


and for the bsp tree..



struct Object /* Will be used to encompass and keep track of _ALL_*/
{ /* moving object */
GLfloat objPos[ 2 ]; //X and Y
GLfloat objSize[ 2 ]; //Width and height
GLfloat boundsLeft[ 2 ]; //bottom
GLfloat boundsRight[ 2 ]; //top

struct Object *link[ 2 ];
};

struct ObjectTree
{
struct Object *root;
};


Oh, and I have this to keep info about all the bots / player


typedef struct /* Bot instance info... */
{
struct Object objectID; //to relate to globObject.
unsigned int botID;
int state; //Dead/alive/walking?? etc, ref to textureID
int skill;
int health;
float mapPos[ 2 ]; //mapPosX and pamPosY
int weapons[ 11 ]; // Players and bots can only carry 10
unsigned int ammo[ 11 ]; //Ammo count per gun
int currentGun;
} AIObject;


globBots is simply to keep track of the different types of ai, and the player (bot[ 0 ]), AIObject is the ionstances of globBots that run ingame, respawn if killed to keep resorce usage down. The Object structure is meant to hold collision information for bots, player, powerups and bullets.

_NK47
01-16-2009, 10:28 AM
"So, to get down to the point. How do I implement collision detection?!"
what has collision detection to do with OpenGL? wrong forum (http://en.wikipedia.org/wiki/Collision_detection) .

satan
01-17-2009, 06:30 AM
what has collision detection to do with OpenGL?
That's the twist I suppose.

Spock
01-18-2009, 07:26 PM
Yhea, I though I'd be a laught :D

cherryyosh
01-19-2009, 02:55 AM
humm.. maybe he wants to make a GLSL based collision detection algorithm? :P

_NK47
01-19-2009, 02:59 AM
good luck then. :)
under the link <wrong forum> i posted above you can find some physics libs for collision detection in the end of the page. i would not try to reinvent the wheel because those libs have already what it takes for propper collision detection and/or physics simulation.