Пример #1
0
        // Przyciski górnego menu
        private void EVENT_ButtonLoadPSA(object sender, EventArgs e)
        {
            OpenFileDialog openFile = new OpenFileDialog();

            openFile.Filter = "PSA Animation File|*.psa";
            openFile.Title  = "Select a Animation File";
            if (openFile.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                if (model == null)
                {
                    return;
                }
                AnimationManager.AnimationLoad(openFile.FileName);
                KeyFrame frame = AnimationManager.GetActualFrame();
                model.UpdateTransform(frame.Bones);
                BonePanel.Update(frame.Bones);
            }
        }
Пример #2
0
        private void EVENT_ButtonLoadPSK(object sender, EventArgs e)
        {
            OpenFileDialog openFile = new OpenFileDialog();

            openFile.Filter = "PSK File|*.psk";
            openFile.Title  = "Select a Skeletal Mesh File";
            if (openFile.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                model = KFile.LoadPSK(RenderingPanel.Renderer.device, openFile.FileName);
                RenderingPanel.SetMesh(model);
                if (model != null)
                {
                    BonePanel.SetData(model.GetBones());
                    menu_animload.Enabled      = true;
                    menu_animsave.Enabled      = true;
                    menu_modelmaterial.Enabled = true;
                    AnimPanel.Enabled          = true;
                }
            }
        }
Пример #3
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;
                                }
                            }
                        }
                    }
                }
            }
        }