Debug mode for displaying crash spheres, closes #400
parent
34136c4538
commit
15c9cbd228
|
@ -3065,6 +3065,18 @@ void CEngine::ApplyChange()
|
||||||
SetFocus(m_focus);
|
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);
|
m_device->SetRenderState(RENDER_STATE_LIGHTING, false);
|
||||||
|
|
||||||
|
DrawCrashSpheres();
|
||||||
|
|
||||||
m_app->StartPerformanceCounter(PCNT_RENDER_PARTICLE);
|
m_app->StartPerformanceCounter(PCNT_RENDER_PARTICLE);
|
||||||
m_particle->DrawParticle(SH_WORLD); // draws the particles of the 3D world
|
m_particle->DrawParticle(SH_WORLD); // draws the particles of the 3D world
|
||||||
m_app->StopPerformanceCounter(PCNT_RENDER_PARTICLE);
|
m_app->StopPerformanceCounter(PCNT_RENDER_PARTICLE);
|
||||||
|
@ -3372,6 +3386,60 @@ void CEngine::Draw3DScene()
|
||||||
if (! m_overFront) DrawOverColor(); // draws the foreground color
|
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()
|
void CEngine::RenderShadowMap()
|
||||||
{
|
{
|
||||||
m_shadowMapping = m_shadowMapping && m_device->IsShadowMappingSupported();
|
m_shadowMapping = m_shadowMapping && m_device->IsShadowMappingSupported();
|
||||||
|
@ -3798,8 +3866,10 @@ void CEngine::DrawInterface()
|
||||||
// At the end to not overlap
|
// At the end to not overlap
|
||||||
if (m_renderInterface)
|
if (m_renderInterface)
|
||||||
DrawHighlight();
|
DrawHighlight();
|
||||||
|
|
||||||
DrawTimer();
|
DrawTimer();
|
||||||
DrawStats();
|
DrawStats();
|
||||||
|
|
||||||
if (m_renderInterface)
|
if (m_renderInterface)
|
||||||
DrawMouse();
|
DrawMouse();
|
||||||
|
|
||||||
|
|
|
@ -34,6 +34,7 @@
|
||||||
#include "math/intpoint.h"
|
#include "math/intpoint.h"
|
||||||
#include "math/matrix.h"
|
#include "math/matrix.h"
|
||||||
#include "math/point.h"
|
#include "math/point.h"
|
||||||
|
#include "math/sphere.h"
|
||||||
#include "math/vector.h"
|
#include "math/vector.h"
|
||||||
|
|
||||||
|
|
||||||
|
@ -1180,6 +1181,9 @@ public:
|
||||||
//! Updates the scene after a change of parameters
|
//! Updates the scene after a change of parameters
|
||||||
void ApplyChange();
|
void ApplyChange();
|
||||||
|
|
||||||
|
void ClearDisplayCrashSpheres();
|
||||||
|
void AddDisplayCrashSpheres(const std::vector<Math::Sphere>& crashSpheres);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
//! Prepares the interface for 3D scene
|
//! Prepares the interface for 3D scene
|
||||||
void Draw3DScene();
|
void Draw3DScene();
|
||||||
|
@ -1221,6 +1225,7 @@ protected:
|
||||||
void DrawStats();
|
void DrawStats();
|
||||||
//! Draw mission timer
|
//! Draw mission timer
|
||||||
void DrawTimer();
|
void DrawTimer();
|
||||||
|
void DrawCrashSpheres();
|
||||||
|
|
||||||
//! Creates a new tier 2 object (texture)
|
//! Creates a new tier 2 object (texture)
|
||||||
EngineBaseObjTexTier& AddLevel2(EngineBaseObject& p1, const std::string& tex1Name, const std::string& tex2Name);
|
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::unordered_map<std::string, int> m_staticMeshBaseObjects;
|
||||||
|
|
||||||
|
std::vector<Math::Sphere> m_displayCrashSpheres;
|
||||||
|
|
||||||
//! Pause the animation updates
|
//! Pause the animation updates
|
||||||
bool m_pause = false;
|
bool m_pause = false;
|
||||||
};
|
};
|
||||||
|
|
|
@ -250,6 +250,8 @@ CRobotMain::CRobotMain()
|
||||||
m_showLimit[i].link = nullptr;
|
m_showLimit[i].link = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_debugCrashSpheres = false;
|
||||||
|
|
||||||
m_engine->SetTerrain(m_terrain.get());
|
m_engine->SetTerrain(m_terrain.get());
|
||||||
|
|
||||||
m_app->SetMouseMode(MOUSE_ENGINE);
|
m_app->SetMouseMode(MOUSE_ENGINE);
|
||||||
|
@ -1394,6 +1396,16 @@ void CRobotMain::ExecuteCmd(char *cmd)
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (strcmp(cmd, "debugcrashon") == 0)
|
||||||
|
{
|
||||||
|
m_debugCrashSpheres = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (strcmp(cmd, "debugcrashoff") == 0)
|
||||||
|
{
|
||||||
|
m_debugCrashSpheres = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strcmp(cmd, "debugmode") == 0)
|
if (strcmp(cmd, "debugmode") == 0)
|
||||||
|
@ -2457,6 +2469,8 @@ bool CRobotMain::EventFrame(const Event &event)
|
||||||
m_lightning->EventProcess(event);
|
m_lightning->EventProcess(event);
|
||||||
m_planet->EventProcess(event);
|
m_planet->EventProcess(event);
|
||||||
|
|
||||||
|
UpdateDebugCrashSpheres();
|
||||||
|
|
||||||
Ui::CMap* pm = nullptr;
|
Ui::CMap* pm = nullptr;
|
||||||
Ui::CWindow* pw = static_cast<Ui::CWindow*>(m_interface->SearchControl(EVENT_WINDOW1));
|
Ui::CWindow* pw = static_cast<Ui::CWindow*>(m_interface->SearchControl(EVENT_WINDOW1));
|
||||||
if (pw == nullptr)
|
if (pw == nullptr)
|
||||||
|
@ -6003,3 +6017,21 @@ void CRobotMain::SetCodeBattleSpectatorMode(bool mode)
|
||||||
if (mode)
|
if (mode)
|
||||||
m_camera->SetFixDirectionV(-0.25f*Math::PI);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -407,6 +407,7 @@ protected:
|
||||||
void CreateCodeBattleInterface();
|
void CreateCodeBattleInterface();
|
||||||
void DestroyCodeBattleInterface();
|
void DestroyCodeBattleInterface();
|
||||||
void SetCodeBattleSpectatorMode(bool mode);
|
void SetCodeBattleSpectatorMode(bool mode);
|
||||||
|
void UpdateDebugCrashSpheres();
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -583,4 +584,5 @@ protected:
|
||||||
int m_shotSaving = 0;
|
int m_shotSaving = 0;
|
||||||
|
|
||||||
std::deque<CObject*> m_selectionHistory;
|
std::deque<CObject*> m_selectionHistory;
|
||||||
|
bool m_debugCrashSpheres;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue