PDA

View Full Version : Collision detection.... please help



Music_Man
11-27-2002, 12:31 PM
I am trying to create a 3 maze, which you can walk around, and I have no idea how to use collision detection when it comes to the individual walls. I have one method for a wall, and I am constantly calling it and rotating it as necessary for all the interior walls. The walls are simple polygons written using GL_QUADS..... any help would be much appreciated.

Many thanks in advance

Music_Man http://www.opengl.org/discussion_boards/ubb/confused.gif

nexusone
11-27-2002, 12:44 PM
You can do map, break it down into cells.

X = wall
* = open area

012345678
1XXXXXXXX
2X******X
3XXXXXX*X
4X*XXXX*X
5X*XX***X
6X*XX*XXX
7X******X
8XXXXXXXX


int map[8][8]; // 8x8 map

example:


if( map[x_new][y_new] == '*')
{
x_player = x_new;
y_player = y_new;
}else
{
x_player = x_old;
y_player = y_old;
}

Hope this gives you an idea, let me know if you need more detail.


Originally posted by Music_Man:
I am trying to create a 3 maze, which you can walk around, and I have no idea how to use collision detection when it comes to the individual walls. I have one method for a wall, and I am constantly calling it and rotating it as necessary for all the interior walls. The walls are simple polygons written using GL_QUADS..... any help would be much appreciated.

Many thanks in advance

Music_Man http://www.opengl.org/discussion_boards/ubb/confused.gif

Music_Man
11-27-2002, 01:09 PM
Thanks for your reply, but unfortunately, I dont think it will work. My maze is 1000x1000, and with the walls being simple polygons, their thickness is 1, so I would need an array 1000 by 1000....

Sorry to be a pain, but any other ideas?

Much appreciated

Music_Man http://www.opengl.org/discussion_boards/ubb/confused.gif

nexusone
11-27-2002, 01:24 PM
Still the same why, each cell could have a width of 10. Which would give you 100 x 100 array.


The best way is to have a map, you need to know anyway where to draw the walls. That same data is your map.

I dont have time go into detail, but you could have only wall position in data arrays. which if you had only a limited amount of walls to do would work else the map idea it just as good.

Every time you move check the array for the object getting close to a wall. Just a simple vector distance check to see how close you are to a wall.

http://www.opengl.org/discussion_boards/ubb/smile.gif


Originally posted by Music_Man:
Thanks for your reply, but unfortunately, I dont think it will work. My maze is 1000x1000, and with the walls being simple polygons, their thickness is 1, so I would need an array 1000 by 1000....

Sorry to be a pain, but any other ideas?

Much appreciated

Music_Man http://www.opengl.org/discussion_boards/ubb/confused.gif

31337
11-27-2002, 01:42 PM
Does the maze go up and down or is it flat? Do two rectangles ever have the same x and z position? If not here's what I would suggest:

Load the maze in through a file type you come up with. Then draw the map from memory. Then hit testing would be simple. Is this how you already do it?

Music_Man
11-27-2002, 05:27 PM
How I do it at the moment, is just call the draw method repeatedly to draw each wall.... no matricies of anything of the such.... sorry if this makes no sense.... just got in... its 2:26am, and I am drunk.....

Thanks for any help....

Music_Man http://www.opengl.org/discussion_boards/ubb/confused.gif

Jambolo
11-28-2002, 06:38 PM
The simplest way to do it is to check the distance to each wall. If it is less than a certain value, you have collided. To speed it up, you can put the walls into groups and only check the walls in the groups that you are close to. Three ways to group the walls - BSP trees, octrees/quadtrees, cells.