BASIC

Author Topic: Change screen orientation on the iPhone/iPad [SOLVED]  (Read 19103 times)

Offline XanthorXIII

  • Mr. Polyvector
  • ***
  • Posts: 197
    • View Profile
Excellent! I think this should be a must add update for GLBasic.
Owlcat has wise

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10714
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
You want me to auto-flip the screen?

Offline Hark0

  • Prof. Inline
  • *****
  • Posts: 1020
  • Geek Developer
    • View Profile
    • LitioPixel - Desarrollo de videojuegos con GLBasic | Videogame development with GLBasic
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
« Last Edit: 2010-Nov-09 by Hark0 »
http://litiopixel.blogspot.com
litiopixel.blogspot.com - Desarrollo videojuegos Indie · Pixel-Art · Retroinformática · Electrónica Development Indie Videogames · Pixel-Art · Retrocomputing · Electronic

Offline Hark0

  • Prof. Inline
  • *****
  • Posts: 1020
  • Geek Developer
    • View Profile
    • LitioPixel - Desarrollo de videojuegos con GLBasic | Videogame development with GLBasic
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]
« Last Edit: 2010-Nov-09 by Hark0 »
http://litiopixel.blogspot.com
litiopixel.blogspot.com - Desarrollo videojuegos Indie · Pixel-Art · Retroinformática · Electrónica Development Indie Videogames · Pixel-Art · Retrocomputing · Electronic

Offline Hark0

  • Prof. Inline
  • *****
  • Posts: 1020
  • Geek Developer
    • View Profile
    • LitioPixel - Desarrollo de videojuegos con GLBasic | Videogame development with GLBasic
Look the sample here:  =D

<a href="http://www.youtube.com/watch?v=XjdBPJ3Aa9w" target="_blank">http://www.youtube.com/watch?v=XjdBPJ3Aa9w</a>


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

And NOW.... preparing for iPad test speed.....  :P
« Last Edit: 2010-Nov-09 by Hark0 »
http://litiopixel.blogspot.com
litiopixel.blogspot.com - Desarrollo videojuegos Indie · Pixel-Art · Retroinformática · Electrónica Development Indie Videogames · Pixel-Art · Retrocomputing · Electronic

Offline bigsofty

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 2628
    • View Profile
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)

Offline Millerszone

  • Dr. Type
  • ****
  • Posts: 307
  • www.smashedfly.com
    • View Profile
    • Smashed Fly
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! :)

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

Offline Hark0

  • Prof. Inline
  • *****
  • Posts: 1020
  • Geek Developer
    • View Profile
    • LitioPixel - Desarrollo de videojuegos con GLBasic | Videogame development with GLBasic
Good Luck with Appstore!!!

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

Offline matchy

  • Prof. Inline
  • *****
  • Posts: 1543
    • View Profile
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:

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10714
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
the x_rotate is only for 3D. Or what do you mean?

Offline matchy

  • Prof. Inline
  • *****
  • Posts: 1543
    • View Profile
glRotatef only rotate 2D not 3D (camera).

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10714
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
You should apply it to the GL_PROJECTION matrix, not modelview.