Beispiel #1
0
 public Window()
 {
     InitializeComponent();
     KTimer.SetupTimer();
     AnimationManager               = AnimPanel.AnimationManager;
     SensorManager                  = KinectPanel.Sensor;
     SensorManager.StatusChanged   += new EventHandler(EVENT_Kinect_StatusChanged);
     SensorManager.TrackingChanged += new EventHandler(EVENT_Kinect_TrackingChanged);
     LKinectStatus.Text             = KKinectHelper.GetDeviceStatusDesc(SensorManager.Status);
 }
Beispiel #2
0
        void DoUpdate()
        {
            float time = KTimer.GetElapsedTime();

            // Licznik FPS
            Timer_TotalTime += time;
            Timer_FPSCount++;
            if (Timer_TotalTime > 1.0f)
            {
                RenderingPanel.SetFPS(Timer_FPSCount);
                Timer_TotalTime -= 1.0f;
                Timer_FPSCount   = 0;
            }

            if (model != null && AnimationManager != null)
            {
                if (AnimationManager.IsAnimationLoaded)
                {
                    if (AnimationManager.IsPlaying)
                    {
                        AnimationManager.Update(time);
                    }

                    if (prevFrame != AnimationManager.CurrentFrame || AnimationManager.IsPlaying)
                    {
                        KeyFrame frame = AnimationManager.GetActualFrame();
                        model.UpdateTransform(frame.Bones);
                        BonePanel.Update(frame.Bones);
                        prevFrame = AnimationManager.CurrentFrame;
                    }
                }
                else
                {
                    if (SensorManager != null)
                    {
                        if (SensorManager.IsRunning())
                        {
                            // Szkielet
                            VBone[]  bones = KMeshHelper.CopyBones(model.GetBones());
                            Skeleton skel  = SensorManager.GetSkeletonFrame();

                            if (skel != null && model != null)
                            {
                                KJointType[] JointList = BonePanel.BoneConnections.ToArray();

                                for (int i = 0; i < bones.Length; i++)
                                {
                                    if (JointList[i] != KJointType.None)
                                    {
                                        JointType ktype = (JointType)JointList[i];
                                        if (skel.Joints[ktype].TrackingState == JointTrackingState.Tracked)
                                        {
                                            Quaternion rotation = KKinectHelper.RecalculateKinectJointOrientation(ktype, skel);

                                            if (bones[i].ParentIndex == -1) // Gdy kość root
                                            {
                                                rotation.W *= -1;
                                                if (!RootBoneScaleSet)
                                                {
                                                    RootBoneScale      = bones[i].BonePos.Position.Z / skel.Joints[ktype].Position.Y; // KINECT.Y == XNA.Z
                                                    DistanceFromSensor = skel.Joints[ktype].Position.Z;
                                                    RootBoneScaleSet   = true;
                                                }
                                                bones[i].BonePos.Position.X = skel.Joints[ktype].Position.X * RootBoneScale;
                                                bones[i].BonePos.Position.Y = (skel.Joints[ktype].Position.Z - DistanceFromSensor) * RootBoneScale;
                                                bones[i].BonePos.Position.Z = skel.Joints[ktype].Position.Y * RootBoneScale;
                                            }

                                            bones[i].BonePos.Orientation = rotation;
                                        }
                                    }
                                }
                                model.UpdateTransform(bones);
                                BonePanel.Update(bones);
                            }

                            if (AnimationManager.IsRecording)
                            {
                                Timer_RecordTime += time;
                                if (Timer_RecordTime > AnimationManager.StepTime)
                                {
                                    KeyFrame key = new KeyFrame();
                                    key.Time  = AnimationManager.StepTime * (AnimationManager.GetFrameCount() + 1);
                                    key.Bones = bones;
                                    AnimationManager.AddKeyFrame(key);
                                    Timer_RecordTime -= AnimationManager.StepTime;
                                }
                            }
                        }
                    }
                }
            }
        }