void RecordPose(float delta, Pose p) { if (packet == null) //If this is our first packet, store the pose as the initial frame { packet = new OvrAvatarPacket(p); delta = 0; } var recorded = 0f; while (recorded < delta) { var left = delta - recorded; var inPacket = PacketDurationSec - packet.LastTime; //what if it's negative? if (left < inPacket) //If we're not going to fill the packet, just add the frame { packet.AddFrame(p, left); recorded += left; } else { // If we're going to fill the packet, interpolate the pose, send the packet, // and open a new one // Interpolate between the packet's last frame and our target pose // to compute a pose at the end of the packet time. var pose = Pose.Interpolate(packet.LastFrame, p, inPacket / left); packet.AddFrame(pose, inPacket); recorded += inPacket; PacketRecorded?.Invoke(this, new PacketEventArgs(packet)); //Broadcast the recorded packet packet = new OvrAvatarPacket(pose); //Open a new packet } } }
public Frame GetPoseFrame(float seconds) { if (frames.Count == 1) { return(frames[0]); } int id = 1; //This can be replaced with a more efficient binary search while (id < times.Count && times[id] < seconds) { ++id; } var from = times[id - 1]; var to = times[id]; var time = (seconds - from) / (to - from); return(Frame.Interpolate(frames[id - 1], frames[id], time)); }