DayZ 1.28
DayZ Explorer by KGB
 
Загрузка...
Поиск...
Не найдено
WeaponLiftDiag.c
См. документацию.
1#ifdef DIAG_DEVELOPER
2#ifndef SERVER
3//----------------------------------------------------------------------------------------
5class WeaponLiftDiagData
6{
7 vector m_Transform[4];
8
9 vector m_Start;
10 vector m_Direction;
11 float m_WeaponStartDist
12 float m_WeaponEndDist;
13 float m_EffectiveAttachmentLength;
14 float m_ObstructionDistanceCfg;
15 float m_ObstructionDistance;
16
17 float m_RayRadius;
18 float m_RayRadiusOverride;
19 ref RaycastRVResult m_RayResult;
20 float m_HitFraction;
21 float m_HitDistance;
22
23 vector m_LastPosition;
24
25 float m_InterpInTime;
26 float m_InterpInTimeLift;
27 float m_InterpOutTime;
28 float m_InterpCurrTime;
29 float m_InterpCurrValue;
30 float m_InterpTgtValue;
31 float m_InterpSmoothValue;
32
33 float m_AimUD;
34 float m_AimLR;
35 float m_AimUD11;
36 float m_AimLR11;
37
39 void SetTransform(vector transform[4])
40 {
41 for (int i = 0; i < 4; ++i) m_Transform[i] = transform[i];
42 }
43
45 void SetAimAngles(float udAngle, float lrAngle, float udAngle11, float lrAngle11)
46 {
47 m_AimUD = udAngle;
48 m_AimLR = lrAngle;
49 m_AimUD11 = udAngle11;
50 m_AimLR11 = lrAngle11;
51 }
52
54 void SetWeaponRayParams(vector rayOrigin, vector rayDirection, float weaponStartDist, float weaponEndDist, float effectiveAttachmentLength, float obstructionDistanceCfg, float obstructionDistance, float rayRadius)
55 {
56 m_Start = rayOrigin;
57 m_Direction = rayDirection;
58 m_WeaponStartDist = weaponStartDist;
59 m_WeaponEndDist = weaponEndDist;
60 m_EffectiveAttachmentLength = effectiveAttachmentLength;
61 m_ObstructionDistanceCfg = obstructionDistanceCfg;
62 m_ObstructionDistance = obstructionDistance;
63 m_RayRadius = rayRadius;
64 }
65
67 void SetIntersectionParams(RaycastRVResult rayResult, float hitFraction = 0, float hitDistance = 0)
68 {
69 m_RayResult = rayResult;
70 m_HitFraction = hitFraction;
71 m_HitDistance = hitDistance;
72 }
73
75 void SetLastPosition(vector lastPosition)
76 {
77 m_LastPosition = lastPosition;
78 }
79
81 void SetInterpolation(float inTime, float inTimeLift, float outTime, float currentTime, float smoothValue, float currentValue, float targetValue)
82 {
83 m_InterpInTime = inTime;
84 m_InterpInTimeLift = inTimeLift;
85 m_InterpOutTime = outTime;
86 m_InterpCurrTime = currentTime;
87 m_InterpSmoothValue = smoothValue;
88 m_InterpCurrValue = currentValue;
89 m_InterpTgtValue = targetValue;
90 }
91
93 void Clear()
94 {
95 Math3D.MatrixIdentity4(m_Transform);
96 SetIntersectionParams(null, 0, 0);
97 SetWeaponRayParams(vector.Zero, vector.Zero, 0, 0, 0, 0, 0, 0);
98 SetLastPosition(vector.Zero);
99 SetInterpolation(0,0,0,0,0,0,0);
100 SetAimAngles(0,0,0,0);
101 }
102}
103
104//----------------------------------------------------------------------------------------
106class WeaponLiftDiag
107{
108 private ref WeaponLiftDiagData m_Data = new WeaponLiftDiagData();
109
110 private const int COLOR_START = 0xFF2ECC71; // Green
111 private const int COLOR_END = 0xFF4B77BE; // Blue
112 private const int COLOR_END_NOATTACH = 0xFFF7CA18; // Yellow
113 private const int COLOR_OBSTRUCTION = 0xFFFF00FF; // Pink
114 private const int COLOR_HIT = 0xFFFF0000; // Red
115 private const int COLOR_GUIDE = 0xC03A3A3A; // Semi-transparent gray
116 private const int COLOR_WEAPON = 0x1FFFFFFF; // Semi-transparent white
117 private const int COLOR_LAST_POS = 0x3AF7CA18; // Semi-transparent yellow
118
119 private bool m_bDrawGizmos = true;
120 private bool m_bDrawTransform = false;
121 private bool m_bSmallShapes = false;
122 private bool m_bZBuffer = false;
123 private bool m_bWireOnly = true;
124 private bool m_bForceRaised = false;
125 private int m_iColorCrosshair= false;
126
127 private int m_iCrosshairR = 255;
128 private int m_iCrosshairG = 0;
129 private int m_iCrosshairB = 0;
130 private int m_iCrosshairA = 255;
131
132 private float m_fCrosshairBlendPow = 1;
133
134 //----------------------------------------------------------------------------------------
135 WeaponLiftDiagData Data()
136 {
137 return m_Data;
138 }
139
140 //----------------------------------------------------------------------------------------
141 void Reset()
142 {
143 m_Data.Clear();
144 }
145
146 //----------------------------------------------------------------------------------------
147 void DrawDiag(int mode, float deltaTime)
148 {
149 const int MODE_BASIC = 1;
150 const int MODE_EXTENDED = 2;
151
152
153 bool wasColoringCrosshair = m_iColorCrosshair;
154
155 WeaponLiftDiagData data = m_Data;
156 if (data)
157 {
159 DbgUI.Begin("Weapon Lift/Obstruction Diag");
160 {
162 int gray = 0x80FFFFFF; // semi transparent white (gray)
163 int darkObst = gray&COLOR_OBSTRUCTION;
164 int endNoAttachCol = gray & COLOR_END_NOATTACH;
165 DbgUI.ColoredText(COLOR_WHITE, "Weapon properties");
166 DbgUI.ColoredText(COLOR_START, " weaponStartDist: " + data.m_WeaponStartDist);
167 DbgUI.ColoredText(COLOR_WHITE, " weaponLength: " + (data.m_WeaponEndDist - data.m_WeaponStartDist));
168 DbgUI.ColoredText(COLOR_END, " weaponEndDist: " + data.m_WeaponEndDist);
169 if (data.m_EffectiveAttachmentLength > 0)
170 {
171 DbgUI.ColoredText(gray, " attachmentLength: " + data.m_EffectiveAttachmentLength);
172 DbgUI.ColoredText(endNoAttachCol, " distNoAttachment: " + (data.m_WeaponEndDist-data.m_EffectiveAttachmentLength));
173 }
174
175 DbgUI.ColoredText(COLOR_OBSTRUCTION, " obstructionDist(cfg): " + data.m_ObstructionDistanceCfg);
176 if (DbgUI.FloatOverride("weaponObstruction", data.m_ObstructionDistance, 0.0, data.m_WeaponEndDist - data.m_EffectiveAttachmentLength))
177 {
178 data.m_ObstructionDistance += data.m_EffectiveAttachmentLength; // value was overriden directly, take attachment into account
179 }
180
181 DbgUI.ColoredText(darkObst, " obstructionDist(act): " + data.m_ObstructionDistance);
182 DbgUI.ColoredText(COLOR_HIT, " hitDistance: " + data.m_HitDistance);
183 DbgUI.PushID_Str("rayRadiusText");
184 DbgUI.ColoredText(0xFFAAAAAA, " rayRadius: " + data.m_RayRadius );
185 DbgUI.SameSpot();
186 DbgUI.Text( " "); // ugly, but prevents some layouting spasms
187 DbgUI.PopID();
188 float rayRadius = data.m_RayRadius;
189 if (DbgUI.FloatOverride("rayRadiusOverride", rayRadius, 0.0, 0.200, 1000))
190 {
191 data.m_RayRadiusOverride = rayRadius;
192 }
193 else
194 {
195 data.m_RayRadiusOverride = rayRadius;
196 }
198
200 DbgUI.Spacer(10);
201 DbgUI.ColoredText(COLOR_WHITE, "Utility");
202 DbgUI.Check("Force raised", m_bForceRaised);
203 TStringArray crossMode = { "Off", "On Obstruction", "On Lift", "On Both (Blend)" };
204 DbgUI.Combo("Color crosshair", m_iColorCrosshair, crossMode);
206
208 if (m_iColorCrosshair)
209 {
210 DbgUI.SameLine();
211 float r = m_iCrosshairR;
212 float g = m_iCrosshairG;
213 float b = m_iCrosshairB;
214 float a = m_iCrosshairA;
215 DbgUI.ColoredText(ARGB(m_iCrosshairA, m_iCrosshairR, m_iCrosshairG, m_iCrosshairB), " -|-");
216 //R
217 DbgUI.SliderFloat("Red: ", r, 0, 255);
218 DbgUI.SameLine();
219 DbgUI.PushID_Str("ObstructionDiagColorR");
220 DbgUI.ColoredText(0xFFFF0000, m_iCrosshairR.ToString());
221 DbgUI.PopID();
222 //G
223 DbgUI.SliderFloat("Green: ", g, 0, 255);
224 DbgUI.SameLine();
225 DbgUI.PushID_Str("ObstructionDiagColorG");
226 DbgUI.ColoredText(0xFF00FF00, m_iCrosshairG.ToString());
227 DbgUI.PopID();
228 //B
229 DbgUI.SliderFloat("Blue: ", b, 0, 255);
230 DbgUI.SameLine();
231 DbgUI.PushID_Str("ObstructionDiagColorB");
232 DbgUI.ColoredText(0xFF0000FF, m_iCrosshairB.ToString());
233 DbgUI.PopID();
234 // A
235 DbgUI.SliderFloat("Alpha: ", a, 0, 255);
236 DbgUI.SameLine();
237 DbgUI.PushID_Str("ObstructionDiagColorA");
238 DbgUI.ColoredText(0xAAFFFFFF, m_iCrosshairA.ToString());
239 DbgUI.PopID();
240 m_iCrosshairR = r;
241 m_iCrosshairG = g;
242 m_iCrosshairB = b;
243 m_iCrosshairA = a;
244
245 float pow = m_fCrosshairBlendPow * 5000;
246 DbgUI.SliderFloat("BlendPow: ", pow, 1, 5000);
247 DbgUI.SameLine();
248 pow = pow / 1000.0;
249 DbgUI.Text(pow.ToString());
250 m_fCrosshairBlendPow = pow;
251 }
253
254
256 if (mode > MODE_BASIC)
257 {
258 DbgUI.Spacer(10);
259 DbgUI.ColoredText(COLOR_WHITE, "Intersection data");
260 if (data.m_RayResult && data.m_RayResult.surface)
261 {
262 DbgUI.Text(" Name: " + data.m_RayResult.surface.GetName());
263 DbgUI.Text(" EntryName: " + data.m_RayResult.surface.GetEntryName());
264 DbgUI.Text(" SurfaceType: " + data.m_RayResult.surface.GetSurfaceType());
265
266 DbgUI.Text(" IsPassThrough: " + data.m_RayResult.surface.IsPassthrough());
267 DbgUI.Text(" IsSolid: " + data.m_RayResult.surface.IsSolid());
268
269 DbgUI.Text(" HitFraction: " + data.m_HitFraction);
270 }
271 else
272 {
273 DbgUI.Text(" Name: - " );
274 DbgUI.Text(" EntryName: - " );
275 DbgUI.Text(" SurfaceType: - " );
276
277 DbgUI.Text(" IsPassThrough: - " );
278 DbgUI.Text(" IsSolid: - " );
279
280 DbgUI.Text(" HitFraction: - " );
281 }
282 }
284
286 if (mode > MODE_BASIC)
287 {
288 DbgUI.Spacer(10);
289 DbgUI.ColoredText(COLOR_WHITE, "Interpolation");
290 DbgUI.Text(" In time: " + data.m_InterpInTime);
291 DbgUI.Text(" In time lift: " + data.m_InterpInTimeLift);
292 DbgUI.Text(" Out time: " + data.m_InterpOutTime);
293 DbgUI.Text(" Current time: " + data.m_InterpCurrTime);
294 DbgUI.Text(" Actual value: " + data.m_InterpCurrValue);
295 DbgUI.Text(" Target value: " + data.m_InterpTgtValue);
296 DbgUI.Text(" Smooth value: " + data.m_InterpSmoothValue);
297 }
299
301 if (mode > MODE_BASIC)
302 {
303 DbgUI.Spacer(10);
304 DbgUI.ColoredText(COLOR_WHITE, "Aiming");
305 DbgUI.ColoredText(0xFF80FF80, " UD Angle: " + data.m_AimUD);
306 DbgUI.ColoredText(0xFFAAFFAA, " UD[-1,1]: " + data.m_AimUD11);
307 DbgUI.ColoredText(0xFFFF8080, " LR Angle: " + data.m_AimLR);
308 DbgUI.ColoredText(0xFFFFAAAA, " LR[-1,1]: " + data.m_AimLR11);
309 }
311
313 if (mode > MODE_BASIC)
314 {
315 DbgUI.Spacer(10);
316 DbgUI.ColoredText(COLOR_WHITE, "Preferences");
317 DbgUI.Check(" Draw shapes", m_bDrawGizmos);
318 DbgUI.Check(" Small shapes", m_bSmallShapes);
319 DbgUI.Check(" Z-buffer", m_bZBuffer);
320 DbgUI.Check(" Draw approx transform", m_bDrawTransform);
321 DbgUI.Check(" Wire only", m_bWireOnly);
322 }
324
326 if (mode >= MODE_BASIC)
327 {
328 DbgUI.ColoredText(COLOR_WHITE, "CfgGameplay WeaponObstructionData");
329 DbgUI.Text(" Static: " + EnumTools.EnumToString(EWeaponObstructionMode, CfgGameplayHandler.GetWeaponObstructionModeStatic()));
330 DbgUI.Text(" Dynamic: " + EnumTools.EnumToString(EWeaponObstructionMode, CfgGameplayHandler.GetWeaponObstructionModeDynamic()));
331 }
333 }
334 DbgUI.End();
335
336 // Override input! Extremely helpful!!
337 if (m_bForceRaised && GetGame().GetPlayer())
338 {
339 DayZPlayer ply = GetGame().GetPlayer();
340 HumanInputController hic = ply.GetInputController();
341 hic.OverrideRaise( HumanInputControllerOverrideType.ONE_FRAME, true );
342 }
343
344 float radius = rayRadius;
345 if (m_bSmallShapes) radius = 0.01;
346
347 // gizmos
348 if (m_bDrawTransform) Shape.CreateMatrix(data.m_Transform, 1.0, 0.05);
349
350 // "Apply" settings
351 ShapeFlags flags = ShapeFlags.ONCE | ShapeFlags.TRANSP;
352 ShapeFlags flags2 = ShapeFlags.ONCE | ShapeFlags.TRANSP | ShapeFlags.NOOUTLINE;
353 if (!m_bZBuffer)
354 {
355 flags |= ShapeFlags.NOZBUFFER;
356 flags2 |= ShapeFlags.NOZBUFFER;
357 }
358 if (m_bWireOnly)
359 {
360 flags |= ShapeFlags.WIREFRAME;
361 }
362 else
363 {
364 flags |= ShapeFlags.NOOUTLINE;
365 }
366
367 vector wepStart = data.m_Start + (data.m_WeaponStartDist * data.m_Direction);
368 vector wepEnd = data.m_Start + (data.m_WeaponEndDist * data.m_Direction);
369 vector wepEndNoAttach = data.m_Start + ((data.m_WeaponEndDist - data.m_EffectiveAttachmentLength) * data.m_Direction);
370
371 if (m_bDrawGizmos)
372 {
373 // Draw "guide" line, start->end
374 Shape.Create(ShapeType.LINE, COLOR_GUIDE, flags2, data.m_Start, wepEnd);
375 // Draw weapon points
376 Shape.CreateSphere(COLOR_START, flags, wepStart, radius);
377 Shape.CreateSphere(COLOR_END_NOATTACH, flags, wepEndNoAttach, radius);
378 Shape.CreateSphere(COLOR_END, flags, wepEnd, radius);
379 // Draw obstruction distance point
380 if (data.m_ObstructionDistance != 0)
381 {
382 vector wepObstr = data.m_Start + (data.m_ObstructionDistance * data.m_Direction);
383 Shape.CreateSphere(COLOR_OBSTRUCTION, flags, wepObstr, radius);
384 }
385 // Draw last hit position (in ext. mode)
386 if (mode >= MODE_EXTENDED && data.m_LastPosition != vector.Zero)
387 {
388 Shape.Create(ShapeType.LINE, COLOR_LAST_POS, flags2, data.m_Start, data.m_LastPosition);
389 }
390 // Draw the weapon as it moves (a that slides along the "guide" line)
391 {
392 float cylinderLength = (wepEnd - wepStart).Length();
393 vector cylinderOffset = 0.5 * cylinderLength * data.m_Transform[2];
394 Shape cylinder = Shape.CreateCylinder(COLOR_WHITE, flags2, vector.Zero, 0.3 * radius, cylinderLength);
395 vector tm0[4], tm1[3];
396 Math3D.DirectionAndUpMatrix(data.m_Transform[2], data.m_Transform[1], tm0);
397 Math3D.YawPitchRollMatrix("90 0 90", tm1);
398 Math3D.MatrixMultiply3(tm0, tm1, tm0);
399 float fraction = Math.Clamp(data.m_HitFraction, 0, 1);
400 if (!data.m_RayResult) fraction = 1.0;
401 vector center = (data.m_Start + (fraction * (wepEnd - data.m_Start))) - cylinderOffset;
402 tm0[3] = center;
403 cylinder.SetMatrix(tm0);
404 }
405 // Draw hit
406 if (data.m_RayResult)
407 {
408 Shape.CreateSphere(COLOR_HIT, flags, data.m_RayResult.pos, 0.5 * radius);
409 }
410 }
411
412 if (m_iColorCrosshair || wasColoringCrosshair)
413 {
414 int crossColor = 0xFFFFFFFF;
415 if (m_iColorCrosshair) // only set if not "restoring"
416 {
417
418 if (m_iColorCrosshair == 1) // obstruction
419 {
420 float hitFraction = Data().m_HitFraction;
421 if (hitFraction != 0 && hitFraction < 1.0)
422 {
423 crossColor = ARGB(m_iCrosshairA, m_iCrosshairR, m_iCrosshairG, m_iCrosshairB);
424 }
425 }
426 else if (m_iColorCrosshair == 2) // lift only
427 {
428 float hitDist = Data().m_HitDistance;
429 float obstDist = Data().m_ObstructionDistance;
430 if (hitDist != 0 && hitDist < obstDist)
431 {
432 crossColor = ARGB(m_iCrosshairA, m_iCrosshairR, m_iCrosshairG, m_iCrosshairB);
433 }
434 }
435 else if (m_iColorCrosshair == 3) // magic
436 {
437 float t = 0.0;
438 if (Data().m_HitFraction != 0)
439 {
440 float fr = 1.0-Math.InverseLerp( Data().m_ObstructionDistance, Data().m_WeaponEndDist, Data().m_HitDistance );
441 t = Math.Clamp( fr, 0.0, 1.0 );
442 t = Math.Pow(t, m_fCrosshairBlendPow);
443 }
444
445 int white=0xFF;
446 int bA = Math.Lerp(white, m_iCrosshairA, t);
447 int bR = Math.Lerp(white, m_iCrosshairR, t);
448 int bG = Math.Lerp(white, m_iCrosshairG, t);
449 int bB = Math.Lerp(white, m_iCrosshairB, t);
450
451 crossColor = ARGB(bA, bR, bG, bB);
452 }
453 }
454
455 WorkspaceWidget ww = GetGame().GetWorkspace();
456 if (ww)
457 {
458 Widget cw = ww.FindAnyWidget("CrossHairs");
459 if (cw)
460 {
461 Widget child = cw.GetChildren();
462 while (child)
463 {
464 child.SetColor(crossColor);
465 child = child.GetSibling();
466 }
467 }
468 }
469 }
470 }
471 }
472}
473#endif
474#endif
void Reset()
EWeaponObstructionMode
Определения CfgGameplayDataJson.c:365
JsonDataAreaData Data
Определения JsonDataContaminatedArea.c:13
PlayerBase GetPlayer()
Определения ModifierBase.c:51
vector m_Transform[4]
If 'OnDebug' is to be called.
Определения Object.c:21
void Clear(bool clearFile=false)
Определения ScriptConsoleEnfScriptTab.c:359
string m_Data
Определения UniversalTemperatureSource.c:257
proto native DayZPlayer GetPlayer()
proto native WorkspaceWidget GetWorkspace()
proto native void OverrideRaise(HumanInputControllerOverrideType overrideType, bool value)
proto string ToString(bool simple=true)
proto native CGame GetGame()
const int COLOR_WHITE
Определения 1_Core/constants.c:63
ShapeType
Определения EnDebug.c:116
ShapeFlags
Определения EnDebug.c:126
class DiagMenu Shape
don't call destructor directly. Use Destroy() instead
array< string > TStringArray
Определения EnScript.c:709
WorkspaceWidget Widget
Defined in code.
proto native void SetTransform(vector mat[4], bool immedUpdate=true)
HumanInputControllerOverrideType
Определения human.c:8
int ARGB(int a, int r, int g, int b)
Определения proto.c:322