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

◆ DetectFlippedUsingSurface()

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

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

284 {
285 vector corners[4];
286 GetTightlyPackedCorners(ETransformationAxis.BOTTOM, corners);
287
288 // compute the average position to find the lowest "center-most" position
289 vector avgPosition = vector.Zero;
290 for (int i = 0; i < 4; i++)
291 {
292 avgPosition = avgPosition + corners[i];
293 }
294
295 avgPosition = avgPosition * 0.25;
296
297 // get depth of the water to determine if we should use the roadway surface normal or just up vector
298 float depth = GetGame().GetWaterDepth(avgPosition);
299
300 vector normal = vector.Up;
301 vector dirUp = GetDirectionUp();
302
303 bool testLand = depth < -1.0;
304
305 // iterate over the corners to find the average normal
306 if (testLand)
307 {
308 // trace roadway, incase the vehicle is on a rock, or bridge
310
311 // ignore expensive water computation, we already know we are above land
312 ctx.m_SurfaceParams.includeWater = false;
313
314 // ignore this vehicle, it may have a roadway LOD
315 ctx.m_SurfaceParams.ignore = this;
316
317 // detect closest to the given point
318 ctx.m_SurfaceParams.rsd = RoadSurfaceDetection.CLOSEST;
319
320 for (i = 0; i < 4; i++)
321 {
322 ctx.m_SurfaceParams.position = corners[i];
323
325
326 corners[i][1] = ctx.m_SurfaceResult.height;
327 }
328
329 vector d0 = vector.Direction(corners[0], corners[1]);
330 vector d1 = vector.Direction(corners[0], corners[2]);
331
332 d0.Normalize();
333 d1.Normalize();
334
335 // cross product the two directions to get the normal vector of the land
336 normal = d0 * d1;
337 }
338
339 bool isFlipped = vector.Dot(normal, dirUp) < Math.Cos(angleTolerance * Math.DEG2RAD);
340
341#ifdef DIAG_DEVELOPER
342 if (ctx.IsDebug())
343 {
344 int color = 0xFF00FF00;
345 if (isFlipped)
346 color = 0xFFFF0000;
347
348 ctx.AddShape(Shape.Create(ShapeType.LINE, color, ShapeFlags.NOZBUFFER, corners[0], corners[0] + normal));
349 ctx.AddShape(Shape.Create(ShapeType.LINE, color, ShapeFlags.NOZBUFFER, corners[1], corners[1] + normal));
350 ctx.AddShape(Shape.Create(ShapeType.LINE, color, ShapeFlags.NOZBUFFER, corners[2], corners[2] + normal));
351 ctx.AddShape(Shape.Create(ShapeType.LINE, color, ShapeFlags.NOZBUFFER, corners[3], corners[3] + normal));
352 }
353#endif
354
355 return isFlipped;
356 }
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:671
ref SurfaceDetectionResult m_SurfaceResult
Определения Transport.c:672
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.