OpenGL ES : getting a fixed size for an object
I have an open GL ES (1.1) scene with many 3d objects and a "player" model. I'd like the player to have the same pixel size, regardless of the screen orientation on an Android phone or Iphone. I'm not using glOrtho or billboards. That's a perspective 3d scene, but I just want the objects to have the same size in both screen orientation. Currently, if I rotate the 开发者_JAVA技巧phone, I keep the same aspect ratio but the scene "zooms out" in landscape mode. I suspect that I have to play with parameters to glFrustrum to get this; but can't figure out yet how to do it. So any ideas are welcome!
Thanks
You will need to change the aspect ratio when the device is turned to go from a the otherwise the size of the objects are going to change. THink of yourself looking out through a window, the objects on the other side of the window are only going to be the same size if you don't change your distance from the window (i.e. zooom in and out), when you "turn" the window sidewayse, the aspect ratio of the window changes (the metaphor is starting to not work).
If you draw a square in the view with the side length being the short side of the screen, then you should still have a square when you turn the phone sideways, still covering the same area on the screen.
Things will probably be easier to calculate if you use the code from gluPerspective
. You set the aspect ratio to the actual aspect ratio, fix the fovy
for the first aspect ratio. You can then use what would be fovx
for this aspect ratio as the fovy
for your rotated view.
精彩评论