Beispiel #1
0
        public void BodyFrameUpdate(HolofunKinect kinect)
        {
            // thread-safe operation: snapshot current sample time
            Moment now = HolofunkModel.Clock.Now;

            // get the head position
            Vector2 headPosition = kinect.GetJointViewportPosition(PlayerIndex, Microsoft.Kinect.JointType.Head);

            // need to find a rectangle centered on headPosition that doesn't cross the viewport edge
            Rectangle rect = new Rectangle(
                (int)headPosition.X - MagicNumbers.HeadCaptureSize / 2,
                (int)headPosition.Y - MagicNumbers.HeadCaptureSize / 2,
                MagicNumbers.HeadCaptureSize,
                MagicNumbers.HeadCaptureSize);

            if (rect.X < 0) {
                rect.Offset(new Point(-rect.X, 0));
            }
            if (rect.Y < 0) {
                rect.Offset(new Point(0, -rect.Y));
            }
            if (rect.Right > kinect.ViewportSize.X) {
                rect.Offset(new Point((int)kinect.ViewportSize.X - rect.Right, 0));
            }
            if (rect.Bottom > kinect.ViewportSize.Y) {
                rect.Offset(new Point(0, (int)kinect.ViewportSize.Y - rect.Bottom));
            }

            int startOffset = rect.X * 4;
            if (rect.Y > 0) {
                startOffset += (rect.Y - 1) * kinect.DisplayTexture.Width * 4;
            }

            // if we are recording, get the head position
            // this method and the regular hand event handling are both called on Kinect thread,
            // so no need to worry about races on this field
            lock (m_recorders) {
                if (m_recorders.Count > 0) {
                    lock (kinect.DisplayTextureBuffer) {
                        // loop from end to start, so we can remove recorders in mid-iteration
                        for (int i = m_recorders.Count - 1; i >= 0; i--) {
                            bool done = m_recorders[i].Record(
                                now.Time,
                                kinect.DisplayTextureBuffer,
                                startOffset,
                                rect.Width * 4, // * 4 because RGBA
                                kinect.DisplayTexture.Width * 4,
                                rect.Height);

                            if (done) {
                                m_recorders.RemoveAt(i);
                            }
                        }
                    }
                }
            }
        }
        /// <summary>Update the scene's background based on the current beat, and the positions of
        /// the two hands based on the latest data polled from Kinect.</summary>
        /// <remarks>We pass in the current value of "now" to ensure consistent
        /// timing between the PlayerState update and the scene graph udpate.</remarks>
        internal void Update(
            PlayerModel playerState,
            HolofunKinect kinect,
            Moment now)
        {
            m_headGroup.LocalTransform = new Transform(
                kinect.GetJointViewportPosition(PlayerIndex, JointType.Head) + MagicNumbers.ScreenHandAdjustment,
                new Vector2(1f));

            m_headMikeSignal.Update(now, false, playerState.PlayerColor);

            m_leftHandSceneGraph.Update(playerState.LeftHandModel, kinect, now);
            m_rightHandSceneGraph.Update(playerState.RightHandModel, kinect, now);
        }
        internal void Update(PlayerHandModel playerHandModel, HolofunKinect kinect, Moment now)
        {
            // The position adjustment here is purely ad hoc -- the depth image still
            // doesn't line up well with the skeleton-to-depth-mapped hand positions.
            m_handGroup.LocalTransform = new Transform(
                kinect.GetJointViewportPosition(
                    playerHandModel.PlayerModel.PlayerIndex,
                    playerHandModel.IsRightHand ? JointType.HandRight : JointType.HandLeft) + MagicNumbers.ScreenHandAdjustment,
                new Vector2(MagicNumbers.LoopieScale));

            // and make the mike signal update appropriately
            m_handMikeSignal.Update(now, false, playerHandModel.PlayerModel.PlayerColor);

            if (m_effectLabelShownMoment.HasValue) {
                Duration<Sample> elapsed = now.Time - m_effectLabelShownMoment.Value.Time;
                Color color = new Color(0, 0, 0, 0);
                if (elapsed > MagicNumbers.EffectLabelFadeDuration) {
                    m_effectLabelShownMoment = Option<Moment>.None;
                }
                else {
                    float fraction = 1f - ((float)(long)elapsed / MagicNumbers.EffectLabelFadeDuration);
                    color = Alpha(fraction);
                }
                m_effectLabels[0].Color = color;
                m_effectLabels[1].Color = color;
                m_effectLabels[2].Color = color;
                m_effectLabels[3].Color = color;
            }

            // Debugging elbow arm pose label.
            ArmPose armPose = kinect.GetArmPose(m_parent.PlayerIndex, m_isRight ? Side.Right : Side.Left);
            m_armPoseLabel.Text.Clear();
            m_armPoseLabel.Text.Append(
                armPose == ArmPose.AtChest ? "Chest"
                : armPose == ArmPose.AtMouth ? "Mouth"
                : armPose == ArmPose.OnHead ? "Head"
                : "");
            m_armPoseLabel.LocalTransform = new Transform(
                kinect.GetJointViewportPosition(m_parent.PlayerIndex, m_isRight ? JointType.HandRight : JointType.HandLeft)
                    + new Vector2(0, 50),
                new Vector2(0.7f));
        }