private void NewFrameAvailable(Frame frame)
 {
     if (NewFrame != null)
     {
         NewFrame(frame);
     }
     try
     {
         _frameBuffer.Add(frame);
         if (frame.Hands.Count > 0)
         {
             var physicsCmd = new PhysicCommand();
             foreach (var hand in frame.Hands)
             {
                 var parts = CreateHand(hand, hand.IsLeft ? JointType.HAND_LEFT : JointType.HAND_RIGHT);
                 foreach (var bodyPart in parts)
                 {
                     physicsCmd.AddCollider(bodyPart);
                 }
             }
             FireNewCommand(physicsCmd);
         }
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
     }
 }
        public PhysicCommand CreatePhysicCommand(IList<ISkeleton> newests)
        {
            var newestSkeleton = newests.First();
            var prevSkeleton = newests.Count > 1 ? newests[1] : null;
            var beforePrevSkeleton = newests.Count > 2 ? newests[2] : null;
            var command = new PhysicCommand { UserId = newests.First().ID };
            uint time1 = 1, time2 = 1;

            if (prevSkeleton != null)
            {
                time2 = newestSkeleton.Timestamp - prevSkeleton.Timestamp;
                if (beforePrevSkeleton != null)
                {
                    time1 = prevSkeleton.Timestamp - beforePrevSkeleton.Timestamp;
                }

            }
            
            foreach (var part in newestSkeleton.Joints.Where(Filter).Select(ExtractData))
            {
                if (prevSkeleton != null)
                {
                    var prevJoint = prevSkeleton.GetJoint((JointType) part.Id);
                    part.Velocity = CalculateVelocity(prevJoint.Point, part.Position, time2);
                    if (beforePrevSkeleton != null)
                    {
                        var beforePrevJoint = beforePrevSkeleton.GetJoint((JointType)part.Id);
                        part.Acceleration = CalculateAcceleration(beforePrevJoint.Point, prevJoint.Point, part.Position, time1, time2);
                    }
                }
                
                command.AddCollider(part);
            }

            return command;
        }