Skip to content

Commit

Permalink
[Editor] Improve Cameracontrol in Editor (#1879)
Browse files Browse the repository at this point in the history
* [Editor] Allow panning while Alt-Keys are beeing pressed

* Change: Remove check for altIsDown

* [Editor] Change movement speed with MouseWheel

* Change: Use Mousewheel during movement to control the movement speed of the camera

* [Editor] Use Camera movementspeed methods to control

* [Editor] Improve speed increments

* [Editor] Fix camera panning speed

* Change: Do not use basespeed multiplier, to be independent from current movement speed multiplier

* [Editor] Improve panning & Zoomlevels

* [Editor] Improve Comments

* [Editor] Improve speed calc, speedsteps & UI-layout

* Change: Calculate panningspeed by multiplication & predefine the factor
* Change: Add more speed increments
* Change: Improve Layout in Sceneview -> Camerasettings (add display of current speed-value and extended sliderbar size, due to more increments)

* [Editor] Fix margins for cameraspeed settings
  • Loading branch information
SVNMLR committed Oct 7, 2023
1 parent 2fc12c5 commit b4442c1
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 10 deletions.
Expand Up @@ -29,6 +29,7 @@ protected struct Input
public bool isOrbiting;
public bool isShiftDown;
};
private const float panningSpeedModifier = 0.033f;

private readonly EntityHierarchyEditorViewModel editor;
private float revolutionRadius;
Expand Down Expand Up @@ -167,7 +168,7 @@ private Input GetInput()
bool isAltDown = Game.Input.IsKeyDown(Keys.LeftAlt) || Game.Input.IsKeyDown(Keys.RightAlt);
input.isShiftDown = Game.Input.IsKeyDown(Keys.LeftShift) || Game.Input.IsKeyDown(Keys.RightShift);

input.isPanning = !isAltDown && mbDown && !rbDown;
input.isPanning = mbDown && !rbDown;
input.isRotating = !isAltDown && !mbDown && rbDown;
input.isMoving = !isAltDown && mbDown && rbDown;
input.isZooming = (isAltDown && !lbDown && !mbDown && rbDown) || (MathF.Abs(Game.Input.MouseWheelDelta) > MathUtil.ZeroTolerance);
Expand Down Expand Up @@ -240,6 +241,19 @@ protected void UpdateCameraBase(ref float yaw, ref float pitch, ref Vector3 posi
z = 0f;
}

// Dynamically change MovementSpeed of Camera by using MouseWheel while moving around
if (input.isRotating)
{
if (Game.Input.MouseWheelDelta > 0.0f)
{
editor.Dispatcher.InvokeAsync(() => Camera.IncreaseMovementSpeed());
}
if (Game.Input.MouseWheelDelta < 0.0f)
{
editor.Dispatcher.InvokeAsync(() => Camera.DecreaseMovementSpeed());
}
}

var localDirection = Vector3.Normalize(new Vector3(x, y, -z));
position += Vector3.Transform(localDirection, rotation) * baseSpeed * dt * 60f;
}
Expand All @@ -248,7 +262,7 @@ protected void UpdateCameraBase(ref float yaw, ref float pitch, ref Vector3 posi
if (input.isPanning)
{
float panningSpeed = asOrthographic ? Component.OrthographicSize : revolutionRadius;
panningSpeed *= MouseMoveSpeedFactor * baseSpeed;
panningSpeed *= MouseMoveSpeedFactor * baseSpeed * panningSpeedModifier;
if (InvertPanningAxis.GetValue())
panningSpeed = -panningSpeed;

Expand All @@ -272,7 +286,7 @@ protected void UpdateCameraBase(ref float yaw, ref float pitch, ref Vector3 posi
}

// Forward/backward
if (input.isZooming)
if (!input.isRotating && input.isZooming)
{
if (asOrthographic)
{
Expand Down
Expand Up @@ -673,12 +673,12 @@
<Border Padding="8,2" Background="{StaticResource NormalBrush}" HorizontalAlignment="Stretch">
<TextBlock Text="{sd:Localize Movement}" FontWeight="Bold"/>
</Border>
<StackPanel Margin="4">
<sd:KeyValueGrid>
<TextBlock DockPanel.Dock="Left" Text="{sd:Localize Speed:}" Margin="5"/>
<Slider sd:KeyValueGrid.UseFullRow="True" HorizontalAlignment="Stretch" Height="18" Margin="5" Minimum="0" Maximum="{Binding Camera.AvailableMovementSpeedCount}" Value="{Binding Camera.MoveSpeedIndex}"/>
</sd:KeyValueGrid>
</StackPanel>
<UniformGrid Columns="3" Margin="4,4,4,2">
<TextBlock DockPanel.Dock="Left" Text="{sd:Localize Speed:}" Margin="5,5,5,2"/>
<TextBlock DockPanel.Dock="Right" Text="{Binding Camera.MoveSpeed}" Margin="5,5,0,2" TextAlignment="Right"/>
<TextBlock DockPanel.Dock="Left" Text="x" Margin="0,5,5,2" TextAlignment="Left"/>
</UniformGrid>
<Slider sd:KeyValueGrid.UseFullRow="True" HorizontalAlignment="Stretch" Height="18" Margin="5,2,5,5" Minimum="0" Maximum="{Binding Camera.AvailableMovementSpeedCount}" Value="{Binding Camera.MoveSpeedIndex}"/>
<Border Padding="8,2" Background="{StaticResource NormalBrush}" HorizontalAlignment="Stretch">
<TextBlock Text="{sd:Localize Orientation}" FontWeight="Bold"/>
</Border>
Expand Down
Expand Up @@ -23,11 +23,27 @@ public class EditorCameraViewModel : DispatcherViewModel

public static float[] AvailableMovementSpeed =
{
0.05f,
0.1f,
0.5f,
1.0f,
3.0f,
1.5f,
2.5f,
5.0f,
10.0f,
15.0f,
30.0f,
45.0f,
60.0f,
80.0f,
100.0f,
130.0f,
180.0f,
250.0f,
400.0f,
500.0f,
700.0f,
1000.0f
};

public int AvailableMovementSpeedCount => AvailableMovementSpeed.Length - 1;
Expand Down

0 comments on commit b4442c1

Please sign in to comment.