OpenGL orientation on iPad

Member
Posts: 34
Joined: 2009.01
Post: #1
Hello all

App rejected because it does not orientate in both variants of portrait.
Actually part of the game is in landscape, but mainly in portrait.

To go to landscapeLeft I use
glTranslatef(0.0f, backingHeight, 0.0f);
glRotatef(270.0f, 0.0f, 0.0f, 1.0f);
then back to portrait
glTranslatef(0.0f, 0.0f, 0.0f);
glRotatef(0.0f, 0.0f, 0.0f, 1.0f);

Now I need to do the same for portraitUpsideDown and LandscapeRight

I'm wondering if it's the only way to do that, or is there another method.

How are you handling that ?

Thanks
Fred

My first game on AppStore : here
Quote this message in a reply
Moderator
Posts: 1,560
Joined: 2003.10
Post: #2
(Nov 8, 2010 10:19 AM)Fred9000 Wrote:  glTranslatef(0.0f, 0.0f, 0.0f);
glRotatef(0.0f, 0.0f, 0.0f, 1.0f);

These two statements have no effect. In general, though, you seem to be on the right track; altering your transformation and layout to match the desired orientation is the normal way to do this for an OpenGL application.
Quote this message in a reply
Member
Posts: 34
Joined: 2009.01
Post: #3
(Nov 8, 2010 12:25 PM)ThemsAllTook Wrote:  
(Nov 8, 2010 10:19 AM)Fred9000 Wrote:  glTranslatef(0.0f, 0.0f, 0.0f);
glRotatef(0.0f, 0.0f, 0.0f, 1.0f);

These two statements have no effect. In general, though, you seem to be on the right track; altering your transformation and layout to match the desired orientation is the normal way to do this for an OpenGL application.

These statements have the effect of putting me back in portrait orientation after being in landscape.
Now I'm OK with orientations, I'm enjoying the handling of oriented touch Events Smile

My first game on AppStore : here
Quote this message in a reply
Moderator
Posts: 1,560
Joined: 2003.10
Post: #4
(Nov 8, 2010 12:54 PM)Fred9000 Wrote:  These statements have the effect of putting me back in portrait orientation after being in landscape.

They actually don't. Both perform a no-op on the current matrix and leave it in precisely the state it was in before they were executed. Any effect they appear to have is coming from something else in your code, such as a call to glLoadIdentity().

glRotate, glTranslate, and similar functions alter the selected matrix based on its current state, not based on the identity matrix. For example, if you call glTranslate(1, 0, 0) twice in a row, you end up translating two units forward on the X axis, not one. The second call doesn't override the first one, and the translation is kept in the matrix until either canceled out by a translation in the opposite direction, or reset by a call to either glLoadIdentity() or glLoadMatrix(). The same principle applies to glRotate(), glScale(), glMultMatrix(), etc.

You can test this by commenting out those two lines on your code and observing that transformations are unaffected.
Quote this message in a reply
Member
Posts: 34
Joined: 2009.01
Post: #5
(Nov 8, 2010 01:50 PM)ThemsAllTook Wrote:  They actually don't. Both perform a no-op on the current matrix and leave it in precisely the state it was in before they were executed. Any effect they appear to have is coming from something else in your code, such as a call to glLoadIdentity().

You're absolutely right, thanks for your explanations.
To go to landscape I use this :
glViewport(0, 0, backingWidth, backingHeight);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrthof(0.0f, backingWidth, 0.0f, backingHeight, -1.0f, 1.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0f, backingHeight, 0.0f);
glRotatef(270.0f, 0.0f, 0.0f, 1.0f);
to go back to portrait is the same with zeros Smile
Now I understand that the translate and rotate don't do anything with zeros as parameters, and I will correct that.

My first game on AppStore : here
Quote this message in a reply
Member
Posts: 34
Joined: 2009.01
Post: #6
Hello

the handling of orientation is OK now in openGL, but it's a bit abrupt.
I'm wondering if there is any iOS library to handle a smooth transition ?
I can't find documentation about that.

Any help appreciated.

My first game on AppStore : here
Quote this message in a reply
Moderator
Posts: 1,560
Joined: 2003.10
Post: #7
Good to hear it's working! To smooth out the abruptness, you'll probably just want a simple interpolation over time of your view rotation. For OpenGL, there isn't likely to be much in the way of system APIs to help you with this (if not OpenGL, you'd probably use Core Animation), so the implementation would be up to you. To implement it, I'd just save the current time (from mach_absolute_time or however you measure it in your game) when you start a rotation, then each time you draw, rotate by an amount between the old value and the new value modulated by the time elapsed since you started rotating.
Quote this message in a reply
Member
Posts: 34
Joined: 2009.01
Post: #8
It's OK. The App has been approved. Here

The orientation is done by interpolating both rotation and translation, giving it a funky effect Smile

I should have centered the rotation but since I don't know what is on screen at orientation time, it probably need screen capture etc...

I will think about it for next time !

My first game on AppStore : here
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  SDL1.3/OpenGLES and iPhone Orientation SparkyNZ 10 10,786 Apr 13, 2011 02:38 AM
Last Post: SparkyNZ
  Orientation/rotation events shyguy 1 4,500 Dec 30, 2010 04:43 PM
Last Post: reubert