private void SetHandPosition(Hand hand, PXCMHandData.IHand handInfo) { var imagePosition = ToPoint3D(handInfo.QueryMassCenterImage()); var worldPosition = ToPoint3D(handInfo.QueryMassCenterWorld()); hand.Position = CreatePosition(imagePosition, worldPosition); }
private void SetHandPosition(Hand hand, PXCMHandData.IHand handInfo) { var world = handInfo.QueryMassCenterWorld(); if (_smoothers.ContainsKey(hand)) { world = _smoothers[hand].SmoothValue(world); } var imagePosition = ToPoint3D(handInfo.QueryMassCenterImage()); var worldPosition = ToPoint3D(world); hand.Position = CreatePosition(imagePosition, worldPosition); }
/// <summary> 指のデータを取得する </summary> private void GetFingerData(PXCMHandData.IHand hand, PXCMHandData.JointType jointType) { PXCMHandData.JointData jointData; var sts = hand.QueryTrackedJoint(jointType, out jointData); if (sts < pxcmStatus.PXCM_STATUS_NO_ERROR) { return; } // Depth座標系をカラー座標系に変換する var depthPoint = new PXCMPoint3DF32[1]; var colorPoint = new PXCMPointF32[1]; depthPoint[0].x = jointData.positionImage.x; depthPoint[0].y = jointData.positionImage.y; depthPoint[0].z = jointData.positionWorld.z * 1000; projection.MapDepthToColor(depthPoint, colorPoint); var masp = hand.QueryMassCenterImage(); var mdp = new PXCMPoint3DF32[1]; var mcp = new PXCMPointF32[1]; mdp[0].x = masp.x; mdp[0].y = masp.y; mdp[0].z = hand.QueryMassCenterWorld().z * 1000; projection.MapDepthToColor(mdp, mcp); //Console.WriteLine(mcp[0].x); AddEllipse(new Point(mcp[0].x, mcp[0].y), 10, Brushes.Red, 1); colorPoint = mcp; //AddEllipse(new Point(colorPoint[0].x, colorPoint[0].y), 5, Brushes.White, 1); if (ensembleTimer.IsEnabled) { DetectTap(hand, mcp[0]); } //if (ensembleTimer.IsEnabled) RecogMove(hand,mcp[0]); //RecogMove(hand,mcp[0]); }
public override bool Process(Trigger trigger) { trigger.ErrorDetected = false; if (!SenseToolkitManager.Instance.IsSenseOptionSet(SenseOption.SenseOptionID.Hand)) { trigger.ErrorDetected = true; Debug.LogError("Hand Analysis Module Not Set"); return(false); } if (!(trigger is RotationTrigger || trigger is ScaleTrigger)) { trigger.ErrorDetected = true; return(false); } #region Rotation //Rotation if (trigger is RotationTrigger) { //AcquireFrame if (SenseToolkitManager.Instance.Initialized && SenseToolkitManager.Instance.HandDataOutput != null) { if (SenseToolkitManager.Instance.HandDataOutput.QueryNumberOfHands() > 1) { PXCMHandData.IHand leftHand = null; PXCMHandData.IHand rightHand = null; //Query both hands if (SenseToolkitManager.Instance.HandDataOutput.QueryHandData(PXCMHandData.AccessOrderType.ACCESS_ORDER_LEFT_HANDS, 0, out leftHand) >= pxcmStatus.PXCM_STATUS_NO_ERROR) { if (SenseToolkitManager.Instance.HandDataOutput.QueryHandData(PXCMHandData.AccessOrderType.ACCESS_ORDER_RIGHT_HANDS, 0, out rightHand) >= pxcmStatus.PXCM_STATUS_NO_ERROR) { RotationTrigger rotationTrig = (RotationTrigger)trigger; float yCurDiff = rightHand.QueryMassCenterWorld().y * 100 - leftHand.QueryMassCenterWorld().y * 100; float zCurDiff = rightHand.QueryMassCenterWorld().z * 100 - leftHand.QueryMassCenterWorld().z * 100; //Initialization if (rotationTrig.Restart) { _roll = yCurDiff; _pitch = (float)(Math.Atan2(yCurDiff, zCurDiff)); _yaw = zCurDiff; rotationTrig.Restart = false; } rotationTrig.Roll = yCurDiff - _roll; rotationTrig.Roll *= -1; if (Math.Abs(rotationTrig.Roll) < DistanceThresholdX) { rotationTrig.Roll = 0; } rotationTrig.Pitch = (float)(Math.Atan2(yCurDiff, zCurDiff) - _pitch); if (Math.Abs(rotationTrig.Pitch) < DistanceThresholdZ) { rotationTrig.Pitch = 0; } rotationTrig.Yaw = zCurDiff - _yaw; if (Math.Abs(rotationTrig.Yaw) < DistanceThresholdY) { rotationTrig.Yaw = 0; } if ((rotationTrig.Roll == rotationTrig.Yaw) && (rotationTrig.Yaw == rotationTrig.Pitch) && (rotationTrig.Pitch == 0)) { return(false); } return(true); } } } } return(false); } #endregion #region Scale //Scale if (trigger is ScaleTrigger) { //AcquireFrame if (SenseToolkitManager.Instance.Initialized && SenseToolkitManager.Instance.HandDataOutput != null) { if (SenseToolkitManager.Instance.HandDataOutput.QueryNumberOfHands() > 1) { PXCMHandData.IHand leftHand = null; PXCMHandData.IHand rightHand = null; //Query both hands if (SenseToolkitManager.Instance.HandDataOutput.QueryHandData(PXCMHandData.AccessOrderType.ACCESS_ORDER_LEFT_HANDS, 0, out leftHand) >= pxcmStatus.PXCM_STATUS_NO_ERROR) { if (SenseToolkitManager.Instance.HandDataOutput.QueryHandData(PXCMHandData.AccessOrderType.ACCESS_ORDER_RIGHT_HANDS, 0, out rightHand) >= pxcmStatus.PXCM_STATUS_NO_ERROR) { ScaleTrigger scaleTrig = (ScaleTrigger)trigger; float xCurDiff = rightHand.QueryMassCenterWorld().x * 100 - leftHand.QueryMassCenterWorld().x * 100; //Initialization if (scaleTrig.Restart) { _scale = xCurDiff; scaleTrig.Restart = false; scaleTrig.Scale = 0; } else { scaleTrig.Scale = _scale - xCurDiff; } if (Math.Abs(scaleTrig.Scale) < DistanceThresholdX) { scaleTrig.Scale = 0; return(false); } return(true); } } } } return(false); } #endregion return(false); }
/// <summary> 指のデータを取得する </summary> private bool GetFingerData(PXCMHandData.IHand hand, PXCMHandData.JointType jointType) { PXCMHandData.JointData jointData; var sts = hand.QueryTrackedJoint(jointType, out jointData); if (sts < pxcmStatus.PXCM_STATUS_NO_ERROR) { return(false); } // Depth座標系をカラー座標系に変換する var depthPoint = new PXCMPoint3DF32[1]; var colorPoint = new PXCMPointF32[1]; depthPoint[0].x = jointData.positionImage.x; depthPoint[0].y = jointData.positionImage.y; depthPoint[0].z = jointData.positionWorld.z * 1000; projection.MapDepthToColor(depthPoint, colorPoint); var masp = hand.QueryMassCenterImage(); var mdp = new PXCMPoint3DF32[1]; var mcp = new PXCMPointF32[1]; mdp[0].x = masp.x; mdp[0].y = masp.y; mdp[0].z = hand.QueryMassCenterWorld().z * 1000; projection.MapDepthToColor(mdp, mcp); //Console.WriteLine(mcp[0].x); AddEllipse(new Point(mcp[0].x, mcp[0].y), 10, Brushes.Red, 1); colorPoint = mcp; //ユーザの右手に対して演奏領域の当たり判定確認 if (hand.QueryBodySide() == PXCMHandData.BodySideType.BODY_SIDE_LEFT) { for (int i = 0; i < 5; i++) { if ((imageColor.Height / 5) * i <= colorPoint[0].y && colorPoint[0].y < (imageColor.Height / 5) * (i + 1)) { if (16 - i != NowRange) { NowRange = 16 - i; PivotList.Dispatcher.BeginInvoke( new Action(() => { PivotList.SelectedItem = NowRange; } )); } } } } //ユーザの左手に対してアイコンの当たり判定の確認 if (hand.QueryBodySide() == PXCMHandData.BodySideType.BODY_SIDE_RIGHT) { IconHitCheck(colorPoint[0]); } AddEllipse(new Point(colorPoint[0].x, colorPoint[0].y), 5, Brushes.White, 1); return(true); }