Gyroscope

class in UnityEngine

示例脚本演示如何使用陀螺仪类查看IOS设备空间中的方向

// iOS 陀螺仪范例using UnityEngine;
using UnityEngine.iOS;public class ExampleScript : MonoBehaviour
{// 创建六个Plane作为测试参照物private GameObject[] quads = new GameObject[6];// 有适当的颜色,如红色、绿色、蓝色等public Texture[] labels;void Start(){// 使相机的颜色为单色调GetComponent<Camera>().backgroundColor = new Color(49.0f / 255.0f, 77.0f / 255.0f, 121.0f / 255.0f);GetComponent<Camera>().transform.position = new Vector3(0, 0, 0);GetComponent<Camera>().clearFlags = CameraClearFlags.SolidColor;// 创建六个Plane 作为测试参照物GameObject quad = GameObject.CreatePrimitive(PrimitiveType.Quad);quads[0] = createQuad(quad, new Vector3(1,   0,   0), new Vector3(0,  90, 0), "plus x",new Color(0.90f, 0.10f, 0.10f, 1), labels[0]);quads[1] = createQuad(quad, new Vector3(0,   1,   0), new Vector3(-90,   0, 0), "plus y",new Color(0.10f, 0.90f, 0.10f, 1), labels[1]);quads[2] = createQuad(quad, new Vector3(0,   0,   1), new Vector3(0,   0, 0), "plus z",new Color(0.10f, 0.10f, 0.90f, 1), labels[2]);quads[3] = createQuad(quad, new Vector3(-1,   0,   0), new Vector3(0, -90, 0), "neg x",new Color(0.90f, 0.50f, 0.50f, 1), labels[3]);quads[4] = createQuad(quad, new Vector3(0,  -1,  0), new Vector3(90,   0,  0), "neg y",new Color(0.50f, 0.90f, 0.50f, 1), labels[4]);quads[5] = createQuad(quad, new Vector3(0,   0, -1), new Vector3(0, 180,  0), "neg z",new Color(0.50f, 0.50f, 0.90f, 1), labels[5]);GameObject.Destroy(quad);}GameObject createQuad(GameObject quad, Vector3 pos, Vector3 rot, string name, Color col, Texture t){Quaternion quat = Quaternion.Euler(rot);GameObject GO = Instantiate(quad, pos, quat);GO.name = name;GO.GetComponent<Renderer>().material.color = col;GO.GetComponent<Renderer>().material.mainTexture = t;GO.transform.localScale += new Vector3(0.25f, 0.25f, 0.25f);return GO;}protected void Update(){GyroModifyCamera();}protected void OnGUI(){GUI.skin.label.fontSize = Screen.width / 40;GUILayout.Label("Orientation: " + Screen.orientation);GUILayout.Label("input.gyro.attitude: " + Input.gyro.attitude);GUILayout.Label("iphone width/font: " + Screen.width + " : " + GUI.skin.label.fontSize);}/********************************************/// 陀螺仪是惯用右手的。 统一是左撇子。// 对相机做必要的改动。void GyroModifyCamera(){transform.rotation = GyroToUnity(Input.gyro.attitude);}private static Quaternion GyroToUnity(Quaternion q){return new Quaternion(q.x, q.y, -q.z, -q.w);}
}

示例脚本演示如何使用陀螺仪类查看Android设备空间中的方向

[资源结构]

using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class Gyroscope : MonoBehaviour {private Quaternion gyroscopeQua;private Quaternion quatMult = new Quaternion(0, 0, 1, 0);private float speedH = 0.2f;    //差值protected void Start(){//激活陀螺仪Input.gyro.enabled = true;//因安卓设备的陀螺仪四元数水平值为[0,0,0,0]水平向下,所以将相机初始位置修改与其对齐transform.eulerAngles = new Vector3(90, 90, 0);}protected void Update(){GyroModifyCamera();}protected void GyroModifyCamera(){gyroscopeQua = Input.gyro.attitude * quatMult;      //为球面运算做准备Camera.main.transform.localRotation = Quaternion.Slerp(Camera.main.transform.localRotation, gyroscopeQua, speedH);}protected void OnGUI(){GUI.skin.label.fontSize = Screen.width / 40;GUILayout.Label("Orientation: " + Screen.orientation);GUILayout.Label("input.gyro.eulerAngles: " + Input.gyro.attitude.eulerAngles);GUILayout.Label("now eulerAngles: " + Camera.main.transform.eulerAngles);GUILayout.Label("iphone width/font: " + Screen.width + " : " + GUI.skin.label.fontSize);}
}
案例源代码

