Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_TestRaycaster.c
Go to the documentation of this file.
1 [EntityEditorProps(category: "GameScripted/Test", description: "Entity that fires raycasts to a target", color: "0 0 255 255")]
2 class SCR_TestRaycasterClass: GenericEntityClass
3 {
4 };
5 
7 {
8  LINE = 0,
9  SPHERE = 1
10 };
11 
12 //------------------------------------------------------------------------------------------------
14 {
15  [Attribute("0", UIWidgets.ComboBox, "Type Of Raycast used", "", ParamEnumArray.FromEnum(ETestRaycaster))]
16  int m_iTypeOfRaycast;
17 
18  private void DBG_Line()
19  {
20  vector p[2];
21  p[0] = m_vRCStart;
22  p[1] = m_vRCEnd;
23 
24  int shapeFlags = ShapeFlags.NOOUTLINE;
25  Shape s = Shape.CreateLines(ARGBF(1, 1, 1, 1), shapeFlags, p, 2);
26  m_aDbgShapes.Insert(s);
27  }
28 
29  private void DBG_Sphere(vector pos, int color)
30  {
31  vector matx[4];
32  Math3D.MatrixIdentity4(matx);
33  matx[3] = pos;
34  int shapeFlags = ShapeFlags.NOOUTLINE|ShapeFlags.NOZBUFFER|ShapeFlags.TRANSP;
35  Shape s = Shape.CreateSphere(color, shapeFlags, pos, 0.05);
36  s.SetMatrix(matx);
37  m_aDbgShapes.Insert(s);
38  }
39 
40  private void DoTraceLine()
41  {
42  autoptr TraceParam param = new TraceParam;
43  param.Exclude = this;
44  param.Flags = TraceFlags.ENTS | TraceFlags.WORLD;
45  param.LayerMask = TRACE_LAYER_MASK;
46  param.Start = m_vRCStart;
47  param.End = m_vRCEnd;
48 
49  TraceResult(param);
50  }
51 
52  private void DoTraceSphere()
53  {
54  autoptr TraceSphere param = new TraceSphere;
55  param.Exclude = this;
56  param.Flags = TraceFlags.ENTS | TraceFlags.WORLD;
57  param.LayerMask = TRACE_LAYER_MASK;
58  param.Start = m_vRCStart;
59  param.End = m_vRCEnd;
60  param.Radius = 0.5;
61 
62  TraceResult(param);
63  }
64 
65  private void TraceResult(TraceParam param)
66  {
67  float hit = GetWorld().TraceMove(param, null);
68 
69  if (!param.TraceEnt)
70  return;
71 
72  Print("_____");
73  Print("| " + GetName() + " results" );
74  Print("|_ Entity: " + param.TraceEnt);
75  Print("|_ Collider: " + param.ColliderName);
76  //Print("|_ Material type: " + param.MaterialType);
77  Print(" ");
78 
79  vector hitPos = m_vRCStart + vector.Forward * (hit * RAY_LENGTH);
80  DBG_Sphere(hitPos, ARGBF(0.5, 1, 0, 0));
81  }
82 
83  void DoRaycast(int typeOfRayCast)
84  {
85  switch (typeOfRayCast)
86  {
87  case ETestRaycaster.LINE:
88  DoTraceLine();
89  break;
90  case ETestRaycaster.SPHERE:
91  DoTraceSphere();
92  break;
93  default:
94  break;
95  }
96  }
97 
98  //------------------------------------------------------------------------------------------------
99  override void EOnFrame(IEntity owner, float timeSlice)
100  {
101  m_fTime += timeSlice;
102 
103  if (m_fTime > MEASURE_INTERVAL)
104  {
105  m_aDbgShapes.Clear();
106 
107  DoRaycast(m_iTypeOfRaycast);
108 
109  DBG_Line();
110  DBG_Sphere(m_vRCStart, ARGBF(1, 1, 1, 1));
111  DBG_Sphere(m_vRCEnd, ARGBF(1, 1, 1, 1));
112 
113  m_fTime = 0;
114  }
115  }
116 
117  //------------------------------------------------------------------------------------------------
118  void SCR_TestRaycaster(IEntitySource src, IEntity parent)
119  {
120  SetEventMask(EntityEvent.FRAME);
121  SetFlags(EntityFlags.ACTIVE, false);
122 
123  vector worldMat[4];
124  GetWorldTransform(worldMat);
125 
126  m_vRCStart = worldMat[3];
127  m_vRCEnd = m_vRCStart + vector.Forward * RAY_LENGTH;
128 
129  m_aDbgShapes = new array<ref Shape>;
130  }
131 
132  //------------------------------------------------------------------------------------------------
133  void ~SCR_TestRaycaster()
134  {
135  }
136 
137  private const int TRACE_LAYER_MASK = EPhysicsLayerDefs.Projectile;
138  private const float MEASURE_INTERVAL = 1.0;
139  private const float RAY_LENGTH = 3.0;
140  private float m_fTime;
141 
142  private vector m_vRCStart;
143  private vector m_vRCEnd;
144 
146  private ref array<ref Shape> m_aDbgShapes;
147 };
GetName
string GetName()
Definition: SCR_ScenarioFrameworkLayerBase.c:85
SCR_TestRaycasterClass
Definition: SCR_TestRaycaster.c:2
EntityEditorProps
enum EQueryType EntityEditorProps(category:"GameScripted/Sound", description:"THIS IS THE SCRIPT DESCRIPTION.", color:"0 0 255 255")
Definition: SCR_AmbientSoundsComponent.c:12
LINE
@ LINE
Definition: SCR_TestRaycaster.c:8
GenericEntity
SCR_GenericBoxEntityClass GenericEntity
Attribute
typedef Attribute
Post-process effect of scripted camera.
ETestRaycaster
ETestRaycaster
Definition: SCR_TestRaycaster.c:6
SPHERE
@ SPHERE
Definition: SCR_TestRaycaster.c:9
SCR_TestRaycaster
Definition: SCR_TestRaycaster.c:13
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180