Imagine you are standing on the ground looking at a cube in the sky. When you tilt your head, the cube moves. I am trying to reproduce this using OpenGL ES on an iPhone, manipulating the tilt of the camera, looking at a simple 3D cube drawn around the source. I use the gluLookAt() function from Cocos2d, which should emulate the OpenGL version, and it seems that when I try to redo any values, my cube disappears.
My question is: Can you provide the use of gluLookAt() here to get me to start manipulating the camera so that I can understand how this works? I am really interested to know how to tilt the camera along the Y axis.
Here is my current code:
Viewport Configuration
glBindFramebufferOES(GL_FRAMEBUFFER_OES, _viewFramebuffer); glViewport(0, 0, _backingWidth, _backingHeight);
Design matrix
glMatrixMode(GL_PROJECTION); glLoadIdentity();
ModelView Matrix
glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt()
Drawing code
static const GLfloat cubeVertices[] = { -1.0, -1.0, 1.0, 1.0, -1.0, 1.0, -1.0, 1.0, 1.0, 1.0, 1.0, 1.0, -1.0, -1.0, -1.0, 1.0, -1.0, -1.0, -1.0, 1.0, -1.0, 1.0, 1.0, -1.0, }; static const GLushort cubeIndices[] = { 0, 1, 2, 3, 7, 1, 5, 4, 7, 6, 2, 4, 0, 1 }; static const GLubyte cubeColors[] = { 255, 255, 0, 255, 0, 255, 255, 255, 0, 0, 0, 0, 255, 0, 255, 255, 255, 255, 0, 255, 0, 255, 255, 255, 0, 0, 0, 0, 255, 0, 255, 255 }; glVertexPointer(3, GL_FLOAT, 0, cubeVertices); glEnableClientState(GL_VERTEX_ARRAY); glColorPointer(4, GL_UNSIGNED_BYTE, 0, cubeColors); glEnableClientState(GL_COLOR_ARRAY); glDrawElements(GL_TRIANGLE_STRIP, 14, GL_UNSIGNED_SHORT, cubeIndices);