Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question Use quaternion to determine rotation direction - Leap motion controller

Discussion in 'AR' started by OffTheBear, Aug 20, 2023.

  1. OffTheBear


    Jan 12, 2022
    Hey guys i am trying to use quaternion data (specifically Quaternion Bone Rotation) from leap motion controller to determine if the user is rotating their hand to the left or right.
    I want the user to lift their hand up where all fingers face the -Y axis and rotate their hand along the Y-axis; i should get a change in yaw angle so that positive values indicate a left turn (counterclockwise) while negative values indicate a right turn (clockwise)
    However, I encountered an issue: the delta yaw angles are very small: eg 0.001986674, 0.009016895, and -0.003356934 and they fluctuate a lot.
    Here is my code:
    Code (CSharp):
    1.  Bone _indexMetacarpal = _index.Bone(Bone.BoneType.TYPE_METACARPAL);
    2.                     Quaternion boneRotation = _indexMetacarpal.Rotation;
    3.                     Vector3 currentEulerAngle = boneRotation.eulerAngles;
    4.                     Vector3 deltaEulerAngle = currentEulerAngle - previousBoneRotation.eulerAngles;
    5.                     if (deltaEulerAngle.y > 0)
    6.                     {
    7.                         Debug.Log("LEFT");
    8.                     }
    9.                     else if(deltaEulerAngle.y < 0)
    10.                     {
    11.                         Debug.Log("RIGHT");
    12.                     }
    14.                     previousBoneRotation = boneRotation;
    What went wrong here? Should i use deltaEulerAngle.z instead of y because of how the hand is positioned?