DayZ 1.24
Loading...
Searching...
No Matches
DayZPlayerCameraIronsights.c
Go to the documentation of this file.
1
3class DayZPlayerCameraIronsights extends DayZPlayerCameraBase
4{
5 static const float CONST_UD_MIN = -85.0;
6 static const float CONST_UD_MAX = 85.0;
7 static const float CONST_UD_MIN_BACK = -25.0;
8
9 static const float CONST_LR_MIN = -160.0;
10 static const float CONST_LR_MAX = 160.0;
11
12 protected bool m_isEntering = false;
13 protected bool m_opticsHasWeaponOverride = false;
14 protected ref array<float> temp_array; //DOF only
15
17
19 float m_velocityYaw[1];
20 float m_velocityPitch[1];
24
30
31
33 {
34 if (!temp_array)
35 temp_array = new array<float>;
36 m_iBoneIndex = pPlayer.GetBoneIndexByName("RightHand_Dummy");
37
38 if (m_iBoneIndex == -1)
39 Print("DayZPlayerCamera1stPerson: main bone not found");
40
41 m_dynamicsStrength = 2;
42 m_dynamicsSmoothTime = 0.3;
43
45 GetCurrentSightInfo(m_OpticsCamPos, m_OpticsCamDir);
46 m_isEntering = true;
48
49 m_movementTimeAcc = 0;
50 m_movementAmplitudeX = 1;
51 m_movementAmplitudeY = 1;
52 m_movementFrequencyX = 1;
53 m_movementFrequencyY = 2;
54
56
57 Init();
58 }
59
61 {
62 EntityAI inHands = m_pPlayer.GetHumanInventory().GetEntityInHands();
63 if (inHands)
64 {
66 if (m_weaponUsed)
67 {
68 m_SightMisalignmentModifier = m_weaponUsed.GetPropertyModifierObject().m_SightMisalignment;
69 m_dynamicsStrength = m_dynamicsStrength * m_SightMisalignmentModifier[0];
70 m_dynamicsSmoothTime = m_dynamicsSmoothTime * m_SightMisalignmentModifier[1];
71 m_opticsUsed = m_weaponUsed.GetAttachedOptics();
72 if (m_opticsUsed)
73 m_opticsHasWeaponOverride = m_opticsUsed.HasWeaponIronsightsOverride();
74 }
75 else
77 }
78 }
79
80 //
96
98 {
99 if (m_opticsHasWeaponOverride)
100 return m_opticsUsed;
101
102 return m_weaponUsed;
103 }
104
106 {
108 if (e)
109 {
110 if (e == m_weaponUsed)
111 {
112 m_weaponUsed.GetCameraPoint(m_weaponUsed.GetCurrentMuzzle(), camPos, camDir);
113 return true;
114 }
115 else if (e == m_opticsUsed)
116 {
117 m_opticsUsed.UseWeaponIronsightsOverride(m_opticsHasWeaponOverride);
119 return true;
120 }
121 }
122 else
123 ErrorEx("No sight entity found in " + this, ErrorExSeverity.INFO);
124 return false;
125 }
126
127 //
129 {
131 float min;
133 if (player && player.IsPlayerInStance(DayZPlayerConstants.STANCEMASK_RAISEDPRONE))
135 else
137
140
141 // get model space transform matrix of the gun's eye vector
142 vector matTM[4];
143 HumanItemAccessor hia = m_pPlayer.GetItemAccessor();
145 hia.WeaponGetCameraPointBoneRelative(GetCurrentSightEntity(), m_OpticsCamPos, m_OpticsCamDir, m_iBoneIndex, matTM);
146
147 // aim change based on character movement
151
152 HumanCommandMove hcm = m_pPlayer.GetCommand_Move();
153 if (hcm)
154 {
155 float speed = hcm.GetCurrentMovementSpeed();
156
157 if (speed > 0)
158 m_movementTimeAcc += pDt;
159 else
160 m_movementTimeAcc = 0;
161
162 aimChangeX += m_movementAmplitudeX * speed * Math.Sin(Math.PI2 * m_movementFrequencyX * m_movementTimeAcc);
163 aimChangeY += m_movementAmplitudeY * speed * Math.Sin(Math.PI2 * m_movementFrequencyY * m_movementTimeAcc);
164 }
165
166 aimChangeYPR[0] = Math.SmoothCD(aimChangeYPR[0], -(m_dynamicsStrength * aimChangeY), m_velocityYaw, m_dynamicsSmoothTime, 1000, pDt);
167 aimChangeYPR[1] = Math.SmoothCD(aimChangeYPR[1], -(m_dynamicsStrength * aimChangeX), m_velocityPitch, m_dynamicsSmoothTime, 1000, pDt);
168 aimChangeYPR[2] = 0;
169
170 vector dynamics[4];
172 dynamics[3] = vector.Zero;
173
174 // aiming model offsets
176 hia.WeaponGetAimingModelDirTm(aimingMatTM);
177
178 // final offset matrix
181
185
186 if (m_CameraShake)
187 {
188 float x, y;
189 m_CameraShake.Update(pDt, x, y);
190 DayZPlayerImplement.Cast(m_pPlayer).GetAimingModel().SetCamShakeValues(x, y);
191 }
192 }
193
195 {
196 vector a;
197 a[0] = m_fUpDownAngle;
198 a[1] = m_fLeftRightAngle;
199 a[2] = 0;
200 return a;
201 }
202
204 {
205 vector a;
206 a[0] = m_fUpDownAngleAdd;
208 a[2] = 0;
209 return a;
210 }
211
213 {
214 pOutResult.m_iDirectBone = m_iBoneIndex;
215 pOutResult.m_iDirectBoneMode = 4;
216
217 pOutResult.m_fFovAbsolute = HoldBreathFOVEffect(pDt);
218
219 pOutResult.m_bUpdateWhenBlendOut = false;
220 pOutResult.m_fDistance = 0;
221 pOutResult.m_fUseHeading = 0;
222 pOutResult.m_fInsideCamera = 1.0;
223 pOutResult.m_fShootFromCamera = m_fShootFromCamera;
224
225 pOutResult.m_fNearPlane = 0.04; //0.07 default
226 }
227
229 {
230 if (m_pPlayer.IsHoldingBreath())
232 else if (m_isEntering) //sets FOV immediatelly to avoid "floating camera" effect
233 {
235 m_isEntering = false;
236 }
237 else
239
240 return m_fFovAbsolute;
241 }
242
243 // sets PP for ironsights and optics (override) cameras
245 {
246 //Print("SetCameraPP - ADS");
247 if (PlayerBase.Cast(m_pPlayer) && launchedFrom.Type() != PlayerBase.Cast(m_pPlayer).GetCurrentPlayerCamera().Type())
248 {
249 //Print("DayZPlayerCameraIronsights | SetCameraPP | skipping, wrong camera type active!");
250 return;
251 }
252
253 //if (!state || !m_weaponUsed || (PlayerBase.Cast(m_pPlayer) && launchedFrom != PlayerBase.Cast(m_pPlayer).GetCurrentPlayerCamera()))
254 if (!state || !m_weaponUsed)
255 {
256 m_RequesterADS.Stop();
257
258 if (IsCameraNV())
260 else
262 }
263 else
264 {
265 temp_array = {false, 0.0, 0.0, 0.0, 0.0, 1.0};
266
267 if (m_weaponUsed.GetWeaponDOF() || (m_opticsUsed && m_opticsUsed.GetOpticsDOF()))
268 {
269 if (m_opticsUsed && m_opticsUsed.GetOpticsDOF().Count() == 6)
270 temp_array = m_opticsUsed.GetOpticsDOF();
271 else
272 temp_array = m_weaponUsed.GetWeaponDOF();
273 if (temp_array.Count() != 6)
274 temp_array = {false, 0.0, 0.0, 0.0, 0.0, 1.0};
275 }
276
277 m_RequesterADS.SetValuesIronsights(temp_array); //DOF only
278
279 if (IsCameraNV())
281 else
283 }
284
285 if (m_weaponUsed)
286 m_weaponUsed.HideWeaponBarrel(false);
287 }
288
289 override string GetCameraName()
290 {
291 return "DayZPlayerCameraIronsights";
292 }
293
295 {
296 if (pPrevCamera.GetCameraName() == "DayZPlayerCamera1stPerson")
297 {
298 //Print("---ironsights---DayZPlayerCamera1stPerson");
300 }
301 else if (pPrevCamera.GetCameraName() == "DayZPlayerCameraOptics")
302 m_CameraPPDelay = 0;
303 else
304 {
305 //Print("---ironsights---else");
307 }
308 }
309
311 {
313 if (optics)
314 optics.UpdateOpticsReddotVisibility();
315 }
316
318 protected float m_fShootFromCamera = 0.0;
319
321 protected int m_iBoneIndex;
324
325 protected float m_fUpDownAngle;
326 protected float m_fUpDownAngleAdd;
327 protected float m_fLeftRightAngle;
328 protected float m_fLeftRightAngleAdd;
329
330}
331
332class DayZPlayerCameraOptics : DayZPlayerCameraIronsights
333{
334 static const float CONST_NEARPLANE_OPTICS = 0.06; //Default near plane value for this camera
335 protected float m_RecoilOffsetZ = 0.0;
336
338 {
339 if (!temp_array)
340 temp_array = new array<float>;
342 }
343
344 override void Init()
345 {
347 SetCameraNV(true);
348 else
349 SetCameraNV(false);
350 }
351
353 {
354 return m_opticsUsed;
355 }
356
358 {
359 if (m_opticsUsed)
360 {
363 return true;
364 }
365 return false;
366 }
367
369 {
371
373 if (player && m_opticsUsed)
374 GetGame().GetCallQueue(CALL_CATEGORY_GUI).CallLater(player.HideClothing, m_CameraPPDelay * 1000, false, m_opticsUsed, true);
375 }
376
378 {
379 pOutResult.m_iDirectBone = m_iBoneIndex;
380 pOutResult.m_iDirectBoneMode = 4;
381
382 pOutResult.m_fFovAbsolute = HoldBreathFOVEffect(pDt);
383
384 pOutResult.m_bUpdateWhenBlendOut = false;
385 pOutResult.m_fDistance = 0;
386 pOutResult.m_fUseHeading = 0;
387 pOutResult.m_fInsideCamera = 1.0;
388 pOutResult.m_fShootFromCamera = m_fShootFromCamera;
389
390 if (!m_opticsUsed)
392 else
393 pOutResult.m_fNearPlane = Math.Clamp(m_opticsUsed.GetNearPlaneValue() - m_RecoilOffsetZ, CONST_NEARPLANE_OPTICS, 10.0); //some sufficiently nonsensical max
394 }
395
396 override float HoldBreathFOVEffect(float pDt)
397 {
398 //hotfix; two cameras exist and update simultaneously during transition, even if optics/weapons is no longer present!
399 /*PlayerBase player = PlayerBase.Cast(m_pPlayer);
400 if (player && player.GetCurrentCamera() != this)
401 return 0.6;*/
402
404 if (optics)
405 {
406 if (optics.GetCurrentStepFOV() >= GameConstants.DZPLAYER_CAMERA_FOV_EYEZOOM && (m_pPlayer.IsHoldingBreath() || m_pPlayer.GetEyeZoomLevel()))
408 else if (m_isEntering) //sets FOV immediatelly to avoid "floating camera" effect
409 {
410 m_fFovAbsolute = optics.GetCurrentStepFOV();
411 m_isEntering = false;
412 }
413 else
414 {
415 m_fFovAbsolute = Math.SmoothCD(m_fFovAbsolute, optics.GetCurrentStepFOV(), m_fFovAbsVel, 0.1, 1000, pDt);
416 //m_fFovAbsolute = optics.GetCurrentStepFOV();
417 }
418 return m_fFovAbsolute;
419 }
420 else
421 {
422 //Error("optic camera, but there is no optic item or optic on weapon"); //camera update ticks on transitions as well, caused problems
423 return 0.6; //TODO figure some other way to get original FOV here!
424 }
425 }
426
428 {
429 //Print("SetCameraPP - optics");
430 if (PlayerBase.Cast(m_pPlayer) && launchedFrom.Type() != PlayerBase.Cast(m_pPlayer).GetCurrentPlayerCamera().Type())
431 {
432 //Print("DayZPlayerCameraOptics | SetCameraPP | skipping, wrong camera type active!");
433 return;
434 }
435
436 if (!state || !m_opticsUsed)
437 {
438 m_RequesterADS.Stop();
439
440 if (IsCameraNV())
442 else
444
445 if (m_weaponUsed)
446 m_weaponUsed.HideWeaponBarrel(false);
447 }
448 else
449 {
452 float gauss = 0.0;
453 temp_array = {false, 0.0, 0.0, 0.0, 0.0, 1.0};
454
455 // 1x scopes only
456 if (m_opticsUsed.AllowsDOF() && !NVGoggles.Cast(m_opticsUsed))
457 {
458 if (m_weaponUsed)
459 {
460 if (m_opticsUsed.GetOpticsDOF().Count() == 6)
461 temp_array = m_opticsUsed.GetOpticsDOF();
462 else
463 {
464 temp_array = m_weaponUsed.GetWeaponDOF(); //TODO should some optics have own DOF settings (different eye point)?
465 }
466
467 if (temp_array.Count() != 6)
468 temp_array = {false, 0.0, 0.0, 0.0, 0.0, 1.0};
469 }
470
471 m_RequesterADS.SetValuesIronsights(temp_array); //DOF only
472
473 // optics NV mode
475 {
476 SetCameraNV(true);
478 }
479 else
480 {
481 if (IsCameraNV())
483 else
485 }
486 }
487 else //magnifying scopes
488 {
489 // optics mask
492
493 //optics lens
496
497 //optics blur
498 if (m_opticsUsed.GetOpticsPPBlur() != 0)
500
501 m_RequesterADS.SetValuesOptics(mask_values, lens_values, gauss);
502
503 // optics NV mode
505 {
506 SetCameraNV(true);
508 }
509 else
510 {
511 SetNVPostprocess(NVTypes.NONE); //magnifying optics do not combine with other NV sources (would render NV optics obsolete)
512 }
513 }
514
515 if (m_weaponUsed)
516 m_weaponUsed.HideWeaponBarrel(true);
517 }
518 }
519
520 override string GetCameraName()
521 {
522 return "DayZPlayerCameraOptics";
523 }
524
526 {
527 if (pPrevCamera.GetCameraName() == "DayZPlayerCameraIronsights")
529 else if (pPrevCamera.GetCameraName() == "DayZPlayerCamera1stPerson")
530 {
531 m_CameraPPDelay = DayZPlayerCameras.TIME_CAMERACHANGE_02 - 0.05; //changed to accomodate handheld optics, had to be changed here also
532 }
533 else if (!pPrevCamera.IsCamera3rdRaised())
535 else
537 }
538
539 override void SendRecoilOffsetZ(float offset)
540 {
542 }
543};
544
override Widget Init()
Definition DayZGame.c:120
int m_iBoneIndex
main bone
float m_fLeftRightAngle
left right angle in rad (in freelook only)
float m_fUpDownAngle
up down angle in rad
static const float CONST_UD_MAX
up limit
float m_fLeftRightAngleAdd
left right angle in rad (in freelook only)
float m_fUpDownAngleAdd
up down angle in rad
static const float CONST_LR_MIN
down limit
static const float CONST_LR_MAX
up limit
static const float CONST_UD_MIN
down limit
float UpdateLRAngleUnlocked(out float pAngle, out float pAngleAdd, float pMin, float pMax, float pDt)
ref CameraShake m_CameraShake
float m_CurrentCameraYaw
float m_CurrentCameraPitch
float UpdateUDAngleUnlocked(out float pAngle, out float pAngleAdd, float pMin, float pMax, float pDt)
Weapon_Base m_weaponUsed
bool IsCameraNV()
float m_CameraPPDelay
void SetNVPostprocess(int NVtype)
DayZPlayerCameraOptics handles this separately, otherwise it takes active NVType from PlayerBase::Get...
void SetCameraPP(bool state, DayZPlayerCamera launchedFrom)
by default sets camera PP to zero, regardless of parameter. Override if needed.
void SetCameraNV(bool nightvision)
float m_WeaponSwayModifier
void UpdateCameraNV(PlayerBase player)
float m_fFovAbsVel[1]
int GetCameraNVType()
ItemOptics m_opticsUsed
void SetCameraPPDelay(DayZPlayerCamera pPrevCamera)
void DayZPlayerCameraOptics(DayZPlayer pPlayer, HumanInputController pInput)
override bool GetCurrentSightInfo(out vector camPos, out vector camDir)
override float HoldBreathFOVEffect(float pDt)
override EntityAI GetCurrentSightEntity()
override void Init()
Launched from 'DayZGame.DeferredInit' to make earlier access, use, and updates impossible (downside o...
override void AdjustCameraParameters(float pDt, inout DayZPlayerCameraResult pOutResult)
float m_RecoilOffsetZ
class DayZPlayerCameraIronsights extends DayZPlayerCameraBase CONST_NEARPLANE_OPTICS
Icon x
Icon y
PlayerBase GetPlayer()
Super root of all classes in Enforce script.
Definition EnScript.c:11
this is main camera class
float m_fLeftRightAngleAdd
left right angle in rad (in freelook only)
override void SetCameraPP(bool state, DayZPlayerCamera launchedFrom)
override void SetCameraPPDelay(DayZPlayerCamera pPrevCamera)
static const float CONST_UD_MIN_BACK
down limit on back
PPERequester_CameraADS m_RequesterADS
override void OnActivate(DayZPlayerCamera pPrevCamera, DayZPlayerCameraResult pPrevCameraResult)
void AdjustCameraParameters(float pDt, inout DayZPlayerCameraResult pOutResult)
bool GetCurrentSightInfo(out vector camPos, out vector camDir)
static const float CONST_UD_MIN
down limit
void DayZPlayerCameraIronsights(DayZPlayer pPlayer, HumanInputController pInput)
override void OnUpdate(float pDt, out DayZPlayerCameraResult pOutResult)
float m_fUpDownAngleAdd
up down angle in rad
float m_fLeftRightAngle
left right angle in rad (in freelook only)
void UpdateBatteryOptics(EntityAI entity)
float m_fUpDownAngle
up down angle in rad
static const float TIME_CAMERACHANGE_03
static const float TIME_CAMERACHANGE_02
static const float TIME_CAMERACHANGE_01
for two handed items
override int GetEyeZoomLevel()
proto native vector GetAimDelta(float dt)
returns aim change (in radians)
ref array< float > GetOpticsPPLens()
Definition ItemOptics.c:459
bool IsWorking()
Definition ItemOptics.c:188
bool AllowsDOF()
returns 'true' for non-magnifying optics
Definition ItemOptics.c:394
int GetCurrentNVType()
Definition ItemOptics.c:404
ref array< float > GetOpticsPPMask()
Definition ItemOptics.c:455
float GetNearPlaneValue()
Definition ItemOptics.c:468
proto native bool UseWeaponIronsightsOverride(bool state)
switches into ironsights override settings
float GetOpticsPPBlur()
Definition ItemOptics.c:463
bool IsNVOptic()
Definition ItemOptics.c:399
proto native void GetCameraPoint(out vector pos, out vector dir)
gets camera position & direction in model space of optics entity
ref array< float > GetOpticsDOF()
Definition ItemOptics.c:451
proto native bool HasWeaponIronsightsOverride()
is weapon in optics mode or not
Definition EnMath.c:7
static const vector Zero
Definition EnConvert.c:110
DayZPlayerConstants
defined in C++
Definition dayzplayer.c:597
void SendRecoilOffsetZ(float offset)
m_fCamPosOffsetZ info, used to adjust near plane in DayZPlayerCameraIronsights now
Definition dayzplayer.c:139
DayZPlayer m_pPlayer
data
Definition dayzplayer.c:135
HumanInputController m_pInput
human input
Definition dayzplayer.c:136
float m_fShootFromCamera
1(default) - uses shoot from camera (+aiming sway), 0 pure weapon shoot (ironsights == 0)
Definition dayzplayer.c:71
string GetCameraName()
Definition dayzplayer.c:92
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()
ErrorExSeverity
Definition EnDebug.c:62
proto void Print(void var)
Prints content of variable to console/log.
enum ShapeType ErrorEx
const float DZPLAYER_CAMERA_FOV_EYEZOOM
FOV (vertical angle/2) in radians. Take care to modify also in "basicDefines.hpp".
Definition constants.c:834
const float DZPLAYER_CAMERA_FOV_IRONSIGHTS
Definition constants.c:836
static proto bool CastTo(out Class to, Class from)
Try to safely down-cast base class to child class.
static proto void MatrixMultiply4(vector mat0[4], vector mat1[4], out vector res[4])
Transforms matrix.
static proto void YawPitchRollMatrix(vector ang, out vector mat[3])
Creates rotation matrix from angles.
static const float PI2
Definition EnMath.c:13
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'.
static proto float Sin(float angle)
Returns sinus of angle in radians.
static const float RAD2DEG
Definition EnMath.c:16
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.
const int CALL_CATEGORY_GUI
Definition tools.c:9
class HumanMovementState OnActivate()
HumanCommandScript fully scriptable command.
Definition human.c:1167
void HumanItemAccessor()
Definition humanitems.c:135