DayZ 1.24
Loading...
Searching...
No Matches
DayZPlayerCamera_Base.c
Go to the documentation of this file.
1
2float Limit(float pV, float pMin, float pMax)
3{
4 if (pV >= pMin && pV <= pMax)
5 return pV;
6 else if (pV < pMin)
7 return pMin;
8 else
9 return pMax;
10}
11
12
14{
15 while (pAngle > Math.PI)
16
17 pAngle -= Math.PI2;
18
19 while (pAngle < -Math.PI)
20
21 pAngle += Math.PI2;
22
23 return pAngle;
24}
25
27{
28 while (pAngle > 180)
29
30 pAngle -= 360;
31
32 while (pAngle < -180)
33
34 pAngle += 360;
35
36 return pAngle;
37}
38
39
54
56{
57 static const float CONST_NEARPLANE_OPTICS_MIN = 0.04; //Minimal safe near plane value, artifacts on the far plane otherwise!
58
62
65 {
66 m_fLRAngleVel[0] = 0;
67 m_fUDAngleVel[0] = 0;
68 m_fFovAbsVel[0] = 0;
70
73 /*
74 {
75 int perItemCamUD = pPlayer.GetCurrentPerItemCameraUD();
76 string a = "Per Item Camera User Data: " + perItemCamUD.ToString();
77 Print(a);
78 }
79 */
81
82 m_CommandWeapons = pPlayer.GetCommandModifier_Weapons();
83 Init();
85 };
86
87 //disabled by default, overrides on select 3rd person cameras
93
94 void ProcessCameraShake(float delta, out float leftRight, out float upDown)
95 {
96 if (m_CameraShake)
97 {
98 float x, y;
99 m_CameraShake.Update(delta, x, y);
100 leftRight += x;
101 upDown += y;
102 }
103 }
104
105 void Init()
106 {
108 if (player && player.IsNVGWorking() != IsCameraNV())
109 {
110 SetCameraNV(player.IsNVGWorking());
111 SetCameraNVType(player.GetNVType());
112 }
113 }
114
115 float UpdateUDAngleUnlocked(out float pAngle, out float pAngleAdd, float pMin, float pMax, float pDt)
116 {
118
120 {
122 pAngle = target;
123
124 m_fUDAngleVel[0] = 0;
125 }
126 else
127 {
128 if (Math.AbsFloat(pAngleAdd) > 0.001)
129 {
131 pAngle = target;
132 }
133
135 {
137
138 m_fUDAngleVel[0] = 0;
139 }
140 else
141 pAngleAdd = Math.SmoothCD(pAngleAdd, 0.0, m_fUDAngleVel, 0.14, 1000, pDt);
142
145 }
146
149 return pAngle + pAngleAdd;
150 }
151
152 float UpdateLRAngleUnlocked(out float pAngle, out float pAngleAdd, float pMin, float pMax, float pDt)
153 {
154 float target = 0;
155
157 {
159 pAngle = target;
160
161 m_fUDAngleVel[0] = 0;
162 }
163 else
164 {
165 if (Math.AbsFloat(pAngleAdd) > 0.001)
166 {
168 pAngle = target;
169 }
170
172 {
174
175 m_fLRAngleVel[0] = 0;
176 }
177 else
178 pAngleAdd = Math.SmoothCD(pAngleAdd, 0.0, m_fLRAngleVel, 0.14, 1000, pDt);
179
181 }
182
185
186 return pAngle + pAngleAdd;
187 }
188
189 float UpdateUDAngle(out float pAngle, out float pAngleAdd, float pMin, float pMax, float pDt)
190 {
191 if (Math.AbsFloat(pAngleAdd) > 0.001)
192 {
194
197
198 // override actual angle
201
202 // Print("Angle: " + pAngle.ToString() + " Aim: " + actualUDAngle.ToString() );
203 }
204
207 {
210
211 m_fUDAngleVel[0] = 0;
212 }
213 else
214 {
216 {
219
220 m_fUDAngleVel[0] = 0;
221 }
222 else
223 {
227
228 pAngleAdd = Math.SmoothCD(pAngleAdd, 0, m_fUDAngleVel, 0.14, 1000, pDt);
229 }
230 }
231
232 /*{
233 float change = m_pInput.GetAimChange()[1] * Math.RAD2DEG;
234
235 Print ("Script: Camera ud angle: " + pAngle.ToString() + " change: " + change.ToString() );
236 }*/
237
238 return Limit(pAngle + pAngleAdd, pMin, pMax);
239 }
240
241 float UpdateLRAngle(float pAngle, float pMin, float pMax, float pDt)
242 {
245 {
249
250 m_fLRAngleVel[0] = 0; // reset filter
251
252 }
253 else
254 {
256 {
259
260 m_fLRAngleVel[0] = 0; // reset filter
261 }
262 else
263 {
264 // smooth value back to 0
265 pAngle = Math.SmoothCD(pAngle, 0, m_fLRAngleVel, 0.14, 1000, pDt);
266 // m_fLeftRightAngle = 0.9 * (1.0 - pDt);
267 }
268 }
269
270 return pAngle;
271 }
272
273
275 {
277 switch (m_pPlayer.GetEyeZoomLevel())
278 {
279 // ordered in likelihood of occurance for perf. reasons
280 case ECameraZoomType.NONE:
281 m_fFovAbsolute = Math.SmoothCD(m_fFovAbsolute, GetDayZGame().GetFOVByZoomType(ECameraZoomType.NONE), m_fFovAbsVel, 0.1, 1000, pDt);
282 break;
283 case ECameraZoomType.NORMAL:
284 m_fFovAbsolute = Math.SmoothCD(m_fFovAbsolute, GetDayZGame().GetFOVByZoomType(ECameraZoomType.NORMAL), m_fFovAbsVel, 0.1, 1000, pDt);
285 break;
286 case ECameraZoomType.SHALLOW:
287 m_fFovAbsolute = Math.SmoothCD(m_fFovAbsolute, GetDayZGame().GetFOVByZoomType(ECameraZoomType.SHALLOW), m_fFovAbsVel, 0.1, 1000, pDt);
288 break;
289 default:
290 m_fFovAbsolute = Math.SmoothCD(m_fFovAbsolute, GetDayZGame().GetFOVByZoomType(ECameraZoomType.NONE), m_fFovAbsVel, 0.1, 1000, pDt);
291 break;
292 }
293
294 pOutResult.m_fFovAbsolute = m_fFovAbsolute;
295
298 pOutResult.m_fShootFromCamera = 0.0;
299 }
300
301 override void SpawnCameraShakeProper(float strength, float radius, float smoothness, float radius_decay_speed)
302 {
304 }
305
307 {
308 if (!m_pPlayer || !PlayerBase.Cast(m_pPlayer))
309 {
310 Debug.Log("DayZPlayerCameraBase | OnUpdate | no player!");
311 return;
312 }
313
314 if (PlayerBase.Cast(m_pPlayer).GetCurrentCamera() != this)
315 {
316 //Print("DayZPlayerCameraBase | OnUpdate | unused camera! | " + this + "/" + PlayerBase.Cast(m_pPlayer).GetCurrentCamera());
317 return;
318 }
319
320 super.OnUpdate(pDt, pOutResult);
324 }
325
327 {
328 InitCameraOnPlayer(true);
330
331 if (DayZPlayerCameraBase.Cast(pPrevCamera) && DayZPlayerCameraBase.Cast(pPrevCamera).IsCameraNV() && !IsCameraNV())
332 PPERequesterBank.GetRequester(PPERequesterBank.REQ_CAMERANV).Start(new Param1<int>(PPERequester_CameraNV.NV_TRANSITIVE));
333
334 GetGame().GetCallQueue(CALL_CATEGORY_GUI).CallLater(SetCameraPP, m_CameraPPDelay * 1000, false, true, this); // this takes care of weapon/optics postprocessing
337 GetGame().GetCallQueue(CALL_CATEGORY_GUI).Call(PlayerBase.Cast(m_pPlayer).HideClothing, null, false);
338 }
339
341 {
343 }
344
345 override string GetCameraName()
346 {
347 return "DayZPlayerCameraBase";
348 }
349
353
355 {
357 }
358
360 {
361 return m_IsNightvision;
362 }
363
364 void SetCameraNVType(int type)
365 {
366 m_NightvisionType = type;
367 }
368
370 {
371 return m_NightvisionType;
372 }
373
375 {
376 if (!player)
377 return;
378
379 if (player.IsNVGWorking() != IsCameraNV() || player.GetNVType() != GetCameraNVType())
380 {
381 SetCameraNV(player.IsNVGWorking());
382 SetCameraNVType(player.GetNVType());
383 SetCameraPP(true, this);
384 }
385 }
386
389 {
390 PPERequesterBank.GetRequester(PPERequester_CameraADS).Stop();
391
392 if (IsCameraNV())
394 else
396
397 m_weaponUsed = Weapon_Base.Cast(m_pPlayer.GetHumanInventory().GetEntityInHands());
398 if (m_weaponUsed)
399 m_weaponUsed.HideWeaponBarrel(false);
400 }
401
402 override float GetCurrentYaw()
403 {
404 return m_CurrentCameraYaw;
405 }
406
407 override float GetCurrentPitch()
408 {
410 }
411
412 override float GetCurrentRoll()
413 {
414 return m_CurrentCameraRoll;
415 }
416
418 {
420 }
421
422 //TODO - better handling of distinct occluder types
425 {
426 //Print("+++Setting NV type: " + NVtype + " +++");
427 switch (NVtype)
428 {
429 case NVTypes.NONE:
430 {
431 PPERequesterBank.GetRequester(PPERequester_CameraNV).Stop();
432 if (GetGame().GetMission() && GetGame().GetMission().GetEffectWidgets())
433 {
434 GetGame().GetMission().GetEffectWidgets().RemoveActiveEffects({EffectWidgetsTypes.NVG_OCCLUDER});
435 GetGame().GetMission().GetEffectWidgets().RemoveActiveEffects({EffectWidgetsTypes.PUMPKIN_OCCLUDER});
436 }
437 }
438 break;
439
440 //night-vision modes
441 case NVTypes.NV_OPTICS_KAZUAR_NIGHT:
442 case NVTypes.NV_OPTICS_STARLIGHT_NIGHT:
443 case NVTypes.NV_OPTICS_ON:
444 {
445 PPERequesterBank.GetRequester(PPERequesterBank.REQ_CAMERANV).Start(new Param1<int>(PPERequester_CameraNV.NV_DEFAULT_OPTICS));
446 if (GetGame().GetMission() && GetGame().GetMission().GetEffectWidgets())
447 {
448 GetGame().GetMission().GetEffectWidgets().RemoveActiveEffects({EffectWidgetsTypes.NVG_OCCLUDER});
449 GetGame().GetMission().GetEffectWidgets().RemoveActiveEffects({EffectWidgetsTypes.PUMPKIN_OCCLUDER});
450 }
451 }
452 break;
453
454 //daytime filter modes
455 case NVTypes.NV_OPTICS_KAZUAR_DAY:
456 case NVTypes.NV_OPTICS_STARLIGHT_DAY:
457 {
458 PPERequesterBank.GetRequester(PPERequesterBank.REQ_CAMERANV).Start(new Param1<int>(PPERequester_CameraNV.NV_DAYTIME_OPTICS));
459 if (GetGame().GetMission() && GetGame().GetMission().GetEffectWidgets())
460 {
461 GetGame().GetMission().GetEffectWidgets().RemoveActiveEffects({EffectWidgetsTypes.NVG_OCCLUDER});
462 GetGame().GetMission().GetEffectWidgets().RemoveActiveEffects({EffectWidgetsTypes.PUMPKIN_OCCLUDER});
463 }
464 }
465 break;
466
467 case NVTypes.NV_GOGGLES_OFF:
468 case NVTypes.NV_OPTICS_OFF:
469 {
470 PPERequesterBank.GetRequester(PPERequesterBank.REQ_CAMERANV).Start(new Param1<int>(PPERequester_CameraNV.NV_NO_BATTERY));
471 if (GetGame().GetMission() && GetGame().GetMission().GetEffectWidgets())
472 {
473 GetGame().GetMission().GetEffectWidgets().RemoveActiveEffects({EffectWidgetsTypes.NVG_OCCLUDER});
474 GetGame().GetMission().GetEffectWidgets().RemoveActiveEffects({EffectWidgetsTypes.PUMPKIN_OCCLUDER});
475 }
476 }
477 break;
478
479 case NVTypes.NV_GOGGLES:
480 {
481 PPERequesterBank.GetRequester(PPERequesterBank.REQ_CAMERANV).Start(new Param1<int>(PPERequester_CameraNV.NV_DEFAULT_GLASSES));
482 if (GetGame().GetMission() && GetGame().GetMission().GetEffectWidgets())
483 {
484 GetGame().GetMission().GetEffectWidgets().AddActiveEffects({EffectWidgetsTypes.NVG_OCCLUDER});
485 GetGame().GetMission().GetEffectWidgets().RemoveActiveEffects({EffectWidgetsTypes.PUMPKIN_OCCLUDER});
486 }
487 }
488 break;
489
490 case NVTypes.NV_PUMPKIN:
491 {
492 PPERequesterBank.GetRequester(PPERequesterBank.REQ_CAMERANV).Start(new Param1<int>(PPERequester_CameraNV.NV_PUMPKIN));
493 if (GetGame().GetMission() && GetGame().GetMission().GetEffectWidgets())
494 {
495 GetGame().GetMission().GetEffectWidgets().AddActiveEffects({EffectWidgetsTypes.PUMPKIN_OCCLUDER});
496 GetGame().GetMission().GetEffectWidgets().RemoveActiveEffects({EffectWidgetsTypes.NVG_OCCLUDER});
497 }
498 }
499 break;
500 }
501
502 if (PlayerBaseClient.Cast(m_pPlayer))
503 PlayerBaseClient.Cast(m_pPlayer).SwitchPersonalLight(NVtype < 1);
504 }
505
506 void InitCameraOnPlayer(bool force = false)
507 {
509 if (!player.GetCurrentPlayerCamera() || (force && player.GetCurrentPlayerCamera() != this))
510 player.OnCameraChanged(this);
511 }
512
513 protected float m_fLRAngleVel[1];
514 protected float m_fUDAngleVel[1];
515 protected float m_fFovAbsVel[1];
516 protected float m_fFovAbsolute;
517 protected bool m_bForceFreeLook;
518 protected float m_WeaponSwayModifier;
519 protected float m_CameraPPDelay;
520
521 protected float m_CurrentCameraYaw;
522 protected float m_CurrentCameraPitch;
523 protected float m_CurrentCameraRoll;
524
526 protected bool m_IsNightvision;
527 protected int m_NightvisionType;
528}
DayZGame GetDayZGame()
Definition DayZGame.c:3530
float m_fUDAngleVel[1]
float UpdateLRAngleUnlocked(out float pAngle, out float pAngleAdd, float pMin, float pMax, float pDt)
ref CameraShake m_CameraShake
float m_CurrentCameraYaw
bool m_IsNightvision
float m_CurrentCameraPitch
float UpdateUDAngleUnlocked(out float pAngle, out float pAngleAdd, float pMin, float pMax, float pDt)
int m_NightvisionType
Weapon_Base m_weaponUsed
float Limit(float pV, float pMin, float pMax)
limit function
void StdFovUpdate(float pDt, out DayZPlayerCameraResult pOutResult)
@ NV_GOGGLES_OFF
@ NV_OPTICS_OFF
@ NV_OPTICS_STARLIGHT_DAY
@ NV_OPTICS_KAZUAR_DAY
@ NV_OPTICS_STARLIGHT_NIGHT
@ NV_OPTICS_KAZUAR_NIGHT
float m_CurrentCameraRoll
bool IsCameraNV()
float fixAngle_PI_PI(float pAngle)
float UpdateLRAngle(float pAngle, float pMin, float pMax, float pDt)
bool m_bForceFreeLook
float m_CameraPPDelay
float GetWeaponSwayModifier()
void DayZPlayerCameraBase(DayZPlayer pPlayer, HumanInputController pInput)
constructor must be same
void SetNVPostprocess(int NVtype)
DayZPlayerCameraOptics handles this separately, otherwise it takes active NVType from PlayerBase::Get...
void InitCameraOnPlayer(bool force=false)
void HandleShoulderCameraOverride(HumanInputController pInput)
float fixAngle_180_180(float pAngle)
void SetCameraNV(bool nightvision)
float m_WeaponSwayModifier
enum NVTypes CONST_NEARPLANE_OPTICS_MIN
void UpdateCameraNV(PlayerBase player)
void SetCameraNVType(int type)
float m_fFovAbsVel[1]
int GetCameraNVType()
void ForceFreelook(bool state)
ItemOptics m_opticsUsed
float UpdateUDAngle(out float pAngle, out float pAngleAdd, float pMin, float pMax, float pDt)
HumanCommandWeapons m_CommandWeapons
void ProcessCameraShake(float delta, out float leftRight, out float upDown)
float m_fLRAngleVel[1]
void DayZPlayerCameraOptics(DayZPlayer pPlayer, HumanInputController pInput)
override void Init()
Launched from 'DayZGame.DeferredInit' to make earlier access, use, and updates impossible (downside o...
ECameraZoomType
Icon x
Icon y
this is main camera class
override void SetCameraPP(bool state, DayZPlayerCamera launchedFrom)
override void SetCameraPPDelay(DayZPlayerCamera pPrevCamera)
override bool IsShootingFromCamera()
override int GetEyeZoomLevel()
Definition Debug.c:14
static void Log(string message=LOG_DEFAULT, string plugin=LOG_DEFAULT, string author=LOG_DEFAULT, string label=LOG_DEFAULT, string entity=LOG_DEFAULT)
Prints debug message with normal prio.
Definition Debug.c:133
proto native float GetBaseAimingAngleUD()
returns base aiming angle UD - without sway/offsets/...
proto native bool CameraIsFreeLook()
returns true if freelook is active
proto native vector GetAimChange()
returns per tick aim change (in radians)
proto native bool CameraIsTracking()
returns if camera is tracking (using IR device)
proto native void Override3rdIsRightShoulder(HumanInputControllerOverrideType overrideType, bool value)
proto native vector GetTracking()
returns absolute tracking change (in radians)
proto native vector GetAimDelta(float dt)
returns aim change (in radians)
Definition EnMath.c:7
float GetCurrentRoll()
Definition dayzplayer.c:107
float GetCurrentYaw()
Definition dayzplayer.c:97
void SpawnCameraShakeProper(float strength, float radius, float smoothness, float radius_decay_speed)
DayZPlayer m_pPlayer
data
Definition dayzplayer.c:135
HumanInputController m_pInput
human input
Definition dayzplayer.c:136
float GetCurrentPitch()
Definition dayzplayer.c:102
class DayZPlayerCameraResult DayZPlayerCamera(DayZPlayer pPlayer, HumanInputController pInput)
Definition dayzplayer.c:56
float m_fFovAbsolute
fov absolute value override - -1.0 default, if set - overrides absolute fov setting
Definition dayzplayer.c:60
proto native CGame GetGame()
static const float PI2
Definition EnMath.c:13
static const float RAD2DEG
Definition EnMath.c:16
static proto float AbsFloat(float f)
Returns absolute value.
static proto float SmoothCD(float val, float target, inout float velocity[], float smoothTime, float maxVelocity, float dt)
Does the CD smoothing function - easy in | easy out / S shaped smoothing.
static const float PI
Definition EnMath.c:12
proto native void OnUpdate()
Definition tools.c:333
const int CALL_CATEGORY_GUI
Definition tools.c:9
HumanInputControllerOverrideType
Definition human.c:8
class HumanMovementState OnActivate()
HumanCommandScript fully scriptable command.
Definition human.c:1167