3[
EditorAttribute(
"box",
"GameLib/Scripted",
"Script camera",
"-0.25 -0.25 -0.25",
"0.25 0.25 0.25",
"255 0 0 255")]
9ScriptCameraClass ScriptCameraSource;
11class 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")]
20 [Attribute(
"1",
"combobox",
"Projection type",
"", ParamEnumArray.FromEnum(
CameraType) )]
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;
56 override protected void EOnFrame(IEntity other,
float timeSlice)
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];
120 vector move = vector.Zero;
121 vector forward = camMat[2];
122 vector up = camMat[1];
123 vector side = camMat[0];
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);
144 DbgUI.Text(
String(
"Orientation (Y, P, R): " + GetYawPitchRoll().
ToString()));
145 DbgUI.Text(
String(
"Speed : " + Speed.ToString()));
146 DbgUI.Text(
String(
"Mouse sensitivity : " + (2000 - (1 / m_MouseSensitivity)).
ToString()));
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"));
override void EOnFrame(IEntity other, float timeSlice)
proto native CGame GetGame()
proto native void SetCamera(int cam, vector origin, vector angle)
proto native void SetCameraEx(int cam, const vector mat[4])
Changes camera matrix.
proto native void SetCameraFarPlane(int cam, float farplane)
proto native void SetCameraNearPlane(int cam, float nearplane)
proto native void SetCameraVerticalFOV(int cam, float fovy)
proto native void SetCameraType(int cam, CameraType type)
proto native void SetFlags(ShapeFlags flags)
string String(string s)
Helper for passing string expression to functions with void parameter. Example: Print(String("Hello "...
EntityEvent
Entity events for event-mask, or throwing event from code.
void EditorAttribute(string style, string category, string description, vector sizeMin, vector sizeMax, string color, string color2="0 0 0 0", bool visible=true, bool insertable=true, bool dynamicBox=false)