Move velocity line to the debug mode DEBUG_AIRVEL.

This commit is contained in:
Saveliy Skresanov 2025-01-17 22:38:30 +07:00
parent fa8237218d
commit f7bedb3b5f
7 changed files with 73 additions and 7 deletions

51
src/debug/AirVelocity.cpp Normal file
View File

@ -0,0 +1,51 @@
#include "AirVelocity.h"
#include "gui/game/GameView.h"
#include "gui/game/GameController.h"
#include "gui/interface/Engine.h"
#include "simulation/Simulation.h"
#include "simulation/ElementClasses.h"
#include "graphics/Graphics.h"
AirVelocity::AirVelocity(unsigned int id, const Simulation *newSim, GameView *newView, GameController *newController) :
DebugInfo(id), sim(newSim), view(newView), controller(newController)
{
}
void AirVelocity::Draw()
{
auto *g = ui::Engine::Ref().g;
ui::Point pos = controller->PointTranslate(view->GetCurrentMouse());
float velx = sim->vx[pos.Y/CELL][pos.X/CELL];
float vely = sim->vy[pos.Y/CELL][pos.X/CELL];
int endx = pos.X + (int)(10.0f*velx);
int endy = pos.Y + (int)(10.0f*vely);
//Air velocity line near cursor
g->XorLine({pos.X, pos.Y}, {endx, endy});
//Air velocity magnitude
float vlen = std::sqrt(velx*velx + vely*vely);
if (vlen > 0.001f)
{
StringBuilder velocity;
velocity << Format::Precision(2) << vlen;
int width = Graphics::TextSize(velocity.Build()).X;
int height = Graphics::TextSize(velocity.Build()).Y;
//Rectangle in polar coordinates, here diff is radius
int dx = endx - pos.X;
int dy = endy - pos.Y;
float diff = 0;
if (width*std::abs(dy) < height*std::abs(dx))
diff = ((float)width)/((float)std::abs(dx));
else
diff = ((float)height)/((float)std::abs(dy));
float circx = (diff/1.5f) * (endx - pos.X) + endx;
float circy = (diff/1.5f) * (endy - pos.Y) + endy;
g->BlendText({(int)circx - width/2, (int)circy - height/2 + 2}, velocity.Build(), 0xFFFFFF_rgb .WithAlpha(255));
}
}

17
src/debug/AirVelocity.h Normal file
View File

@ -0,0 +1,17 @@
#pragma once
#include "DebugInfo.h"
class Simulation;
class GameView;
class GameController;
class AirVelocity : public DebugInfo
{
const Simulation *sim;
GameView *view;
GameController *controller;
public:
AirVelocity(unsigned int id, const Simulation *newSim, GameView *newView, GameController *newController);
void Draw() override;
};

View File

@ -4,4 +4,5 @@ powder_files += files(
'ElementPopulation.cpp',
'ParticleDebug.cpp',
'SurfaceNormals.cpp',
'AirVelocity.cpp',
)

View File

@ -26,6 +26,7 @@
#include "debug/ElementPopulation.h"
#include "debug/ParticleDebug.h"
#include "debug/SurfaceNormals.h"
#include "debug/AirVelocity.h"
#include "graphics/Renderer.h"
#include "simulation/Air.h"
#include "simulation/ElementClasses.h"
@ -100,6 +101,7 @@ GameController::GameController():
debugInfo.push_back(std::make_unique<DebugLines >(DEBUG_LINES , gameView, this));
debugInfo.push_back(std::make_unique<ParticleDebug >(DEBUG_PARTICLE , gameModel->GetSimulation(), gameModel));
debugInfo.push_back(std::make_unique<SurfaceNormals >(DEBUG_SURFNORM , gameModel->GetSimulation(), gameView, this));
debugInfo.push_back(std::make_unique<AirVelocity >(DEBUG_AIRVEL , gameModel->GetSimulation(), gameView, this));
}
GameController::~GameController()

View File

@ -20,6 +20,7 @@ constexpr auto DEBUG_PARTICLE = 0x0008;
constexpr auto DEBUG_SURFNORM = 0x0010;
constexpr auto DEBUG_SIMHUD = 0x0020;
constexpr auto DEBUG_RENHUD = 0x0040;
constexpr auto DEBUG_AIRVEL = 0x0080;
class DebugInfo;
class SaveFile;

View File

@ -2208,13 +2208,6 @@ void GameView::OnDraw()
ui::Point finalCurrentMouse = c->PointTranslate(currentMouse);
ui::Point initialDrawPoint = drawPoint1;
//Air velocity line near cursor
if (showDebug && (rendererSettings->displayMode & DISPLAY_AIRV))
{
g->XorLine({finalCurrentMouse.X, finalCurrentMouse.Y},
{finalCurrentMouse.X + (int)(10.0f*sample.AirVelocityX), finalCurrentMouse.Y + (int)(10.0f*sample.AirVelocityY)});
}
if (wallBrush)
{
finalCurrentMouse = c->NormaliseBlockCoord(finalCurrentMouse);

View File

@ -297,6 +297,7 @@ void LuaMisc::Open(lua_State *L)
LCONST(DEBUG_SURFNORM);
LCONST(DEBUG_SIMHUD);
LCONST(DEBUG_RENHUD);
LCONST(DEBUG_AIRVEL);
#undef LCONST
{
lua_newtable(L);