0
votes

I'm using OpenGL ES to draw my images and I currently my view setups are these:

    gl.glClearColor(0.6f, 0.6f, 1f, 1f);
    gl.glClearDepthf(1.0f);
    gl.glViewport(0, 0, varScreenWidth, varScreenHeight);
    gl.glShadeModel(GL10.GL_SMOOTH);
    gl.glDisable(GL10.GL_DEPTH_TEST);
    gl.glEnable(GL10.GL_TEXTURE_2D);
    gl.glMatrixMode(GL10.GL_PROJECTION);
    gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_NICEST);
    gl.glLoadIdentity();
    gl.glViewport(0, 0, width, height);
    gl.glMatrixMode(GL10.GL_PROJECTION);
    gl.glOrthof(0f, width, 0f, height, -10f, 10f);
    gl.glMatrixMode(GL10.GL_MODELVIEW);
    gl.glLoadIdentity();

I want to roll my whole view on Z axis but I can't use glRotate(). Because my objects are moving from the right to the left and when I do that I have to add offset to their Y position. I need a way to rotate whole view on Z axis like camera roll so the objects are gonna move on Y position automatically. I've tryed to add y offset by multiplying (ScreenWidth - ObjPositionX) and sin(Zroll) but this has some visual problems objects are not staying in their position perfectly. Thank you for any help...

  • Edit

Ok someones wanted me to be more Clear. So the function glRotate is rolling my objects over their orgin. But I need a way to roll whole view on Z axis as it's orgin is center of view not the single object. So if the object is on the left side of center it will be seen higher. If objects is on the right side it will seen lower.

2
Aside from your problem, you need a glLoadIdentity before glOrthodatenwolf
well I've added it and I didn't saw any difference what is the theory?Evren Ozturk
@PsyCoder: This was not about to fix your original problem, but for correctness and robusness reasons.datenwolf

2 Answers

0
votes

I assume this is in your display function (where this belongs! Never put projection and viewport setup in the window resize handler – it will bite you, badly!)

gl.glViewport(0, 0, width, height);

gl.glMatrixMode(GL10.GL_PROJECTION);
gl.glLoadIdentity(); // glOrtho needs a identity matrix to work upon
gl.glOrthof(0f, width, 0f, height, -10f, 10f);

gl.glMatrixMode(GL10.GL_MODELVIEW);
gl.glLoadIdentity();

You're assuming your viewing volume to span the range (x,y) in [0, width]×[0, height]. So to rotate about the center of this volume along the Z axis you must move the pivot point first there. Transformations are applied in the reverse order they're multiplied onto the stack, so:

gl.glTranslatef(width/2., height/2., 0); // move back to origin
gl.glRotate(angle, 0, 0, 1); // rotate about Z
gl.glTranslatef(-width/2, -height/2., 0); // move pivot point to middle of viewing volume

draw_scene();
0
votes

Well I've used the glRotatef() function again. The problem was that: I was using glTranslate() to put things in their position. To do so I had to call glLoadIdentity for every single object. Solution: Now I'm using glRotate() only once, just before starting to draw my objects. To put thing in their position: I realized that I can add X offset into the vertexBuffer itself. I hope that helps someone...