From e1ee054a0b652d0eb63fc2d1e661183217b2fdac Mon Sep 17 00:00:00 2001 From: Robert Menger Date: Mon, 2 Sep 2019 14:19:59 +0200 Subject: [PATCH 1/3] added adjustment-value for the camera movement speed relative to the selected target --- .../SpaceNavigator/Editor/ViewportController.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Space Navigator Unity project/Assets/SpaceNavigator/Editor/ViewportController.cs b/Space Navigator Unity project/Assets/SpaceNavigator/Editor/ViewportController.cs index 08a3f8f..159af7f 100644 --- a/Space Navigator Unity project/Assets/SpaceNavigator/Editor/ViewportController.cs +++ b/Space Navigator Unity project/Assets/SpaceNavigator/Editor/ViewportController.cs @@ -110,6 +110,18 @@ static void Fly(SceneView sceneView) { static void Fly(SceneView sceneView, Vector3 translationInversion, Vector3 rotationInversion) { SyncRigWithScene(); + + //calculate distance to selected object or world center, to adjust fly speed + Vector3 targetPosition = (Selection.activeTransform != null) ? Selection.activeTransform.position : new Vector3(); + float distanceToTarget = (_camera.position - targetPosition).magnitude; + float flySpeedAdjustment = Mathf.Pow(distanceToTarget * 0.3f, 1.1f); + if (flySpeedAdjustment > 1000f) flySpeedAdjustment = 1000f; //limit maximum speed, so that camera cannot exit valid value-range too fast. + + + // Apply inversion of axes for fly/grabmove mode. + Vector3 translation = Vector3.Scale(SpaceNavigator.Translation, translationInversion) * flySpeedAdjustment; + + // Apply inversion of axes for fly/grabmove mode. Vector3 translation = Vector3.Scale(SpaceNavigator.Translation, translationInversion); Vector3 rotation = Vector3.Scale(SpaceNavigator.Rotation.eulerAngles, rotationInversion); From 3a5b27a78624a88c6a762074be9c17c5e2ab6f01 Mon Sep 17 00:00:00 2001 From: Robert Menger Date: Thu, 5 Sep 2019 14:12:02 +0200 Subject: [PATCH 2/3] added flyspeedadjustment to orbitmode, added a practical slowdown for huge distances --- .../Editor/ViewportController.cs | 34 +++++++++++++------ .../Plugins/Settings/Settings.cs | 6 ++++ 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/Space Navigator Unity project/Assets/SpaceNavigator/Editor/ViewportController.cs b/Space Navigator Unity project/Assets/SpaceNavigator/Editor/ViewportController.cs index 159af7f..668812b 100644 --- a/Space Navigator Unity project/Assets/SpaceNavigator/Editor/ViewportController.cs +++ b/Space Navigator Unity project/Assets/SpaceNavigator/Editor/ViewportController.cs @@ -110,16 +110,9 @@ static void Fly(SceneView sceneView) { static void Fly(SceneView sceneView, Vector3 translationInversion, Vector3 rotationInversion) { SyncRigWithScene(); - - //calculate distance to selected object or world center, to adjust fly speed - Vector3 targetPosition = (Selection.activeTransform != null) ? Selection.activeTransform.position : new Vector3(); - float distanceToTarget = (_camera.position - targetPosition).magnitude; - float flySpeedAdjustment = Mathf.Pow(distanceToTarget * 0.3f, 1.1f); - if (flySpeedAdjustment > 1000f) flySpeedAdjustment = 1000f; //limit maximum speed, so that camera cannot exit valid value-range too fast. - // Apply inversion of axes for fly/grabmove mode. - Vector3 translation = Vector3.Scale(SpaceNavigator.Translation, translationInversion) * flySpeedAdjustment; + Vector3 translation = Vector3.Scale(SpaceNavigator.Translation, translationInversion) * cameraFlySpeedAdjustment(); // Apply inversion of axes for fly/grabmove mode. @@ -154,9 +147,9 @@ static void Orbit(SceneView sceneView) { } SyncRigWithScene(); - + // Apply inversion of axes for orbit mode. - Vector3 translation = Vector3.Scale(SpaceNavigator.Translation, Settings.OrbitInvertTranslation); + Vector3 translation = Vector3.Scale(SpaceNavigator.Translation, Settings.OrbitInvertTranslation) * cameraFlySpeedAdjustment(); Vector3 rotation = Vector3.Scale(SpaceNavigator.Rotation.eulerAngles, Settings.OrbitInvertRotation); _camera.Translate(translation, Space.Self); @@ -332,5 +325,26 @@ private static Vector3 SnapOnTranslation(Vector3 v, float snap) { Mathf.RoundToInt(v.z / snap) * snap); } #endregion - Snapping - + + + private static float cameraFlySpeedAdjustment() { + + if (Settings.Mode == OperationMode.Fly && !Settings.EnableCameraFlyspeedAdjustmentFlymode) return 1f; + if (Settings.Mode == OperationMode.Orbit && !Settings.EnableCameraFlyspeedAdjustmentOrbitmode) return 1f; + + //calculate distance to selected object or world center, to adjust fly speed + Vector3 targetPosition = (Selection.activeTransform != null) ? Selection.activeTransform.position : new Vector3(); + float distanceToTarget = (_camera.position - targetPosition).magnitude; + float flySpeedAdjustment = 1f; + + if (distanceToTarget <= Settings.FlyspeedSlowdownDistance) { + //this is the practical maximum camera distance in Unity 2019.2, as with bigger distances the gizmos disappear + flySpeedAdjustment = Mathf.Pow(distanceToTarget * Settings.FlyspeedConstant, Settings.FlyspeedExponent); + } else { + flySpeedAdjustment = Mathf.Pow(Settings.FlyspeedSlowdownDistance * Settings.FlyspeedConstant, Settings.FlyspeedExponent) + (distanceToTarget - Settings.FlyspeedSlowdownDistance) * (Settings.FlyspeedSlowdownDistance / distanceToTarget); + } + + return flySpeedAdjustment; + } } } diff --git a/Space Navigator Unity project/Assets/SpaceNavigator/Plugins/Settings/Settings.cs b/Space Navigator Unity project/Assets/SpaceNavigator/Plugins/Settings/Settings.cs index 2eb1265..8d77bfd 100644 --- a/Space Navigator Unity project/Assets/SpaceNavigator/Plugins/Settings/Settings.cs +++ b/Space Navigator Unity project/Assets/SpaceNavigator/Plugins/Settings/Settings.cs @@ -53,6 +53,12 @@ public static class Settings { public static float RotSens = RotSensDefault; public static float RotSensMin = RotSensMinDefault; public static float RotSensMax = RotSensMaxDefault; + + public static bool EnableCameraSpeedAdjustmentFlymode = true; + public static bool EnableCameraSpeedAdjustmentOrbitmode = true; + public static int FlyspeedSlowdownDistance = 100000; + public static float FlyspeedExponent = 1.05f; + public static float FlyspeedConstant = 0.1f; #if UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX public const float RotDeadDefault = 30, RotDeadMinDefault = 0, RotDeadMaxDefault = 100f; From 3507b8f8cac4d4dcacd36177ff13c3f3bad10f0e Mon Sep 17 00:00:00 2001 From: Robert Menger Date: Thu, 5 Sep 2019 14:19:47 +0200 Subject: [PATCH 3/3] corrected a typo in a settings-variable --- .../Assets/SpaceNavigator/Editor/ViewportController.cs | 1 - .../Assets/SpaceNavigator/Plugins/Settings/Settings.cs | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/Space Navigator Unity project/Assets/SpaceNavigator/Editor/ViewportController.cs b/Space Navigator Unity project/Assets/SpaceNavigator/Editor/ViewportController.cs index 668812b..f4ff3aa 100644 --- a/Space Navigator Unity project/Assets/SpaceNavigator/Editor/ViewportController.cs +++ b/Space Navigator Unity project/Assets/SpaceNavigator/Editor/ViewportController.cs @@ -326,7 +326,6 @@ private static Vector3 SnapOnTranslation(Vector3 v, float snap) { } #endregion - Snapping - - private static float cameraFlySpeedAdjustment() { if (Settings.Mode == OperationMode.Fly && !Settings.EnableCameraFlyspeedAdjustmentFlymode) return 1f; diff --git a/Space Navigator Unity project/Assets/SpaceNavigator/Plugins/Settings/Settings.cs b/Space Navigator Unity project/Assets/SpaceNavigator/Plugins/Settings/Settings.cs index 8d77bfd..03541c3 100644 --- a/Space Navigator Unity project/Assets/SpaceNavigator/Plugins/Settings/Settings.cs +++ b/Space Navigator Unity project/Assets/SpaceNavigator/Plugins/Settings/Settings.cs @@ -54,8 +54,8 @@ public static class Settings { public static float RotSensMin = RotSensMinDefault; public static float RotSensMax = RotSensMaxDefault; - public static bool EnableCameraSpeedAdjustmentFlymode = true; - public static bool EnableCameraSpeedAdjustmentOrbitmode = true; + public static bool EnableCameraFlyspeedAdjustmentFlymode = true; + public static bool EnableCameraFlyspeedAdjustmentOrbitmode = true; public static int FlyspeedSlowdownDistance = 100000; public static float FlyspeedExponent = 1.05f; public static float FlyspeedConstant = 0.1f;