Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Editor] Improve Cameracontrol in Editor #1879

Merged
merged 14 commits into from Oct 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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