-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathCameraManager.cs
87 lines (72 loc) · 2.38 KB
/
CameraManager.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
using System;
using Core;
using Core.Camera;
using Core.CustomEvent;
using OpenTK;
using OpenTK.Mathematics;
using OpenTK.Windowing.Common;
namespace Engine
{
public class CameraManager : Singleton<CameraManager>
{
public CameraManager()
{
currentCamera = freeCamera;
}
public bool IsOrbitCameraMode()
{
return currentCamera == orbitCamera ? true : false;
}
public bool IsFreeCameraMode()
{
return !IsOrbitCameraMode();
}
public void SwitchCamera()
{
if (currentCamera == freeCamera)
{
orbitCamera.DestLocation = orbitCamera.EyeLocation = freeCamera.EyeLocation;
orbitCamera.LookAtLocation = freeCamera.EyeLocation + freeCamera.GetLookAtDir() * 50.0f;
orbitCamera.SetDistanceToLookAt(50.0f);
orbitCamera.AspectRatio = freeCamera.AspectRatio;
orbitCamera.FOV = freeCamera.FOV;
currentCamera = orbitCamera;
}
else
{
currentCamera = freeCamera;
}
}
public void OnKeyDown(object sender, KeyboardKeyEventArgs e)
{
if (currentCamera != null)
{
currentCamera.OnKeyDown(sender, e);
}
}
public void OnKeyUp(object sender, KeyboardKeyEventArgs e)
{
if (currentCamera != null)
{
currentCamera.OnKeyUp(sender, e);
}
}
public void OnWindowResized(int width, int height)
{
if (currentCamera != null)
{
currentCamera.OnWindowResized(width, height);
}
}
public Matrix4 CurrentCameraView => currentCamera.View;
public Matrix4 CurrentCameraProj => currentCamera.Proj;
public Matrix4 PrevCameraProj => currentCamera.PrevProj;
public Matrix4 PrevCameraView => currentCamera.PrevView;
public Vector3 CurrentCameraEye => currentCamera.EyeLocation;
public Matrix4 CurrentViewport => currentCamera.Viewport;
public CameraBase CurrentCamera => currentCamera;
protected CameraBase currentCamera = null;
protected OrbitCamera orbitCamera = new OrbitCamera();
protected FreeCamera freeCamera = new FreeCamera();
}
}