Change screen orientation in a Unity Google Cardboard project - android

I'm just starting a cardboard project as it's really joyful to experiment VR without any huge hardware, but I have a little problem which sounds really basic : the screen orientation. I just would have my game playable in Landscape Right instead of Left as I'm developing on my Xperia Z.
Usually screen orientation's problems are solved by forcing the orientation through the Player's Settings in the Build Menu. But here, the fact is that when I tick the "Landscape Right" box instead of the left one (which is the default setting of the Cardboard API) it correctly inverts my display but my camera stays at the same orientation as before.
From this results that my gyroscope works in reverse and that the ground is seen on the top, with all the texts reversed as well.
I've already done what Eldir tried here (Google cardboard device orientation) but as it wasn't the same problem I'm having, it wasn't efficient.
Do you have any ideas that if the API allows a quick change for this, or if I have to modify the whole parameters of the gyroscope ?
Thanks !

Related

UNITY: How to make the UNITY preview look like an android portrait

I usually develope apps for android with visual studio, but i want to increase my programming knowledge a little and am trying into game development.
I watched some tutorials and get everything to debug on my phone, but I have one major question ahead of me, before I can really start:
So, in Visual Studio I usually deliever 5 different hdpi folders, and work with linearlayouts and set weights which work as some form of percentage towards the users screen. With this technique, the apps that I build usually look more or less the same on every android device out there (which indeed are LOT).
If I come to unity now, I'd like to set the preview window of my mobile game to already be in a portrait format. Which would be some kind of 90 degree 16:9 ratio. I can bring it to 16:9 ratio but, again this is always landscape and never portrait. But that means that I kind of need to guess what the game will look like when finished - and that is a no go!
So how could I achieve what I need? Sort of tilt the 16:9 ratio over by 90 degrees.
I hope I made myself clear!
Thank you!
Okay thanks, I kinda found a way just by playing around with it.
Where it said "16:9" right above the preview screen. When clicking on it and then clicking on this little "+" i could manually provide a resolution such as 1440 x 2560. This brought it into portrait android mode. THANKS :)

Wrong Camera Orientation with Android & Vuforia

