当前位置: 首页>>代码示例>>C#>>正文


C# Controller.frame方法代码示例

本文整理汇总了C#中Controller.frame方法的典型用法代码示例。如果您正苦于以下问题:C# Controller.frame方法的具体用法?C# Controller.frame怎么用?C# Controller.frame使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Controller的用法示例。


在下文中一共展示了Controller.frame方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: onFrame

    public override void onFrame(Controller controller)
    {
        // Get the most recent frame and report some basic information
        Frame frame = controller.frame();
        HandArray hands = frame.hands();
        int numHands = hands.Count;
        SafeWriteLine("Frame id: " + frame.id()
                + ", timestamp: " + frame.timestamp()
                + ", hands: " + numHands);

        if (numHands >= 1) {
          // Get the first hand
          Hand hand = hands[0];

          // Check if the hand has any fingers
          FingerArray fingers = hand.fingers();
          int numFingers = fingers.Count;
          if (numFingers >= 1) {
        // Calculate the hand's average finger tip position
        Vector pos = new Vector(0, 0, 0);
        foreach (Finger finger in fingers) {
          Ray tip = finger.tip();
          pos.x += tip.position.x;
          pos.y += tip.position.y;
          pos.z += tip.position.z;
        }
        pos = new Vector(pos.x/numFingers, pos.y/numFingers, pos.z/numFingers);
        SafeWriteLine("Hand has " + numFingers + " fingers with average tip position"
                    + " (" + pos.x.ToString("n2") + ", " + pos.y.ToString("n2")
                    + ", " + pos.z.ToString("n2") + ")");
          }

          // Check if the hand has a palm
          Ray palmRay = hand.palm();
          if (palmRay != null) {
        // Get the palm position and wrist direction
        Vector palm = palmRay.position;
        Vector wrist = palmRay.direction;
        SafeWriteLine("Palm position: (" + palm.x.ToString("n2") + ", "
                                         + palm.y.ToString("n2") + ", "
                                         + palm.z.ToString("n2") + ")");

        // Check if the hand has a normal vector
        Vector normal = hand.normal();
        if (normal != null) {
          // Calculate the hand's pitch, roll, and yaw angles
          double pitchAngle = Math.Atan2(normal.z, normal.y) * 180/Math.PI + 180;
          double rollAngle = Math.Atan2(normal.x, normal.y) * 180/Math.PI + 180;
          double yawAngle = Math.Atan2(wrist.z, wrist.x) * 180/Math.PI - 90;
          // Ensure the angles are between -180 and +180 degrees
          if (pitchAngle > 180) pitchAngle -= 360;
          if (rollAngle > 180) rollAngle -= 360;
          if (yawAngle > 180) yawAngle -= 360;
          SafeWriteLine("Pitch: " + pitchAngle.ToString("n0") + " degrees,  "
                      + "roll: " + rollAngle.ToString("n0") + " degrees,  "
                      + "yaw: " + yawAngle.ToString("n0") + " degrees");
        }
          }

          // Check if the hand has a ball
          Ball ball = hand.ball();
          if (ball != null) {
        SafeWriteLine("Hand curvature radius: " + ball.radius.ToString("n2") + " mm");
          }
        }
    }
开发者ID:hbradlow,项目名称:LeapConductor,代码行数:66,代码来源:Sample.cs


注:本文中的Controller.frame方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。