Unity 3D基于steamvr unity plugin进行开发,怎么判断手柄与其他物体的接触

Unity 3D基于SteamVR进行开发,怎么判断手柄与其他物体的接触?_unity3d吧_百度贴吧
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&签到排名:今日本吧第个签到,本吧因你更精彩,明天继续来努力!
本吧签到人数:0成为超级会员,使用一键签到本月漏签0次!成为超级会员,赠送8张补签卡连续签到:天&&累计签到:天超级会员单次开通12个月以上,赠送连续签到卡3张
关注:51,643贴子:
Unity 3D基于SteamVR进行开发,怎么判断手柄与其他物体的接触?收藏
Unity 3D基于SteamVR进行开发,怎么判断手柄与其他物体的接触? openVR SDK API中是否有相应接口?请大神赐教
小白一个,刚开始做
登录百度帐号推荐应用
为兴趣而生,贴吧更懂你。或http://blog.csdn.net/ystistheking/article/details/
想交流的朋友我们可以微博互粉,我的微博黑石铸造厂厂长&,缺粉丝啊 。。。。。求粉求粉
研究了几天htc vive的接口,总算是把基本的按键功能研究出来了,这里分享一下,一来当做笔记,二来也希望对大家有所帮助。
如何导入Steam_VR那个包什么的我就不说了,网上有几个前辈已经教了,蛮牛论坛啥的上面都有,这里只把比较详细的按键功能分享一下,不知啥高端的东西,也算一段时间劳动成果啦,所以转载的帮我留个名写个转,谢谢啦。
个人感觉手柄上开始比较难搞明白的就是那个圆盘键,这个键是一个以中心为(0,0)点的直角坐标系,四个端长度都是1,可接收触摸和按压两种事件,大体就是下图这个意思(手绘水平略渣,见谅见谅),触摸touch或按压press会通过GetAxis方法返回一个坐标系中的点,可以判断你按在哪里,触发不同的事件,可以根据角度或各种方法来切分按键为n个按钮(就像切蛋糕一样)
这里用的是C#脚本 ,直接上代码了,我个人写注释比较话唠,适合新手看:
[csharp]&&
using&UnityE&&
using&System.C&&
public&class&ButtonTouchAction&:&MonoBehaviour&{&&
&&&&SteamVR_TrackedObject&trackdeO&&
&&&&void&Awake()&{&&
&&&&&&&&trackdeObjec&=&GetComponent&SteamVR_TrackedObject&();&&
&&&&void&Start&()&{&&&&&
&&&&void&FixedUpdate()&&
&&&&&&&&var&device&=&SteamVR_Controller.Input((int)trackdeObjec.index);&&
&&&&&&&&&&&
&&&&&&&&if&(device.GetTouch(SteamVR_Controller.ButtonMask.Trigger))&{&&
&&&&&&&&&&&&Debug.Log("按了&&trigger&&&扳机键&");&&
&&&&&&&&&&&&&
&&&&&&&&&&&&
&&&&&&&&&&&&
&&&&&&&&&&&&var&deviceIndex2&=&SteamVR_Controller.GetDeviceIndex(SteamVR_Controller.DeviceRelation.Rightmost);&&
&&&&&&&&&&&&SteamVR_Controller.Input(deviceIndex2).TriggerHapticPulse(500);&&
&&&&&&&&}&&
&&&&&&&&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(3000);&&
&&&&&&&&&&&&&
&&&&&&&&&&&&
&&&&&&&&&&&&var&deviceIndex1&=&SteamVR_Controller.GetDeviceIndex(SteamVR_Controller.DeviceRelation.Rightmost);&&
&&&&&&&&&&&&SteamVR_Controller.Input(deviceIndex1).TriggerHapticPulse(3000);&&
&&&&&&&&}&&
&&&&&&&&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&&&扳机键&");&&
&&&&&&&&}&&
&&&&&&&&if&(device.GetTouchDown(SteamVR_Controller.ButtonMask.System))&&
&&&&&&&&{&&
&&&&&&&&&&&&Debug.Log("按下了&&system&&&系统按钮/Steam&");&&
&&&&&&&&}&&
&&&&&&&&if&(device.GetPressDown(SteamVR_Controller.ButtonMask.System))&&
&&&&&&&&{&&
&&&&&&&&&&&&Debug.Log("用press按下了&&System&&&系统按钮/Steam&");&&
&&&&&&&&}&&
&&&&&&&&if&(device.GetTouchDown(SteamVR_Controller.ButtonMask.ApplicationMenu))&&
&&&&&&&&{&&
&&&&&&&&&&&&Debug.Log("按下了&&ApplicationMenu&&&菜单键&");&&
&&&&&&&&}&&
&&&&&&&&if&(device.GetPressDown(SteamVR_Controller.ButtonMask.ApplicationMenu))&&
&&&&&&&&{&&
&&&&&&&&&&&&Debug.Log("用press按下了&&ApplicationMenu&&&菜单键&");&&
&&&&&&&&}&&
&&&&&&&&if&(device.GetTouchDown(SteamVR_Controller.ButtonMask.Grip))&&
&&&&&&&&{&&
&&&&&&&&&&&&Debug.Log("按下了&&Grip&&&&&");&&
&&&&&&&&}&&
&&&&&&&&if&(device.GetPressDown(SteamVR_Controller.ButtonMask.Grip))&&
&&&&&&&&{&&
&&&&&&&&&&&&Debug.Log("用press按下了&&Grip&&&&&");&&
&&&&&&&&}&&
&&&&&&&&&&
&&&&&&&&if&(device.GetTouchDown(SteamVR_Controller.ButtonMask.Axis0))&&
&&&&&&&&{&&
&&&&&&&&&&&&Debug.Log("按下了&&Axis0&&&方向&&");&&
&&&&&&&&}&&
&&&&&&&&if&(device.GetPressDown(SteamVR_Controller.ButtonMask.Axis0))&&
&&&&&&&&{&&
&&&&&&&&&&&&Debug.Log("用press按下了&&Axis0&&&方向&&");&&
&&&&&&&&}&&
&&&&&&&&if&(device.GetTouchDown(SteamVR_Controller.ButtonMask.Axis1))&&
&&&&&&&&{&&
&&&&&&&&&&&&Debug.Log("按下了&&Axis1&&&&&");&&
&&&&&&&&}&&
&&&&&&&&if&(device.GetPressDown(SteamVR_Controller.ButtonMask.Axis1))&&
&&&&&&&&{&&
&&&&&&&&&&&&Debug.Log("用press按下了&&Axis1&&&&&");&&
&&&&&&&&}&&
&&&&&&&&if&(device.GetTouchDown(SteamVR_Controller.ButtonMask.Axis2))&&
&&&&&&&&{&&
&&&&&&&&&&&&Debug.Log("按下了&&Axis2&&&&&");&&
&&&&&&&&}&&
&&&&&&&&if&(device.GetPressDown(SteamVR_Controller.ButtonMask.Axis2))&&
&&&&&&&&{&&
&&&&&&&&&&&&Debug.Log("用press按下了&&Axis2&&&&&");&&
&&&&&&&&}&&
&&&&&&&&if&(device.GetTouchDown(SteamVR_Controller.ButtonMask.Axis3))&&
&&&&&&&&{&&
&&&&&&&&&&&&Debug.Log("按下了&&Axis3&&&&&");&&
&&&&&&&&}&&
&&&&&&&&if&(device.GetPressDown(SteamVR_Controller.ButtonMask.Axis3))&&
&&&&&&&&{&&
&&&&&&&&&&&&Debug.Log("用press按下了&&Axis3&&&&&");&&
&&&&&&&&}&&
&&&&&&&&if&(device.GetTouchDown(SteamVR_Controller.ButtonMask.Axis4))&&
&&&&&&&&{&&
&&&&&&&&&&&&Debug.Log("按下了&&Axis4&&&&&");&&
&&&&&&&&}&&
&&&&&&&&if&(device.GetPressDown(SteamVR_Controller.ButtonMask.Axis4))&&
&&&&&&&&{&&
&&&&&&&&&&&&Debug.Log("用press按下了&&Axis4&&&&&");&&
&&&&&&&&}&&
&pre&name="code"&class="csharp"&&&&&&&&
&&&&&&&&if&(device.GetTouchDown(SteamVR_Controller.ButtonMask.Axis0))&&
&&&&&&&&{&&
&&&&&&&&&&&&Debug.Log("按下了&&Axis0&&&方向&&");&&
&&&&&&&&}&&
&&&&&&&&if&(device.GetPressDown(SteamVR_Controller.ButtonMask.Axis0))&&
&&&&&&&&{&&
&&&&&&&&&&&&Debug.Log("用press按下了&&Axis0&&&方向&&");&&
&&&&&&&&}&&
&&&&&&&&if&(device.GetTouchDown(SteamVR_Controller.ButtonMask.Axis1))&&
&&&&&&&&{&&
&&&&&&&&&&&&Debug.Log("按下了&&Axis1&&&&&");&&
&&&&&&&&}&&
&&&&&&&&if&(device.GetPressDown(SteamVR_Controller.ButtonMask.Axis1))&&
&&&&&&&&{&&
&&&&&&&&&&&&Debug.Log("用press按下了&&Axis1&&&&&");&&
&&&&&&&&}&&
&&&&&&&&if&(device.GetTouchDown(SteamVR_Controller.ButtonMask.Axis2))&&
&&&&&&&&{&&
&&&&&&&&&&&&Debug.Log("按下了&&Axis2&&&&&");&&
&&&&&&&&}&&
&&&&&&&&if&(device.GetPressDown(SteamVR_Controller.ButtonMask.Axis2))&&
&&&&&&&&{&&
&&&&&&&&&&&&Debug.Log("用press按下了&&Axis2&&&&&");&&
&&&&&&&&}&&
&&&&&&&&if&(device.GetTouchDown(SteamVR_Controller.ButtonMask.Axis3))&&
&&&&&&&&{&&
&&&&&&&&&&&&Debug.Log("按下了&&Axis3&&&&&");&&
&&&&&&&&}&&
&&&&&&&&if&(device.GetPressDown(SteamVR_Controller.ButtonMask.Axis3))&&
&&&&&&&&{&&
&&&&&&&&&&&&Debug.Log("用press按下了&&Axis3&&&&&");&&
&&&&&&&&}&&
&&&&&&&&if&(device.GetTouchDown(SteamVR_Controller.ButtonMask.Axis4))&&
&&&&&&&&{&&
&&&&&&&&&&&&Debug.Log("按下了&&Axis4&&&&&");&&
&&&&&&&&}&&
&&&&&&&&if&(device.GetPressDown(SteamVR_Controller.ButtonMask.Axis4))&&
&&&&&&&&{&&
&&&&&&&&&&&&Debug.Log("用press按下了&&Axis4&&&&&");&&
&&&&&&&&}&&
&&&&&&&&if&(device.GetTouchDown(SteamVR_Controller.ButtonMask.Touchpad))&&
&&&&&&&&{&&&&&
&&&&&&&&&&&&Debug.Log("按下了&&Touchpad&&&&&");&&
&&&&&&&&&&&&&&
&&&&&&&&&&&&
&&&&&&&&&&&&Vector2&cc&=&device.GetAxis();&&
&&&&&&&&&&&&Debug.Log(cc);&&
&&&&&&&&&&&&
&&&&&&&&&&&&float&jiaodu&=&VectorAngle(new&Vector2(1,&0),&cc);&&
&&&&&&&&&&&&Debug.Log(jiaodu);&&
&&&&&&&&&&&&
&&&&&&&&&&&&if&(jiaodu&&&45&&&&jiaodu&&&135)&&
&&&&&&&&&&&&{&&
&&&&&&&&&&&&&&&&Debug.Log("下");&&
&&&&&&&&&&&&}&&
&&&&&&&&&&&&
&&&&&&&&&&&&if&(jiaodu&&&-45&&&&jiaodu&&&-135)&&
&&&&&&&&&&&&{&&
&&&&&&&&&&&&&&&&Debug.Log("上");&&
&&&&&&&&&&&&}&&
&&&&&&&&&&&&
&&&&&&&&&&&&if&((jiaodu&&&180&&&&jiaodu&&&135)&||&(jiaodu&&&-135&&&&jiaodu&&&-180))&&
&&&&&&&&&&&&{&&
&&&&&&&&&&&&&&&&Debug.Log("左");&&
&&&&&&&&&&&&}&&
&&&&&&&&&&&&
&&&&&&&&&&&&if&((jiaodu&&&0&&&&jiaodu&&&45)&||&(jiaodu&&&-45&&&&jiaodu&&&0))&&
&&&&&&&&&&&&{&&
&&&&&&&&&&&&&&&&Debug.Log("右");&&
&&&&&&&&&&&&}&&
&&&&&&&&}&&
&&&&&&&&if&(device.GetPressDown(SteamVR_Controller.ButtonMask.Touchpad))&&
&&&&&&&&{&&
&&&&&&&&&&&&Debug.Log("用press按下了&&Touchpad&&&&&");&&
&&&&&&&&}&&
&&&&&&&&void&Update&()&{&&
&&&&float&VectorAngle(Vector2&from,&Vector2&to)&&
&&&&&&&&float&&&
&&&&&&&&Vector3&cross&=&Vector3.Cross(from,&to);&&
&&&&&&&&angle&=&Vector2.Angle(from,&to);&&
&&&&&&&&return&cross.z&&&0&?&-angle&:&&&
阅读(...) 评论()我有话说:

我要回帖

更多关于 unity3d steamvr 的文章

 

随机推荐