Merge branch 'ortho' of git://github.com/jb-perrier/FlaxEngine into jb-perrier-ortho
This commit is contained in:
@@ -18,6 +18,13 @@ namespace FlaxEditor.Options
|
||||
[EditorDisplay("General"), EditorOrder(100), Tooltip("The mouse movement sensitivity scale applied when using the viewport camera.")]
|
||||
public float MouseSensitivity { get; set; } = 1.0f;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the mouse wheel sensitivity applied to zoom in orthographic mode.
|
||||
/// </summary>
|
||||
[DefaultValue(1.0f), Limit(0.01f, 100.0f)]
|
||||
[EditorDisplay("General"), EditorOrder(101), Tooltip("The mouse wheel sensitivity applied to zoom in orthographic mode.")]
|
||||
public float MouseWheelSensitivity { get; set; } = 1.0f;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the default movement speed for the viewport camera (must match the dropdown menu values in the viewport).
|
||||
/// </summary>
|
||||
|
||||
@@ -88,6 +88,17 @@ namespace FlaxEditor.Viewport.Cameras
|
||||
Editor.GetActorEditorSphere(actor, out BoundingSphere sphere);
|
||||
ShowSphere(ref sphere);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Moves the viewport to visualize selected actors.
|
||||
/// </summary>
|
||||
/// <param name="actor">The actors to show.</param>
|
||||
/// <param name="orientation">The used orientation.</param>
|
||||
public void ShowActor(Actor actor, ref Quaternion orientation)
|
||||
{
|
||||
Editor.GetActorEditorSphere(actor, out BoundingSphere sphere);
|
||||
ShowSphere(ref sphere, ref orientation);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Moves the viewport to visualize selected actors.
|
||||
@@ -111,17 +122,50 @@ namespace FlaxEditor.Viewport.Cameras
|
||||
ShowSphere(ref mergesSphere);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Moves the viewport to visualize selected actors.
|
||||
/// </summary>
|
||||
/// <param name="actors">The actors to show.</param>
|
||||
/// <param name="orientation">The used orientation.</param>
|
||||
public void ShowActors(List<SceneGraphNode> actors, ref Quaternion orientation)
|
||||
{
|
||||
if (actors.Count == 0)
|
||||
return;
|
||||
|
||||
BoundingSphere mergesSphere = BoundingSphere.Empty;
|
||||
for (int i = 0; i < actors.Count; i++)
|
||||
{
|
||||
if (actors[i] is ActorNode actor)
|
||||
{
|
||||
Editor.GetActorEditorSphere(actor.Actor, out BoundingSphere sphere);
|
||||
BoundingSphere.Merge(ref mergesSphere, ref sphere, out mergesSphere);
|
||||
}
|
||||
}
|
||||
|
||||
ShowSphere(ref mergesSphere, ref orientation);
|
||||
}
|
||||
|
||||
private void ShowSphere(ref BoundingSphere sphere)
|
||||
{
|
||||
// Calculate view transform
|
||||
Quaternion orientation = new Quaternion(0.424461186f, -0.0940724313f, 0.0443938486f, 0.899451137f);
|
||||
Vector3 position = sphere.Center - Vector3.Forward * orientation * (sphere.Radius * 2.5f);
|
||||
|
||||
// Move viewport
|
||||
TargetPoint = sphere.Center;
|
||||
MoveViewport(position, orientation);
|
||||
var q = new Quaternion(0.424461186f, -0.0940724313f, 0.0443938486f, 0.899451137f);
|
||||
ShowSphere(ref sphere, ref q);
|
||||
}
|
||||
|
||||
private void ShowSphere(ref BoundingSphere sphere, ref Quaternion orientation)
|
||||
{
|
||||
Vector3 position;
|
||||
|
||||
if (Viewport.UseOrthographicProjection)
|
||||
{
|
||||
position = sphere.Center + Vector3.Backward * orientation * (sphere.Radius * 5.0f);
|
||||
Viewport.OrthographicScale = Vector3.Distance(position, sphere.Center) / 1000;
|
||||
}
|
||||
else
|
||||
position = sphere.Center - Vector3.Forward * orientation * (sphere.Radius * 2.5f);
|
||||
TargetPoint = position;
|
||||
MoveViewport(position, orientation);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Update(float deltaTime)
|
||||
{
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// Copyright (c) 2012-2021 Wojciech Figat. All rights reserved.
|
||||
|
||||
using System;
|
||||
using FlaxEditor.Gizmo;
|
||||
using FlaxEditor.GUI.ContextMenu;
|
||||
using FlaxEditor.GUI.Input;
|
||||
using FlaxEditor.Options;
|
||||
@@ -538,21 +539,30 @@ namespace FlaxEditor.Viewport
|
||||
{
|
||||
_isOrtho = checkBox.Checked;
|
||||
ViewWidgetButtonMenu.Hide();
|
||||
if (_isOrtho)
|
||||
{
|
||||
var orient = ViewOrientation;
|
||||
OrientViewport(ref orient);
|
||||
}
|
||||
}
|
||||
};
|
||||
ViewWidgetButtonMenu.VisibleChanged += control => orthoValue.Checked = _isOrtho;
|
||||
}
|
||||
|
||||
// Cara Orientation
|
||||
// Camera Viewpoints
|
||||
{
|
||||
var cameraView = ViewWidgetButtonMenu.AddChildMenu("Orientation").ContextMenu;
|
||||
for (int i = 0; i < EditorViewportCameraOrientationValues.Length; i++)
|
||||
var cameraView = ViewWidgetButtonMenu.AddChildMenu("Viewpoints").ContextMenu;
|
||||
for (int i = 0; i < EditorViewportCameraViewpointValues.Length; i++)
|
||||
{
|
||||
var co = EditorViewportCameraOrientationValues[i];
|
||||
var co = EditorViewportCameraViewpointValues[i];
|
||||
var button = cameraView.AddButton(co.Name);
|
||||
button.Tag = co.Orientation;
|
||||
}
|
||||
cameraView.ButtonClicked += button => ViewOrientation = Quaternion.Euler((Vector3)button.Tag);
|
||||
cameraView.ButtonClicked += button =>
|
||||
{
|
||||
var orient = Quaternion.Euler((Vector3)button.Tag);
|
||||
OrientViewport(ref orient);
|
||||
};
|
||||
}
|
||||
|
||||
// Field of View
|
||||
@@ -654,6 +664,19 @@ namespace FlaxEditor.Viewport
|
||||
task.Begin += OnRenderBegin;
|
||||
}
|
||||
|
||||
private void OrientViewport(ref Quaternion orientation)
|
||||
{
|
||||
if (Editor.Instance.SceneEditing.HasSthSelected)
|
||||
{
|
||||
((FPSCamera)ViewportCamera).ShowActors(Editor.Instance.Windows.EditWin.Viewport.TransformGizmo.SelectedParents, ref orientation);
|
||||
}
|
||||
else
|
||||
{
|
||||
var pos = new Vector3(0.0f) + Vector3.Backward * orientation * 2000.0f;
|
||||
((FPSCamera)ViewportCamera).MoveViewport(pos, orientation);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnEditorOptionsChanged(EditorOptions options)
|
||||
{
|
||||
_mouseSensitivity = options.Viewport.MouseSensitivity;
|
||||
@@ -994,6 +1017,7 @@ namespace FlaxEditor.Viewport
|
||||
var options = Editor.Instance.Options.Options.Input;
|
||||
if (_isControllingMouse)
|
||||
{
|
||||
var rmbWheel = false;
|
||||
// Gather input
|
||||
{
|
||||
bool isAltDown = _input.IsAltDown;
|
||||
@@ -1009,10 +1033,11 @@ namespace FlaxEditor.Viewport
|
||||
_input.IsOrbiting = isAltDown && lbDown && !mbDown && !rbDown;
|
||||
|
||||
// Control move speed with RMB+Wheel
|
||||
if (useMovementSpeed && _input.IsMouseRightDown && wheelInUse)
|
||||
rmbWheel = useMovementSpeed && _input.IsMouseRightDown && wheelInUse;
|
||||
if (rmbWheel)
|
||||
{
|
||||
float step = 4.0f;
|
||||
_wheelMovementChangeDeltaSum += _input.MouseWheelDelta;
|
||||
_wheelMovementChangeDeltaSum += _input.MouseWheelDelta * Editor.Instance.Options.Options.Viewport.MouseWheelSensitivity;
|
||||
int camValueIndex = -1;
|
||||
for (int i = 0; i < EditorViewportCameraSpeedValues.Length; i++)
|
||||
{
|
||||
@@ -1076,7 +1101,7 @@ namespace FlaxEditor.Viewport
|
||||
// Calculate smooth mouse delta not dependant on viewport size
|
||||
|
||||
Vector2 offset = _viewMousePos - _startPos;
|
||||
if (_input.IsZooming && !_input.IsMouseRightDown && !_input.IsMouseLeftDown && !_input.IsMouseMiddleDown)
|
||||
if (_input.IsZooming && !_input.IsMouseRightDown && !_input.IsMouseLeftDown && !_input.IsMouseMiddleDown && !_isOrtho && !rmbWheel)
|
||||
{
|
||||
offset = Vector2.Zero;
|
||||
}
|
||||
@@ -1125,6 +1150,14 @@ namespace FlaxEditor.Viewport
|
||||
Vector2 center = PointToWindow(_startPos);
|
||||
win.MousePosition = center;
|
||||
}
|
||||
|
||||
// Change Ortho size on mouse scroll
|
||||
if (_isOrtho && !rmbWheel)
|
||||
{
|
||||
var scroll = _input.MouseWheelDelta;
|
||||
if (scroll > Mathf.Epsilon || scroll < -Mathf.Epsilon)
|
||||
_orthoSize -= scroll * Editor.Instance.Options.Options.Viewport.MouseWheelSensitivity * 0.2f * _orthoSize;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1260,26 +1293,26 @@ namespace FlaxEditor.Viewport
|
||||
base.OnDestroy();
|
||||
}
|
||||
|
||||
private struct CameraOrientation
|
||||
private struct CameraViewpoint
|
||||
{
|
||||
public readonly string Name;
|
||||
public readonly Vector3 Orientation;
|
||||
|
||||
public CameraOrientation(string name, Vector3 orientation)
|
||||
public CameraViewpoint(string name, Vector3 orientation)
|
||||
{
|
||||
Name = name;
|
||||
Orientation = orientation;
|
||||
}
|
||||
}
|
||||
|
||||
private readonly CameraOrientation[] EditorViewportCameraOrientationValues =
|
||||
private readonly CameraViewpoint[] EditorViewportCameraViewpointValues =
|
||||
{
|
||||
new CameraOrientation("Front", new Vector3(0, 0, 0)),
|
||||
new CameraOrientation("Back", new Vector3(0, 180, 0)),
|
||||
new CameraOrientation("Left", new Vector3(0, -90, 0)),
|
||||
new CameraOrientation("Right", new Vector3(0, 90, 0)),
|
||||
new CameraOrientation("Top", new Vector3(90, 0, 0)),
|
||||
new CameraOrientation("Bottom", new Vector3(-90, 0, 0))
|
||||
new CameraViewpoint("Front", new Vector3(0, 180, 0)),
|
||||
new CameraViewpoint("Back", new Vector3(0, 0, 0)),
|
||||
new CameraViewpoint("Left", new Vector3(0, 90, 0)),
|
||||
new CameraViewpoint("Right", new Vector3(0, -90, 0)),
|
||||
new CameraViewpoint("Top", new Vector3(90, 0, 0)),
|
||||
new CameraViewpoint("Bottom", new Vector3(-90, 0, 0))
|
||||
};
|
||||
|
||||
private readonly float[] EditorViewportCameraSpeedValues =
|
||||
|
||||
@@ -243,7 +243,13 @@ namespace FlaxEditor.Windows
|
||||
/// </summary>
|
||||
public void ShowSelectedActors()
|
||||
{
|
||||
((FPSCamera)Viewport.ViewportCamera).ShowActors(Viewport.TransformGizmo.SelectedParents);
|
||||
if (Viewport.UseOrthographicProjection)
|
||||
{
|
||||
var orient = Viewport.ViewOrientation;
|
||||
((FPSCamera)Viewport.ViewportCamera).ShowActors(Viewport.TransformGizmo.SelectedParents, ref orient);
|
||||
}
|
||||
else
|
||||
((FPSCamera)Viewport.ViewportCamera).ShowActors(Viewport.TransformGizmo.SelectedParents);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user