2
votes

I done a quick search for collision detection for OpenGl however most things come back with 2D examples using CGRectIntersectsRect. Do I use CGRectIntersectsRect for 3D detection to? I am making a basic 3D maze game and I just want to stop people walking through the walls which are just Squares (made from triangles) as opposed to imported objects (yep, I am new to this).

Thanks, Simon

3
Update: I actually wrote my own simple collision routine :) - Burf2000

3 Answers

5
votes

You will struggle.

Consider just using Unity3D, which will allow you to access nVidia physX, which is the type of 3D physics solution you want.

Conversely, start from scratch with this! http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.4.5881&rep=rep1&type=pdf

Conversely, become an expert in something like this http://www.ode.org/ which you can then conceivably use with OpenGL, http://www.ogre3d.org/about/features, etc.

Here is an important clarification regarding the comments on "images":

Images are utterly unrelated to collision detection. OpenGL has utterly no relationship, whatsoever in any way to collision detection or physics of any kind. Images have absolutely no connection, whatsoever, to collision detection. There is no connection, zero, between OpenGL and collisions. Absolutely nothing.

2
votes

OpenGL is a pure visualization library and doesn't provide any collision detection. You'll have to roll your own or use a third party collision detection library.

The function CGRectIntersectsRect looks like it comes from the Cocos library and does 2D collision detection between rectangles. If the actual gameplay in your game is restricted to 2D this function might be all you need but if the player moves in three dimensions it won't be sufficient.

0
votes
  1. OpenGL does not do collision detection, at least not intentionally. You can use some features to do sprite collision detection, but I’m not sure if that applies to the latest OpenGL ES on the iPhones.

  2. CGRectIntersectsRect comes from Core Graphics, it’s a simple envelope check you can do to avoid more precise and expensive check when obviously not needed. It only works in 2D.

  3. Collisions in 3D are tricky. Maybe you could start by projecting the avatar to the floor and check the resulting polygon (or even a rectangle) for collision with the wall lines? Sounds easier.