Using iPhone OpenGl ES is effective for 2d (and collision detection)

this may be a more general question. using OpenGL ES for 2d and reading the tutorials, I've learned how to do basic matrix transformations like rotating and moving an object around the screen. so far, so good - I have some objects moving and rotating.

the next step for me is collision detection. something as simple as checking for intersection between bounding boxes would probably be ok. however I am stuck because in order to know when intersecting rectangles intersect I have to know the translated, rotated coordinates of my objects. but I cannot find a way to get these numbers from OpenGL.

so do I really need to do the rotations and transforms myself, besides OpenGL doing them, just to get the translated coordinates? or is there a way to apply the current matrices to the vertex and get the results? couldn't OpenGL do the math much faster than me?

thanks for any help, I would appreciate some general advice on how this is usually done.

+2


source to share


2 answers


Visual and collision information is usually handled individually in games. Note that you must reuse all your transformation information in your physical code (i.e. all your matrices), not the vertex information. It sounds a bit inefficient and disgustingly intuitive at first.

One reason is that it is unusual to require collision detection with polygon accuracy. Instead, rough volumes are usually sufficient.

As such, you rarely ever come across multiple polygons with a different set of polygons - in fact, you should try your best not to. You must be colliding spheres with yourself, boxes, lines, or "enclosed" spheres (capsules). Large, non-convex models can be split into multiple convex volumes and processed separately.



So, if you were using the visual mesh directly for collisions, your physics code would be much slower than using a lower detail mesh, or an approximate volume like a sphere or field. This is a little more painful, but the slow part of the collision is not the transformation, the actual detection of it - so this method is faster.

Depending on your game, I would consider using the orbs as much as possible - they don't need to be rotated and the tests are simple. It's also easy to create a bounded sphere at model load times before the geometry disappears on GPU ground.

This book is a very good resource and there are many online .

+7


source


You have to do the translations and rotations yourself. It's rather inefficient to ask OpenGL for data. Graphics engines often store OpenGL data (especially state data) and tell the OpenGL state machine the minimum information it needs.



0


source







All Articles