Compare commits
5 Commits
52541f6d83
...
b553f2e9b7
Author | SHA1 | Date |
---|---|---|
ktyl | b553f2e9b7 | |
ktyl | c692487b24 | |
ktyl | 3b626494d8 | |
ktyl | fc9ee5441a | |
ktyl | a890b71df0 |
|
@ -4,9 +4,7 @@
|
||||||
|
|
||||||
[node name="OrbitCamera" type="Spatial"]
|
[node name="OrbitCamera" type="Spatial"]
|
||||||
script = ExtResource( 1 )
|
script = ExtResource( 1 )
|
||||||
_zoomSensitivity = 50.0
|
|
||||||
_cameraPath = NodePath("Camera")
|
|
||||||
|
|
||||||
[node name="Camera" type="Camera" parent="."]
|
[node name="Camera" type="Camera" parent="."]
|
||||||
transform = Transform( 1, 0, 0, 0, 0.964146, 0.265371, 0, -0.265371, 0.964146, 0, 7.12726, 27.3456 )
|
transform = Transform( 1, 0, 0, 0, 0.964146, 0.265371, 0, -0.265371, 0.964146, 0, 2.21115, 9.48434 )
|
||||||
fov = 25.0
|
fov = 25.0
|
||||||
|
|
|
@ -4,26 +4,7 @@ using System;
|
||||||
public class OrbitCamera : Spatial
|
public class OrbitCamera : Spatial
|
||||||
{
|
{
|
||||||
[Export]
|
[Export]
|
||||||
private float _lookSensitivity = 200f;
|
private float _sensitivity = 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 Vector2 _rotation;
|
||||||
private bool _canRotate = false;
|
private bool _canRotate = false;
|
||||||
|
@ -43,8 +24,7 @@ public class OrbitCamera : Spatial
|
||||||
public override void _Process(float delta)
|
public override void _Process(float delta)
|
||||||
{
|
{
|
||||||
Rotation = Vector3.Zero;
|
Rotation = Vector3.Zero;
|
||||||
var sensitivity = -1f / _lookSensitivity;
|
var sensitivity = -1f / _sensitivity;
|
||||||
|
|
||||||
Rotate(Vector3.Right, _rotation.y * sensitivity);
|
Rotate(Vector3.Right, _rotation.y * sensitivity);
|
||||||
Rotate(Vector3.Up, _rotation.x * sensitivity);
|
Rotate(Vector3.Up, _rotation.x * sensitivity);
|
||||||
}
|
}
|
||||||
|
@ -52,32 +32,9 @@ public class OrbitCamera : Spatial
|
||||||
// left click to drag
|
// left click to drag
|
||||||
private void HandleMouseButton(InputEventMouseButton mouseButton)
|
private void HandleMouseButton(InputEventMouseButton mouseButton)
|
||||||
{
|
{
|
||||||
switch ((ButtonList)mouseButton.ButtonIndex)
|
if (mouseButton.ButtonIndex != (int)ButtonList.Left) return;
|
||||||
{
|
|
||||||
case ButtonList.Left:
|
|
||||||
_canRotate = mouseButton.Pressed;
|
|
||||||
break;
|
|
||||||
case ButtonList.WheelUp:
|
|
||||||
Zoom(-1);
|
|
||||||
break;
|
|
||||||
case ButtonList.WheelDown:
|
|
||||||
Zoom(1);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void Zoom(int dir)
|
_canRotate = mouseButton.Pressed;
|
||||||
{
|
|
||||||
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)
|
private void HandleMouseMovement(InputEventMouseMotion mouseMotion)
|
||||||
|
|
Loading…
Reference in New Issue