forked from AerysBat/XNALara
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCameraParamsDialog.cs
163 lines (132 loc) · 5.62 KB
/
CameraParamsDialog.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
using System;
using System.Windows.Forms;
using Microsoft.Xna.Framework;
namespace XNALara
{
public partial class CameraParamsDialog : Form
{
public static readonly Vector3 DefaultCameraTarget = new Vector3(0, 1, 0);
public static readonly float DefaultCameraRotationHoriz = 0.0f;
public static readonly float DefaultCameraRotationVert = 10.0f;
public static readonly float DefaultCameraDistance = 4.0f;
public static readonly float DefaultCameraFOV = 30.0f;
private Game game;
public CameraParamsDialog(Game game) {
this.game = game;
InitializeComponent();
game.Camera.CameraEvent += HandleCameraEvent;
HandleCameraEvent();
}
private void ButtonResetAllClick(object sender, EventArgs e) {
game.Camera.FieldOfViewHorizontal = MathHelper.ToRadians(DefaultCameraFOV);
game.Camera.Target = DefaultCameraTarget;
game.Camera.Distance = DefaultCameraDistance;
game.Camera.SetRotation(MathHelper.ToRadians(DefaultCameraRotationHoriz), MathHelper.ToRadians(DefaultCameraRotationVert));
}
protected override void OnActivated(EventArgs e) {
game.HasFocus = false;
}
protected override void OnDeactivate(EventArgs e) {
game.HasFocus = true;
}
protected override void OnClosed(EventArgs e) {
game.Camera.CameraEvent -= HandleCameraEvent;
game.ControlGUI.HandleCameraParamsDialogClosed();
}
private void HandleCameraEvent() {
textBoxTargetX.Text = string.Format("{0:0.0###}", game.Camera.Target.X);
textBoxTargetY.Text = string.Format("{0:0.0###}", game.Camera.Target.Y);
textBoxTargetZ.Text = string.Format("{0:0.0###}", game.Camera.Target.Z);
textBoxRotationHoriz.Text = string.Format("{0:0.0###}", MathHelper.ToDegrees(game.Camera.RotationHorizontal));
textBoxRotationVert.Text = string.Format("{0:0.0###}", MathHelper.ToDegrees(game.Camera.RotationVertical));
textBoxDistance.Text = string.Format("{0:0.0###}", game.Camera.Distance);
int fovDeg = (int)Math.Round(MathHelper.ToDegrees(game.Camera.FieldOfViewHorizontal));
trackBarFOV.Value = fovDeg;
textBoxFOV.Text = string.Format("{0}", fovDeg);
}
private bool HandleTextInputTarget() {
float targetX, targetY, targetZ;
if (!float.TryParse(textBoxTargetX.Text, out targetX)) {
return false;
}
if (!float.TryParse(textBoxTargetY.Text, out targetY)) {
return false;
}
if (!float.TryParse(textBoxTargetZ.Text, out targetZ)) {
return false;
}
game.Camera.Target = new Vector3(targetX, targetY, targetZ);
return true;
}
private bool HandleTextInputRotation() {
float angleHoriz, angleVert;
if (!float.TryParse(textBoxRotationHoriz.Text, out angleHoriz)) {
return false;
}
if (!float.TryParse(textBoxRotationVert.Text, out angleVert)) {
return false;
}
game.Camera.SetRotation(MathHelper.ToRadians(angleHoriz), MathHelper.ToRadians(angleVert));
return true;
}
private bool HandleTextInputDistance() {
float distance;
if (!float.TryParse(textBoxDistance.Text, out distance)) {
return false;
}
game.Camera.Distance = distance;
return true;
}
private void TextBoxTargetXKeyPress(object sender, KeyPressEventArgs e) {
if (e.KeyChar == 13) {
HandleTextInputTarget();
}
}
private void TextBoxTargetYKeyPress(object sender, KeyPressEventArgs e) {
if (e.KeyChar == 13) {
HandleTextInputTarget();
}
}
private void TextBoxTargetZKeyPress(object sender, KeyPressEventArgs e) {
if (e.KeyChar == 13) {
HandleTextInputTarget();
}
}
private void TextBoxTargetXValidated(object sender, EventArgs e) {
HandleTextInputTarget();
}
private void TextBoxTargetYValidated(object sender, EventArgs e) {
HandleTextInputTarget();
}
private void TextBoxTargetZValidated(object sender, EventArgs e) {
HandleTextInputTarget();
}
private void TextBoxRotationHorizKeyPress(object sender, KeyPressEventArgs e) {
if (e.KeyChar == 13) {
HandleTextInputRotation();
}
}
private void TextBoxRotationVertKeyPress(object sender, KeyPressEventArgs e) {
if (e.KeyChar == 13) {
HandleTextInputRotation();
}
}
private void TextBoxRotationHorizValidated(object sender, EventArgs e) {
HandleTextInputRotation();
}
private void TextBoxRotationVertValidated(object sender, EventArgs e) {
HandleTextInputRotation();
}
private void TextBoxDistanceKeyPress(object sender, KeyPressEventArgs e) {
if (e.KeyChar == 13) {
HandleTextInputDistance();
}
}
private void TextBoxDistanceValidated(object sender, EventArgs e) {
HandleTextInputDistance();
}
private void TrackBarFOVScroll(object sender, EventArgs e) {
game.Camera.FieldOfViewHorizontal = MathHelper.ToRadians(trackBarFOV.Value);
}
}
}