當我們在不同方向轉動或旋轉手機(例如加速汽車)時,人們如何創建使對象移動的遊戲? 他們使用加速度計和陀螺儀的讀數,還是使用Android中的OpenGL?Android遊戲如何使用傳感器?
0
A
回答
4
它們很可能使用加速計,因爲它在各種設備上廣泛使用。
你可能想看看這個教程:http://blog.androgames.net/85/android-accelerometer-tutorial/
2
這個例子顯示了一個簡單的計算爲3個方向看重
間距,方向和方位角。
if(SensorManager.getRotationMatrix(R, null, AccelerometerValues_last, MagneticFieldValues_last))
{
SensorManager.remapCoordinateSystem(R, SensorManager.AXIS_Y, SensorManager.AXIS_MINUS_X, remapR);
SensorManager.getOrientation(remapR, orientationValues);
Matrix.multiplyMV(orientationVector, 0, remapR, 0, sZVector, 0);
pitch = (float) (-Math.atan2(orientationVector[1], orientationVector[2]) * RADIANS_TO_DEGREES);
Matrix.multiplyMV(orientationVector, 0, remapR, 0, sZVector, 0);
orientation = (float) (-Math.atan2(orientationVector[0], orientationVector[1]) * RADIANS_TO_DEGREES);
Matrix.invertM(remapR_inv, 0, remapR, 0);
Matrix.multiplyMV(azimuthVector, 0, remapR_inv, 0, sZVector, 0);
azimuth = (float) (180 + Math.atan2(azimuthVector[0], azimuthVector[1]) * RADIANS_TO_DEGREES);
}
文章How to use Android sensors?中的完整代碼。僅供參考。
相關問題
- 1. 傳感器的Android遊戲應用
- 2. Android如何使用傳感器?
- 3. 如何使用傳感器
- 4. Android傳感器
- 5. Android:傳感器
- 6. 如何使用pyserial流式傳感器傳感器?
- 7. 如何在玩SteamVR遊戲期間記錄Oculus傳感器數據?
- 8. 如何轉換遊戲旋轉矢量傳感器結果軸角
- 9. Android傳感器CPU使用率
- 10. 在Android上使用React Native傳感器
- 11. 服務器爲Android遊戲
- 12. 如何使用Google遊戲服務獲取連接到Android遊戲的玩家?
- 13. 如何使用指紋傳感器在Android中驗證用戶?
- 14. 的Android 2D遊戲開發使用Unity遊戲引擎
- 15. Android HTML5遊戲
- 16. android opengl遊戲
- 17. 與Android遊戲
- 18. 如何鏈接遊戲引擎和Android遊戲?
- 19. 如何在android中使用外部傳感器?
- 20. 如何在Unity中使用Android光傳感器
- 21. 如何使用Android傳感器計算旋轉角度?
- 22. Android上傳apk遊戲與apk擴展
- 23. Android:如何使遊戲資產文件可讀取使用ndk
- 24. Android Wear Wellness傳感器Moto360
- 25. Android傳感器類型3?
- 26. 聲音傳感器,Android
- 27. 傳感器和min3d ANDROID
- 28. android:光傳感器nullPointerException
- 29. Android傳感器:指南針
- 30. 在Android晃動傳感器
他們使用傳感器讀數來控制他們用來繪製的任何東西,不管它是2D還是3D等。 –