MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / DrawPhysicsDebug

Method DrawPhysicsDebug

Source/Engine/Terrain/TerrainPatch.cpp:2338–2389  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2336}
2337
2338void TerrainPatch::DrawPhysicsDebug(RenderView& view)
2339{
2340#if COMPILE_WITH_DEBUG_DRAW
2341 const BoundingBox bounds(_bounds.Minimum - view.Origin, _bounds.Maximum - view.Origin);
2342 if (!_physicsShape || !view.CullingFrustum.Intersects(bounds))
2343 return;
2344 PROFILE_MEM(LevelTerrain);
2345 if (view.Mode == ViewMode::PhysicsColliders)
2346 {
2347 const auto& triangles = GetCollisionTriangles();
2348 typedef DebugDraw::Vertex Vertex;
2349 if (!_collisionTrianglesBuffer)
2350 _collisionTrianglesBuffer = GPUDevice::Instance->CreateBuffer(TEXT("Terrain.CollisionTriangles"));
2351 const uint32 count = triangles.Count();
2352 if (_collisionTrianglesBuffer->GetElementsCount() != count)
2353 {
2354 if (_collisionTrianglesBuffer->Init(GPUBufferDescription::Vertex(Vertex::GetLayout(), sizeof(Vertex), count)))
2355 return;
2356 _collisionTrianglesBufferDirty = true;
2357 }
2358 if (_collisionTrianglesBufferDirty)
2359 {
2360 const Color32 color(Color::DarkOliveGreen);
2361 Array<Vertex> vertices;
2362 vertices.Resize((int32)count);
2363 const Vector3* src = triangles.Get();
2364 Vertex* dst = vertices.Get();
2365 for (uint32 i = 0; i < count; i++)
2366 {
2367 dst[i] = { (Float3)src[i], color };
2368 }
2369 _collisionTrianglesBuffer->SetData(vertices.Get(), _collisionTrianglesBuffer->GetSize());
2370 _collisionTrianglesBufferDirty = false;
2371 }
2372 DebugDraw::DrawTriangles(_collisionTrianglesBuffer, Matrix::Identity, 0, true);
2373 }
2374 else
2375 {
2376 BoundingSphere sphere;
2377 BoundingSphere::FromBox(bounds, sphere);
2378 if (Vector3::Distance(sphere.Center, view.Position) - sphere.Radius < METERS_TO_UNITS(500))
2379 {
2380 if (!_debugLines || _debugLinesDirty)
2381 CacheDebugLines();
2382 const float size = _terrain->_chunkSize * TERRAIN_UNITS_PER_VERTEX * Terrain::ChunksCountEdge;
2383 const Transform localTransform(Vector3(_x * size, _yOffset, _z * size), Quaternion::Identity, Vector3(_collisionScaleXZ, _yHeight, _collisionScaleXZ));
2384 const Matrix world = localTransform.GetWorld() * _terrain->_transform.GetWorld();
2385 DebugDraw::DrawLines(_debugLines, world);
2386 }
2387 }
2388#endif
2389}
2390
2391#endif
2392

Callers

nothing calls this directly

Calls 12

DistanceFunction · 0.85
DrawLinesFunction · 0.85
VertexClass · 0.50
IntersectsMethod · 0.45
CreateBufferMethod · 0.45
CountMethod · 0.45
InitMethod · 0.45
ResizeMethod · 0.45
GetMethod · 0.45
SetDataMethod · 0.45
GetSizeMethod · 0.45
GetWorldMethod · 0.45

Tested by

no test coverage detected