We are developing our own Android-based hardware and we wish to use Vuforia (developed via Unity3D) for certain applications. However, we are having problems making Vuforia work well with our current camera orientation settings.
On our hardware, when the camera is placed horizontally - everything works fine. That is, when the camera is parallel to the placement of the display. However, we need to place the camera vertically, or in other words, with a 90 degree difference to the placement of the display. These are all hardware settings. Our kernel is programmed according to such settings and every other program that utilises the camera works compatibly with everything, including our IMU sensors. However, apps developed with Vuforia behave completely odd when the camera is placed vertically.
We assume the problem to be related to Vuforia's algorithms of processing raw camera data however we are not sure. Moreover, we do not know how to fix the situation. For further details, I can list:
-When "Enable Video Background" is on, the projected image is distorted and no video feed is available. The AR projection appears on a black background with distorted dimensions.
-When "Enable Video Background" is on and the device is rotated, the black background is replaced by flickering solid colors.
-When "Enable Video Background" is off, the AR projection has normal dimensions (no distortion) however it is tracked with wrong axis settings. For example, when the target moves left in real world, the projection moves up.
-When "Enable Video Background" is off and the device is rotated, the AR projection is larger compared to its appearance when the device is in it's default state.
I will be glad to provide any more information you need.
Thank you very much, have a nice day.
PS: We have found out that applications that use the camera as a main purpose (Camera apps, Barcode Scanners, etc) work fine while apps for which camera usage is an extra quality (such as some games) have the same problem as Vuforia. This make me think that apps who access the camera directly work fine whereas those who use Android API and classes fail for some reason.
First understand that every platform deals with cameras differently and that beyond this different android phone manufacturers deal with these differently as well. In my testing WITHOUT vuforia I had to transform the plane I cast the video feed onto 0,-90,90 for android/iphone and -270,-90,90 for the windows surface tablet. Past this the iPhone rear camera was mirrored, the android front camera was mirrored as well as the surface front camera. That is easy to account for, but an annoying issue is that the Google Pixel and Samsung front cameras were mirrored across the y (as were ALL iOS on the back camera), but the Nexus 6p was mirrored across the x. What I am getting at here is that there are a LOT of devices to account for with android so try more than just that one device. Vuforia so far has dealt with my pixel and 4 of my iOS devices just fine.
As for how to fix your problem:
Go into your player settings for unity and look at the orientation. There are a few options here and my application only uses portrait so I force portrait and it seems to work fine (none of the problems I had to account for with the above mentioned scenario). Vuforia previously did NOT support auto rotation so you need to make sure you have the latest version since it sounds like that is what you need. If the auto rotate is set and it is not working right you may have to account for that specific device (don't do this for all devices until after you test those devices). To account for that device use an if (or construct a case statement if you have multiple instances of this problem with different devices) and then reflect or translate as needed. Cross platform development systems (like unity) doesn't always get everything perfect since there is basically no standard. In these cases you have to directly account for them by creating a method and a case statement within that so you can cleanly and modularly manipulate all necessary devices. It is a pain, but it beats developing for all devices separately.
One more thing is make sure you check out the vuforia configuration file as it has some settings such as camera mirror and direction settings on there. These seem to be public settings so you should also be able to script to these in your case statement in the event you need to use "Flip Horizontally" for one phone, but not another.

Unity3d ARTookit5 Blurred camera on android mobile

i'm trying to do a simple AR scene with NFT image that i've created with genTextData. The result works fairly well in unity editor, but once compiled and run on an android device, the camera resolution is very bad and there's no focus at all.
My marker is rather small (3 cm picture), and the camera is so blurred that the AR cannot identify the marker from far away. I have to put the phone right in front of it (still verrrrryy blurred) and it will show my object but with a lot of flickering and jittering.
I tried playing with the filter fields (Sample rate/cutoff..), it helped just a little bit wit the flickering of the object, but it would never display it from far away..i always have to put my phone like right in front of it. The result that i want should be: detecting the small marker (sharp resolution or/and good focus) from a fair distance away from it..just like the distance from your computer screen to your eyes.
The problem could be camera resolution and focus, or it could be something else. But i'm pretty sure that the AR cannot identify the marker points because of the blurriness.
Any ideas or solutions about this problem ?
You can have a look here:
http://augmentmy.world/augmented-reality-unity-games-artoolkit-video-resolution-autofocus
I compiled the Unity plugin java part and set it to use the highest resolution from your phone. Also the auto focus mode is activated.
Tell me if that helps.

How to detect when device is oriented upside-down in libGDX

I'm starting to develop a game for Android using libGDX.
I noticed that some sample games for this library all have fixed screen orientation. I want my game to be landscape all the time, but I want to rotate the camera 180 degrees when the device is turned upside down (most well behaved Android apps do this automatically).
I'm looking at the docs and Googling, but can't find anything about it.
Basically, I'd like to know what to add to base libGDX app. that shows libGDX logo, to just react when phone is turned upside down?
The Android docs, list this functionality in getRotation function here:
http://developer.android.com/reference/android/view/Display.html#getRotation%28%29
This allows you to get 0/180 or 90/270 for rotation and thus detect how the device is turned.
But I don't see this exposed in libGDX?
Nevermind, I just found it. You need to change:
android:screenOrientation="landscape"
to:
android:screenOrientation="sensorLandscape"
and it works automagically. Maybe libGDX devs should make this the default.

Zxing - Changing camera view -90 degrees

First of all, I would like to refer to this Issue on the google groups.
My problem is i want the landscape-native app to work in portrait mode. The way of getting the app into portrait mode is no problem at all, but when you display the app in portrait mode, my problem occurs.
When the Barcode Scanner is starting op, its camera view is (pr. default) at a +90 degree angle. When viewing the app in portrait mode the Barcode Scanner is (naturally) still at a +90 degree angle.
In the referred Issue-page there is displayed a hack to get around the problem, but this does not seem to work on most devices. This does also not work on my targeted devices.
I would like to hear if some of you have got a work around, or found the place in the source where you can 'undo' the 90 degree flipping?
A usable answer will be utmost appriciated :D Unfortunately i can't make progress in the project before this is solved. It is demanded to run in portrait mode ;)
In advance ... Thanks :)
I have implemented this in a private build. It is complicated and I can't share the details. The key steps are:
Call Camera.setDisplayOrientation() to counteract the rotation; see the Android javadoc for some discussion on that
Make sure that Camera.Parameters.setPreviewSize() is called correctly; preview sizes are reported in landscape but need to be set in portrait
(And guess what -- the default orientation of phones is considered portrait but tablets is considered landscape! Make sure you've accounted for that too.)
Finally, the preview data is always in landscape mode. You need to rotate it yourself to read it right-side-up, or otherwise account for that.

Categories

Resources