3 [
EditorAttribute(
"box",
"GameLib/Scripted",
"Script camera",
"-0.25 -0.25 -0.25",
"0.25 0.25 0.25",
"255 0 0 255")]
4 class ScriptCameraClass
9 ScriptCameraClass ScriptCameraSource;
11 class ScriptCamera: GenericEntity
13 [
Attribute(
"60",
"slider",
"Field of view",
"0 180 1")]
15 [
Attribute(
"1",
"editbox",
"Near plane clip")]
17 [
Attribute(
"4000",
"editbox",
"Far plane clip")]
22 [
Attribute(
"5",
"slider",
"Camera speed",
"0 20 1")]
24 [
Attribute(
"1",
"combobox",
"Free Fly",
"", ParamEnumArray.FromEnum(
EBool) )]
26 [
Attribute(
"0",
"combobox",
"Invert vertical",
"", ParamEnumArray.FromEnum(
EBool) )]
28 [
Attribute(
"0",
"slider",
"Camera index",
"0 31 1")]
30 float m_MouseSensitivity = 0.001;
31 float m_GamepadSensitivity = 0.2;
35 int m_DbgListSelection = 0;
36 ref
array<string> m_DbgOptions = {
"Perspective",
"Orthographic"};
47 m_DbgListSelection =
Type - 1;
48 SetCamera(Index, GetOrigin(), GetYawPitchRoll());
53 m_GamepadFreeFly = FreeFly;
58 GetGame().GetInputManager().ActivateContext(
"ScriptCameraContext");
60 if (
GetGame().GetInputManager().GetActionTriggered(
"CamFreeFly"))
76 if (GameSettings.Debug)
82 protected void FreeFly(
float timeSlice)
84 vector camPosition = GetOrigin();
85 vector angles = GetYawPitchRoll();
88 InputManager imanager =
GetGame().GetInputManager();
89 imanager.ActivateContext(
"ScriptCameraFreeFlyContext");
92 float turnX = imanager.LocalValue(
"CamTurnRight") * 20.0 * timeSlice;
93 float turnY = imanager.LocalValue(
"CamTurnUp") * 20.0 * timeSlice;
94 float turnZ = imanager.LocalValue(
"CamRotate") * 20.0 * timeSlice;
95 float moveForward = imanager.LocalValue(
"CamForward");
96 float moveRight = imanager.LocalValue(
"CamRight");
97 float moveAscend = imanager.LocalValue(
"CamAscend");
98 float speedDelta = imanager.LocalValue(
"CamSpeedDelta") * timeSlice;
99 bool speedBoostHigh = imanager.GetActionTriggered(
"CamSpeedBoostHigh");
100 bool speedBoostLow = imanager.GetActionTriggered(
"CamSpeedBoostLow");
102 Speed =
Math.Clamp(Speed + speedDelta * Speed * 0.25, 0.1, 1000.0);
104 float finalSpeed = Speed;
107 else if (speedBoostHigh)
111 angles[0] = turnX + angles[0];
113 angles[1] = turnY + angles[1];
115 angles[1] = -turnY + angles[1];
117 angles[2] = turnZ + angles[2];
121 vector forward = camMat[2];
125 move += forward * moveForward;
126 move += side * moveRight;
127 move += up * moveAscend;
130 camPosition = (move * timeSlice * finalSpeed) + camPosition;
132 Math3D.YawPitchRollMatrix(angles, camMat);
133 camMat[3] = camPosition;
138 protected void DebugInfo()
140 InputManager imanager =
GetGame().GetInputManager();
141 DbgUI.Begin(
String(
"Camera #" + Index.ToString()), 0, Index * 300);
147 DbgUI.Check(
"Select Free fly", FreeFly);
148 DbgUI.List(
"Camera type", m_DbgListSelection, m_DbgOptions);
149 if (m_DbgListSelection + 1 !=
Type)
151 Type = m_DbgListSelection + 1;
155 float sensitivity = 2000 - (1 / m_MouseSensitivity);
156 DbgUI.SliderFloat(
"Mouse sensitivity", sensitivity, 1, 1999);
157 m_MouseSensitivity = 1 / (2000 - sensitivity);
159 DbgUI.Text(
"CamTurnRight: " + imanager.LocalValue(
"CamTurnRight"));
160 DbgUI.Text(
"CamTurnUp: " + imanager.LocalValue(
"CamTurnUp"));
161 DbgUI.Text(
"CamSpeedDelta: " + imanager.LocalValue(
"CamSpeedDelta"));
162 DbgUI.Text(
"CamForward: " + imanager.LocalValue(
"CamForward"));
163 DbgUI.Text(
"CamRight: " +imanager.LocalValue(
"CamRight"));
164 DbgUI.Text(
"CamAscend: " + imanager.LocalValue(
"CamAscend"));
165 DbgUI.Text(
"CamSpeedBoostHigh: " + imanager.GetActionTriggered(
"CamSpeedBoostHigh"));
166 DbgUI.Text(
"CamSpeedBoostLow:" + imanager.GetActionTriggered(
"CamSpeedBoostLow"));