跳跃运动 - 近端骨骼到掌骨的角度(从一侧到另一侧的运动)

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

我试图获得骨骼之间的角度,例如掌骨和近端骨骼(手指左右移动的角度,例如当食指靠近拇指时的角度,你可以移动它和然后你的食指靠近你的中指的角度,你可以移动它)。

我已经尝试使用Vector3.Angle与骨骼的方向,但这不起作用,因为它包括手指的弯曲,所以如果手握拳,它给开放的手提供完全不同的值。

我真正想要的是一种我可以“正常化”的方式(我知道正常化不是正确的术语,但它是我能想到的最好的)骨骼的方向,这样即使手指弯曲,方向矢量仍然会指出向前而不是向下,但是会指向手指的方向(从一侧到另一侧)。

我在下面添加了一个图表,试图说明我的意思。

在第二个图中,蓝色代表我目前得到的东西,如果我使用骨骼的方向,绿色是掌骨方向,红色是我想要的(从侧视图)。第一个图表从上到下的视图显示了我正在寻找的内容。蓝线是掌骨方向,在这个例子中,红线是近端骨骼方向,绿色涂抹代表我正在寻找的角度。

enter image description here

enter image description here

unity3d vector rotation angle leap-motion
1个回答
0
投票

要获得此值,您需要根据当前的掌骨方向“展开”手指方向。它有点参与到最后;你必须构造一些基础向量,以便沿着右边的轴线展开手。希望这个示例脚本中的注释将解释所有内容。

using Leap;
using Leap.Unity;
using UnityEngine;

public class MeasureIndexSplay : MonoBehaviour {

  // Update is called once per frame
  void Update () {
    var hand = Hands.Get(Chirality.Right);
    if (hand != null) {
      Debug.Log(GetIndexSplayAngle(hand));
    }
  }

  // Some member variables for drawing gizmos.
  private Ray _metacarpalRay;
  private Ray _proximalRay;
  private Ray _uncurledRay;

  /// <summary>
  /// This method returns the angle of the proximal bone of the index finger relative to
  /// its metacarpal, when ignoring any angle due to the curling of the finger.
  /// 
  /// In other words, this method measures the "side-to-side" angle of the finger.
  /// </summary>
  public float GetIndexSplayAngle(Hand h) {
    var index = h.GetIndex();

    // These are the directions we care about.
    var metacarpalDir = index.bones[0].Direction.ToVector3();
    var proximalDir   = index.bones[1].Direction.ToVector3();

    // Let's start with the palm basis vectors.
    var distalAxis = h.DistalAxis(); // finger axis
    var radialAxis = h.RadialAxis(); // thumb axis
    var palmarAxis = h.PalmarAxis(); // palm axis

    // We need a basis whose forward direction is aligned to the metacarpal, so we can
    // uncurl the finger with the proper uncurling axis. The hand's palm basis is close,
    // but not aligned with any particular finger, so let's fix that.
    //
    // We construct a rotation from the palm "finger axis" to align it to the metacarpal
    // direction. Then we apply that same rotation to the other two basis vectors so
    // that we still have a set of orthogonal basis vectors.
    var metacarpalRotation = Quaternion.FromToRotation(distalAxis, metacarpalDir);
    distalAxis = metacarpalRotation * distalAxis;
    radialAxis = metacarpalRotation * radialAxis;
    palmarAxis = metacarpalRotation * palmarAxis;

    // Note: At this point, we don't actually need the distal axis anymore, and we
    // don't need to use the palmar axis, either. They're included above to clarify that
    // we're able to apply the aligning rotation to each axis to maintain a set of
    // orthogonal basis vectors, in case we wanted a complete "metacarpal-aligned basis"
    // for performing other calculations.

    // The radial axis, which has now been rotated a bit to be orthogonal to our
    // metacarpal, is the axis pointing generally towards the thumb. This is our curl
    // axis.
    // If you're unfamiliar with using directions as rotation axes, check out the images
    // here: https://en.wikipedia.org/wiki/Right-hand_rule
    var curlAxis = radialAxis;

    // We want to "uncurl" the proximal bone so that it is in line with the metacarpal,
    // when considered only on the radial plane -- this is the plane defined by the
    // direction approximately towards the thumb, and after the above step, it's also
    // orthogonal to the direction our metacarpal is facing.
    var proximalOnRadialPlane = Vector3.ProjectOnPlane(proximalDir, radialAxis);
    var curlAngle = Vector3.SignedAngle(metacarpalDir, proximalOnRadialPlane,
                                        curlAxis);

    // Construct the uncurling rotation from the axis and angle and apply it to the
    // *original* bone direction. We determined the angle of positive curl, so our
    // rotation flips its sign to rotate the other direction -- to _un_curl.
    var uncurlingRotation = Quaternion.AngleAxis(-curlAngle, curlAxis);
    var uncurledProximal = uncurlingRotation * proximalDir;

    // Upload some data for gizmo drawing (optional).
    _metacarpalRay = new Ray(index.bones[0].PrevJoint.ToVector3(),
                             index.bones[0].Direction.ToVector3());
    _proximalRay = new Ray(index.bones[1].PrevJoint.ToVector3(),
                           index.bones[1].Direction.ToVector3());
    _uncurledRay = new Ray(index.bones[1].PrevJoint.ToVector3(),
                           uncurledProximal);

    // This final direction is now uncurled and can be compared against the direction
    // of the metacarpal under the assumption it was constructed from an open hand.
    return Vector3.Angle(metacarpalDir, uncurledProximal);
  }

  // Draw some gizmos for debugging purposes.
  public void OnDrawGizmos() {
    Gizmos.color = Color.white;
    Gizmos.DrawRay(_metacarpalRay.origin, _metacarpalRay.direction);

    Gizmos.color = Color.blue;
    Gizmos.DrawRay(_proximalRay.origin, _proximalRay.direction);

    Gizmos.color = Color.red;
    Gizmos.DrawRay(_uncurledRay.origin, _uncurledRay.direction);
  }
}

对于它的价值,当食指卷曲时,跟踪的闰手在这个轴上没有很大的灵活性。

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