Debug mode for displaying crash spheres, closes #400

dev-time-step
Piotr Dziwinski 2016-03-17 16:31:16 +13:00
parent 34136c4538
commit 15c9cbd228
4 changed files with 111 additions and 0 deletions

View File

@ -3065,6 +3065,18 @@ void CEngine::ApplyChange()
SetFocus(m_focus);
}
void CEngine::ClearDisplayCrashSpheres()
{
m_displayCrashSpheres.clear();
}
void CEngine::AddDisplayCrashSpheres(const std::vector<Math::Sphere>& crashSpheres)
{
for (const auto& crashSphere : crashSpheres)
{
m_displayCrashSpheres.push_back(crashSphere);
}
}
/*******************************************************
@ -3359,6 +3371,8 @@ void CEngine::Draw3DScene()
m_device->SetRenderState(RENDER_STATE_LIGHTING, false);
DrawCrashSpheres();
m_app->StartPerformanceCounter(PCNT_RENDER_PARTICLE);
m_particle->DrawParticle(SH_WORLD); // draws the particles of the 3D world
m_app->StopPerformanceCounter(PCNT_RENDER_PARTICLE);
@ -3372,6 +3386,60 @@ void CEngine::Draw3DScene()
if (! m_overFront) DrawOverColor(); // draws the foreground color
}
void CEngine::DrawCrashSpheres()
{
Math::Matrix worldMatrix;
worldMatrix.LoadIdentity();
m_device->SetTransform(TRANSFORM_WORLD, worldMatrix);
SetState(ENG_RSTATE_OPAQUE_COLOR);
const int LINE_SEGMENTS = 32;
const int LONGITUDE_DIVISIONS = 16;
const int LATITUDE_DIVISIONS = 8;
VertexCol line[LINE_SEGMENTS];
Color color(0.0f, 0.0f, 1.0f);
auto SpherePoint = [&](float sphereRadius, float latitude, float longitude)
{
float latitudeAngle = (latitude - 0.5f) * 2.0f * Math::PI;
float longitudeAngle = longitude * 2.0f * Math::PI;
return Math::Vector(sphereRadius * sinf(latitudeAngle) * cosf(longitudeAngle),
sphereRadius * cosf(latitudeAngle),
sphereRadius * sinf(latitudeAngle) * sinf(longitudeAngle));
};
for (const auto& crashSphere : m_displayCrashSpheres)
{
for (int longitudeDivision = 0; longitudeDivision <= LONGITUDE_DIVISIONS; ++longitudeDivision)
{
for (int segment = 0; segment < LINE_SEGMENTS; ++segment)
{
Math::Vector pos = crashSphere.pos;
float latitude = static_cast<float>(segment) / LINE_SEGMENTS;
float longitude = static_cast<float>(longitudeDivision) / (LONGITUDE_DIVISIONS);
pos += SpherePoint(crashSphere.radius, latitude, longitude);
line[segment] = VertexCol(pos, color);
}
m_device->DrawPrimitive(PRIMITIVE_LINE_STRIP, line, LINE_SEGMENTS);
}
for (int latitudeDivision = 0; latitudeDivision <= LATITUDE_DIVISIONS; ++latitudeDivision)
{
for (int segment = 0; segment < LINE_SEGMENTS; ++segment)
{
Math::Vector pos = crashSphere.pos;
float latitude = static_cast<float>(latitudeDivision + 1) / (LATITUDE_DIVISIONS + 2);
float longitude = static_cast<float>(segment) / LINE_SEGMENTS;
pos += SpherePoint(crashSphere.radius, latitude, longitude);
line[segment] = VertexCol(pos, color);
}
m_device->DrawPrimitive(PRIMITIVE_LINE_STRIP, line, LINE_SEGMENTS);
}
}
}
void CEngine::RenderShadowMap()
{
m_shadowMapping = m_shadowMapping && m_device->IsShadowMappingSupported();
@ -3798,8 +3866,10 @@ void CEngine::DrawInterface()
// At the end to not overlap
if (m_renderInterface)
DrawHighlight();
DrawTimer();
DrawStats();
if (m_renderInterface)
DrawMouse();

View File

@ -34,6 +34,7 @@
#include "math/intpoint.h"
#include "math/matrix.h"
#include "math/point.h"
#include "math/sphere.h"
#include "math/vector.h"
@ -1180,6 +1181,9 @@ public:
//! Updates the scene after a change of parameters
void ApplyChange();
void ClearDisplayCrashSpheres();
void AddDisplayCrashSpheres(const std::vector<Math::Sphere>& crashSpheres);
protected:
//! Prepares the interface for 3D scene
void Draw3DScene();
@ -1221,6 +1225,7 @@ protected:
void DrawStats();
//! Draw mission timer
void DrawTimer();
void DrawCrashSpheres();
//! Creates a new tier 2 object (texture)
EngineBaseObjTexTier& AddLevel2(EngineBaseObject& p1, const std::string& tex1Name, const std::string& tex2Name);
@ -1468,6 +1473,8 @@ protected:
std::unordered_map<std::string, int> m_staticMeshBaseObjects;
std::vector<Math::Sphere> m_displayCrashSpheres;
//! Pause the animation updates
bool m_pause = false;
};

View File

@ -250,6 +250,8 @@ CRobotMain::CRobotMain()
m_showLimit[i].link = nullptr;
}
m_debugCrashSpheres = false;
m_engine->SetTerrain(m_terrain.get());
m_app->SetMouseMode(MOUSE_ENGINE);
@ -1394,6 +1396,16 @@ void CRobotMain::ExecuteCmd(char *cmd)
}
return;
}
if (strcmp(cmd, "debugcrashon") == 0)
{
m_debugCrashSpheres = true;
return;
}
if (strcmp(cmd, "debugcrashoff") == 0)
{
m_debugCrashSpheres = false;
return;
}
}
if (strcmp(cmd, "debugmode") == 0)
@ -2457,6 +2469,8 @@ bool CRobotMain::EventFrame(const Event &event)
m_lightning->EventProcess(event);
m_planet->EventProcess(event);
UpdateDebugCrashSpheres();
Ui::CMap* pm = nullptr;
Ui::CWindow* pw = static_cast<Ui::CWindow*>(m_interface->SearchControl(EVENT_WINDOW1));
if (pw == nullptr)
@ -6003,3 +6017,21 @@ void CRobotMain::SetCodeBattleSpectatorMode(bool mode)
if (mode)
m_camera->SetFixDirectionV(-0.25f*Math::PI);
}
void CRobotMain::UpdateDebugCrashSpheres()
{
m_engine->ClearDisplayCrashSpheres();
if (m_debugCrashSpheres)
{
for (CObject* obj : m_objMan->GetAllObjects())
{
auto crashSpheres = obj->GetAllCrashSpheres();
std::vector<Math::Sphere> displaySpheres;
for (const auto& crashSphere : crashSpheres)
{
displaySpheres.push_back(crashSphere.sphere);
}
m_engine->AddDisplayCrashSpheres(displaySpheres);
}
}
}

View File

@ -407,6 +407,7 @@ protected:
void CreateCodeBattleInterface();
void DestroyCodeBattleInterface();
void SetCodeBattleSpectatorMode(bool mode);
void UpdateDebugCrashSpheres();
protected:
@ -583,4 +584,5 @@ protected:
int m_shotSaving = 0;
std::deque<CObject*> m_selectionHistory;
bool m_debugCrashSpheres;
};