public void Motion(Skeleton skel)
        {
            sw.Start(); //Recording the movements begins
            Console.WriteLine("----{0}----", bvhSkeletonWritten.Bones.Count);

            for (int k = 0; k < bvhSkeletonWritten.Bones.Count; k++)
            {
                if (bvhSkeletonWritten.Bones[k].End == false)
                {
                    double[] degVec = new double[3];
                    degVec = KinectSkeletonBVH.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];
                }
            }
            //Root Bewegung
            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();
        }
        // 打开xxx.bvh 写“HIERARCHY”
        public writeBVH(string fileName)
        {
            fileName      = fileName + ".bvh";
            this.fileName = fileName;
            KinectSkeletonBVH.AddKinectSkeleton(bvhSkeleton);
            initializing     = true;
            tempOffsetMatrix = new double[3, bvhSkeleton.Bones.Count];
            tempMotionVektor = new double[bvhSkeleton.Channels];

            if (File.Exists(fileName))
            {
                File.Delete(fileName);
            }
            file = File.CreateText(fileName);
            file.WriteLine("HIERARCHY");
            recording = true;
        }
Пример #3
0
        public static double[] getBoneVectorOutofJointPosition(BVHBone bvhBone, Skeleton skel)
        {
            double[] boneVector = new double[3] {
                0, 0, 0
            };
            double[] boneVectorParent = new double[3] {
                0, 0, 0
            };
            string boneName = bvhBone.Name;

            JointType Joint;

            if (bvhBone.Root == true)
            {
                boneVector = new double[3] {
                    0, 0, 0
                };
            }
            else
            {
                if (bvhBone.IsKinectJoint == true)
                {
                    Joint = KinectSkeletonBVH.String2JointType(boneName);

                    boneVector[0] = skel.Joints[Joint].Position.X;
                    boneVector[1] = skel.Joints[Joint].Position.Y;
                    boneVector[2] = skel.Joints[Joint].Position.Z;

                    try
                    {
                        Joint = KinectSkeletonBVH.String2JointType(bvhBone.Parent.Name);
                    }
                    catch
                    {
                        Joint = KinectSkeletonBVH.String2JointType(bvhBone.Parent.Parent.Name);
                    }

                    boneVector[0] -= skel.Joints[Joint].Position.X;
                    boneVector[1] -= skel.Joints[Joint].Position.Y;
                    boneVector[2] -= skel.Joints[Joint].Position.Z;
                }
            }

            return(boneVector);
        }
 //eigentliche Schreibarbeit: 实际书写工作
 public void Entry(Skeleton skel)
 {
     this.intializingCounter++;
     for (int k = 0; k < bvhSkeleton.Bones.Count; k++)
     {
         double[] bonevector = KinectSkeletonBVH.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);
         }
     }
 }