Results 1 to 6 of 6

Thread: Yes, Collision detection, but with a twist ;p

  1. #1
    Junior Member Newbie
    Join Date
    Dec 2008
    Posts
    23

    Yes, Collision detection, but with a twist ;p

    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:

    Code :
    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

    However, I have now become utterly confused in how to implement collision detection. I've checked out <http://eternallyconfuzzled.com/tuts/...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.

    Code :
    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..

    Code :
    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
    Code :
    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.

  2. #2
    Senior Member Frequent Contributor _NK47's Avatar
    Join Date
    Mar 2008
    Posts
    574

    Re: Yes, Collision detection, but with a twist ;p

    "So, to get down to the point. How do I implement collision detection?!"
    what has collision detection to do with OpenGL? wrong forum .

  3. #3
    Senior Member Regular Contributor
    Join Date
    Feb 2002
    Posts
    374

    Re: Yes, Collision detection, but with a twist ;p

    Quote Originally Posted by _NK47
    what has collision detection to do with OpenGL?
    That's the twist I suppose.

  4. #4
    Junior Member Newbie
    Join Date
    Dec 2008
    Posts
    23

    Re: Yes, Collision detection, but with a twist ;p

    Yhea, I though I'd be a laught

  5. #5
    Member Newbie
    Join Date
    Dec 2008
    Posts
    41

    Re: Yes, Collision detection, but with a twist ;p

    humm.. maybe he wants to make a GLSL based collision detection algorithm? :P

  6. #6
    Senior Member Frequent Contributor _NK47's Avatar
    Join Date
    Mar 2008
    Posts
    574

    Re: Yes, Collision detection, but with a twist ;p

    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.

Similar Threads

  1. BSP and collision detection
    By Michael Mei in forum OpenGL: General
    Replies: 0
    Last Post: 09-16-2005, 05:41 AM
  2. Collision detection.... please help
    By Music_Man in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 11-28-2002, 06:38 PM
  3. Collision detection
    By in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 03-19-2001, 07:14 AM
  4. collision detection
    By imported_robert in forum OpenGL: Basic Coding
    Replies: 13
    Last Post: 02-17-2001, 03:09 AM
  5. collision detection contest: collision crazy
    By in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 09-19-2000, 02:33 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean