Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (481)
Games in Android Showcase (110)
games submitted by our members
Games in WIP (548)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Detecting Screen Orientation and Angle  (Read 4145 times)
0 Members and 1 Guest are viewing this topic.
Offline Oskuro

JGO Knight


Medals: 39
Exp: 6 years


Coding in Style


« Posted 2012-08-07 17:42:52 »


I can easily detect the screen orientation by doing the following:

1  
2  
3  
4  
int height = GraphicsEnvironment.getDefaultScreenDevice().getDisplayMode().getHeight();
int width  = GraphicsEnvironment.getDefaultScreenDevice().getDisplayMode().getWidth();
     
String orientation = height/width >= 1? "Portrait" : "Landscape";


The problem is that I can't know if the screen has been turned 90º, -90º or 180º.

I came unto this problem testing fullscreen mode on my portrait-oriented monitor, and finding out that all the input (mouse) is rotated. Knowing the angle is necessary thus to filter the input correctly.

From what I've seeing googling around, mobile platforms like Android have an actual .getRotation() method. How can I check this on standard Java?

Library independence is appreciated if possible  Wink

Offline sproingie

JGO Kernel


Medals: 202



« Reply #1 - Posted 2012-08-07 21:15:11 »

You can't.  Most peoples desktops don't rotate.  Hardware like the accelerometer and tilt sensor are only ever going to be exposed in specialized kits like Android or J2ME, and frankly, not so much J2ME.

Offline R.D.

Senior Member


Medals: 2
Projects: 1


"For the last time, Hats ARE Awesome"


« Reply #2 - Posted 2012-08-07 21:25:50 »

You could also do this on android:
1  
getResources().getConfiguration().orientation


