Saving and restoring OpenGL model-view
I am a new-comer to OpenGL, and much of it remains mysterious to my feeble brain. I have been studying the NeHe demos as well as the Red Book. I am writing an Android application that displays the Earth in the center of the screen. The user can rotate the Earth about any axis (much like 开发者_开发问答a very simple "Google Earth").
This code is working (I based it on the NeHe examples). Now I want to add a feature; the user should be able to save the current model orientation, then later return to that same orientation. For example, the user may save the Earth orientation such that the viewer is looking down at her hometown, and north-east is "up".
How do I do this with OpenGL-ES? To capture and save the current orientation, my code could get the current model-view transformation matrix - I think I understand how to do that. But later on how do I apply that saved matrix to restore the view?
You save the modelview matrix with glGet(Float|Double)v
. You load it with glLoadMatrix[df]
.
Oops -- rereading your question, you're talking about OpenGL-ES. With OpenGL-ES, you have to supply your own matrix math "stuff", and those won't work -- you'll have to do the job on your own. It's hard to be specific without knowing how you're doing things right now.
Assuming you're using ES 1.1 you'll want to look into glLoadMatrixf()
and glGetFloatv(GL_*_MATRIX)
.
If you're using ES 2.0 you'll have to roll your own system.
I'd say you actually build a non-graphical model of what is going on, disencouraging the use of glGet*/glRead*
(latency, portability, etc.). That is of your transform (rotation) matrix. Then you would use glLoadIdentity
each frame, push/popMatrix
and loadMatrix
to apply your transfomation. Saving the current model orientation will be the same as copying the transformation matrix, which is really just a copy of a small bunch of floats.
精彩评论