SteamVR Plugin
使用HTC vive基于unity做虚拟现实,需要用到steamVR插件,最近查找了很多资料,稍微做一下总结。
做虚拟现实无非是头显在场景中的camera功能以及手柄的操作功能。
(一)camera以及controller
第一种方法:此方法为最简单最直接的方法,直接把插件中的prefab拖出来用即可。
此方法手柄和头显均没有问题
第二种方法:把插件中的脚本SteamVR_Camera挂到任一camera上,然后点击expand即可。而对于控制器手柄,则先建立一个游戏物体,添加脚本SteamVR_ControllerManager,然后在此游戏物体下建立两个子游戏物体,然后添加脚本SteamVR_TrackedObject,Index设置为None,并添加SteamVR_ControllerManager脚本中的左右手柄;最后再在两个子游戏物体上各添加一个游戏物体,添加脚本SteamVR_RenderModel用于渲染手柄的模型,并且跟踪手柄的位置。至此就可以完成设置,进行工程了。
(二)controller各个按钮功能
在SteamVR_Controller脚本中有各个按键按下的相关方法,可以自己实验一下或者网上找相关资料看看相关,在此转载http://www.cnblogs.com/czaoth/p/5610883.html#3648603,还是很全面的(当然了如有不妥请转告,并会进行相应修改)。
- using UnityEngine;
- using System.Collections;
- //检测手柄功能的脚本 这个脚本挂到手柄上(controler(right)和controler(left))上
- public class ButtonTouchAction : MonoBehaviour {
- //手柄
- SteamVR_TrackedObject trackdeObjec;
- void Awake() {
- //获取手柄上的这个组件
- trackdeObjec = GetComponent<SteamVR_TrackedObject>();
- }
- // Use this for initialization
- void Start () {
- }
- void FixedUpdate()
- { //获取手柄输入
- var device = SteamVR_Controller.Input((int)trackdeObjec.index);
- //以下是api中复制出来的按键列表
- /* public class ButtonMask
- {
- public const ulong System = (1ul << (int)EVRButtonId.k_EButton_System); // reserved
- public const ulong ApplicationMenu = (1ul << (int)EVRButtonId.k_EButton_ApplicationMenu);
- public const ulong Grip = (1ul << (int)EVRButtonId.k_EButton_Grip);
- public const ulong Axis0 = (1ul << (int)EVRButtonId.k_EButton_Axis0);
- public const ulong Axis1 = (1ul << (int)EVRButtonId.k_EButton_Axis1);
- public const ulong Axis2 = (1ul << (int)EVRButtonId.k_EButton_Axis2);
- public const ulong Axis3 = (1ul << (int)EVRButtonId.k_EButton_Axis3);
- public const ulong Axis4 = (1ul << (int)EVRButtonId.k_EButton_Axis4);
- public const ulong Touchpad = (1ul << (int)EVRButtonId.k_EButton_SteamVR_Touchpad);
- public const ulong Trigger = (1ul << (int)EVRButtonId.k_EButton_SteamVR_Trigger);
- }
- */
- //同样是三种按键方式,以后不做赘述
- if (device.GetTouch(SteamVR_Controller.ButtonMask.Trigger)) {
- Debug.Log("按了 “trigger” “扳机键”");
- //右手震动
- //拉弓类似操作应该就是按住trigger(扳机)gettouch时持续调用震动方法模拟弓弦绷紧的感觉。
- var deviceIndex2 = SteamVR_Controller.GetDeviceIndex(SteamVR_Controller.DeviceRelation.Rightmost);
- SteamVR_Controller.Input(deviceIndex2).TriggerHapticPulse();
- }
- if (device.GetTouchDown(SteamVR_Controller.ButtonMask.Trigger))
- { Debug.Log("按下了 “trigger” “扳机键”");
- }
- if (device.GetTouchUp(SteamVR_Controller.ButtonMask.Trigger)) {
- Debug.Log("松开了 “trigger” “扳机键”");
- //左手震动
- var deviceIndex = SteamVR_Controller.GetDeviceIndex(SteamVR_Controller.DeviceRelation.Leftmost);
- SteamVR_Controller.Input(deviceIndex).TriggerHapticPulse();
- //右手震动
- var deviceIndex1 = SteamVR_Controller.GetDeviceIndex(SteamVR_Controller.DeviceRelation.Rightmost);
- SteamVR_Controller.Input(deviceIndex1).TriggerHapticPulse();
- }
- //这三种也能检测到 后面不做赘述
- if(device.GetPressDown(SteamVR_Controller.ButtonMask.Trigger)) {
- Debug.Log("用press按下了 “trigger” “扳机键”");
- }
- if (device.GetPress(SteamVR_Controller.ButtonMask.Trigger))
- {
- Debug.Log("用press按了 “trigger” “扳机键”");
- }
- if (device.GetPressUp(SteamVR_Controller.ButtonMask.Trigger))
- {
- Debug.Log("用press松开了 “trigger” “扳机键”");
- }
- //system键 圆盘下面那个键
- // reserved 为Steam系统保留,用来调出Steam系统菜单 因此貌似自己加的功能没啥用
- if (device.GetTouchDown(SteamVR_Controller.ButtonMask.System))
- {
- Debug.Log("按下了 “system” “系统按钮/Steam”");
- }
- if (device.GetPressDown(SteamVR_Controller.ButtonMask.System))
- {
- Debug.Log("用press按下了 “System” “系统按钮/Steam”");
- }
- //ApplicationMenu键 带菜单标志的那个按键(在方向圆盘上面)
- if (device.GetTouchDown(SteamVR_Controller.ButtonMask.ApplicationMenu))
- {
- Debug.Log("按下了 “ApplicationMenu” “菜单键”");
- }
- if (device.GetPressDown(SteamVR_Controller.ButtonMask.ApplicationMenu))
- {
- Debug.Log("用press按下了 “ApplicationMenu” “菜单键”");
- }
- //Grip键 两侧的键 (vive雇佣兵游戏中的换弹键),每个手柄左右各一功能相同,同一手柄两个键是一个键。
- if (device.GetTouchDown(SteamVR_Controller.ButtonMask.Grip))
- {
- Debug.Log("按下了 “Grip” “ ”");
- }
- if (device.GetPressDown(SteamVR_Controller.ButtonMask.Grip))
- {
- Debug.Log("用press按下了 “Grip” “ ”");
- }
- //Axis0键 与圆盘有交互 与圆盘有关
- //触摸触发
- if (device.GetTouchDown(SteamVR_Controller.ButtonMask.Axis0))
- {
- Debug.Log("按下了 “Axis0” “方向 ”");
- }
- //按动触发
- if (device.GetPressDown(SteamVR_Controller.ButtonMask.Axis0))
- {
- Debug.Log("用press按下了 “Axis0” “方向 ”");
- }
- //Axis1键 目前未发现按键位置
- //触摸触发
- if (device.GetTouchDown(SteamVR_Controller.ButtonMask.Axis1))
- {
- Debug.Log("按下了 “Axis1” “ ”");
- }
- //按动触发
- if (device.GetPressDown(SteamVR_Controller.ButtonMask.Axis1))
- {
- Debug.Log("用press按下了 “Axis1” “ ”");
- }
- //Axis2键 目前未发现按键位置
- //触摸触发
- if (device.GetTouchDown(SteamVR_Controller.ButtonMask.Axis2))
- {
- Debug.Log("按下了 “Axis2” “ ”");
- }
- //按动触发
- if (device.GetPressDown(SteamVR_Controller.ButtonMask.Axis2))
- {
- Debug.Log("用press按下了 “Axis2” “ ”");
- }
- //Axis3键 未目前未发现按键位置
- //触摸触发
- if (device.GetTouchDown(SteamVR_Controller.ButtonMask.Axis3))
- {
- Debug.Log("按下了 “Axis3” “ ”");
- }
- //按动触发
- if (device.GetPressDown(SteamVR_Controller.ButtonMask.Axis3))
- {
- Debug.Log("用press按下了 “Axis3” “ ”");
- }
- //Axis4键 目前未发现按键位置
- //触摸触发
- if (device.GetTouchDown(SteamVR_Controller.ButtonMask.Axis4))
- {
- Debug.Log("按下了 “Axis4” “ ”");
- }
- //按动触发
- if (device.GetPressDown(SteamVR_Controller.ButtonMask.Axis4))
- {
- Debug.Log("用press按下了 “Axis4” “ ”");
- }
- //ATouchpad键 圆盘交互
- //触摸触发
- if (device.GetTouchDown(SteamVR_Controller.ButtonMask.Touchpad))
- {
- Debug.Log("按下了 “Touchpad” “ ”");
- //方法返回一个坐标 接触圆盘位置
- Vector2 cc = device.GetAxis();
- Debug.Log(cc);
- // 例子:圆盘分成上下左右
- float jiaodu = VectorAngle(new Vector2(, ), cc);
- Debug.Log(jiaodu);
- //下
- if (jiaodu > && jiaodu < )
- {
- Debug.Log("下");
- }
- //上
- if (jiaodu < - && jiaodu > -)
- {
- Debug.Log("上");
- }
- //左
- if ((jiaodu < && jiaodu > ) || (jiaodu < - && jiaodu > -))
- {
- Debug.Log("左");
- }
- //右
- if ((jiaodu > && jiaodu < ) || (jiaodu > - && jiaodu < ))
- {
- Debug.Log("右");
- }
- }
- //按动触发
- if (device.GetPressDown(SteamVR_Controller.ButtonMask.Touchpad))
- {
- Debug.Log("用press按下了 “Touchpad” “ ”");
- }
- }
- //方向圆盘最好配合这个使用 圆盘的.GetAxis()会检测返回一个二位向量,可用角度划分圆盘按键数量
- //这个函数输入两个二维向量会返回一个夹角 180 到 -180
- float VectorAngle(Vector2 from, Vector2 to)
- {
- float angle;
- Vector3 cross = Vector3.Cross(from, to);
- angle = Vector2.Angle(from, to);
- return cross.z > ? -angle : angle;
}
SteamVR Plugin的更多相关文章
- SteamVR Unity Plugin - v2.0.1中的InteractionSystem
最近写VR项目的时候用到了SteamVR Unity Plugin - v2.0.1插件,感觉比之前用到的SteamVR plugin for Unity - v1.2.2版本改进了很多,就算不用VR ...
- SteamVR Unity工具包(VRTK)之概览和控制器事件
快速上手 · 克隆仓库 git clone https://github.com/thestonefox/SteamVR_Unity_Toolkit.git · 用Unity3d打开SteamVR_ ...
- 【UE4+Vive】学习笔记1
16.9.10为了做房产项目,这两天开始学习Unreal Engine 4.之前一直用unity,但是视觉效果一直不满意,听说虚幻4的效果更好,就来试一试水. 1.安装UE4 参考资料一: http: ...
- unity htc vive使用
本文介绍如何在Unity中使用HTC vive设备,当前VR作为市场比较火热的热点,HTC VIVE设备作为三大供应商之一,许多人购买了该设备,却不知道如何使用,本文通过图文并茂的形式,进行手把手的讲 ...
- Unity 5.4大赞:HTC Vive经典The lab渲染器开源
HTC Vive提供了一个不错的免费VR demo,最近1周仔细体验了一番. 仔细看了其安装文件,竟然是Unity 5.4beta版本(通过查log,知道Valve公司用的是最新的5.4.0b11版本 ...
- unity3D HTC VIVE开发-物体高亮功能实现
在VR开发时,有时需要用到物体高亮的功能.这里使用Highlighting System v3.0.1.unitypackage插件实现. Highlighting System v3.0.1的介绍访 ...
- 关于VRTK的使用(一)—— VR开发环境搭建
首先在Hierarchy窗口中添加GameEmpty,并重命名为VRTK.然后给VRTK添加一个子容器命名为SteamVR.从Asset Store导入SteamVR Plugin: 然后分别选中预制 ...
- 使用UE4/Unity创建VR项目
一.主要的步骤是说一下使用UE4,在此之前先说一下使用unity创建的VR项目 1.unity创建oculus rift dk2项目 在unity中创建一个简单的场景,让摄像机能看见场景中的物体,不对 ...
- HTCVive使用
1.设备的安装与配置 https://wenku.baidu.com/view/fa172fd7482fb4daa48d4b44.html?from=search 2.接入SDK.实现简单示例场景.更 ...
随机推荐
- Java的EOF标识?
这篇是关于JAVA中EOF标识的讲解,之前在工作上碰到过一个问题,有人问过,不能通过判断EOF来知道文件有没有读取完毕吗?其实,还真不能. 直接从JDK接口文档入手,以FileInputStrea ...
- linux中将video转换成gif
我使用的机器是Linux mint 17,因为习惯了在linux中开发而有时候在写小demo的时候要带一些演示,虽然可以使用录屏也可以但是视屏演示这些小demo也不是特别的方便.之前一直在linux中 ...
- Kubernetes 系列(四):使用Traefik访问.net core api
一. 准备 本篇的要求是在前三篇的基础上已经搭建好的本地k8s以及部署了Traefik,我们将会使用Traefik Ingress来访问.net core api,比较简单,做个记录,如果还没有搭建k ...
- overflow滚动条如何隐藏
隐藏滚动条有很多方法,比较简单和直观的方法可以使用::-webkit-scrollbar来完成 例如: .box::-webkit-scrollbar{ display:none } 这样的话就把bo ...
- 使用.Htaccess文件实现301重定向常用的七种方法
使用.Htaccess文件实现301重定向常用的七种方法 301重定向对广大站长来说并不陌生,从网站建设到目录优化,避免不了对网站目录进行更改,在这种情况下用户的收藏夹里面和搜索引擎里面可能保存的 ...
- Pycharm 快捷键大全 2019.2.3
在Pycharm中打开Help->Keymap Reference可查看默认快捷键帮助文档,文档为PDF格式,位于安装路径的help文件夹中,包含MAC操作系统适用的帮助文档. 下图为2019. ...
- B-微积分-Sigmoid函数
目录 Sigmoid函数 一.Sigmoid函数详解 更新.更全的<机器学习>的更新网站,更有python.go.数据结构与算法.爬虫.人工智能教学等着你:https://www.cnbl ...
- deferred对象和promise对象(一)
个人认为阮一峰老师讲的关于deferred对象是最容易理解的. deferred对象是jquery的回调函数解决方案.解决了如何处理耗时操作的问题,对那些操作提供了更好的控制,以及统一的编程接口. d ...
- app微信支付
<?php namespace app\api\controller\v1; use think\Request; use app\api\exception\weappay\lib\WxPay ...
- 【源码解析】自动配置的这些细节不知道,别说你会 springboot
spring-boot 相对于 spring,很重要的一个特点就是自动配置,使约定大于配置思想成功落地.xxx-spring-boot-starter 一系列引导器能够开箱即用,或者只需要很少的配置( ...