Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
ScriptCamera.c
Go to the documentation of this file.
1[EntityEditorProps(category: "GameLib/Scripted", description:"Script camera")]
2class ScriptCameraClass: GenericEntityClass
3{
4
5}
6
8{
9 [Attribute("60", UIWidgets.Slider, "Field of view", "0 180 1")]
10 float FOV;
11 [Attribute("1", UIWidgets.EditBox, "Near plane clip")]
12 float NearPlane;
13 [Attribute("4000", UIWidgets.EditBox, "Far plane clip")]
14 float FarPlane;
15
16 [Attribute("1", UIWidgets.ComboBox, "Projection type", "", enumType: CameraType )]
17 int Type;
18 [Attribute("5", UIWidgets.Slider, "Camera speed", "0 20 1")]
19 float Speed;
20 [Attribute("1", UIWidgets.CheckBox, "Free Fly", "" )]
21 bool FreeFly;
22 [Attribute("0", UIWidgets.CheckBox, "Invert vertical", "")]
24 [Attribute("0", UIWidgets.Slider, "Camera index", "0 31 1")]
25 int Index;
26 [Attribute("0", UIWidgets.CheckBox, "Enable preload", "")]
28 float m_MouseSensitivity = 0.001; // should be somewhere else.
29 float m_GamepadSensitivity = 0.2; // should be somewhere else.
31
32 // debug variables
34 ref array<string> m_DbgOptions = {"Perspective", "Orthographic"};
35
37 {
38 SetFlags(EntityFlags.ACTIVE, false);
39 SetEventMask(EntityEvent.POSTFRAME);
40
41 BaseWorld world = GetWorld();
42 world.SetCameraVerticalFOV(Index, FOV);
43 world.SetCameraFarPlane(Index, FarPlane);
44 world.SetCameraNearPlane(Index, NearPlane);
45 world.SetCameraType(Index, Type);
47 world.SetCamera(Index, GetOrigin(), GetYawPitchRoll());
48 vector camMat[4];
49 GetTransform(camMat);
50 world.SetCameraEx(Index, camMat);
51 if (EnablePreload)
52 world.SchedulePreload(GetOrigin(), 500);
54 }
55
56 override protected void EOnPostFrame(IEntity owner, float timeSlice) //EntityEvent.FRAME
57 {
58 g_Game.GetInputManager().ActivateContext("ScriptCameraContext");
59
60 if (g_Game.GetInputManager().GetActionTriggered("CamFreeFly"))
61 {
63 }
64
65 if (FreeFly)
66 {
67 FreeFly(timeSlice);
68 }
69 else
70 {
71 vector camMat[4]; // matrix can be set outside the class
72 GetWorldTransform(camMat);
73 GetWorld().SetCameraEx(Index, camMat);
74 }
75
76 // DebugInfo();
77 }
78
79 protected void FreeFly(float timeSlice)
80 {
81 vector camPosition = GetOrigin();
83 vector camMat[4];
84 GetTransform(camMat);
85 InputManager imanager = g_Game.GetInputManager();
86 imanager.ActivateContext("ScriptCameraFreeFlyContext");
87
88 // get input
89 float turnX = imanager.GetActionValue("CamTurnRight") * 20.0 * timeSlice;
90 float turnY = imanager.GetActionValue("CamTurnUp") * 20.0 * timeSlice;
91 float turnZ = imanager.GetActionValue("CamRotate") * 20.0 * timeSlice;
92 float moveForward = imanager.GetActionValue("CamForward");
93 float moveRight = imanager.GetActionValue("CamRight");
94 float moveAscend = imanager.GetActionValue("CamAscend");
95 float speedDelta = imanager.GetActionValue("CamSpeedDelta") * timeSlice;
96 bool speedBoostHigh = imanager.GetActionTriggered("CamSpeedBoostHigh");
97 bool speedBoostLow = imanager.GetActionTriggered("CamSpeedBoostLow");
98
99 Speed = Math.Clamp(Speed + speedDelta * Speed * 0.25, 0.1, 1000.0);
100
101 float finalSpeed = Speed;
102 if (speedBoostHigh)
103 finalSpeed *= 25;
104 else if (speedBoostLow)
105 finalSpeed *= 5;
106
107 // rotation
108 angles[0] = turnX + angles[0];
109 if (Inverted)
110 angles[1] = turnY + angles[1];
111 else
112 angles[1] = -turnY + angles[1];
113
114 angles[2] = turnZ + angles[2];
115
116 // movement
117 vector move = vector.Zero;
118 vector forward = camMat[2];
119 vector up = camMat[1];
120 vector side = camMat[0];
121
122 move += forward * moveForward;
123 move += side * moveRight;
124 move += up * moveAscend;
125
126 // ------------
127 camPosition = (move * timeSlice * finalSpeed) + camPosition;
128
129 Math3D.AnglesToMatrix(angles, camMat);
130 camMat[3] = camPosition;
131 SetTransform(camMat);
132 GetWorld().SetCameraEx(Index, camMat);
133 }
134
135 protected void DebugInfo()
136 {
137 InputManager imanager = g_Game.GetInputManager();
138 DbgUI.Begin(String("Camera #" + Index.ToString()), 0, Index * 300);
139
140 DbgUI.Text(String("Position : " + GetOrigin().ToString()));
141 DbgUI.Text(String("Orientation (Y, P, R): " + GetYawPitchRoll().ToString()));
142 DbgUI.Text(String("Speed : " + Speed.ToString()));
143 DbgUI.Text(String("Mouse sensitivity : " + (2000 - (1 / m_MouseSensitivity)).ToString()));
144 DbgUI.Check("Select Free fly", FreeFly);
145 DbgUI.List("Camera type", m_DbgListSelection, m_DbgOptions);
146 if (m_DbgListSelection + 1 != Type)
147 {
149 GetWorld().SetCameraType(Index, Type);
150 }
151
152 float sensitivity = 2000 - (1 / m_MouseSensitivity);
153 DbgUI.SliderFloat("Mouse sensitivity", sensitivity, 1, 1999);
154 m_MouseSensitivity = 1 / (2000 - sensitivity);
155
156 DbgUI.Text("CamTurnRight: " + imanager.GetActionValue("CamTurnRight"));
157 DbgUI.Text("CamTurnUp: " + imanager.GetActionValue("CamTurnUp"));
158 DbgUI.Text("CamSpeedDelta: " + imanager.GetActionValue("CamSpeedDelta"));
159 DbgUI.Text("CamForward: " + imanager.GetActionValue("CamForward"));
160 DbgUI.Text("CamRight: " +imanager.GetActionValue("CamRight"));
161 DbgUI.Text("CamAscend: " + imanager.GetActionValue("CamAscend"));
162 DbgUI.Text("CamSpeedBoostHigh: " + imanager.GetActionTriggered("CamSpeedBoostHigh"));
163 DbgUI.Text("CamSpeedBoostLow:" + imanager.GetActionTriggered("CamSpeedBoostLow"));
164
165 DbgUI.End();
166 }
167}
int Index
Definition worldEditor.c:28
ref array< string > angles
enum SCR_ECompassType EntityEditorProps(category:"GameScripted/Gadgets", description:"Compass", color:"0 0 255 255")
Prefab data class for compass component.
bool EnablePreload
float FarPlane
float m_MouseSensitivity
float m_GamepadSensitivity
float Speed
void ScriptCamera(IEntitySource src, IEntity parent)
bool Inverted
int m_DbgListSelection
bool FreeFly
int m_GamepadFreeFly
ref array< string > m_DbgOptions
int Type
void DebugInfo()
Definition DbgUI.c:66
proto external EntityEvent SetEventMask(EntityEvent e)
proto external vector GetOrigin()
proto external vector GetYawPitchRoll()
void EOnPostFrame(IEntity owner, float timeSlice)
proto external void GetWorldTransform(out vector mat[])
See IEntity::GetTransform.
proto external BaseWorld GetWorld()
proto external bool SetTransform(vector mat[4])
proto external EntityFlags SetFlags(EntityFlags flags, bool recursively=false)
proto external void GetTransform(out vector mat[])
Input management system for user interactions.
Definition Math.c:13
Game g_Game
Game singleton instance.
Definition gameLib.c:13
SCR_FieldOfViewSettings Attribute
EntityEvent
Various entity events.
Definition EntityEvent.c:14
EntityFlags
Various entity flags.
Definition EntityFlags.c:14
proto external string ToString()
Plain C++ pointer, no weak pointers, no memory management.
string String(string s)
Definition Types.c:14
CameraType
Definition CameraType.c:14