PE: Added - Use "R" key to rotate selections by 45 degrees.

This commit is contained in:
Preben Eriksen
2022-10-23 09:45:27 +02:00
parent 2efc97b64f
commit b3bb860195
2 changed files with 48 additions and 0 deletions

View File

@@ -68,6 +68,10 @@ namespace FlaxEditor.Options
[EditorDisplay("Common"), EditorOrder(220)]
public InputBinding ContentFinder = new InputBinding(KeyboardKeys.O, KeyboardKeys.Control);
[DefaultValue(typeof(InputBinding), "R")]
[EditorDisplay("Common"), EditorOrder(230)]
public InputBinding RotateSelection = new InputBinding(KeyboardKeys.R);
#endregion
#region Scene

View File

@@ -362,6 +362,7 @@ namespace FlaxEditor.Viewport
InputActions.Add(options => options.RotateMode, () => TransformGizmo.ActiveMode = TransformGizmoBase.Mode.Rotate);
InputActions.Add(options => options.ScaleMode, () => TransformGizmo.ActiveMode = TransformGizmoBase.Mode.Scale);
InputActions.Add(options => options.FocusSelection, FocusSelection);
InputActions.Add(options => options.RotateSelection, RotateSelection);
InputActions.Add(options => options.Delete, _editor.SceneEditing.Delete);
}
@@ -666,6 +667,49 @@ namespace FlaxEditor.Viewport
Gizmos.ForEach(x => x.OnSelectionChanged(selection));
}
/// <summary>
/// Press "R" to rotate the selected gizmo objects 45 degrees.
/// </summary>
public void RotateSelection()
{
var win = (WindowRootControl)Root;
var selection = _editor.SceneEditing.Selection;
var IsShiftDown = win.GetKey(KeyboardKeys.Shift);
Quaternion rotationDelta;
if(IsShiftDown)
rotationDelta = Quaternion.Euler(0.0f, -45.0f, 0.0f);
else
rotationDelta = Quaternion.Euler(0.0f, 45.0f, 0.0f);
bool useObjCenter = TransformGizmo.ActivePivot == TransformGizmoBase.PivotType.ObjectCenter;
Vector3 gizmoPosition = TransformGizmo.Position;
//PE: Rotate selected objects.
bool isPlayMode = Editor.Instance.StateMachine.IsPlayMode;
for (int i = 0; i < selection.Count; i++)
{
var obj = selection[i];
if (isPlayMode && obj.CanTransform == false)
continue;
var trans = obj.Transform;
Vector3 pivotOffset = trans.Translation - gizmoPosition;
if (useObjCenter || pivotOffset.IsZero)
{
trans.Orientation *= Quaternion.Invert(trans.Orientation) * rotationDelta * trans.Orientation;
}
else
{
Matrix.RotationQuaternion(ref trans.Orientation, out var transWorld);
Matrix.RotationQuaternion(ref rotationDelta, out var deltaWorld);
Matrix world = transWorld * Matrix.Translation(pivotOffset) * deltaWorld * Matrix.Translation(-pivotOffset);
trans.SetRotation(ref world);
trans.Translation += world.TranslationVector;
}
obj.Transform = trans;
}
}
/// <summary>
/// Focuses the viewport on the current selection of the gizmo.
/// </summary>