DayZ 1.27
DayZ Explorer by KGB
 
Загрузка...
Поиск...
Не найдено
RecoilBase.c
См. документацию.
2{
4
7 protected bool m_DeleteRequested;
8 protected float m_Time;//how much time has elapsed since first update
9 protected float m_ReloadTime;//reload time config parameter of the weapon
11 protected bool m_IsClient;
12 // for mouse offset
13 float m_MouseOffsetRangeMin;//in degrees min
14 float m_MouseOffsetRangeMax;//in degrees max
15 float m_MouseOffsetRelativeTime = 1;//[0..1] a time it takes to move the mouse the required distance relative to the reload time of the weapon(firing mode)
16 float m_HandsOffsetRelativeTime = 1;//[0..1] a time it takes to move the hands the required distance given by the curve relative to the reload time of the weapon(firing mode)
17 float m_CamOffsetRelativeTime = 1;//[0..1] a time it takes to move the camera the required distance relative to the reload time of the weapon(firing mode)
18 float m_CamOffsetDistance = 0.05;//how far the camera will travel along the z-axis in cm
19 float m_MouseOffsetDistance;//how far should the mouse travel
21 //protected float m_MouseOffsetResult;//in degrees max
22 protected vector m_MouseOffsetTarget;//move the mouse towards this point
23 protected vector m_MouseOffsetTargetAccum;//the overall mouse offset so far(all deltas accumulated)
24 protected float m_Angle;//result between the min and max
25 // mouse end
26
28
30 {
31 m_Weapon = weapon;
32 //m_DebugMode = false;
33 m_DebugMode = GetDayZGame().IsAimLogEnabled();
34 m_Player = PlayerBase.Cast(weapon.GetHierarchyRootPlayer());
36 Init();
37 PostInit(weapon);
38 }
39
40 void Init();
41
43 {
44 return m_Weapon;
45 }
46
47 void PostInit(Weapon_Base weapon)
48 {
49 int muzzleIndex = weapon.GetCurrentMuzzle();
50 m_Angle = m_Player.GetRandomGeneratorSyncManager().GetRandomInRange(RandomGeneratorSyncUsage.RGSRecoil, m_MouseOffsetRangeMin, m_MouseOffsetRangeMax);
53
54 m_ReloadTime = weapon.GetReloadTime(muzzleIndex);
59 }
60
62 void Destroy()
63 {
64 m_DeleteRequested = true;
65 }
66
67 // called externally per update, not to be overriden in children
68 void Update( SDayZPlayerAimingModel pModel, out float axis_mouse_x, out float axis_mouse_y, out float axis_hands_x, out float axis_hands_y, float pDt )
69 {
71 {
72 delete this;
73 }
74
77
78 ApplyMouseOffset(pDt, axis_mouse_x, axis_mouse_y);
79 ApplyHandsOffset(pDt, axis_hands_x, axis_hands_y);
80 if(m_IsClient)
81 ApplyCamOffset(pModel);
82 #ifdef DEVELOPER
83 if(m_DebugMode)
84 PrintString("RecoilBase | BEFORE | axis_mouse_y: " + axis_mouse_y.ToString());
85 #endif
86 axis_mouse_x = axis_mouse_x * m_RecoilModifier[0];
87 axis_mouse_y = axis_mouse_y * m_RecoilModifier[1];
88
89 axis_hands_x = axis_hands_x * m_RecoilModifier[0];
90 axis_hands_y = axis_hands_y * m_RecoilModifier[1];
91
92 #ifdef DEVELOPER
93 if(m_DebugMode)
94 {
95 PrintString("RecoilBase | AFTER | axis_mouse_y: " + axis_mouse_y.ToString());
96 }
97 #endif
98 m_Time += pDt;
99
100 if( m_Time >= m_ReloadTime )
101 {
102 Destroy();
103 }
104 }
105
107 {
109 float offset = 0;
110 float time = Easing.EaseOutBack(time_rel);
111 if(time == 1)
112 {
113 offset = 0;
114 }
115 else
116 {
117 offset = Math.Lerp(0,m_CamOffsetDistance,time);
118 }
119
120 pModel.m_fCamPosOffsetZ = offset;
121
122 m_Player.GetCurrentCamera().SendRecoilOffsetZ(offset);
123 }
124
125 void ApplyHandsOffset(float pDt, out float pRecResultX, out float pRecResultY)
126 {
127 float relative_time = m_TimeNormalized / Math.Clamp(m_HandsOffsetRelativeTime, 0.001,1);
128 vector pos_on_curve = GetPositionOnCurve(m_HandsCurvePoints, relative_time);
129
130 /*if(m_DebugMode)
131 {
132 PrintString("pos_on_curve: " + pos_on_curve.ToString());
133 PrintString("normalized time: " + m_TimeNormalized.ToString());
134 PrintString("elapsed time: " + m_Time.ToString());
135 PrintString("curve pos x: " + pos_on_curve[0].ToString());
136 PrintString("curve pos y: " + pos_on_curve[1].ToString());
137 PrintString("relative_time: " + relative_time.ToString());
138 }*/
139
140 pRecResultX = pos_on_curve[0];
141 pRecResultY = pos_on_curve[1];
142 }
143
144 void ApplyMouseOffset(float pDt, out float pRecResultX, out float pRecResultY)
145 {
146 #ifdef DEVELOPER
147 if(m_DebugMode)
148 {
150 PrintString( "RecoilBase | ApplyMouseOffset processing: " + b1 );
151 PrintString( "RecoilBase | m_MouseOffsetTargetAccum : " + m_MouseOffsetTargetAccum.ToString() );
152 PrintString( "RecoilBase | m_MouseOffsetTarget : " + m_MouseOffsetTarget.ToString() );
153 }
154 #endif
155
157 {
158 float relative_delta = pDt / m_ReloadTime / Math.Clamp(m_MouseOffsetRelativeTime, 0.001,1);
159
160 float delta_mouse_offset_x = m_MouseOffsetTarget[0] * relative_delta;
161 float delta_mouse_offset_y = m_MouseOffsetTarget[1] * relative_delta;
162
163 if( ( m_MouseOffsetTargetAccum[1] + delta_mouse_offset_y) > m_MouseOffsetTarget[1] )
164 {
165 delta_mouse_offset_x = m_MouseOffsetTarget[0] - m_MouseOffsetTargetAccum[0];
166 delta_mouse_offset_y = m_MouseOffsetTarget[1] - m_MouseOffsetTargetAccum[1];
167 }
168
169 m_MouseOffsetTargetAccum[0] = m_MouseOffsetTargetAccum[0] + delta_mouse_offset_x;
170 m_MouseOffsetTargetAccum[1] = m_MouseOffsetTargetAccum[1] + delta_mouse_offset_y;
171
172 pRecResultX = delta_mouse_offset_x;
173 pRecResultY = delta_mouse_offset_y;
174
175 /*if(m_DebugMode)
176 {
177 PrintString( "delta x: "+ delta_mouse_offset_x );
178 PrintString( "delta y: "+ delta_mouse_offset_y );
179 PrintString( "target x: "+ m_MouseOffsetTarget[0] );
180 PrintString( "target y: "+ m_MouseOffsetTarget[1] );
181 PrintString( "accum x: "+ m_MouseOffsetTargetAccum[0] );
182 PrintString( "accum y: "+ m_MouseOffsetTargetAccum[1] );
183 }*/
184 }
185 #ifdef DEVELOPER
186 if(m_DebugMode)
187 {
188 PrintString( "RecoilBase | pRecResultY: " + pRecResultY );
189 }
190 #endif
191 }
192
194 {
195 if( weapon )
196 {
197 return weapon.GetPropertyModifierObject().m_RecoilModifiers;
198 }
199 else return "1 1 1";
200 }
201
203 {
204 return Math3D.Curve(ECurveType.CatmullRom, time, points);
205 }
206}
DayZGame GetDayZGame()
Определения DayZGame.c:3870
RandomGeneratorSyncUsage
Определения RandomGeneratorSyncManager.c:2
proto native bool IsDedicatedServer()
Robust check which is preferred than the above, as it is valid much sooner.
static float EaseOutBack(float t, float magnitude=1.70158)
Определения Easing.c:173
Input value between 0 and 1, returns value adjusted by easing, no automatic clamping of input(do your...
Определения Easing.c:3
Определения EnMath3D.c:28
Определения EnMath.c:7
Определения PlayerBaseClient.c:2
float m_ReloadTime
Определения RecoilBase.c:9
bool m_IsClient
Определения RecoilBase.c:11
void RecoilBase(Weapon_Base weapon)
Определения RecoilBase.c:29
void Destroy()
Destroys this object next update tick.
Определения RecoilBase.c:62
vector GetRecoilModifier(Weapon_Base weapon)
Определения RecoilBase.c:193
float m_CamOffsetRelativeTime
Определения RecoilBase.c:17
float m_CamOffsetDistance
Определения RecoilBase.c:18
float m_MouseOffsetDistance
Определения RecoilBase.c:19
PlayerBase m_Player
Определения RecoilBase.c:6
float m_MouseOffsetRangeMax
Определения RecoilBase.c:14
vector GetPositionOnCurve(array< vector > points, float time)
Определения RecoilBase.c:202
bool m_DeleteRequested
Определения RecoilBase.c:7
void Update(SDayZPlayerAimingModel pModel, out float axis_mouse_x, out float axis_mouse_y, out float axis_hands_x, out float axis_hands_y, float pDt)
Определения RecoilBase.c:68
void PostInit(Weapon_Base weapon)
Определения RecoilBase.c:47
vector m_MouseOffsetTargetAccum
Определения RecoilBase.c:23
float m_TimeNormalized
Определения RecoilBase.c:20
void ApplyMouseOffset(float pDt, out float pRecResultX, out float pRecResultY)
Определения RecoilBase.c:144
float m_Angle
Определения RecoilBase.c:24
void ApplyHandsOffset(float pDt, out float pRecResultX, out float pRecResultY)
Определения RecoilBase.c:125
float m_MouseOffsetRelativeTime
Определения RecoilBase.c:15
float m_HandsOffsetRelativeTime
Определения RecoilBase.c:16
vector m_MouseOffsetTarget
Определения RecoilBase.c:22
float m_Time
Определения RecoilBase.c:8
Weapon_Base m_Weapon
Определения RecoilBase.c:5
void ApplyCamOffset(SDayZPlayerAimingModel pModel)
Определения RecoilBase.c:106
vector m_RecoilModifier
Определения RecoilBase.c:10
void Init()
float m_MouseOffsetRangeMin
Определения RecoilBase.c:13
Weapon_Base GetWeapon()
Определения RecoilBase.c:42
ref array< vector > m_HandsCurvePoints
Определения RecoilBase.c:27
bool m_DebugMode
Определения RecoilBase.c:3
float m_fCamPosOffsetZ
Определения dayzplayer.c:1112
shorthand
Определения BoltActionRifle_Base.c:6
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
proto static native vector YawToVector(float yaw)
Returns vector of yaw.
Определения EnConvert.c:106
proto native CGame GetGame()
proto void Print(void var)
Prints content of variable to console/log.
void PrintString(string s)
Helper for printing out string expression. Example: PrintString("Hello " + var);.
Определения EnScript.c:345
ECurveType
Определения EnMath3D.c:21
static proto native vector Curve(ECurveType type, float param, notnull array< vector > points)
Computes curve.
static proto float Lerp(float a, float b, float time)
Linearly interpolates between 'a' and 'b' given 'time'.
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 InverseLerp(float a, float b, float value)
Calculates the linear value that produces the interpolant value within the range [a,...