for rotation:
1  
int rot =((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getRotation();

there might be a shorter way xD

For Desktop you should never think that someone flips his monitor xD How should the monitor check this? You only need the code for Android and even there... just cap the view to portrait and landscape like so:
1  
android:screenOrientation="portrait"/"landscape"

(In the  AndroidMenifest.xml file)
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Oskuro

JGO Knight


Medals: 39
Exp: 6 years


Coding in Style


« Reply #3 - Posted 2012-08-07 21:37:33 »

The monitor itself doesn't check it, but the display drivers do, as many Graphic cards give the option to rotate the display (not all, and not all the angles).

In my case I work with a rotated monitor, and happen to have a convertible laptop/tablet, so yeah, it might be of marginal interest, but since I'm building the screen management infrastructure for my project, I'd like to investigate possibilities now.

To the very least, having a rotation stub will help if I port the engine to Android or similar.


Offline Cero
« Reply #4 - Posted 2012-08-07 22:04:25 »

For Desktop you should never think that someone flips his monitor xD




Offline pitbuller
« Reply #5 - Posted 2012-08-07 22:37:49 »

It's client problem. They can easily turn the rotation for their monitor. ctrl + alt + arrow does that for me.
Offline ReBirth
« Reply #6 - Posted 2012-08-08 03:22:44 »

Why need to rotate anyway? Cranky

Offline R.D.

Senior Member


Medals: 2
Projects: 1


"For the last time, Hats ARE Awesome"


« Reply #7 - Posted 2012-08-08 09:20:05 »

@Cero
Those are all vertical shooters... Do you have any other examples? If not then you still have 98% of people playing games without rotating there monitors and without games that expect that. Or does... uhm... Deus Ex check if you flip you monitor and react to it?

Oskuro
If you use libGDX you won't havem uch problems porting it to android anyway. And even there... I don't remember much games doing that. Most games a portrait or landscape and if I flip my device nothing happens :/
Do you create are game where it is really necessary?
Offline Oskuro

JGO Knight


Medals: 39
Exp: 6 years


Coding in Style


« Reply #8 - Posted 2012-08-08 11:39:12 »

It's not a matter of actual application to a game, but rather curiosity, as the issue has come up while I was testing my screen manager code.

Still, this would be essential in mobile devices, I've experienced quite a few times games on tablets that do not rotate as I physically rotate the device, even though the API does offer the information (Since other games do rotate), and it's a bit obnoxious to have the user hold the device in an specific orientation, when the whole idea of a mobile device is ease of use.


But again, not concerned with what use I'd give to it. I just enjoy a lot solving programming problems  Smiley


Offline davedes
« Reply #9 - Posted 2012-08-08 11:54:27 »

Portrait orientation on desktop (i.e. flipped monitors) is all the rave these days -- lots of people in my office have one or both of their monitors rotated. Good for programming, heavy reading, Reddit, etc.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Oskuro

JGO Knight


Medals: 39
Exp: 6 years


Coding in Style


« Reply #10 - Posted 2012-08-08 14:40:32 »

I know, I do precisely that (That's why I noticed the issue, I ran my fullscreen code on my work's computer).


I'm investigating. To the very least, I'll probably add a "rotate" button so the user can manually adjust the screen if needed, but having some autodetection would be nice.

Offline sproingie

JGO Kernel


Medals: 202



« Reply #11 - Posted 2012-08-08 14:41:25 »

I know all about rotating monitors, my last one had that trick too.  Fact remains that there's still no standard Java API to deal with it, certainly not in the J2SE JDK.  

Possibly with LWJGL you can poll for resolution changes, though I tend to doubt Display deals with that gracefully.  Maybe JOGL does?
Offline Oskuro

JGO Knight


Medals: 39
Exp: 6 years


Coding in Style


« Reply #12 - Posted 2012-08-08 16:42:51 »

The thing is that the API for rotation details isn't well defined. It depends heavily on the display drivers and how much information they rely to the system, if they have the rotation capability at all.

I actually had a fun time coding scripts for screen rotation in Ubuntu (It wouldn't auto-detect screen rotation on my combo laptop/tablet, so I do it manually), so this isn't exactly new... But I doubt there's an easy OS agnostic solution.


I kind of suspect that in future JDKs this might pop up. Ginourmous monitors that get rotated and graphics cards with easy rotation interfaces are increasingly common these days, hopefully these things will get standarized.

Offline Roquen
« Reply #13 - Posted 2012-08-08 20:04:46 »

My thinking is: so what? I mean do you really want to interactively rotate your monitor?  If not..put an option in your graphics configuration options screen and stick a fork in issue until someone solves the problem for you.
Offline Oskuro

JGO Knight


Medals: 39
Exp: 6 years


Coding in Style


« Reply #14 - Posted 2012-08-08 23:01:27 »

Ok, I don't want to be rude, but this is something I often see in programming threads when someone asks something, so let me rant for a moment....

I'm not pondering if I should do it, I'm pondering how to do it.

I appreciate the discussion about the relevance of the issue at hand, but when it has been said a couple times that I'm interested in attempting to solve this just for the sake of doing it, rather than for any practical purpose, it becomes extremely obnoxious to have people keep insisting about whether I should or shouldn't do it.

Ok, rant over.

Offline ctomni231

JGO Wizard


Medals: 99
Projects: 1
Exp: 7 years


Not a glitch. Just have a lil' pixelexia...


« Reply #15 - Posted 2012-08-08 23:05:14 »

Well, I'm very unsure if screens have auto- rotate, except for the tablet devices.

However, there might be a temporary hack you can use in the meantime until a better solution can be found. The only information readily available continuously is the Java Toolkit screen size. You might be able to get away with it by comparing the Dimensions.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
...
    Toolkit toolkit = Toolkit.getDefaultToolkit();
    Dimension scrnsize = toolkit.getScreenSize();
    if(scrnsize.getWidth() > scrnsize.getHeight())
    {
         // Do normal x-axis mouse
   }
    else
    {
        //  Do inverted y-axis mouse
   }    
...


Of course, this comparison will fail if the width and the height is the same, but then, you can always have the user just set an option for it. Hopefully, this helps a little bit...

Offline Riven
« League of Dukes »

JGO Overlord


Medals: 781
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #16 - Posted 2012-08-08 23:14:45 »

and finding out that all the input (mouse) is rotated.
I have 1 monitor that is rotated +90deg and one monitor rotated -90deg.

I have never had problems with 'rotated' mouse coordinates in AWT. (as you're posting this in the Java2D board)

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline princec

JGO Kernel


Medals: 362
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #17 - Posted 2012-08-08 23:20:36 »

Client OS automatically handles everything for you. Nothing to see here. All you need to know is the width and height of the display. It is not a case of what you "should" do or "can" do, there is simply nothing to do.

Cas Smiley

Offline sproingie

JGO Kernel


Medals: 202



« Reply #18 - Posted 2012-08-09 01:09:40 »

Ok, I don't want to be rude, but this is something I often see in programming threads when someone asks something, so let me rant for a moment....

I'm not pondering if I should do it, I'm pondering how to do it.

Your original question was this:

Quote
From what I've seeing googling around, mobile platforms like Android have an actual .getRotation() method. How can I check this on standard Java?

So I'll just go back to my original answer: You Can't.
Offline Roquen
« Reply #19 - Posted 2012-08-09 08:00:49 »

Ok, I don't want to be rude, but this is something I often see in programming threads when someone asks something, so let me rant for a moment....

I'm not pondering if I should do it, I'm pondering how to do it.

I appreciate the discussion about the relevance of the issue at hand, but when it has been said a couple times that I'm interested in attempting to solve this just for the sake of doing it, rather than for any practical purpose, it becomes extremely obnoxious to have people keep insisting about whether I should or shouldn't do it.

Ok, rant over.

I qualified my statement with "My thinking is..".  What I see alot in various programming forums is people insisting on wasting time on things that are pointless.  The subsystem they're describing has no added value and won't provide any meaningful learning experience to the person in question.  I'm not gonna beat people over the head, but I think it useful to point out that IHMO what they are attempt to do is a waste of time.
Offline princec

JGO Kernel


Medals: 362
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #20 - Posted 2012-08-09 08:13:46 »

Especially when we know it's actually impossible because it simply isn't an actual "problem" Smiley

Cas Smiley

Offline Roquen
« Reply #21 - Posted 2012-08-09 08:24:14 »

Exactly.  Wasting time is the death of most projects.  This is why I hate the "premature optimization" thing.  It's simply one example of wasting time and an infrequent one at that.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

atombrot (27 views)
2014-08-19 09:29:53

Tekkerue (25 views)
2014-08-16 06:45:27

Tekkerue (23 views)
2014-08-16 06:22:17

Tekkerue (15 views)
2014-08-16 06:20:21

Tekkerue (22 views)
2014-08-16 06:12:11

Rayexar (61 views)
2014-08-11 02:49:23

BurntPizza (39 views)
2014-08-09 21:09:32

BurntPizza (31 views)
2014-08-08 02:01:56

Norakomi (37 views)
2014-08-06 19:49:38

BurntPizza (67 views)
2014-08-03 02:57:17
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!