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)]
|
||||
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")]
|
||||
[EditorDisplay("Viewport", "Toggle Camera Rotation"), EditorOrder(1560)]
|
||||
public InputBinding CameraToggleRotation = new InputBinding(KeyboardKeys.None);
|
||||
|
||||
@@ -21,6 +21,7 @@ namespace FlaxEditor.Viewport.Cameras
|
||||
private Transform _startMove;
|
||||
private Transform _endMove;
|
||||
private float _moveStartTime = -1;
|
||||
private float _additionalFOV;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether this viewport is animating movement.
|
||||
@@ -32,6 +33,15 @@ namespace FlaxEditor.Viewport.Cameras
|
||||
/// </summary>
|
||||
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>
|
||||
/// Sets view.
|
||||
/// </summary>
|
||||
@@ -216,7 +226,7 @@ namespace FlaxEditor.Viewport.Cameras
|
||||
pitch += mouseDelta.Y;
|
||||
}
|
||||
|
||||
// Zoom in/out
|
||||
// Zoom in/out with mouse wheel
|
||||
if (input.IsZooming && !input.IsRotating)
|
||||
{
|
||||
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
|
||||
if (input.IsOrbiting && isUsingGizmo)
|
||||
{
|
||||
|
||||
@@ -51,6 +51,16 @@ namespace FlaxEditor.Viewport
|
||||
/// </summary>
|
||||
public bool IsOrbiting;
|
||||
|
||||
/// <summary>
|
||||
/// The zoom in state.
|
||||
/// </summary>
|
||||
public bool ZoomInDown;
|
||||
|
||||
/// <summary>
|
||||
/// The zoom out state.
|
||||
/// </summary>
|
||||
public bool ZoomOutDown;
|
||||
|
||||
/// <summary>
|
||||
/// The is control down flag.
|
||||
/// </summary>
|
||||
@@ -109,6 +119,10 @@ namespace FlaxEditor.Viewport
|
||||
IsAltDown = window.GetKey(KeyboardKeys.Alt);
|
||||
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);
|
||||
IsMouseMiddleDown = useMouse && window.GetMouseButton(MouseButton.Middle);
|
||||
IsMouseLeftDown = useMouse && window.GetMouseButton(MouseButton.Left);
|
||||
@@ -1433,7 +1447,10 @@ namespace FlaxEditor.Viewport
|
||||
else
|
||||
{
|
||||
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