【3D技术宅公社】XR数字艺术论坛  XR技术讨论 XR互动电影 定格动画

 找回密码
 立即注册

QQ登录

只需一步,快速开始

调查问卷
论坛即将给大家带来全新的技术服务,面向三围图形学、游戏、动画的全新服务论坛升级为UTF8版本后,中文用户名和用户密码中有中文的都无法登陆,请发邮件到324007255(at)QQ.com联系手动修改密码

3D技术论坛将以计算机图形学为核心,面向教育 推出国内的三维教育引擎该项目在持续研发当中,感谢大家的关注。

查看: 2649|回复: 1

[Oculus&VR] Unity3d-陀螺仪问题

[复制链接]
发表于 2015-4-24 15:05:11 | 显示全部楼层 |阅读模式
using UnityEngine;
using System.Collections;

public class GyroController_02: MonoBehaviour
{
        private bool gyroBool = true;
        private Gyroscope gyro;
        private Quaternion rotFix;

        void Start ()
        {
                Transform originalParent = transform.parent;
                GameObject camParent = new GameObject ("camParent");
                camParent.transform.position = transform.position;
                transform.parent = camParent.transform;
                camParent.transform.parent = originalParent;
               
                gyroBool = Input.isGyroAvailable;
               
                if (gyroBool)
                {
                        gyro = Input.gyro;
                        gyro.enabled = true;

                        if (Screen.orientation == ScreenOrientation.LandscapeLeft)
                        {
                                camParent.transform.eulerAngles = new Vector3(90,90,0);
                        }
                        else if (Screen.orientation == ScreenOrientation.Portrait)
                        {
                                camParent.transform.eulerAngles = new Vector3(90,180,0);
                        }
                        
                        if (Screen.orientation == ScreenOrientation.LandscapeLeft)
                        {
                                rotFix = new Quaternion(0,0,0.7071f,0.7071f);
                        }
                        else if (Screen.orientation == ScreenOrientation.Portrait)
                        {
                                rotFix = new Quaternion(0,0,1,0);
                        }
                }
                else
                {
                        //LogManager.Instance.Log("NO GYRO");
                }
        }

        void Update ()
        {
                if (gyroBool)
                {
                        Quaternion camRot = gyro.attitude * rotFix;
                        transform.localRotation = camRot;
                        //LogManager.Instance.Log("Angles:" + camRot.eulerAngles);
                }
        }
}
问题:
android下运行时,Input.gyro. attitude 取出的值一直是(0,0,0,0)
谁知道问题在哪儿,如何解决,请留言指点一下,谢谢


发表于 2015-4-25 11:39:10 | 显示全部楼层
Gear VR的能帮上忙,Oc的暂时还没接触
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|3D数字艺术论坛 ( 沪ICP备14023054号 )

GMT+8, 2024-4-28 15:11

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表