Comparing Two Quaternions for a mobile game

I'm curently working on a mobile game using Unity. It involve using the gyroscope to get the orientation/rotation of a cellphone in space. I've been having a hard time comparing two Quaternions in C#. Here's my code:

transform.rotation = Input.gyro.attitude;       // Take the gyroscope rotation data and copy it
transform.rotation.Set(0, 0, 0, 1);             // change current Quaternion rotation data of the copy
                                                // Copy shoud now represent a vertical rotation
Angle = Quaternion.Angle(Input.gyro.attitude,); // Calculate the Angle between the 2
if (Angle < 45)                                 // if it's almost in vertical postion start the game
   /* do something */

What I'm actually trying to do is verify if the cellphone is in a vertical position (like if you stick it on your forehead). I create a copy of the original orientation and change it to the one I would like it to be. Afterwards I compare the two and if they are almost the same the game can continue. I have almost no knowledge on quaternions. I tried to find out what quaternion values of w,x,y,z I should put to represent a vertical orientation but couldn't find any clues while searching on google. So this is why I'm asking for help over here.


You mention that you're trying to see if the cellphone is in a vertical orientation.

I'm not sure exactly how accurate you're looking to get, but if that is simply all you'd like to determine, try the following:

if (Screen.orientation == ScreenOrientation.LandscapeLeft) {
    // screen is horizontal

Need Your Help

Qt 4.6.x under MacOS/X: widget update performance mystery

macos qt performance partial

I'm working on a Qt-based MacOS/X audio metering application, which contains audio-metering widgets (potentially a lot of them), each of which is supposed to be updated every 50ms (i.e. at 20Hz).

Assembly Program: Game of Fizz

assembly x86 nasm

This assembly program is a Fizz game. It should follow the rules for the children's counting game Fizz: It should print from 1-100 and whenever the number is evenly divisible by 5, or contains the ...