DayZ 1.27
DayZ Explorer by KGB
 
Загрузка...
Поиск...
Не найдено

◆ DetectFlippedUsingSurface()

bool EntityAI::DetectFlippedUsingSurface ( VehicleFlippedContext ctx,
float angleTolerance )
inlineprotected

См. определение в файле Transport.c строка 215

216 {
217 vector corners[4];
218 GetTightlyPackedCorners(ETransformationAxis.BOTTOM, corners);
219
220 // compute the average position to find the lowest "center-most" position
221 vector avgPosition = vector.Zero;
222 for (int i = 0; i < 4; i++)
223 {
224 avgPosition = avgPosition + corners[i];
225 }
226
227 avgPosition = avgPosition * 0.25;
228
229 // get depth of the water to determine if we should use the roadway surface normal or just up vector
230 float depth = GetGame().GetWaterDepth(avgPosition);
231
232 vector normal = vector.Up;
233 vector dirUp = GetDirectionUp();
234
235 bool testLand = depth < -1.0;
236
237 // iterate over the corners to find the average normal
238 if (testLand)
239 {
240 // trace roadway, incase the vehicle is on a rock, or bridge
242
243 // ignore expensive water computation, we already know we are above land
244 ctx.m_SurfaceParams.includeWater = false;
245
246 // ignore this vehicle, it may have a roadway LOD
247 ctx.m_SurfaceParams.ignore = this;
248
249 // detect closest to the given point
250 ctx.m_SurfaceParams.rsd = RoadSurfaceDetection.CLOSEST;
251
252 for (i = 0; i < 4; i++)
253 {
254 ctx.m_SurfaceParams.position = corners[i];
255
257
258 corners[i][1] = ctx.m_SurfaceResult.height;
259 }
260
261 vector d0 = vector.Direction(corners[0], corners[1]);
262 vector d1 = vector.Direction(corners[0], corners[2]);
263
264 d0.Normalize();
265 d1.Normalize();
266
267 // cross product the two directions to get the normal vector of the land
268 normal = d0 * d1;
269 }
270
271 bool isFlipped = vector.Dot(normal, dirUp) < Math.Cos(angleTolerance * Math.DEG2RAD);
272
273#ifdef DIAG_DEVELOPER
274 if (ctx.IsDebug())
275 {
276 int color = 0xFF00FF00;
277 if (isFlipped)
278 color = 0xFFFF0000;
279
280 ctx.AddShape(Shape.Create(ShapeType.LINE, color, ShapeFlags.NOZBUFFER, corners[0], corners[0] + normal));
281 ctx.AddShape(Shape.Create(ShapeType.LINE, color, ShapeFlags.NOZBUFFER, corners[1], corners[1] + normal));
282 ctx.AddShape(Shape.Create(ShapeType.LINE, color, ShapeFlags.NOZBUFFER, corners[2], corners[2] + normal));
283 ctx.AddShape(Shape.Create(ShapeType.LINE, color, ShapeFlags.NOZBUFFER, corners[3], corners[3] + normal));
284 }
285#endif
286
287 return isFlipped;
288 }
ETransformationAxis
Определения ETransformationAxis.c:2
SurfaceDetectionType
Определения SurfaceInfo.c:66
proto native float GetWaterDepth(vector posWS)
proto native bool GetSurface(SurfaceDetectionParameters params, SurfaceDetectionResult result)
API for surface detection.
bool includeWater
Include water in the surface detection, will return the water if it is higher than the surface.
Определения SurfaceInfo.c:83
SurfaceDetectionType type
Type of surface to detect.
Определения SurfaceInfo.c:77
RoadSurfaceDetection rsd
See RoadSurfaceDetection, SurfaceTraceType.Roadway only.
Определения SurfaceInfo.c:92
Object ignore
Object to ignore tracing against, SurfaceTraceType.Roadway only.
Определения SurfaceInfo.c:89
vector position
3D position to trace the surface from
Определения SurfaceInfo.c:80
float height
Height position.
Определения SurfaceInfo.c:102
ref SurfaceDetectionParameters m_SurfaceParams
Определения Transport.c:577
ref SurfaceDetectionResult m_SurfaceResult
Определения Transport.c:578
proto float Normalize()
Normalizes vector. Returns length.
proto native CGame GetGame()
ShapeType
Определения EnDebug.c:116
ShapeFlags
Определения EnDebug.c:126
class DiagMenu Shape
don't call destructor directly. Use Destroy() instead

Перекрестные ссылки Math::Cos(), Math::DEG2RAD, vector::Direction(), vector::Dot(), GetGame(), CGame::GetSurface(), CGame::GetWaterDepth(), SurfaceDetectionResult::height, SurfaceDetectionParameters::ignore, SurfaceDetectionParameters::includeWater, VehicleFlippedContext::m_SurfaceParams, VehicleFlippedContext::m_SurfaceResult, vector::Normalize(), SurfaceDetectionParameters::position, SurfaceDetectionParameters::rsd, Shape, SurfaceDetectionParameters::type, vector::Up и vector::Zero.