0
我正在使用Unity的手機遊戲。它涉及使用陀螺儀來獲取手機在空間中的方向/旋轉。我一直在比較C#中的兩個四元數的困難。這裏是我的代碼:比較兩個四元組的手機遊戲
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 */
什麼實際上,我試圖做的是驗證,如果手機處於垂直位置(比如,如果你把它貼在你的額頭)。我創建了原始方向的副本,並將其更改爲我希望的方向。之後我比較兩者,如果他們幾乎相同,遊戲可以繼續。我幾乎沒有關於四元數的知識。我試圖找出w,x,y,z的四元數值應該代表垂直方向,但在谷歌上搜索時找不到任何線索。所以這就是我在這裏尋求幫助的原因。
是不是我要找的屏幕的方向,但更多的是手機本身的方向。謝謝你的Screen.orientation順便說一句,它是有用的設置我的遊戲水平只:) –