I’m don’t understand how we can positioning objects with opengl. All transformation values is between “-1.0f” – “1.0f”. I’m made some game using with surfaceview. And I can simply change and defined objects x and y position. example; if android screen width is 480px, so my box max x values is 480. but how can I do this on opengl? How make the limits and how use pixel or dpi metrics? how can I change a box position on my finger touch place?
I’m don’t understand how we can positioning objects with opengl. All transformation values is
Share
First off, glTranslate and most if not all transformation values are not restricted to values between “-1.0” to “1.0”. Being able to move an object 10px to the left or right is going to require setting up your transformation matrices properly. Below is the order of how OpenGL manipulates vertexes you give it.
[(4×4) Projection][(4×4) View][(4×4) Model]*[(4×1) your vertex]
You would probably want to use glOrtho(0.0,width,0.0,height,-1.0,1.0) to setup your Projection matrix. You can leave the View matrix as the identity matrix. Finally, you can use your model matrix to translate, rotate, and scale your objects at a pixel scale. Now a glTranslatef(10.0,0.0,0.0) on the Model matrix should move your object 10px in the x direction. Alternatively, you could leave the Model matrix as the identity matrix, and let your vertexes represent pixel coordinates.
You can look at this powerpoint, and on slide 4 you can see a nice graphic detailing whats happening to your vertexes. https://wiki.engr.illinois.edu/download/attachments/195761441/OpenGL.pptx?version=1&modificationDate=1326820017000