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 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 TrackingShot Load() { string shotstr = SettingsStore.Get <string>(Entity, "shot", null); if (shotstr == null) { return(new TrackingShot()); } var parser = new RDParser(shotstr); parser.Expect("Position"); parser.Expect(":"); var position_timeline = Timeline.Deserialize(parser); parser.Expect(","); parser.Expect("LookAt"); parser.Expect(":"); var lookat_timeline = Timeline.Deserialize(parser); parser.Expect(","); parser.Expect("UpVec"); parser.Expect(":"); var upvec_timeline = Timeline.Deserialize(parser); parser.End(); return(new TrackingShot(position_timeline, lookat_timeline, upvec_timeline)); }
private async void LoadSettings() { var gs = await SettingsStore.Get(); foreach (var item in gs.GetType().GetTypeInfo().DeclaredProperties) { item.SetValue(this, item.GetValue(gs)); } }
TrackingShot playing_shot = null; // when playing, this will be non-null public void InitLate() { block_initialized = true; frame = SettingsStore.Get(Entity, "frame", 0); OriginalLocalMatrix = Entity.LocalMatrix; if (!CameraUI.initialized) { CameraUI.InitLate(); } }
public static void InitLate() { initialized = true; nextFrameAction = MyAPIGateway.TerminalControls.CreateAction <IMyCameraBlock>("Camera_NextFrame"); nextFrameAction.Name = new StringBuilder("Next Frame"); nextFrameAction.Action = ActionNextFrame; nextFrameAction.Writer = FrameNumWriterGen("+1"); MyAPIGateway.TerminalControls.AddAction <IMyCameraBlock>(nextFrameAction); prevFrameAction = MyAPIGateway.TerminalControls.CreateAction <IMyCameraBlock>("Camera_PrevFrame"); prevFrameAction.Name = new StringBuilder("Prev Frame"); prevFrameAction.Action = ActionPrevFrame; prevFrameAction.Writer = FrameNumWriterGen("-1"); MyAPIGateway.TerminalControls.AddAction <IMyCameraBlock>(prevFrameAction); nextFrame10Action = MyAPIGateway.TerminalControls.CreateAction <IMyCameraBlock>("Camera_NextFrame10"); nextFrame10Action.Name = new StringBuilder("Next Frame +10"); nextFrame10Action.Action = ActionNextFrame10; nextFrame10Action.Writer = FrameNumWriterGen("+10"); MyAPIGateway.TerminalControls.AddAction <IMyCameraBlock>(nextFrame10Action); prevFrame10Action = MyAPIGateway.TerminalControls.CreateAction <IMyCameraBlock>("Camera_PrevFrame10"); prevFrame10Action.Name = new StringBuilder("Prev Frame -10"); prevFrame10Action.Action = ActionPrevFrame10; prevFrame10Action.Writer = FrameNumWriterGen("-10"); MyAPIGateway.TerminalControls.AddAction <IMyCameraBlock>(prevFrame10Action); nextKeyFrameAction = MyAPIGateway.TerminalControls.CreateAction <IMyCameraBlock>("Camera_NextKeyFrame"); nextKeyFrameAction.Name = new StringBuilder("Next Keyframe"); nextKeyFrameAction.Action = ActionNextKeyFrame; nextKeyFrameAction.Writer = FrameNumWriterGen("+K"); MyAPIGateway.TerminalControls.AddAction <IMyCameraBlock>(nextKeyFrameAction); prevKeyFrameAction = MyAPIGateway.TerminalControls.CreateAction <IMyCameraBlock>("Camera_PrevKeyFrame"); prevKeyFrameAction.Name = new StringBuilder("Prev Keyframe"); prevKeyFrameAction.Action = ActionPrevKeyFrame; prevKeyFrameAction.Writer = FrameNumWriterGen("-K"); MyAPIGateway.TerminalControls.AddAction <IMyCameraBlock>(prevKeyFrameAction); playAction = MyAPIGateway.TerminalControls.CreateAction <IMyCameraBlock>("Camera_Play"); playAction.Name = new StringBuilder("Play"); playAction.Action = ActionPlay; playAction.Writer = ConditionToggleWriterGen((cam) => cam.PlaybackState == PlaybackMode.Playing, "Play"); MyAPIGateway.TerminalControls.AddAction <IMyCameraBlock>(playAction); pauseAction = MyAPIGateway.TerminalControls.CreateAction <IMyCameraBlock>("Camera_Pause"); pauseAction.Name = new StringBuilder("Pause"); pauseAction.Action = ActionPause; pauseAction.Writer = ConditionToggleWriterGen((cam) => cam.PlaybackState == PlaybackMode.Paused, "Paus"); MyAPIGateway.TerminalControls.AddAction <IMyCameraBlock>(pauseAction); playPauseAction = MyAPIGateway.TerminalControls.CreateAction <IMyCameraBlock>("Camera_PlayPause"); playPauseAction.Name = new StringBuilder("Play/Pause"); playPauseAction.Action = ActionPlayPause; playPauseAction.Writer = ConditionToggleWriterGen((cam) => cam.PlaybackState == PlaybackMode.Playing, "Play"); MyAPIGateway.TerminalControls.AddAction <IMyCameraBlock>(playPauseAction); stopAction = MyAPIGateway.TerminalControls.CreateAction <IMyCameraBlock>("Camera_Stop"); stopAction.Name = new StringBuilder("Stop"); stopAction.Action = ActionStop; stopAction.Writer = ConditionToggleWriterGen((cam) => cam.PlaybackState == PlaybackMode.Stopped, "Stop"); MyAPIGateway.TerminalControls.AddAction <IMyCameraBlock>(stopAction); setFrameAction = MyAPIGateway.TerminalControls.CreateAction <IMyCameraBlock>("Camera_SetKey"); setFrameAction.Name = new StringBuilder("Set Frame"); setFrameAction.Action = ActionSetFrame; setFrameAction.Writer = (b, sb) => { sb.Clear(); sb.Append("^Frm"); }; MyAPIGateway.TerminalControls.AddAction <IMyCameraBlock>(setFrameAction); setPosFrameAction = MyAPIGateway.TerminalControls.CreateAction <IMyCameraBlock>("Camera_SetPosKey"); setPosFrameAction.Name = new StringBuilder("Set Pos"); setPosFrameAction.Action = ActionSetPosFrame; setPosFrameAction.Writer = (b, sb) => { sb.Clear(); sb.Append("^Pos"); }; MyAPIGateway.TerminalControls.AddAction <IMyCameraBlock>(setPosFrameAction); setViewFrameAction = MyAPIGateway.TerminalControls.CreateAction <IMyCameraBlock>("Camera_SetViewKey"); setViewFrameAction.Name = new StringBuilder("Set View"); setViewFrameAction.Action = ActionSetViewFrame; setViewFrameAction.Writer = (b, sb) => { sb.Clear(); sb.Append("^View"); }; MyAPIGateway.TerminalControls.AddAction <IMyCameraBlock>(setViewFrameAction); delKeyframeAction = MyAPIGateway.TerminalControls.CreateAction <IMyCameraBlock>("Camera_DelKeyframe"); delKeyframeAction.Name = new StringBuilder("Remove Keyframe"); delKeyframeAction.Action = ActionDelKeyframe; delKeyframeAction.Writer = (b, sb) => { sb.Clear(); sb.Append("RmFrm"); }; MyAPIGateway.TerminalControls.AddAction <IMyCameraBlock>(delKeyframeAction); toggleKeyframeModeAction = MyAPIGateway.TerminalControls.CreateAction <IMyCameraBlock>("Camera_ToggleTransitionMode"); toggleKeyframeModeAction.Name = new StringBuilder("Change Transition"); toggleKeyframeModeAction.Action = ActionToggleKeyframeMode; toggleKeyframeModeAction.Writer = KeyframeModeWriter; MyAPIGateway.TerminalControls.AddAction <IMyCameraBlock>(toggleKeyframeModeAction); lockViewAction = MyAPIGateway.TerminalControls.CreateAction <IMyCameraBlock>("Camera_LockViewToTarget"); lockViewAction.Name = new StringBuilder("Lock View to Target"); lockViewAction.Action = ActionLockViewToTarget; lockViewAction.Writer = ConditionToggleWriterGen((cam) => cam.view_locked_to != null, "VTgt"); MyAPIGateway.TerminalControls.AddAction <IMyCameraBlock>(lockViewAction); lockPosAction = MyAPIGateway.TerminalControls.CreateAction <IMyCameraBlock>("Camera_LockPosToTarget"); lockPosAction.Name = new StringBuilder("Lock Pos to Target"); lockPosAction.Action = ActionLockPosToTarget; lockPosAction.Writer = ConditionToggleWriterGen((cam) => cam.pos_locked_to != null, "PTgt"); MyAPIGateway.TerminalControls.AddAction <IMyCameraBlock>(lockPosAction); setFocusAction = MyAPIGateway.TerminalControls.CreateAction <IMyCameraBlock>("Camera_SetFocusToViewLock"); setFocusAction.Name = new StringBuilder("Set Focus to View Lock"); setFocusAction.Action = ActionSetFocusToViewLock; setFocusAction.Writer = (b, sb) => { sb.Clear(); sb.Append("Focus"); }; MyAPIGateway.TerminalControls.AddAction <IMyCameraBlock>(setFocusAction); rangeSlider = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlSlider, IMyCameraBlock>("Camera_FocusDistance"); rangeSlider.Title = MyStringId.GetOrCompute("Focus Distance"); rangeSlider.Tooltip = MyStringId.GetOrCompute("Focus distance. Important when camera is locked to a distant object."); rangeSlider.SetLogLimits(1.0f, 100000.0f); rangeSlider.SupportsMultipleBlocks = true; rangeSlider.Getter = b => (float)SettingsStore.Get(b, "focus_distance", 1.0f); rangeSlider.Setter = (b, v) => SettingsStore.Set(b, "focus_distance", (float)LogRound(v)); rangeSlider.Writer = (b, result) => result.Append(SettingsStore.Get(b, "focus_distance", 1.0f)); rangeSlider.Visible = BlockIsMyCamera; MyAPIGateway.TerminalControls.AddControl <IMyCameraBlock>(rangeSlider); MyAPIGateway.TerminalControls.CustomActionGetter += GetCameraActions; }