Question

I have an OpenGL ES game that I am hacking together. One part of it involves looking at a large "map-like" area and then double-tapping on one part to "zoom into" it. How would you use OpenGL ES to provide this effect (given that it may need to zoom in on different parts of the map).

I've heard of glScale and glOrtho, but I'm unclear on how they actually work since the whole openGL world is very new to me.

Was it helpful?

Solution

The 2-D zooming you describe might be better achieved using Core Animation. NSView (and its NDA'd iPhone counterpart) provide implicit animation when you change their frame. All you'd need to do in this case would be to set the frame's origin.x and origin.y and size.width and size.height to such values to make the view larger than the screen. If you did this and wrapped it in the appropriate calls to start and commit an animation, you'd get a zooming animation for free. Core Animation uses OpenGL behind the scenes for its animations.

If, however, you feel that you have to do this in OpenGL, may I suggest a little writeup I did at http://www.sunsetlakesoftware.com/2008/08/05/lessons-molecules-opengl-es? I'm the author of Molecules, a free 3-D molecular visualizer for the iPhone, and I knew nothing about OpenGL ES before I started that project. 3 weeks later, it was in the App Store as it launched.

OpenGL calls are pretty simple, it's the math surrounding them that can give you headaches. Zooming in on objects is actually pretty simple, and can be done either by moving the camera or by actually physically scaling objects. For Molecules, I went the route of scaling the object using the glScalef(x,y,z) function, where x, y, and z are the scale factors you wish to apply to your model object. I do my scaling incrementally. That is, I don't reset the transformation matrix at the start of each rendered frame (using glLoadIdentity()), but just scale it a little bit based on user input. If the user moves their fingers apart by 5%, I increase the scale by 5%.

Again, I'd suggest Core Animation for the 2-D zooming you describe, but it isn't too hard to achieve the same results in OpenGL ES.

OTHER TIPS

Respectfully, the answer is to take a few days to learn the basics of OpenGL, and there are much better places for that on the net than here.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top