Esempio n. 1
0
        public void Motion(Skeleton skel)
        {
            sw.Start(); // Begin recording movements

            for (int k = 0; k < bvhSkeletonWritten.Bones.Count; k++)
            {
                if (bvhSkeletonWritten.Bones[k].End == false)
                {
                    double[] degVec = new double[3];
                    degVec = BVHKinectSkeleton.GetEulerFromBone(bvhSkeletonWritten.Bones[k], skel);

                    int indexOffset = 0;
                    if (bvhSkeletonWritten.Bones[k].Root == true)
                    {
                        indexOffset = 3;
                    }

                    tempMotionVektor[bvhSkeletonWritten.Bones[k].MotionSpace + indexOffset]     = degVec[0];
                    tempMotionVektor[bvhSkeletonWritten.Bones[k].MotionSpace + 1 + indexOffset] = degVec[1];
                    tempMotionVektor[bvhSkeletonWritten.Bones[k].MotionSpace + 2 + indexOffset] = degVec[2];

                    // set Textbox
                    string boneName = bvhSkeletonWritten.Bones[k].Name;
                    if (boneName == bvhEditor.DropDownJoint)
                    {
                        // Rotation
                        string textBox = Math.Round(degVec[0], 1).ToString() + " " + Math.Round(degVec[1], 1).ToString() + " " + Math.Round(degVec[2], 1).ToString();
                        bvhEditor.TextBoxAngles = textBox;

                        // Position
                        JointType KinectJoint = BVHKinectSkeleton.GetJointTypeFromBVHBone(bvhSkeletonWritten.Bones[k]);
                        double    x           = skel.Joints[KinectJoint].Position.X;
                        double    y           = skel.Joints[KinectJoint].Position.Y;
                        double    z           = skel.Joints[KinectJoint].Position.Z;
                        bvhEditor.TextPosition = Math.Round(x, 2).ToString() + " " + Math.Round(y, 2).ToString() + " " + Math.Round(z, 2).ToString();

                        // Length
                        BVHBone  tempBone = bvhSkeletonWritten.Bones.Find(i => i.Name == KinectJoint.ToString());
                        double[] boneVec  = BVHKinectSkeleton.GetBoneVectorOutofJointPosition(tempBone, skel);
                        double   length   = Math.Sqrt(Math.Pow(boneVec[0], 2) + Math.Pow(boneVec[1], 2) + Math.Pow(boneVec[2], 2));
                        length = Math.Round(length, 2);
                        bvhEditor.TextBoxLength = length.ToString();
                    }
                }
            }
            // Root motion
            tempMotionVektor[0] = -Math.Round(skel.Position.X * 100, 2);
            tempMotionVektor[1] = Math.Round(skel.Position.Y * 100, 2) + 120;
            tempMotionVektor[2] = 300 - Math.Round(skel.Position.Z * 100, 2);

            WriteMotion(tempMotionVektor);
            file.Flush();

            elapsedTimeSec = Math.Round(Convert.ToDouble(sw.ElapsedMilliseconds) / 1000, 2);
            bvhEditor.TextBoxElapsedTime    = elapsedTimeSec.ToString();
            bvhEditor.TextBoxCapturedFrames = frameCounter.ToString();
            avgFrameRate = Math.Round(frameCounter / elapsedTimeSec, 2);
            bvhEditor.TextBoxFrameRate = avgFrameRate.ToString();
        }
Esempio n. 2
0
 public void Entry(Skeleton skel)
 {
     this.intializingCounter++;
     for (int k = 0; k < bvhSkeleton.Bones.Count; k++)
     {
         double[] bonevector = BVHKinectSkeleton.GetBoneVectorOutofJointPosition(bvhSkeleton.Bones[k], skel);
         {
             if (this.intializingCounter == 1)
             {
                 tempOffsetMatrix[0, k] = Math.Round(bonevector[0] * 100, 2);
                 tempOffsetMatrix[1, k] = Math.Round(bonevector[1] * 100, 2);
                 tempOffsetMatrix[2, k] = Math.Round(bonevector[2] * 100, 2);
             }
             else
             {
                 tempOffsetMatrix[0, k] = (this.intializingCounter * tempOffsetMatrix[0, k] + Math.Round(bonevector[0] * 100, 2)) / (this.intializingCounter + 1);
                 tempOffsetMatrix[1, k] = (this.intializingCounter * tempOffsetMatrix[1, k] + Math.Round(bonevector[1] * 100, 2)) / (this.intializingCounter + 1);
                 tempOffsetMatrix[2, k] = (this.intializingCounter * tempOffsetMatrix[1, k] + Math.Round(bonevector[2] * 100, 2)) / (this.intializingCounter + 1);
             }
         }
     }
 }