当用户使用虚拟现实中的Leap Motion双手旋转对象时,如何触发事件?

问题描述 投票:2回答:2

我是Virtual Reality的新手。我正在使用Oculus Rift for Headset和Leap Motion进行交互。当用户用手旋转对象时,我希望触发特定事件。

这是我的代码:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class step1 : MonoBehaviour
{

    public GameObject object;
    public ParticleSystem event;


    void Start()
    {
    }

    // Update is called once per frame
    void Update()
    {
        if(object.transform.rotation == Quaternion.AngleAxis(-30,Vector3.right))
        {
            Debug.Log("Done");
            event.Play();   
        }
    }
}
unity3d virtual-reality oculus leap-motion
2个回答
1
投票

请注意,因为四元数可以表示最多两个完整旋转(720度)的旋转,所以即使结果旋转看起来相同,此比较也可以返回false。

来自Quaternion.operator == Unity Docs

我会避免全部使用四元数,因为它们很难缠绕你的头并且使用起来很笨拙。

尝试使用Vector3表示与eulerAngles,然后测试近似等于这样的值:

//only checks for one axis!
if(Math.Abs(rotationA.eulerAngles.x - rotationB.eulerAngles.x) <= maxDifference)
{
    //do stuff
}

或坚持使用Quaternion.Angle但使用它像这样:

//compares angle directly
if(Math.Abs(Quaternion.Angle(rotationA, rotationB)) <= maxDifference)
{
    //do stuff
}

内部有三个Vector3值的floatconsists和Quaternion.Angle返回float值。在99%的情况下,比较它们的确切平等并不起作用。将它们与您可以接受的最大差异进行比较,它应该可以工作。


0
投票

你想要开火吗?

  1. 当用户第一次开始旋转对象时
  2. 在用户旋转对象时不断发射
  3. 当用户完成旋转对象时

顺便说一句,你不必只选择其中一个

目前你的实现只会在你的对象具有特定的旋转时触发事件是什么预期的行为?

© www.soinside.com 2019 - 2024. All rights reserved.