public void SetLookatFrame(TrackingShot shot = null) { var worldmat = OriginalLocalMatrix * Entity.Parent.WorldMatrix; var target = worldmat.Translation + worldmat.Forward * SettingsStore.Get(Entity, "focus_distance", 1.0f); var info = new TrackingInfo(); info.Transition = keyframe_mode; if (view_locked_to != null) { info.Mode = TrackMode.Locked; info.Entity = view_locked_to; info.Value3D = Vector3D.Transform(target, MatrixD.Invert(view_locked_to.WorldMatrix)); } else { info.Mode = TrackMode.Unlocked; info.Value3D = target; } if (shot == null) { shot = Load(); shot.lookat_timeline.AddKeyframe(frame, info); Save(shot); } else { shot.lookat_timeline.AddKeyframe(frame, info); } }
public void SetUpFrame(TrackingShot shot = null) { var worldmat = OriginalLocalMatrix * Entity.Parent.WorldMatrix; var upvec = worldmat.Up; // TODO var info = new TrackingInfo(); info.Transition = keyframe_mode; if (pos_locked_to != null) { info.Mode = TrackMode.Locked; info.Entity = pos_locked_to; info.Value3D = Vector3D.TransformNormal(upvec, pos_locked_to.WorldMatrixNormalizedInv); } else { info.Mode = TrackMode.Unlocked; info.Value3D = upvec; } if (shot == null) { shot = Load(); shot.upvec_timeline.AddKeyframe(frame, info); Save(shot); } else { shot.upvec_timeline.AddKeyframe(frame, info); } }
public void SetPosFrame(TrackingShot shot = null) { var worldmat = OriginalLocalMatrix * Entity.Parent.WorldMatrix; var pos = worldmat.Translation; var info = new TrackingInfo(); info.Transition = keyframe_mode; if (pos_locked_to != null) { info.Mode = TrackMode.Locked; info.Entity = pos_locked_to; info.Value3D = Vector3D.Transform(pos, MatrixD.Invert(pos_locked_to.WorldMatrix)); } else { info.Mode = TrackMode.Unlocked; info.Value3D = pos; } MyLog.Default.WriteLine(String.Format("set pos frame <{0},{1},{2}>", info.Value3D.X, info.Value3D.Y, info.Value3D.Z)); if (shot == null) { shot = Load(); shot.position_timeline.AddKeyframe(frame, info); Save(shot); } else { shot.position_timeline.AddKeyframe(frame, info); } }
public void Pause() { playing_shot = null; view_locked = true; // Stop -> Pause: lock // sync frame now that it's no longer changing 60 times per second SettingsStore.Set(Entity, "frame", frame); }
public void UpdateView(TrackingShot shot = null) { if (shot == null) { shot = Load(); } MatrixD proper_worldmat = OriginalLocalMatrix * Entity.Parent.WorldMatrix; Vector3D position = Vector3D.Zero; Vector3D lookat = Vector3D.Zero; Vector3D upvec = Vector3D.Zero; if (!shot.position_timeline.Empty) { position = shot.position_timeline.Evaluate(frame, false); } else { position = proper_worldmat.Translation; } if (!shot.lookat_timeline.Empty) { if (!shot.position_timeline.Empty) { lookat = shot.lookat_by_position_timeline.Evaluate(frame, false); } else { lookat = shot.lookat_timeline.Evaluate(frame, false); } } else { lookat = proper_worldmat.Translation + proper_worldmat.Forward * SettingsStore.Get(Entity, "focus_distance", 1.0f); } if (!shot.upvec_timeline.Empty) { upvec = shot.upvec_timeline.Evaluate(frame, true); } else { upvec = proper_worldmat.Up; } // WorldMatrix: Block space -> World space // CreateWorld: Target space -> World space // needed: Block space -> Target space // CreateWorld * WorldMatrix^-1: Target space -> Block space // local mat: Block space -> Grid space // wanted local mat: Target space -> Grid space var mat = MatrixD.CreateWorld(position, lookat - position, upvec) * MatrixD.Invert(proper_worldmat); // MyLog.Default.WriteLine(String.Format("lmat = {0}", mat)); Entity.SetLocalMatrix(mat * OriginalLocalMatrix); }
public void Play() { view_locked = true; // force view to camera if (playing_shot == null) { playing_shot = Load(); } }
public void Save(TrackingShot shot) { var builder = new StringBuilder(); builder.Append("Position: "); builder.Append(shot.position_timeline.Serialize()); builder.Append(", LookAt: "); builder.Append(shot.lookat_timeline.Serialize()); builder.Append(", UpVec: "); builder.Append(shot.upvec_timeline.Serialize()); SettingsStore.Set(Entity, "shot", builder.ToString()); }