bool ISnapshotArgs.IsApproximate(ISnapshotArgs snapshot) { var s = (RigidBodySnapshot)snapshot; // TODO: Allow custom configuration of error var distanceSquared = Vector3.DistanceSquared(Position, s.Position); if (distanceSquared > 0.01f * 0.01f) { logger.Debug("Position error detected: {0}, Left: {1}, Right: {2}", distanceSquared, Position, s.Position); return(false); } var angle = (Rotation * Quaternion.Invert(s.Rotation)).Angle; if (angle > 1 / 180f * Math.PI) { logger.Debug("Rotation error detected: {0}, Left: {1}, Right: {2}", angle, Rotation, s.Rotation); return(false); } return(true); }
bool ISnapshotArgs.IsApproximate(ISnapshotArgs snapshot) { var otherSnapshot = (SimulatorSnapshot)snapshot; if (Actors.Count != otherSnapshot.Actors.Count) { return(false); } Actors.Sort(SortByActorId); otherSnapshot.Actors.Sort(SortByActorId); for (int i = 0; i < Actors.Count; i++) { var selfActor = Actors[i]; var otherActor = otherSnapshot.Actors[i]; if (selfActor.Desc.Id != otherActor.Desc.Id) { return(false); } if (!selfActor.Args.IsApproximate(otherActor.Args)) { return(false); } } return(true); }
ISnapshotArgs ISnapshotArgs.Interpolate(ISnapshotArgs snapshot, float factor) { if (factor >= 1) { return(snapshot.Clone()); } else { return(((ISnapshotArgs)this).Clone()); } }
protected internal override void OnSnapshotRecovered(ISnapshotArgs snapshot) { base.OnSnapshotRecovered(snapshot); var s = (RigidBodySnapshot)snapshot; rigidBody.CenterOfMassTransform = Matrix.RotationQuaternion(s.Rotation) * Matrix.Translation(s.Position); rigidBody.LinearVelocity = s.LinearVelocity; rigidBody.AngularVelocity = s.AngularVelocity; logger.Debug("Rigidbody recovered for {0}. {1}", this, s); }
ISnapshotArgs ISnapshotArgs.Interpolate(ISnapshotArgs snapshot, float factor) { var s = (RigidBodySnapshot)snapshot; return(new RigidBodySnapshot() { Position = Vector3.Lerp(Position, s.Position, factor), Rotation = Quaternion.Slerp(Rotation, s.Rotation, factor), // TODO: Is it meaningful to get interpolated velocities? LinearVelocity = Vector3.Lerp(LinearVelocity, s.LinearVelocity, factor), AngularVelocity = Vector3.Lerp(AngularVelocity, s.AngularVelocity, factor), }); }
ISnapshotArgs ISnapshotArgs.Interpolate(ISnapshotArgs snapshot, float factor) { var otherSnapshot = (SimulatorSnapshot)snapshot; var newSnapshot = new SimulatorSnapshot(); foreach (var selfActor in Actors) { var otherActor = otherSnapshot.Actors.Find(a => a.Desc.Id == selfActor.Desc.Id); if (otherActor != null) { var newActor = selfActor.Args.Interpolate(otherActor.Args, factor); newSnapshot.Actors.Add(new ActorSnapshot(selfActor.Desc, newActor)); } else { newSnapshot.Actors.Add(new ActorSnapshot(selfActor.Desc, selfActor.Args.Clone())); } } return(newSnapshot); }
bool ISnapshotArgs.IsApproximate(ISnapshotArgs snapshot) { var otherActors = ((SceneSnapshot)snapshot).Actors; if (Actors.Count != otherActors.Count) { return(false); } Actors.Sort(); otherActors.Sort(); for (int i = 0; i < Actors.Count; i++) { if (Actors[i] != otherActors[i]) { return(false); } } return(true); }
public Timepoint AddPoint(int time, ISnapshotArgs snapshot) { if (points.Last != null) { if (time < points.Last.Value.Time) { throw new ArgumentException(string.Format("'time' must > {0}", points.Last.Value.Time)); } if (time == points.Last.Value.Time) { points.Last.Value.Snapshot = snapshot; return(points.Last.Value); } } var point = new Timepoint(this, time, snapshot); points.AddLast(point); return(point); }
public ActorSnapshot(ActorDesc actorDesc, ISnapshotArgs args) { Desc = actorDesc; Args = args; }
public Timepoint(Timeline timeline, int time, ISnapshotArgs snapshot) { this.timeline = timeline; this.time = time; this.snapshot = snapshot; }
protected internal virtual void OnSnapshotRecovered(ISnapshotArgs snapshot) { Snapshot = snapshot; }
internal virtual void Initialize(ActorContext context, ActorDesc desc) { this.context = context; this.desc = desc; this.snapshot = desc.InitSnapshot(); }