Change screen orientation on the iPhone/iPad [SOLVED]

Previous topic - Next topic

XanthorXIII

Excellent! I think this should be a must add update for GLBasic.
Owlcat has wise

Kitty Hello


Hark0

Quote from: Kitty Hello on 2010-Nov-09
You want me to auto-flip the screen?

A NEW function like???:

RotateScreen(orientation)

orientation maybe 0,1,2,3 (up, down, left right) 0,90,180,270

With AUTO correct mouse coordinates?  =D

:P
http://litiopixel.blogspot.com
litiopixel.blogspot.com - Desarrollo videojuegos Indie · Pixel-Art · Retroinformática · Electrónica Development Indie Videogames · Pixel-Art · Retrocomputing · Electronic

Hark0

Quote from: millerszone (KidNovak) on 2010-Nov-07
This code flips the screen 180 degrees either in portrait or landscape using the accelerometer.
(use this code to get the orientation: http://www.glbasic.com/forum/index.php?topic=4650.msg35088#msg35088
You will also have to reverse BOTH X and Y mouse inputs. That's it.
I don't notice any drop in FPS with this procedure, compared to CREATESCREEN that
drops below 40 FPS with nothing in the loop on the iPad.
(I still need a easier way to change the draw and collision positions.)

Add the OpenGL commands to your main loop:
Code (glbasic) Select

SETSCREEN 1024, 768, TRUE
LOADBMP background$

FUNCTION upateGraphics:

    glPushMatrix()

        // use this code to flip 180 landscape (home button on left)
        glRotatef(180.0, 0.0, 0.0, 1.0)
        glTranslatef(-1024, -768, 0.0)  <-- change for iPhone

        //use this code to flip 180 portrait (home button on top)
        //glRotatef(90.0, 0.0, 0.0, 1.0)
        //glTranslatef(-768, -1024, 0.0)  <-- change for iPhone

        //      *** all your DRAW code goes here  ***

    glPopMatrix()

    SHOWSCREEN

ENDFUNCTION



Add this OpenGL wrapper code to a new file in your project.
Code (glbasic) Select

// INLINE functions to use OpenGL functions by Gernot
// directly inside GLBasic

INLINE
#define OGL                ::
typedef float           GLfloat;
ENDINLINE

INLINE
} extern "C" { void __stdcall glTranslatef( GLfloat x , GLfloat y , GLfloat z );; }; namespace __GLBASIC__ {
ENDINLINE
FUNCTION glTranslatef: x, y, z
    INLINE
        OGL glTranslatef(x, y, z);
    ENDINLINE
ENDFUNCTION


INLINE
} extern "C" { void __stdcall glRotatef( GLfloat angle , GLfloat x , GLfloat y , GLfloat z );; }; namespace __GLBASIC__ {
ENDINLINE
FUNCTION glRotatef: angle, x, y, z
    INLINE
        OGL glRotatef(angle, x, y, z);
    ENDINLINE
ENDFUNCTION


INLINE
} extern "C" { void __stdcall glPushMatrix( void );; }; namespace __GLBASIC__ {
ENDINLINE
FUNCTION glPushMatrix:
    INLINE
        OGL glPushMatrix();
    ENDINLINE
ENDFUNCTION


INLINE
} extern "C" { void __stdcall glPopMatrix( void );; }; namespace __GLBASIC__ {
ENDINLINE
FUNCTION glPopMatrix:
    INLINE
        OGL glPopMatrix();
    ENDINLINE
ENDFUNCTION


I made modifications in your source for ANIMATED rotation:

Change this:

glRotatef(180.0, 0.0, 0.0, 1.0)
glTranslatef(-1024, -384, 0.0)

with this for CENTER ROTATION:

glTranslatef(512, 384, 0)
glRotatef(Angulo, 0.0, 0.0, 1.0)
glTranslatef(-512, -384, 0)


and ADD this "trick" for correct mouse coordinates on inverted screen:

MOUSESTATE mx, my, ma, mb

IF Screen_Rotated=TRUE
   mx = (mx * COS(180) - my * SIN(180))+1024
   my = (mx * SIN(180) + my * COS(180))+768
ENDIF

Test my compiled sample...

Use cursors up/down for simulate rotation on win32.
Use cursors left/right for change angle speed rotation.

=D


NOTE: I tried with 1024x1024 png... but seems the app "cut the image" to screen size.  :blink:

[attachment deleted by admin]
http://litiopixel.blogspot.com
litiopixel.blogspot.com - Desarrollo videojuegos Indie · Pixel-Art · Retroinformática · Electrónica Development Indie Videogames · Pixel-Art · Retrocomputing · Electronic

Hark0

Look the sample here:  =D




Rael speed 60 FPS... Reduced with video capture screen to 26+- FPS  ;/

And NOW.... preparing for iPad test speed.....  :P
http://litiopixel.blogspot.com
litiopixel.blogspot.com - Desarrollo videojuegos Indie · Pixel-Art · Retroinformática · Electrónica Development Indie Videogames · Pixel-Art · Retrocomputing · Electronic

bigsofty

Now that's a cool effect, it's good to see how this thread evolved so quickly into something so slick!  :good:

Cheers,


Ian
Cheers,

Ian.

"It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration."
(E. W. Dijkstra)

Millerszone

Quote from: Hark0 on 2010-Nov-09
Quote from: Kitty Hello on 2010-Nov-09
You want me to auto-flip the screen?
A NEW function like???:
RotateScreen(orientation)
orientation maybe 0,1,2,3 (up, down, left right) 0,90,180,270
With AUTO correct mouse coordinates?  =D
:P
That would be nice! :)

