DayZ 1.27
DayZ Explorer by KGB
 
Загрузка...
Поиск...
Не найдено
ScriptCamera.c
См. документацию.
1#ifdef GAME_TEMPLATE
2
3[EditorAttribute("box", "GameLib/Scripted", "Script camera", "-0.25 -0.25 -0.25", "0.25 0.25 0.25", "255 0 0 255")]
4class ScriptCameraClass
5{
6
7}
8
9ScriptCameraClass ScriptCameraSource;
10
11class ScriptCamera: GenericEntity
12{
13 [Attribute("60", "slider", "Field of view", "0 180 1")]
14 float FOV;
15 [Attribute("1", "editbox", "Near plane clip")]
16 float NearPlane;
17 [Attribute("4000", "editbox", "Far plane clip")]
18 float FarPlane;
19
20 [Attribute("1", "combobox", "Projection type", "", ParamEnumArray.FromEnum(CameraType) )]
21 int Type;
22 [Attribute("5", "slider", "Camera speed", "0 20 1")]
23 float Speed;
24 [Attribute("1", "combobox", "Free Fly", "", ParamEnumArray.FromEnum(EBool) )]
25 bool FreeFly;
26 [Attribute("0", "combobox", "Invert vertical", "", ParamEnumArray.FromEnum(EBool) )]
27 bool Inverted;
28 [Attribute("0", "slider", "Camera index", "0 31 1")]
29 int Index;
30 float m_MouseSensitivity = 0.001; // should be somewhere else.
31 float m_GamepadSensitivity = 0.2; // should be somewhere else.
32 int m_GamepadFreeFly;
33
34 // debug variables
35 int m_DbgListSelection = 0;
36 ref array<string> m_DbgOptions = {"Perspective", "Orthographic"};
37
38 void ScriptCamera(IEntitySource src, IEntity parent)
39 {
40 SetFlags(EntityFlags.ACTIVE, false);
41 SetEventMask(EntityEvent.FRAME);
42
43 SetCameraVerticalFOV(Index, FOV);
44 SetCameraFarPlane(Index, FarPlane);
45 SetCameraNearPlane(Index, NearPlane);
46 SetCameraType(Index, Type);
47 m_DbgListSelection = Type - 1;
48 SetCamera(Index, GetOrigin(), GetYawPitchRoll());
49
50 vector camMat[4];
51 GetTransform(camMat);
52 SetCameraEx(Index, camMat);
53 m_GamepadFreeFly = FreeFly;
54 }
55
56 override protected void EOnFrame(IEntity other, float timeSlice) //EntityEvent.FRAME
57 {
58 GetGame().GetInputManager().ActivateContext("ScriptCameraContext");
59
60 if (GetGame().GetInputManager().GetActionTriggered("CamFreeFly"))
61 {
62 FreeFly = !FreeFly;
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 GetTransform(camMat);
73 SetCameraEx(Index, camMat);
74 }
75
76 if (GameSettings.Debug)
77 {
78 DebugInfo();
79 }
80 }
81
82 protected void FreeFly(float timeSlice)
83 {
84 vector camPosition = GetOrigin();
85 vector angles = GetYawPitchRoll();
86 vector camMat[4];
87 GetTransform(camMat);
88 InputManager imanager = GetGame().GetInputManager();
89 imanager.ActivateContext("ScriptCameraFreeFlyContext");
90
91 // get input
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");
101
102 Speed = Math.Clamp(Speed + speedDelta * Speed * 0.25, 0.1, 1000.0);
103
104 float finalSpeed = Speed;
105 if (speedBoostLow)
106 finalSpeed *= 25;
107 else if (speedBoostHigh)
108 finalSpeed *= 5;
109
110 // rotation
111 angles[0] = turnX + angles[0];
112 if (Inverted)
113 angles[1] = turnY + angles[1];
114 else
115 angles[1] = -turnY + angles[1];
116
117 angles[2] = turnZ + angles[2];
118
119 // movement
120 vector move = vector.Zero;
121 vector forward = camMat[2];
122 vector up = camMat[1];
123 vector side = camMat[0];
124
125 move += forward * moveForward;
126 move += side * moveRight;
127 move += up * moveAscend;
128
129 // ------------
130 camPosition = (move * timeSlice * finalSpeed) + camPosition;
131
132 Math3D.YawPitchRollMatrix(angles, camMat);
133 camMat[3] = camPosition;
134 SetTransform(camMat);
135 SetCameraEx(Index, camMat);
136 }
137
138 protected void DebugInfo()
139 {
140 InputManager imanager = GetGame().GetInputManager();
141 DbgUI.Begin(String("Camera #" + Index.ToString()), 0, Index * 300);
142
143 DbgUI.Text(String("Position : " + GetOrigin().ToString()));
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)
150 {
151 Type = m_DbgListSelection + 1;
152 SetCameraType(Index, Type);
153 }
154
155 float sensitivity = 2000 - (1 / m_MouseSensitivity);
156 DbgUI.SliderFloat("Mouse sensitivity", sensitivity, 1, 1999);
157 m_MouseSensitivity = 1 / (2000 - sensitivity);
158
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"));
167
168 DbgUI.End();
169 }
170}
171
172#endif
EBool
Определения EnConvert.c:17
proto string ToString()
int[] IEntitySource
Определения EnEntity.c:2
string Type
Определения JsonDataContaminatedArea.c:11
override void EOnFrame(IEntity other, float timeSlice)
Определения TestFramework.c:240
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)
CameraType
Определения EnWorld.c:39
proto native void SetFlags(ShapeFlags flags)
string String(string s)
Helper for passing string expression to functions with void parameter. Example: Print(String("Hello "...
Определения EnScript.c:339
EntityEvent
Entity events for event-mask, or throwing event from code.
Определения EnEntity.c:45
EntityFlags
Entity flags.
Определения EnEntity.c:115
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)
Определения EnEntity.c:854
proto native void SetTransform(vector mat[4], bool immedUpdate=true)