@@ -88,7 +88,7 @@ namespace FlaxEditor.Viewport.Cameras
|
|||||||
Editor.GetActorEditorSphere(actor, out BoundingSphere sphere);
|
Editor.GetActorEditorSphere(actor, out BoundingSphere sphere);
|
||||||
ShowSphere(ref sphere);
|
ShowSphere(ref sphere);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Moves the viewport to visualize selected actors.
|
/// Moves the viewport to visualize selected actors.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -144,7 +144,7 @@ namespace FlaxEditor.Viewport.Cameras
|
|||||||
|
|
||||||
ShowSphere(ref mergesSphere, ref orientation);
|
ShowSphere(ref mergesSphere, ref orientation);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ShowSphere(ref BoundingSphere sphere)
|
private void ShowSphere(ref BoundingSphere sphere)
|
||||||
{
|
{
|
||||||
var q = new Quaternion(0.424461186f, -0.0940724313f, 0.0443938486f, 0.899451137f);
|
var q = new Quaternion(0.424461186f, -0.0940724313f, 0.0443938486f, 0.899451137f);
|
||||||
@@ -154,18 +154,19 @@ namespace FlaxEditor.Viewport.Cameras
|
|||||||
private void ShowSphere(ref BoundingSphere sphere, ref Quaternion orientation)
|
private void ShowSphere(ref BoundingSphere sphere, ref Quaternion orientation)
|
||||||
{
|
{
|
||||||
Vector3 position;
|
Vector3 position;
|
||||||
|
|
||||||
if (Viewport.UseOrthographicProjection)
|
if (Viewport.UseOrthographicProjection)
|
||||||
{
|
{
|
||||||
position = sphere.Center + Vector3.Backward * orientation * (sphere.Radius * 5.0f);
|
position = sphere.Center + Vector3.Backward * orientation * (sphere.Radius * 5.0f);
|
||||||
Viewport.OrthographicScale = Vector3.Distance(position, sphere.Center) / 1000;
|
Viewport.OrthographicScale = Vector3.Distance(position, sphere.Center) / 1000;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
position = sphere.Center - Vector3.Forward * orientation * (sphere.Radius * 2.5f);
|
position = sphere.Center - Vector3.Forward * orientation * (sphere.Radius * 2.5f);
|
||||||
TargetPoint = position;
|
}
|
||||||
|
TargetPoint = sphere.Center;
|
||||||
MoveViewport(position, orientation);
|
MoveViewport(position, orientation);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override void SetArcBallView(Quaternion orientation, Vector3 orbitCenter, float orbitRadius)
|
public override void SetArcBallView(Quaternion orientation, Vector3 orbitCenter, float orbitRadius)
|
||||||
{
|
{
|
||||||
@@ -212,12 +213,12 @@ namespace FlaxEditor.Viewport.Cameras
|
|||||||
|
|
||||||
Viewport.GetInput(out var input);
|
Viewport.GetInput(out var input);
|
||||||
Viewport.GetPrevInput(out var prevInput);
|
Viewport.GetPrevInput(out var prevInput);
|
||||||
var mainViewport = Viewport as MainEditorGizmoViewport;
|
var transformGizmo = (Viewport as EditorGizmoViewport)?.Gizmos.Active as TransformGizmoBase;
|
||||||
bool isUsingGizmo = mainViewport != null && mainViewport.TransformGizmo.ActiveAxis != TransformGizmoBase.Axis.None;
|
var isUsingGizmo = transformGizmo != null && transformGizmo.ActiveAxis != TransformGizmoBase.Axis.None;
|
||||||
|
|
||||||
// Get current view properties
|
// Get current view properties
|
||||||
float yaw = Viewport.Yaw;
|
var yaw = Viewport.Yaw;
|
||||||
float pitch = Viewport.Pitch;
|
var pitch = Viewport.Pitch;
|
||||||
var position = Viewport.ViewPosition;
|
var position = Viewport.ViewPosition;
|
||||||
var rotation = Viewport.ViewOrientation;
|
var rotation = Viewport.ViewOrientation;
|
||||||
|
|
||||||
@@ -271,7 +272,7 @@ namespace FlaxEditor.Viewport.Cameras
|
|||||||
position += forward * (Viewport.MouseWheelZoomSpeedFactor * input.MouseWheelDelta * 25.0f);
|
position += forward * (Viewport.MouseWheelZoomSpeedFactor * input.MouseWheelDelta * 25.0f);
|
||||||
if (input.IsAltDown)
|
if (input.IsAltDown)
|
||||||
{
|
{
|
||||||
position += forward * (Viewport.MouseSpeed * 40 * Viewport.MouseDeltaRight.ValuesSum);
|
position += forward * (Viewport.MouseSpeed * 40 * Viewport.MousePositionDelta.ValuesSum);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -279,7 +280,7 @@ namespace FlaxEditor.Viewport.Cameras
|
|||||||
if (input.IsOrbiting && isUsingGizmo)
|
if (input.IsOrbiting && isUsingGizmo)
|
||||||
{
|
{
|
||||||
centerMouse = false;
|
centerMouse = false;
|
||||||
Viewport.ViewPosition += mainViewport.TransformGizmo.LastDelta.Translation;
|
Viewport.ViewPosition += transformGizmo.LastDelta.Translation;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -288,7 +289,7 @@ namespace FlaxEditor.Viewport.Cameras
|
|||||||
Viewport.Pitch = pitch;
|
Viewport.Pitch = pitch;
|
||||||
if (input.IsOrbiting)
|
if (input.IsOrbiting)
|
||||||
{
|
{
|
||||||
float orbitRadius = Vector3.Distance(ref position, ref TargetPoint);
|
float orbitRadius = Mathf.Max(Vector3.Distance(ref position, ref TargetPoint), 0.0001f);
|
||||||
Vector3 localPosition = Viewport.ViewDirection * (-1 * orbitRadius);
|
Vector3 localPosition = Viewport.ViewDirection * (-1 * orbitRadius);
|
||||||
Viewport.ViewPosition = TargetPoint + localPosition;
|
Viewport.ViewPosition = TargetPoint + localPosition;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ namespace FlaxEditor.Viewport
|
|||||||
public bool SnapToGround => Editor.Instance.Options.Options.Input.SnapToGround.Process(Root);
|
public bool SnapToGround => Editor.Instance.Options.Options.Input.SnapToGround.Process(Root);
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public Vector2 MouseDelta => _mouseDeltaLeft * 1000;
|
public Vector2 MouseDelta => _mouseDelta * 1000;
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public bool UseSnapping => Root.GetKey(KeyboardKeys.Control);
|
public bool UseSnapping => Root.GetKey(KeyboardKeys.Control);
|
||||||
|
|||||||
@@ -140,7 +140,7 @@ namespace FlaxEditor.Viewport
|
|||||||
private bool _isControllingMouse;
|
private bool _isControllingMouse;
|
||||||
private int _deltaFilteringStep;
|
private int _deltaFilteringStep;
|
||||||
private Vector2 _startPos;
|
private Vector2 _startPos;
|
||||||
private Vector2 _mouseDeltaRightLast;
|
private Vector2 _mouseDeltaLast;
|
||||||
private Vector2[] _deltaFilteringBuffer = new Vector2[FpsCameraFilteringFrames];
|
private Vector2[] _deltaFilteringBuffer = new Vector2[FpsCameraFilteringFrames];
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -159,14 +159,9 @@ namespace FlaxEditor.Viewport
|
|||||||
protected Vector2 _viewMousePos;
|
protected Vector2 _viewMousePos;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The mouse delta (right button down).
|
/// The mouse position delta.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected Vector2 _mouseDeltaRight;
|
protected Vector2 _mouseDelta;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The mouse delta (left button down).
|
|
||||||
/// </summary>
|
|
||||||
protected Vector2 _mouseDeltaLeft;
|
|
||||||
|
|
||||||
// Camera
|
// Camera
|
||||||
|
|
||||||
@@ -213,14 +208,9 @@ namespace FlaxEditor.Viewport
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the mouse movement delta for the right button (user press and move).
|
/// Gets the mouse movement position delta (user press and move).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Vector2 MouseDeltaRight => _mouseDeltaRight;
|
public Vector2 MousePositionDelta => _mouseDelta;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the mouse movement delta for the left button (user press and move).
|
|
||||||
/// </summary>
|
|
||||||
public Vector2 MouseDeltaLeft => _mouseDeltaLeft;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Camera's pitch angle clamp range (in degrees).
|
/// Camera's pitch angle clamp range (in degrees).
|
||||||
@@ -1018,6 +1008,7 @@ namespace FlaxEditor.Viewport
|
|||||||
if (_isControllingMouse)
|
if (_isControllingMouse)
|
||||||
{
|
{
|
||||||
var rmbWheel = false;
|
var rmbWheel = false;
|
||||||
|
|
||||||
// Gather input
|
// Gather input
|
||||||
{
|
{
|
||||||
bool isAltDown = _input.IsAltDown;
|
bool isAltDown = _input.IsAltDown;
|
||||||
@@ -1099,23 +1090,21 @@ namespace FlaxEditor.Viewport
|
|||||||
moveDelta *= 0.3f;
|
moveDelta *= 0.3f;
|
||||||
|
|
||||||
// Calculate smooth mouse delta not dependant on viewport size
|
// Calculate smooth mouse delta not dependant on viewport size
|
||||||
|
|
||||||
Vector2 offset = _viewMousePos - _startPos;
|
Vector2 offset = _viewMousePos - _startPos;
|
||||||
if (_input.IsZooming && !_input.IsMouseRightDown && !_input.IsMouseLeftDown && !_input.IsMouseMiddleDown && !_isOrtho && !rmbWheel)
|
if (_input.IsZooming && !_input.IsMouseRightDown && !_input.IsMouseLeftDown && !_input.IsMouseMiddleDown && !_isOrtho && !rmbWheel)
|
||||||
{
|
{
|
||||||
offset = Vector2.Zero;
|
offset = Vector2.Zero;
|
||||||
}
|
}
|
||||||
|
|
||||||
offset.X = offset.X > 0 ? Mathf.Floor(offset.X) : Mathf.Ceil(offset.X);
|
offset.X = offset.X > 0 ? Mathf.Floor(offset.X) : Mathf.Ceil(offset.X);
|
||||||
offset.Y = offset.Y > 0 ? Mathf.Floor(offset.Y) : Mathf.Ceil(offset.Y);
|
offset.Y = offset.Y > 0 ? Mathf.Floor(offset.Y) : Mathf.Ceil(offset.Y);
|
||||||
_mouseDeltaRight = offset / size;
|
_mouseDelta = offset / size;
|
||||||
_mouseDeltaRight.Y *= size.Y / size.X;
|
_mouseDelta.Y *= size.Y / size.X;
|
||||||
|
|
||||||
Vector2 mouseDelta = Vector2.Zero;
|
Vector2 mouseDelta = Vector2.Zero;
|
||||||
if (_useMouseFiltering)
|
if (_useMouseFiltering)
|
||||||
{
|
{
|
||||||
// Update delta filtering buffer
|
// Update delta filtering buffer
|
||||||
_deltaFilteringBuffer[_deltaFilteringStep] = _mouseDeltaRight;
|
_deltaFilteringBuffer[_deltaFilteringStep] = _mouseDelta;
|
||||||
_deltaFilteringStep++;
|
_deltaFilteringStep++;
|
||||||
|
|
||||||
// If the step is too far, zero
|
// If the step is too far, zero
|
||||||
@@ -1129,14 +1118,16 @@ namespace FlaxEditor.Viewport
|
|||||||
mouseDelta /= FpsCameraFilteringFrames;
|
mouseDelta /= FpsCameraFilteringFrames;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
mouseDelta = _mouseDeltaRight;
|
{
|
||||||
|
mouseDelta = _mouseDelta;
|
||||||
|
}
|
||||||
|
|
||||||
if (_useMouseAcceleration)
|
if (_useMouseAcceleration)
|
||||||
{
|
{
|
||||||
// Accelerate the delta
|
// Accelerate the delta
|
||||||
var currentDelta = mouseDelta;
|
var currentDelta = mouseDelta;
|
||||||
mouseDelta += _mouseDeltaRightLast * _mouseAccelerationScale;
|
mouseDelta += _mouseDeltaLast * _mouseAccelerationScale;
|
||||||
_mouseDeltaRightLast = currentDelta;
|
_mouseDeltaLast = currentDelta;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update
|
// Update
|
||||||
@@ -1161,7 +1152,20 @@ namespace FlaxEditor.Viewport
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_mouseDeltaRight = _mouseDeltaRightLast = Vector2.Zero;
|
if (_input.IsMouseLeftDown || _input.IsMouseRightDown)
|
||||||
|
{
|
||||||
|
// Calculate smooth mouse delta not dependant on viewport size
|
||||||
|
Vector2 offset = _viewMousePos - _startPos;
|
||||||
|
offset.X = offset.X > 0 ? Mathf.Floor(offset.X) : Mathf.Ceil(offset.X);
|
||||||
|
offset.Y = offset.Y > 0 ? Mathf.Floor(offset.Y) : Mathf.Ceil(offset.Y);
|
||||||
|
_mouseDelta = offset / size;
|
||||||
|
_startPos = _viewMousePos;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_mouseDelta = Vector2.Zero;
|
||||||
|
}
|
||||||
|
_mouseDeltaLast = Vector2.Zero;
|
||||||
|
|
||||||
if (ContainsFocus)
|
if (ContainsFocus)
|
||||||
{
|
{
|
||||||
@@ -1198,19 +1202,6 @@ namespace FlaxEditor.Viewport
|
|||||||
UpdateView(dt, ref moveDelta, ref mouseDelta, out _);
|
UpdateView(dt, ref moveDelta, ref mouseDelta, out _);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (_input.IsMouseLeftDown)
|
|
||||||
{
|
|
||||||
// Calculate smooth mouse delta not dependant on viewport size
|
|
||||||
Vector2 offset = _viewMousePos - _startPos;
|
|
||||||
offset.X = offset.X > 0 ? Mathf.Floor(offset.X) : Mathf.Ceil(offset.X);
|
|
||||||
offset.Y = offset.Y > 0 ? Mathf.Floor(offset.Y) : Mathf.Ceil(offset.Y);
|
|
||||||
_mouseDeltaLeft = offset / size;
|
|
||||||
_startPos = _viewMousePos;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_mouseDeltaLeft = Vector2.Zero;
|
|
||||||
}
|
|
||||||
|
|
||||||
_input.MouseWheelDelta = 0;
|
_input.MouseWheelDelta = 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -342,7 +342,7 @@ namespace FlaxEditor.Viewport
|
|||||||
public bool SnapToGround => false;
|
public bool SnapToGround => false;
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public Vector2 MouseDelta => _mouseDeltaLeft * 1000;
|
public Vector2 MouseDelta => _mouseDelta * 1000;
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public bool UseSnapping => Root.GetKey(KeyboardKeys.Control);
|
public bool UseSnapping => Root.GetKey(KeyboardKeys.Control);
|
||||||
|
|||||||
Reference in New Issue
Block a user