43 vector sizes =
Vector(shapeDataArray[0][0],shapeDataArray[0][1],shapeDataArray[0][2]);
44 vector angle =
Vector(shapeDataArray[1][0],shapeDataArray[1][1],shapeDataArray[1][2]);
45 vector targetPoint =
Vector(shapeDataArray[2][0],shapeDataArray[2][1],shapeDataArray[2][2]);
51 Math3D.YawPitchRollMatrix(angle,mat3);
63 private bool m_IsValid =
false;
64 private int m_LastUsedSafePosIdx = -1;
68 private vector m_CenterPos2D;
85 m_IsValid |= ValidatePlayerRestrictedAreaPositions();
89 private bool ValidatePlayerRestrictedAreaPositions()
91 if (PRABoxes.Count() == 0 && PRAPolygons.Count() == 0)
93 Debug.Log(
"No valid coordinates in 'PRABoxes' or 'PRAPolygons' for area: " + areaName,
"n/a",
"n/a",
"",
"PlayerRestrictedAreaInstance");
97 float xMin,zMin =
float.MAX;
98 float xMax,zMax =
float.MIN;
102 if (boxFloatsData.Count() != 3)
104 Debug.Log(
"Invalid box defined in " + areaName +
". Box needs to have sizes, rotation, and position defined!",
"n/a",
"n/a",
"",
"PlayerRestrictedAreaInstance");
110 boxVectors = boxFloatsData[0];
111 if (boxVectors.Count() != 3)
113 Debug.Log(
"Invalid box defined in " + areaName +
". Box size needs to be in an XYZ format!",
"n/a",
"n/a",
"",
"PlayerRestrictedAreaInstance");
118 boxVectors = boxFloatsData[1];
119 if (boxVectors.Count() != 3)
121 Debug.Log(
"Invalid box defined in " + areaName +
". Box rotation needs to be in an XYZ format!",
"n/a",
"n/a",
"",
"PlayerRestrictedAreaInstance");
126 boxVectors = boxFloatsData[2];
127 if (boxVectors.Count() != 3)
129 Debug.Log(
"Invalid box defined in " + areaName +
". Box position needs to be in an XYZ format!",
"n/a",
"n/a",
"",
"PlayerRestrictedAreaInstance");
134 PRAShapeBoxData dta =
new PRAShapeBoxData(boxFloatsData);
137 m_PRABoxDataTranslated.Insert(dta);
139 xMin =
Math.Min(xMin,dta.m_Mins[0]);
140 zMin =
Math.Min(zMin,dta.m_Mins[2]);
141 xMax =
Math.Max(xMax,dta.m_Maxs[0]);
142 zMax =
Math.Max(zMax,dta.m_Maxs[2]);
148 if (polygonData.Count() < 3)
150 Debug.Log(
"Invalid polygon defined in " + areaName +
". At least 3 points necessary!",
"n/a",
"n/a",
"",
"PlayerRestrictedAreaInstance");
156 if (polygonCoords.Count() != 2)
158 Debug.Log(
"Invalid polygon defined in " + areaName +
". Polygon coordinates need to be in a XZ format!",
"n/a",
"n/a",
"",
"PlayerRestrictedAreaInstance");
162 xMin =
Math.Min(xMin,polygonCoords[0]);
163 zMin =
Math.Min(zMin,polygonCoords[1]);
164 xMax =
Math.Max(xMax,polygonCoords[0]);
165 zMax =
Math.Max(zMax,polygonCoords[1]);
169 m_CenterPos2D =
Vector(((xMin + xMax) / 2), 0, ((zMin + zMax) / 2));
174 private bool TranslateSafePositions()
176 if (safePositions2D.Count() == 0 && safePositions3D.Count() == 0)
178 Debug.Log(
"Undefined safe positions for area: " + areaName,
"n/a",
"n/a",
"",
"PlayerRestrictedAreaInstance");
186 m_TranslatedSafePositions3D.Insert(
Vector(arr2d[0],
GetGame().SurfaceY(arr2d[0],arr2d[1]),arr2d[1]));
191 m_TranslatedSafePositions3D.Insert(
Vector(arr3d[0],arr3d[1],arr3d[2]));
204 return m_CenterPos2D;
212 vector closestPos = targetPos;
213 float smallestDist =
float.MAX;
216 foreach (
vector pos : m_TranslatedSafePositions3D)
218 dist =
vector.DistanceSq(targetPos, pos);
219 if (dist < smallestDist)
230 if (!m_RandomizedSafePositions3D || m_RandomizedSafePositions3D.Count() == 0)
233 m_RandomizedSafePositions3D.Copy(m_TranslatedSafePositions3D);
234 m_LastUsedSafePosIdx = -1;
237 int count = m_RandomizedSafePositions3D.Count();
238 m_LastUsedSafePosIdx++;
240 if (m_LastUsedSafePosIdx == count)
242 m_RandomizedSafePositions3D.ShuffleArray();
243 m_LastUsedSafePosIdx = 0;
246 return m_RandomizedSafePositions3D[m_LastUsedSafePosIdx];