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")]
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"))
72 if (GameSettings.Debug)
76 protected void FreeFly(
float timeSlice)
78 vector camPosition = GetOrigin();
79 vector angles = GetYawPitchRoll();
82 InputManager imanager =
GetGame().GetInputManager();
83 imanager.ActivateContext(
"ScriptCameraFreeFlyContext");
86 float turnX = imanager.LocalValue(
"CamTurnRight") * 20.0 * timeSlice;
87 float turnY = imanager.LocalValue(
"CamTurnUp") * 20.0 * timeSlice;
88 float turnZ = imanager.LocalValue(
"CamRotate") * 20.0 * timeSlice;
89 float moveForward = imanager.LocalValue(
"CamForward");
90 float moveRight = imanager.LocalValue(
"CamRight");
91 float moveAscend = imanager.LocalValue(
"CamAscend");
92 float speedDelta = imanager.LocalValue(
"CamSpeedDelta") * timeSlice;
93 bool speedBoostHigh = imanager.GetActionTriggered(
"CamSpeedBoostHigh");
94 bool speedBoostLow = imanager.GetActionTriggered(
"CamSpeedBoostLow");
96 Speed =
Math.
Clamp(Speed + speedDelta * Speed * 0.25, 0.1, 1000.0);
98 float finalSpeed = Speed;
101 else if (speedBoostHigh)
105 angles[0] = turnX + angles[0];
107 angles[1] = turnY + angles[1];
109 angles[1] = -turnY + angles[1];
111 angles[2] = turnZ + angles[2];
115 vector forward = camMat[2];
119 move += forward * moveForward;
120 move += side * moveRight;
121 move += up * moveAscend;
124 camPosition = (move * timeSlice * finalSpeed) + camPosition;
127 camMat[3] = camPosition;
132 protected void DebugInfo()
134 InputManager imanager =
GetGame().GetInputManager();
142 DbgUI.
List(
"Camera type", m_DbgListSelection, m_DbgOptions);
143 if (m_DbgListSelection + 1 !=
Type)
145 Type = m_DbgListSelection + 1;
149 float sensitivity = 2000 - (1 / m_MouseSensitivity);
151 m_MouseSensitivity = 1 / (2000 - sensitivity);
153 DbgUI.
Text(
"CamTurnRight: " + imanager.LocalValue(
"CamTurnRight"));
154 DbgUI.
Text(
"CamTurnUp: " + imanager.LocalValue(
"CamTurnUp"));
155 DbgUI.
Text(
"CamSpeedDelta: " + imanager.LocalValue(
"CamSpeedDelta"));
156 DbgUI.
Text(
"CamForward: " + imanager.LocalValue(
"CamForward"));
157 DbgUI.
Text(
"CamRight: " + imanager.LocalValue(
"CamRight"));
158 DbgUI.
Text(
"CamAscend: " + imanager.LocalValue(
"CamAscend"));
159 DbgUI.
Text(
"CamSpeedBoostHigh: " + imanager.GetActionTriggered(
"CamSpeedBoostHigh"));
160 DbgUI.
Text(
"CamSpeedBoostLow:" + imanager.GetActionTriggered(
"CamSpeedBoostLow"));
override void EOnFrame(IEntity other, float timeSlice)
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
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)
static proto void List(string label, out int selection, TStringArray elems)
static proto native void End()
static proto native void Begin(string windowTitle, float x=0, float y=0)
static proto native void Text(string label)
static proto void Check(string label, out bool checked)
static proto void SliderFloat(string label, out float value, float min, float max, int pxWidth=150)
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)
static proto void YawPitchRollMatrix(vector ang, out vector mat[3])
Creates rotation matrix from angles.
static proto float Clamp(float value, float min, float max)
Clamps 'value' to 'min' if it is lower than 'min', or to 'max' if it is higher than 'max'.