13 ref array<float> m_Points;
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];
20 private bool m_bIsInsideDebug;
23 private float m_fBBoxMinX;
24 private float m_fBBoxMaxX;
25 private float m_fBBoxMinY;
26 private float m_fBBoxMaxY;
35 private bool IsPointInsideBBox(
float minX,
float maxY,
float maxX,
float minY,
float x,
float y)
37 return(x >= minX && x <= maxX && y >= minY && y <= maxY);
43 bool IsEntityInside(IEntity entity)
45 vector entPos = entity.GetOrigin();
46 if ( !m_Points || !IsPointInsideBBox(m_fBBoxMinX, m_fBBoxMaxY, m_fBBoxMaxX, m_fBBoxMinY, entPos[0], entPos[2] ) )
52 return Math2D.IsPointInPolygon(m_PointsWorld, entPos[0], entPos[2]);
56 bool IsPosInside(vector pos)
58 if ( !m_Points || !IsPointInsideBBox(m_fBBoxMinX, m_fBBoxMaxY, m_fBBoxMaxX, m_fBBoxMinY, pos[0], pos[2] ) )
61 return Math2D.IsPointInPolygon(m_PointsWorld, pos[0], pos[2]);
66 override void EOnFrame(IEntity owner,
float timeSlice)
71 IEntity player =
GetGame().GetPlayerController().GetControlledEntity();
73 player.GetTransform(plrMat);
74 int color = ARGB(255, 0, 255, 0);
75 m_bIsInsideDebug = IsEntityInside(player);
77 color = ARGB(255, 255, 0, 0);
78 Shape.CreateSphere(color, ShapeFlags.WIREFRAME|ShapeFlags.NOZBUFFER|ShapeFlags.ONCE, plrMat[3], 0.1);
82 override void EOnInit(IEntity owner)
87 GetWorldTransform(matWrld);
90 for(
int i = 0; i < m_Points.Count();)
93 point[0] = m_Points[i];
95 point[2] = m_Points[i];
98 m_PositionsWorld.Insert(point.Multiply4(matWrld));
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];
107 foreach (
int i, vector pos: m_PositionsWorld)
109 m_PosWorldDbg[i] = pos;
110 m_PointsWorld.Insert(pos[0]);
111 m_PointsWorld.Insert(pos[2]);
114 if (pos[0] < m_fBBoxMinX)
116 m_fBBoxMinX = pos[0];
118 if (pos[0] > m_fBBoxMaxX)
120 m_fBBoxMaxX = pos[0];
122 if (pos[2] < m_fBBoxMinY)
124 m_fBBoxMinY = pos[2];
126 if (pos[2] > m_fBBoxMaxY)
128 m_fBBoxMaxY = pos[2];
131 if (i == m_PositionsWorld.Count() - 1)
133 m_PosWorldDbg[i+1] = m_PosWorldDbg[0];
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;
144 pointLowerRight[0] = m_fBBoxMaxX;
145 pointLowerRight[1] = elevation;
146 pointLowerRight[2] = m_fBBoxMinY;
148 pointUpperLeft[0] = m_fBBoxMinX;
149 pointUpperLeft[1] = elevation;
150 pointUpperLeft[2] = m_fBBoxMaxY;
152 pointUpperRight[0] = m_fBBoxMaxX;
153 pointUpperRight[1] = elevation;
154 pointUpperRight[2] = m_fBBoxMaxY;
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;
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);
177 ShapeEntity child = ShapeEntity.Cast(
GetChildren());
181 m_Points =
new array<float>;
182 auto points =
new array<vector>;
183 child.GetPointsPositions(points);
185 for (
int i = 0; i < points.Count(); i++)
187 vector pos = points.Get(i);
192 m_Points.Insert(posX);
193 m_Points.Insert(posY);
202 if(!
GetGame().GetWorldEntity())
205 SetFlags(EntityFlags.TRACEABLE,
false);
206 SetEventMask(EntityEvent.INIT);
208 SetEventMask(EntityEvent.FRAME);