Quote from: Hark0 on 2010-Nov-09
Quote from: millerszone (KidNovak) on 2010-Nov-07
This code flips the screen 180 degrees either in portrait or landscape using the accelerometer.
...
...
I made modifications in your source for ANIMATED rotation:

Change this:

glRotatef(180.0, 0.0, 0.0, 1.0)
glTranslatef(-1024, -384, 0.0)

with this for CENTER ROTATION:

glTranslatef(512, 384, 0)
glRotatef(Angulo, 0.0, 0.0, 1.0)
glTranslatef(-512, -384, 0)

and ADD this "trick" for correct mouse coordinates on inverted screen:

MOUSESTATE mx, my, ma, mb

IF Screen_Rotated=TRUE
   mx = (mx * COS(180) - my * SIN(180))+1024
   my = (mx * SIN(180) + my * COS(180))+768
ENDIF

Test my compiled sample...

Use cursors up/down for simulate rotation on win32.
Use cursors left/right for change angle speed rotation.
=D
NOTE: I tried with 1024x1024 png... but seems the app "cut the image" to screen size.  :blink:
I figured someone would come up with the code for animated rotation.  :)
I submitted one of my apps to apple yesterday with my code, I'll be
using this animated rotation next app.

Thanks.
Hardware: iMac 27", MacBook Air, PC 3.5Ghz Quad
Developing Tools: GLBasic SDK, Gideros Studio, PureBasic
Developing for: iOS, Android, Windows, OS X, webOS, HTML5

Hark0

http://litiopixel.blogspot.com
litiopixel.blogspot.com - Desarrollo videojuegos Indie · Pixel-Art · Retroinformática · Electrónica Development Indie Videogames · Pixel-Art · Retrocomputing · Electronic

matchy

I can't get this to work with X_MAKE3D although I do need to rotate and translate after every X_MAKE2D. It is only for 2D?  :blink:

Kitty Hello

the x_rotate is only for 3D. Or what do you mean?

matchy

glRotatef only rotate 2D not 3D (camera).

Kitty Hello

You should apply it to the GL_PROJECTION matrix, not modelview.