From ac4d1a4b197f84a4cdbdddc449ac73cee84a2079 Mon Sep 17 00:00:00 2001 From: dexy Date: Thu, 28 Nov 2019 16:36:32 +1100 Subject: [PATCH] Cutscene viewer using znear/zfar when animating camera --- World/CutsceneForm.cs | 24 +++++++++++++++++++++++- WorldForm.cs | 14 ++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/World/CutsceneForm.cs b/World/CutsceneForm.cs index c42520c..d6ac882 100644 --- a/World/CutsceneForm.cs +++ b/World/CutsceneForm.cs @@ -61,6 +61,11 @@ namespace CodeWalker.World WorldForm.SetCameraTransform(pos, rot); + if (Cutscene.CameraClipUpdate) + { + WorldForm.SetCameraClipPlanes(Cutscene.CameraNearClip, Cutscene.CameraFarClip); + Cutscene.CameraClipUpdate = false; + } } } @@ -254,6 +259,18 @@ namespace CodeWalker.World private void AnimateCameraCheckBox_CheckedChanged(object sender, EventArgs e) { AnimateCamera = AnimateCameraCheckBox.Checked; + + if (!AnimateCamera) + { + WorldForm?.ResetCameraClipPlanes(); + } + else + { + if (Cutscene != null) + { + Cutscene.CameraClipUpdate = true; + } + } } private void PlayStopButton_Click(object sender, EventArgs e) @@ -316,7 +333,9 @@ namespace CodeWalker.World public CutsceneObject CameraObject = null; - + public float CameraNearClip { get; set; } = 0.5f; + public float CameraFarClip { get; set; } = 12000.0f; + public bool CameraClipUpdate = false;//signal to the form to update the camera clip planes public Quaternion CameraRotationOffset = Quaternion.RotationAxis(Vector3.UnitX, -1.57079632679f) * Quaternion.RotationAxis(Vector3.UnitZ, 3.141592653f); @@ -962,6 +981,9 @@ namespace CodeWalker.World obj.Position = pos + rot.Multiply(args.vPosition); obj.Rotation = rot * args.vRotationQuaternion; + CameraNearClip = (args.fNearDrawDistance > 0) ? Math.Min(args.fNearDrawDistance, 0.5f) : 0.5f; + CameraFarClip = (args.fFarDrawDistance > 0) ? Math.Max(args.fFarDrawDistance, 1000.0f) : 12000.0f; + CameraClipUpdate = true; CameraObject = obj; } private void CameraShadowCascade(CutEvent e) diff --git a/WorldForm.cs b/WorldForm.cs index 72e3ee9..acb01fd 100644 --- a/WorldForm.cs +++ b/WorldForm.cs @@ -1892,6 +1892,20 @@ namespace CodeWalker camera.TargetRotation = Vector3.Zero; camera.TargetDistance = 0.01f; } + public void SetCameraClipPlanes(float znear, float zfar) + { + //sets the camera clip planes to the specified values, for use in eg cutscenes + camera.ZNear = znear; + camera.ZFar = zfar; + camera.UpdateProj = true; + } + public void ResetCameraClipPlanes() + { + //resets the camera clip planes to the values in the UI controls. + camera.ZNear = (float)NearClipUpDown.Value; + camera.ZFar = (float)FarClipUpDown.Value; + camera.UpdateProj = true; + } public Vector3 GetCameraPosition() {