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

◆ DetectFlippedUsingSurface()

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

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

343 {
344 vector corners[4];
345 GetTightlyPackedCorners(ETransformationAxis.BOTTOM, corners);
346
347 // compute the average position to find the lowest "center-most" position
348 vector avgPosition = vector.Zero;
349 for (int i = 0; i < 4; i++)
350 {
351 avgPosition = avgPosition + corners[i];
352 }
353
354 avgPosition = avgPosition * 0.25;
355
356 // get depth of the water to determine if we should use the roadway surface normal or just up vector
357 float depth = g_Game.GetWaterDepth(avgPosition);
358
359 vector normal = vector.Up;
360 vector dirUp = GetDirectionUp();
361
362 bool testLand = depth < -1.0;
363
364 // iterate over the corners to find the average normal
365 if (testLand)
366 {
367 // trace roadway, incase the vehicle is on a rock, or bridge
369
370 // ignore expensive water computation, we already know we are above land
371 ctx.m_SurfaceParams.includeWater = false;
372
373 // ignore this vehicle, it may have a roadway LOD
374 ctx.m_SurfaceParams.ignore = this;
375
376 // detect closest to the given point
377 ctx.m_SurfaceParams.rsd = RoadSurfaceDetection.CLOSEST;
378
379 for (i = 0; i < 4; i++)
380 {
381 ctx.m_SurfaceParams.position = corners[i];
382
383 g_Game.GetSurface(ctx.m_SurfaceParams, ctx.m_SurfaceResult);
384
385 corners[i][1] = ctx.m_SurfaceResult.height;
386 }
387
388 vector d0 = vector.Direction(corners[0], corners[1]);
389 vector d1 = vector.Direction(corners[0], corners[2]);
390
391 d0.Normalize();
392 d1.Normalize();
393
394 // cross product the two directions to get the normal vector of the land
395 normal = d0 * d1;
396 }
397
398 bool isFlipped = vector.Dot(normal, dirUp) < Math.Cos(angleTolerance * Math.DEG2RAD);
399
400#ifdef DIAG_DEVELOPER
401 if (ctx.IsDebug())
402 {
403 int color = 0xFF00FF00;
404 if (isFlipped)
405 color = 0xFFFF0000;
406
407 ctx.AddShape(Shape.Create(ShapeType.LINE, color, ShapeFlags.NOZBUFFER, corners[0], corners[0] + normal));
408 ctx.AddShape(Shape.Create(ShapeType.LINE, color, ShapeFlags.NOZBUFFER, corners[1], corners[1] + normal));
409 ctx.AddShape(Shape.Create(ShapeType.LINE, color, ShapeFlags.NOZBUFFER, corners[2], corners[2] + normal));
410 ctx.AddShape(Shape.Create(ShapeType.LINE, color, ShapeFlags.NOZBUFFER, corners[3], corners[3] + normal));
411 }
412#endif
413
414 return isFlipped;
415 }
DayZGame g_Game
Определения DayZGame.c:3942
ETransformationAxis
Определения ETransformationAxis.c:2
SurfaceDetectionType
Определения SurfaceInfo.c:66
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:732
ref SurfaceDetectionResult m_SurfaceResult
Определения Transport.c:733
proto float Normalize()
Normalizes vector. Returns length.
static const vector Up
Определения EnConvert.c:120
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(), g_Game, 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.