Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
PolylineArea.c
Go to the documentation of this file.
1 [EntityEditorProps(category: "GameLib/Scripted", description: "Script model", dynamicBox: true)]
2 class PolylineAreaClass: GenericEntityClass
3 {
4 
5 };
6 
8 {
9  [Attribute( "0", UIWidgets.CheckBox, "" )]
10  bool m_bDrawDebug;
11 
12  //[Attribute( "", UIWidgets.None, "" )]
13  ref array<float> m_Points;
14 
15  private ref array<float> m_PointsWorld = new array<float>;
16  private ref array<vector> m_PositionsWorld = new array<vector>;
17  private vector m_PosWorldDbg[256];
18  private vector m_BBoxDbg[5];
19 
20  private bool m_bIsInsideDebug;
21 
22  //bbox in world space
23  private float m_fBBoxMinX;
24  private float m_fBBoxMaxX;
25  private float m_fBBoxMinY;
26  private float m_fBBoxMaxY;
27 
28  //private float m_f
29 
30 
31  //-------------------------------------------------------------------------------
32  //TODO: MOVE TO MATH LIB
35  private bool IsPointInsideBBox(float minX, float maxY, float maxX, float minY,float x,float y)
36  {
37  return(x >= minX && x <= maxX && y >= minY && y <= maxY);
38  }
39 
40 
41  //------------------------------------------------------------------------------------------------
43  bool IsEntityInside(IEntity entity)
44  {
45  vector entPos = entity.GetOrigin();
46  if ( !m_Points || !IsPointInsideBBox(m_fBBoxMinX, m_fBBoxMaxY, m_fBBoxMaxX, m_fBBoxMinY, entPos[0], entPos[2] ) )
47  {
48  //Print("out");
49  return false;
50  }
51  //Print("in");
52  return Math2D.IsPointInPolygon(m_PointsWorld, entPos[0], entPos[2]);
53  }
54  //------------------------------------------------------------------------------------------------
56  bool IsPosInside(vector pos)
57  {
58  if ( !m_Points || !IsPointInsideBBox(m_fBBoxMinX, m_fBBoxMaxY, m_fBBoxMaxX, m_fBBoxMinY, pos[0], pos[2] ) )
59  return false;
60 
61  return Math2D.IsPointInPolygon(m_PointsWorld, pos[0], pos[2]);
62  }
63 
64  //------------------------------------------------------------------------------------------------
66  override void EOnFrame(IEntity owner, float timeSlice)
67  {
68  if (!m_bDrawDebug)
69  return;
70 
71  IEntity player = GetGame().GetPlayerController().GetControlledEntity();
72  vector plrMat[4];
73  player.GetTransform(plrMat);
74  int color = ARGB(255, 0, 255, 0);
75  m_bIsInsideDebug = IsEntityInside(player);
76  if(m_bIsInsideDebug)
77  color = ARGB(255, 255, 0, 0);
78  Shape.CreateSphere(color, ShapeFlags.WIREFRAME|ShapeFlags.NOZBUFFER|ShapeFlags.ONCE, plrMat[3], 0.1);
79  }
80 
81  //------------------------------------------------------------------------------------------------
82  override void EOnInit(IEntity owner)
83  {
84  if (!LoadPolyline())
85  return;
86  vector matWrld[4];
87  GetWorldTransform(matWrld);
88 
89  //transform local pos to world pos
90  for(int i = 0; i < m_Points.Count();)
91  {
92  vector point;
93  point[0] = m_Points[i];
94  i++;
95  point[2] = m_Points[i];
96  i++;
97 
98  m_PositionsWorld.Insert(point.Multiply4(matWrld));
99  }
100 
101  //set a default value to bbox coresponding with an existing point(default can't be a plain 0)
102  m_fBBoxMinX = m_PositionsWorld[0][0];
103  m_fBBoxMaxX = m_PositionsWorld[0][0];
104  m_fBBoxMinY = m_PositionsWorld[0][2];
105  m_fBBoxMaxY = m_PositionsWorld[0][2];
106  // convert array of vectors into array of points, build debug lines and calculate bbox
107  foreach (int i, vector pos: m_PositionsWorld)
108  {
109  m_PosWorldDbg[i] = pos;
110  m_PointsWorld.Insert(pos[0]);
111  m_PointsWorld.Insert(pos[2]);
112 
113  // establish BBox
114  if (pos[0] < m_fBBoxMinX)
115  {
116  m_fBBoxMinX = pos[0];
117  }
118  if (pos[0] > m_fBBoxMaxX)
119  {
120  m_fBBoxMaxX = pos[0];
121  }
122  if (pos[2] < m_fBBoxMinY)
123  {
124  m_fBBoxMinY = pos[2];
125  }
126  if (pos[2] > m_fBBoxMaxY)
127  {
128  m_fBBoxMaxY = pos[2];
129  }
130  //BBox shape
131  if (i == m_PositionsWorld.Count() - 1)
132  {
133  m_PosWorldDbg[i+1] = m_PosWorldDbg[0];
134  }
135  }
136 
137  // construct debug bbox
138  vector pointLowerLeft, pointLowerRight, pointUpperLeft, pointUpperRight;
139  float elevation = matWrld[3][1];
140  pointLowerLeft[0] = m_fBBoxMinX;
141  pointLowerLeft[1] = elevation;
142  pointLowerLeft[2] = m_fBBoxMinY;
143 
144  pointLowerRight[0] = m_fBBoxMaxX;
145  pointLowerRight[1] = elevation;
146  pointLowerRight[2] = m_fBBoxMinY;
147 
148  pointUpperLeft[0] = m_fBBoxMinX;
149  pointUpperLeft[1] = elevation;
150  pointUpperLeft[2] = m_fBBoxMaxY;
151 
152  pointUpperRight[0] = m_fBBoxMaxX;
153  pointUpperRight[1] = elevation;
154  pointUpperRight[2] = m_fBBoxMaxY;
155 
156  m_BBoxDbg[0] = pointLowerLeft;
157  m_BBoxDbg[1] = pointLowerRight;
158  m_BBoxDbg[2] = pointUpperRight;
159  m_BBoxDbg[3] = pointUpperLeft;
160  m_BBoxDbg[4] = pointLowerLeft;
161  //-----------
162 
163 
164  #ifdef WORKBENCH
165  if (m_bDrawDebug)
166  {
167  Shape.CreateLines(ARGB(255, 255, 0, 0), ShapeFlags.NOZBUFFER|ShapeFlags.TRANSP, m_PosWorldDbg, m_PositionsWorld.Count()+1);
168  Shape.CreateLines(ARGB(255, 0, 255, 255), ShapeFlags.NOZBUFFER|ShapeFlags.TRANSP, m_BBoxDbg, 5);
169  }
170  #endif
171  }
172 
173  //------------------------------------------------------------------------------------------------
175  bool LoadPolyline()
176  {
177  ShapeEntity child = ShapeEntity.Cast(GetChildren());
178  if (!child)
179  return false;
180 
181  m_Points = new array<float>;
182  auto points = new array<vector>;
183  child.GetPointsPositions(points);
184 
185  for (int i = 0; i < points.Count(); i++)
186  {
187  vector pos = points.Get(i);
188 
189  float posX = pos[0];
190  float posY = pos[2];
191 
192  m_Points.Insert(posX);
193  m_Points.Insert(posY);
194  }
195  return true;
196  }
197 
198 
199  //------------------------------------------------------------------------------------------------
200  void PolylineArea(IEntitySource src, IEntity parent)
201  {
202  if(!GetGame().GetWorldEntity())
203  return;
204 
205  SetFlags(EntityFlags.TRACEABLE, false);
206  SetEventMask(EntityEvent.INIT);
207  #ifdef WORKBENCH
208  SetEventMask(EntityEvent.FRAME);
209  #endif
210  }
211 
212  //------------------------------------------------------------------------------------------------
213  void ~PolylineArea()
214  {
215 
216  }
217 
218 
219 };
EntityEditorProps
enum EQueryType EntityEditorProps(category:"GameScripted/Sound", description:"THIS IS THE SCRIPT DESCRIPTION.", color:"0 0 255 255")
Definition: SCR_AmbientSoundsComponent.c:12
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
GenericEntity
SCR_GenericBoxEntityClass GenericEntity
Attribute
typedef Attribute
Post-process effect of scripted camera.
PolylineArea
Definition: PolylineArea.c:7
m_bDrawDebug
protected bool m_bDrawDebug
Definition: PrefabGeneratorEntity.c:87
GetChildren
void GetChildren(out array< SCR_ScenarioFrameworkLayerBase > children)
Definition: SCR_ScenarioFrameworkLayerBase.c:359
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180
PolylineAreaClass
Definition: PolylineArea.c:2