openGL Collision detection

I understand that openGL is an API and also a set of functions for creating primarily primitives on a screen. As an API, I understand it does not natively support what modeling and game graphics engines would.

However, I still desire to understand through underlying math the simplicity of collision detection. I have read through the Swiftless, NeHe, and plenty of other online tutorials but none of them put it together for a 3D app in simplicity. NeHe uses some overbloated and complicated mess of garbage to demonstrate collision and others use oversimplified 2-D mechanics or don’t cover 3d dungeon crawling.

I am looking for a cut and dry approach to collision in a 3d environment that does not require me to write 500+ lines of code for it. I have a dungeon, call it that or a maze, generated from a file with nice high walls, wide corridors, pastel colors and the ability to walk through every wall and cheat my way to treasure hidden inside (teapot ftw).

I have thought of many ways to do this in addition to studying the tutorials but I am just stumped. My professor thought it was cool to cover not an ounce of collision but make me do it. I just want a true plain jane simple with code understanding of one way, a method, to do it and use it until I wanna learn another method.

Please help.

i. Divide your level into a quad tree so that objects far from the player are not concidered.

  1. Check distance from player to polygon’s centeroid to see if collision is feasable.
  2. do bounding cube or bounding sphere check.
  3. Do in depth poly-to-poly check.

I am looking for a cut and dry approach to collision in a 3d environment that does not require me to write 500+ lines of code for it.

If you’re not looking to write actual code (being more than 500+ lines), then you’re not going to get very far in making a “3d dungeon crawling” game.

Both Bullet Physics and ODE are reasonably adequate solutions for doing 3D collision detection. But even that is going to take code to integrate with the rest of your system. Probably more than 500+ lines of it.

If you’re looking for the short path for making a game, buy an Unreal game and use its engine to make what you’re looking for. It’ll save you a lot of time and hassle.

Try downloading the quake3 source code. This will give you a bit of an idea what you’re in for. You can generate levels with their tools and then read in the file and use their BSP tree to do your world collision. You might actually get away with 500 lines of code, but it will be utiliting their 100k lines of code to get there!!

2D might be oversimplifying abit but shouldn’t the logic be same?

something like…

#ifdef COLLISION
float tmp_dx, tmp_dy;
for(int k=0; k<BNUM-1; k++){
for (int l=k+1; l<BNUM; l++){
if((ball[k].x+BSIZE > ball[l].x-BSIZE && ball[k].x-BSIZE < ball[l].x+BSIZE)&&
(ball[k].y+BSIZE > ball[l].x-BSIZE && ball[k].y-BSIZE < ball[l].y+BSIZE)){
if(ball[k].x - ball[l].x > ball[k].y - ball[l].y){
if(ball[l].x > ball[k].x){
ball[l].x=ball[k].x+2BSIZE;
}else{
ball[l].x=ball[k].x-2
BSIZE;
}
tmp_dx=ball[l].dx;
ball[l].dx=ball[k].dxPERCENT_AFTER_BOUNCE;
ball[k].dx=tmp_dx
PERCENT_AFTER_BOUNCE;
}else{
if(ball[l].y > ball[k].y){
ball[l].y=ball[k].y+2BSIZE;
}else{
ball[l].y=ball[k].y-2
BSIZE;
}
tmp_dy=ball[l].dy;
ball[l].dy=ball[k].dyPERCENT_AFTER_BOUNCE;
ball[k].dy=tmp_dy
PERCENT_AFTER_BOUNCE;
}
num_bounce++;
ball[k].collided=1;
ball[l].collided=1;
break;
}
}
}
#endif

except even for 2D, it doesn’t work for half the screen (I have yet to figure it out)

I have a strange case where the top left half of triangle has correctly functioning collision region and not the bottom right triangle half. :frowning: beats me