Unity3d_API_Gyroscope 陀螺仪的接口相关推荐

  1. MTK 安卓11 传感器兼容 陀螺仪42607-p

    处于成本或多样性考虑,经常需要新增传感器进行兼容,本次以陀螺仪icm42607-p型号进行分析 1.如果平台或项目首次使用该传感器,需要添加传感器驱动文件(FAE提供),如果已经存在,直接进行下一步: ...

  2. Cocos Creator 获得手机陀螺仪(Gyrometer)数据

    接触 Cocos Creator 已经一年多, 体验是酸甜苦辣俱全, 不过仍然要夸一下这东西确实神作, 可以让我这种网页小白靠着Unity开发经验直接上手. 到目前为止的 Cocos Creator ...

  3. 《UnityAPI.Gyroscope陀螺仪》(Yanlz+Unity+SteamVR+云技术+5G+AI+VR云游戏+Unity+Gyroscope+rotationRate+立钻哥哥++OK++)

    <UnityAPI.Gyroscope陀螺仪> 版本 作者 参与者 完成日期 备注 UnityAPI_Gyroscope_V01_1.0 严立钻 2020.09.03 #<Unity ...

  4. 智能车竞赛技术报告 | 双车接力组 - 黑龙江工程学院 - 睿龙二队

    学 校:黑龙江工程学院       队伍名称:睿龙二队          参赛队员:杜明浩 肖峥 运璟新 马洪岩 带队教师:崔宏耀 张毅        引 言   全国大学生智能汽车竞赛是以" ...

  5. sqllite开发安卓项目_【兼职项目】预算3万开发无线温度电流传感,2万开发直流电机打磨机控制...

    [个人/团队兼职项目]是小包为大家筛选的酬金预算≤3万元的中小型软硬件兼职项目,适合高级工程师.技术团队服务商竞标,从而赚取"零花钱". 个人/团队兼职项目(酬金≤3万元) 1.摄 ...

  6. 谈谈最近很火热的VR

    demo视频 最近听到最多的新技术讨论,不外乎就是VR了,包括各种VR设备也非常热卖,贵的有Oculus Rift DK2或者htc的vive,便宜点的有三星gear VR,最廉价的也有Google的 ...

  7. agx 安装ros opencv_【ROS开源】Jetson Nano阿克曼转向机器人

    塔克创新出品的系列入门ROS智能机器人学习开发平台,包括麦克纳姆轮机器人,四轮差速机器人,三轮全向机器人,两轮差速机器人,阿克曼转向小车等平台.可实现SLAM建图导航.自动避障.雷达跟随.视觉巡线.三 ...

  8. agx 安装ros opencv_【树莓派ROS开源机器人】阿克曼转向机器人,最接近无人自动驾驶的人工智能机器人...

    塔克创新出品的系列入门ROS智能机器人学习开发平台,包括麦克纳姆轮机器人,四轮差速机器人,两轮差速机器人,阿克曼转向小车等平台.可实现SLAM建图导航.自动避障.雷达跟随.视觉巡线.三维建图.手机AP ...

  9. 迅为RK3399开发板Debian系统设置开机自启动脚本

    如果想要开机运行某程序,需要在开发板上编辑"/etc/rc.local"文件,在此文件添加你想开机运行的命令即可.这里给大家做一个示范,我们的需求是开机自启动 hello.sh 脚 ...

最新文章

  1. AttributeError: module librosa has no attribute output No module named numba.decorators错误解决
  2. 求助:一个物理专业的在做GPU的人
  3. 手机qpython3安装库_iPhone手机设置铃声简易教程(iOS12-iOS14)
  4. python如何输入一个数停止输出可循环部分_Python 第04周:控制与循环
  5. 【渝粤题库】陕西师范大学700011 新课程改革与生物教材研究
  6. 诗与远方-:无题(六十九)
  7. php socket 实现ftp,用socket实现FTP教程
  8. 【DRP】【SQL】-悲观锁-防止多用户同时操作时出现脏数据
  9. 使用双向链表构建二叉树_LeetCode-109 有序链表转换二叉搜索树
  10. 【芯片使用】PCF8591
  11. RuntimeError: mat1 and mat2 shapes cannot be multiplied (32x7 and 784x1024) 报错解决
  12. 基于springboot的高校疫情打卡上报系统设计与实现 文档+项目源码及数据库文件+演示视频
  13. 常用数学公式,推导记录
  14. 数据抓取 | 数据分享 - 北京链家二手房成交数据抓取,保存格式为excel
  15. CV算法工程师自修指南
  16. java中上传本地图片
  17. 14. echarts画双y轴
  18. 快速接入百度地图定位、描点
  19. android 仿苹果 小组件,安卓仿ios14桌面小部件
  20. 震荡行情下,使用什么工具博高收益-网格交易

热门文章

  1. IP地址划分--主机号--子网号
  2. HuaWei-面试题Traing-01
  3. 红米点击android版,红米2移动4G版 安卓10 原生体验 LineageOS17.1 ROOT
  4. JavaScript: The Definitive Guide 6th 英文原版书
  5. 如何设置图例的位置?如何去掉图例的边框?如何调整图例的大小?如何调整图例中图标和文字说明的间距?
  6. 银行卡收单____对账___长短款差错处理
  7. codeforces Round #675 (Div. 2) 1422C Bargain
  8. 三年半烧掉88亿、4个月市值暴跌7成,“生鲜电商第一股“每日优鲜首份财报不及格
  9. Mop行话经典(转)
  10. QT+OpenGL导入STL文件(二进制/ascll码格式),鼠标交互实现缩放旋转