Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
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")]
2class SCR_TestRaycasterClass: GenericEntityClass
3{
4};
5
7{
8 LINE = 0,
10};
11
12//------------------------------------------------------------------------------------------------
13class SCR_TestRaycaster : GenericEntity
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 {
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};
enum SCR_ECompassType EntityEditorProps(category:"GameScripted/Gadgets", description:"Compass", color:"0 0 255 255")
Prefab data class for compass component.
ETestRaycaster
void IEntity(IEntitySource src, IEntity parent)
protected script Constructor
proto external EntityEvent SetEventMask(EntityEvent e)
proto external void GetWorldTransform(out vector mat[])
See IEntity::GetTransform.
proto external BaseWorld GetWorld()
proto external EntityFlags SetFlags(EntityFlags flags, bool recursively=false)
proto external string GetName()
Instance of created debug visualizer.
Definition Shape.c:14
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
ShapeFlags
Definition ShapeFlags.c:13
@ SPHERE
Sphere represented by triangle mesh.
Definition ShapeType.c:33
@ LINE
One lines.
Definition ShapeType.c:19
SCR_FieldOfViewSettings Attribute
EntityEvent
Various entity events.
Definition EntityEvent.c:14
EntityFlags
Various entity flags.
Definition EntityFlags.c:14
TraceFlags
Definition TraceFlags.c:13
proto int ARGBF(float fa, float fr, float fg, float fb)
Converts <0.0, 1.0> ARGB into color.