Compare commits

..

7 Commits

Author SHA1 Message Date
ktyl 52541f6d83 move train stuff into folders 2022-09-05 22:15:10 +01:00
ktyl b93511d12f train on bogie on track 2022-09-05 22:15:10 +01:00
ktyl fb9c9d631d bogies and exported properties 2022-09-05 22:15:10 +01:00
ktyl c0fe68a8ac 2 tracks 2022-09-05 22:15:10 +01:00
ktyl 113ae40a9a make train go back n forth 2022-09-05 22:15:10 +01:00
Cat Flynn 8ccd003b00 limit fov range 2022-09-05 20:10:00 +01:00
Cat Flynn 2a4c3b4c88 add camera zoom 2022-09-05 19:58:15 +01:00
2 changed files with 50 additions and 5 deletions

View File

@ -4,7 +4,9 @@
[node name="OrbitCamera" type="Spatial"]
script = ExtResource( 1 )
_zoomSensitivity = 50.0
_cameraPath = NodePath("Camera")
[node name="Camera" type="Camera" parent="."]
transform = Transform( 1, 0, 0, 0, 0.964146, 0.265371, 0, -0.265371, 0.964146, 0, 2.21115, 9.48434 )
transform = Transform( 1, 0, 0, 0, 0.964146, 0.265371, 0, -0.265371, 0.964146, 0, 7.12726, 27.3456 )
fov = 25.0

View File

@ -4,7 +4,26 @@ using System;
public class OrbitCamera : Spatial
{
[Export]
private float _sensitivity = 200f;
private float _lookSensitivity = 200f;
[Export]
private float _zoomSensitivity = 10f;
[Export]
private Vector2 _fovRange = new Vector2(10, 60);
[Export]
private NodePath _cameraPath;
private Camera _camera = null;
private Camera Camera
{
get
{
if (_camera == null)
{
_camera = GetNode<Camera>(_cameraPath);
}
return _camera;
}
}
private Vector2 _rotation;
private bool _canRotate = false;
@ -24,7 +43,8 @@ public class OrbitCamera : Spatial
public override void _Process(float delta)
{
Rotation = Vector3.Zero;
var sensitivity = -1f / _sensitivity;
var sensitivity = -1f / _lookSensitivity;
Rotate(Vector3.Right, _rotation.y * sensitivity);
Rotate(Vector3.Up, _rotation.x * sensitivity);
}
@ -32,9 +52,32 @@ public class OrbitCamera : Spatial
// left click to drag
private void HandleMouseButton(InputEventMouseButton mouseButton)
{
if (mouseButton.ButtonIndex != (int)ButtonList.Left) return;
switch ((ButtonList)mouseButton.ButtonIndex)
{
case ButtonList.Left:
_canRotate = mouseButton.Pressed;
break;
case ButtonList.WheelUp:
Zoom(-1);
break;
case ButtonList.WheelDown:
Zoom(1);
break;
}
}
private void Zoom(int dir)
{
if (dir != 1 && dir != -1)
throw new ArgumentException();
var fov = Camera.Fov;
var zoom = _zoomSensitivity / Camera.Fov;
fov += (float)dir * zoom;
fov = Mathf.Clamp(fov, _fovRange.x, _fovRange.y);
Camera.Fov = fov;
}
private void HandleMouseMovement(InputEventMouseMotion mouseMotion)