mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-07-31 05:30:23 +02:00
Move velocity line to the debug mode DEBUG_AIRVEL.
This commit is contained in:
51
src/debug/AirVelocity.cpp
Normal file
51
src/debug/AirVelocity.cpp
Normal 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
17
src/debug/AirVelocity.h
Normal 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;
|
||||||
|
};
|
@@ -4,4 +4,5 @@ powder_files += files(
|
|||||||
'ElementPopulation.cpp',
|
'ElementPopulation.cpp',
|
||||||
'ParticleDebug.cpp',
|
'ParticleDebug.cpp',
|
||||||
'SurfaceNormals.cpp',
|
'SurfaceNormals.cpp',
|
||||||
|
'AirVelocity.cpp',
|
||||||
)
|
)
|
||||||
|
@@ -26,6 +26,7 @@
|
|||||||
#include "debug/ElementPopulation.h"
|
#include "debug/ElementPopulation.h"
|
||||||
#include "debug/ParticleDebug.h"
|
#include "debug/ParticleDebug.h"
|
||||||
#include "debug/SurfaceNormals.h"
|
#include "debug/SurfaceNormals.h"
|
||||||
|
#include "debug/AirVelocity.h"
|
||||||
#include "graphics/Renderer.h"
|
#include "graphics/Renderer.h"
|
||||||
#include "simulation/Air.h"
|
#include "simulation/Air.h"
|
||||||
#include "simulation/ElementClasses.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<DebugLines >(DEBUG_LINES , gameView, this));
|
||||||
debugInfo.push_back(std::make_unique<ParticleDebug >(DEBUG_PARTICLE , gameModel->GetSimulation(), gameModel));
|
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<SurfaceNormals >(DEBUG_SURFNORM , gameModel->GetSimulation(), gameView, this));
|
||||||
|
debugInfo.push_back(std::make_unique<AirVelocity >(DEBUG_AIRVEL , gameModel->GetSimulation(), gameView, this));
|
||||||
}
|
}
|
||||||
|
|
||||||
GameController::~GameController()
|
GameController::~GameController()
|
||||||
|
@@ -20,6 +20,7 @@ constexpr auto DEBUG_PARTICLE = 0x0008;
|
|||||||
constexpr auto DEBUG_SURFNORM = 0x0010;
|
constexpr auto DEBUG_SURFNORM = 0x0010;
|
||||||
constexpr auto DEBUG_SIMHUD = 0x0020;
|
constexpr auto DEBUG_SIMHUD = 0x0020;
|
||||||
constexpr auto DEBUG_RENHUD = 0x0040;
|
constexpr auto DEBUG_RENHUD = 0x0040;
|
||||||
|
constexpr auto DEBUG_AIRVEL = 0x0080;
|
||||||
|
|
||||||
class DebugInfo;
|
class DebugInfo;
|
||||||
class SaveFile;
|
class SaveFile;
|
||||||
|
@@ -2208,13 +2208,6 @@ void GameView::OnDraw()
|
|||||||
ui::Point finalCurrentMouse = c->PointTranslate(currentMouse);
|
ui::Point finalCurrentMouse = c->PointTranslate(currentMouse);
|
||||||
ui::Point initialDrawPoint = drawPoint1;
|
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)
|
if (wallBrush)
|
||||||
{
|
{
|
||||||
finalCurrentMouse = c->NormaliseBlockCoord(finalCurrentMouse);
|
finalCurrentMouse = c->NormaliseBlockCoord(finalCurrentMouse);
|
||||||
|
@@ -297,6 +297,7 @@ void LuaMisc::Open(lua_State *L)
|
|||||||
LCONST(DEBUG_SURFNORM);
|
LCONST(DEBUG_SURFNORM);
|
||||||
LCONST(DEBUG_SIMHUD);
|
LCONST(DEBUG_SIMHUD);
|
||||||
LCONST(DEBUG_RENHUD);
|
LCONST(DEBUG_RENHUD);
|
||||||
|
LCONST(DEBUG_AIRVEL);
|
||||||
#undef LCONST
|
#undef LCONST
|
||||||
{
|
{
|
||||||
lua_newtable(L);
|
lua_newtable(L);
|
||||||
|
Reference in New Issue
Block a user