Merge branch 'ViewportZoomInOutFOV' of https://github.com/xxSeys1/FlaxEngine into xxSeys1-ViewportZoomInOutFOV
This commit is contained in:
@@ -347,6 +347,14 @@ namespace FlaxEditor.Options
|
|||||||
[EditorDisplay("Viewport"), EditorOrder(1550)]
|
[EditorDisplay("Viewport"), EditorOrder(1550)]
|
||||||
public InputBinding Down = new InputBinding(KeyboardKeys.Q);
|
public InputBinding Down = new InputBinding(KeyboardKeys.Q);
|
||||||
|
|
||||||
|
[DefaultValue(typeof(InputBinding), "C")]
|
||||||
|
[EditorDisplay("Viewport"), EditorOrder(1551)]
|
||||||
|
public InputBinding ZoomIn = new InputBinding(KeyboardKeys.C);
|
||||||
|
|
||||||
|
[DefaultValue(typeof(InputBinding), "Z")]
|
||||||
|
[EditorDisplay("Viewport"), EditorOrder(1552)]
|
||||||
|
public InputBinding ZoomOut = new InputBinding(KeyboardKeys.Z);
|
||||||
|
|
||||||
[DefaultValue(typeof(InputBinding), "None")]
|
[DefaultValue(typeof(InputBinding), "None")]
|
||||||
[EditorDisplay("Viewport", "Toggle Camera Rotation"), EditorOrder(1560)]
|
[EditorDisplay("Viewport", "Toggle Camera Rotation"), EditorOrder(1560)]
|
||||||
public InputBinding CameraToggleRotation = new InputBinding(KeyboardKeys.None);
|
public InputBinding CameraToggleRotation = new InputBinding(KeyboardKeys.None);
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ namespace FlaxEditor.Viewport.Cameras
|
|||||||
private Transform _startMove;
|
private Transform _startMove;
|
||||||
private Transform _endMove;
|
private Transform _endMove;
|
||||||
private float _moveStartTime = -1;
|
private float _moveStartTime = -1;
|
||||||
|
private float _additionalFOV;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets a value indicating whether this viewport is animating movement.
|
/// Gets a value indicating whether this viewport is animating movement.
|
||||||
@@ -32,6 +33,15 @@ namespace FlaxEditor.Viewport.Cameras
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public Vector3 TargetPoint = new Vector3(-200);
|
public Vector3 TargetPoint = new Vector3(-200);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Additional field of view used for zooming the camera in and out.
|
||||||
|
/// </summary>
|
||||||
|
public float AdditionalZoomFOV
|
||||||
|
{
|
||||||
|
get => _additionalFOV;
|
||||||
|
private set => _additionalFOV = Mathf.Clamp(value, 5 - Viewport.FieldOfView, 160f - Viewport.FieldOfView);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sets view.
|
/// Sets view.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -216,7 +226,7 @@ namespace FlaxEditor.Viewport.Cameras
|
|||||||
pitch += mouseDelta.Y;
|
pitch += mouseDelta.Y;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Zoom in/out
|
// Zoom in/out with mouse wheel
|
||||||
if (input.IsZooming && !input.IsRotating)
|
if (input.IsZooming && !input.IsRotating)
|
||||||
{
|
{
|
||||||
position += forward * (Viewport.MouseWheelZoomSpeedFactor * input.MouseWheelDelta * 25.0f);
|
position += forward * (Viewport.MouseWheelZoomSpeedFactor * input.MouseWheelDelta * 25.0f);
|
||||||
@@ -226,6 +236,17 @@ namespace FlaxEditor.Viewport.Cameras
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Zoom in and out by changing FOV
|
||||||
|
if (input.IsRotating && (input.ZoomInDown || input.ZoomOutDown))
|
||||||
|
{
|
||||||
|
float delta = (input.ZoomInDown ? -0.8f : 0.8f);
|
||||||
|
AdditionalZoomFOV += delta;
|
||||||
|
}
|
||||||
|
else if (!input.IsRotating)
|
||||||
|
{
|
||||||
|
AdditionalZoomFOV = 0f;
|
||||||
|
}
|
||||||
|
|
||||||
// Move camera with the gizmo
|
// Move camera with the gizmo
|
||||||
if (input.IsOrbiting && isUsingGizmo)
|
if (input.IsOrbiting && isUsingGizmo)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -51,6 +51,16 @@ namespace FlaxEditor.Viewport
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public bool IsOrbiting;
|
public bool IsOrbiting;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The zoom in state.
|
||||||
|
/// </summary>
|
||||||
|
public bool ZoomInDown;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The zoom out state.
|
||||||
|
/// </summary>
|
||||||
|
public bool ZoomOutDown;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The is control down flag.
|
/// The is control down flag.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -109,6 +119,10 @@ namespace FlaxEditor.Viewport
|
|||||||
IsAltDown = window.GetKey(KeyboardKeys.Alt);
|
IsAltDown = window.GetKey(KeyboardKeys.Alt);
|
||||||
WasAltDownBefore = prevInput.WasAltDownBefore || prevInput.IsAltDown;
|
WasAltDownBefore = prevInput.WasAltDownBefore || prevInput.IsAltDown;
|
||||||
|
|
||||||
|
InputOptions inputOptions = Editor.Instance.Options.Options.Input;
|
||||||
|
ZoomInDown = window.GetKey(inputOptions.ZoomIn.Key);
|
||||||
|
ZoomOutDown = window.GetKey(inputOptions.ZoomOut.Key);
|
||||||
|
|
||||||
IsMouseRightDown = useMouse && window.GetMouseButton(MouseButton.Right);
|
IsMouseRightDown = useMouse && window.GetMouseButton(MouseButton.Right);
|
||||||
IsMouseMiddleDown = useMouse && window.GetMouseButton(MouseButton.Middle);
|
IsMouseMiddleDown = useMouse && window.GetMouseButton(MouseButton.Middle);
|
||||||
IsMouseLeftDown = useMouse && window.GetMouseButton(MouseButton.Left);
|
IsMouseLeftDown = useMouse && window.GetMouseButton(MouseButton.Left);
|
||||||
@@ -1433,7 +1447,10 @@ namespace FlaxEditor.Viewport
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
float aspect = Width / Height;
|
float aspect = Width / Height;
|
||||||
Matrix.PerspectiveFov(_fieldOfView * Mathf.DegreesToRadians, aspect, _nearPlane, _farPlane, out result);
|
float fov = _fieldOfView;
|
||||||
|
if (_camera is FPSCamera fpsCam)
|
||||||
|
fov += fpsCam.AdditionalZoomFOV;
|
||||||
|
Matrix.PerspectiveFov(fov * Mathf.DegreesToRadians, aspect, _nearPlane, _farPlane, out result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user