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 11 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 @@ -167,7 +167,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 +240,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 +261,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) / 30f;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason for this division here? Shouldn't baseSpeed be modified instead?

Copy link
Contributor Author

@SVNMLR SVNMLR Oct 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The intention here was to reduce the calculated panning speed (depending on the current movement speed) at a constant fraction to have a better feeling and control. This value was evaluated during testing.

So panning speed should be higher if the movement speed is higher or lower if the movement speed gets lower, too. But not "equal", to not be too fast. Its adapting some fraction of the current choosen movement speed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, since this is called every frame, can you make the division become multiplication instead and extract the constant 1/30 like

const float panningSpeedModifier = 1/30f;

Copy link
Contributor Author

@SVNMLR SVNMLR Oct 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have implemented your mention. Its now a fixed value, which I have predefined, too.

Additionally I have extended the increments a little further and improved the Camera speed settings in the UI.
It now shows the current speedvalue and the Slider is a little wider, to have better control over the extended increments.

Here you can see the changes to the UI :)
Camera_Speedsettings

I'm done now with all I wanted to do. Hope it is okay now and can be merged :)

if (InvertPanningAxis.GetValue())
panningSpeed = -panningSpeed;

Expand All @@ -272,7 +285,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 @@ -24,10 +24,20 @@ public class EditorCameraViewModel : DispatcherViewModel
public static float[] AvailableMovementSpeed =
{
0.1f,
0.5f,
1.0f,
3.0f,
2.5f,
5.0f,
10.0f,
15.0f,
30.0f,
50.0f,
80.0f,
100.0f,
150.0f,
200.0f,
300.0f,
500.0f
};

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