Skip to content
Snippets Groups Projects
Commit fc4d9400 authored by Armin Co's avatar Armin Co
Browse files

Added cutoff to bat.

parent f1b7db22
Branches
No related tags found
No related merge requests found
...@@ -9,8 +9,8 @@ ...@@ -9,8 +9,8 @@
namespace QPong namespace QPong
{ {
constexpr int arrayWidth = 768; constexpr int arrayWidth = 384;
constexpr int arrayHeight = 768; constexpr int arrayHeight = 384;
constexpr unsigned arraySize = arrayWidth * arrayHeight; constexpr unsigned arraySize = arrayWidth * arrayHeight;
......
...@@ -50,37 +50,32 @@ const double batPotential(double x, double y, Position pos) ...@@ -50,37 +50,32 @@ const double batPotential(double x, double y, Position pos)
{ {
y -= pos.y; y -= pos.y;
constexpr double vx = 0.0001;
double E = 0.0; double E = 0.0;
constexpr double scale = 0.000015;
constexpr double height = 0.31; constexpr double height = 0.31;
constexpr double cutoff = 0.0015;
if (y >= height) if (y >= height)
{ {
double d = sqr(x-pos.x) + sqr(y-height); double d = sqr(x-pos.x) + sqr(y-height) + cutoff;
E = 1.0 / sqrt(d) * vx; E = 1.0 / d * scale;
} }
else if (y <= (-height)) else if (y <= (-height))
{ {
double d = sqr(x-pos.x) + sqr((-y)-height); double d = sqr(x-pos.x) + sqr((-y)-height) + cutoff;
E = 1.0 / sqrt(d) * vx; E = 1.0 / d * scale;
} }
else if ( x >= pos.x && y < height && y>-height) else
{
double d = x-pos.x;
E = 1.0 / d * vx;
}
else if (x < pos.x && y < height && y > -height)
{ {
double d = pos.x-x; double d = sqr(pos.x-x) + cutoff;
E = 1.0 / d * vx; E = 1.0 / d * scale;
} }
return E; return E;
} }
double sumAtInit = 0.0;
void Particle::initMomentum() void Particle::initMomentum()
{ {
sumAtInit = 0.0; double sumAtInit = 0.0;
for (unsigned iy = 0; iy < QPong::arrayHeight; iy++) for (unsigned iy = 0; iy < QPong::arrayHeight; iy++)
{ {
double y = yAt(iy); double y = yAt(iy);
...@@ -89,12 +84,12 @@ void Particle::initMomentum() ...@@ -89,12 +84,12 @@ void Particle::initMomentum()
double x = xAt(ix); double x = xAt(ix);
unsigned index = QPong::arrayWidth * iy + ix; unsigned index = QPong::arrayWidth * iy + ix;
constexpr double k_px0 = 0.075; constexpr double k_px0 = 0.063;
constexpr double k_py0 = 0.052; constexpr double k_py0 = 0.042;
constexpr double k_x0 = 0.0; constexpr double k_x0 = 0.0;
constexpr double k_y0 = -0.0; constexpr double k_y0 = -0.0;
constexpr double lambda = 70.0; constexpr double lambda = 60.0;
constexpr double A0 = 0.9; constexpr double A0 = 0.5;
m_psi[index] = A0 * exp(Ci / hbar * (x * k_px0 + y * k_py0) - lambda * (sqr(x - k_x0) + sqr(y - k_y0))); m_psi[index] = A0 * exp(Ci / hbar * (x * k_px0 + y * k_py0) - lambda * (sqr(x - k_x0) + sqr(y - k_y0)));
sumAtInit += sqr(real(m_psi[index])) + sqr(imag(m_psi[index])); sumAtInit += sqr(real(m_psi[index])) + sqr(imag(m_psi[index]));
} }
...@@ -112,8 +107,6 @@ void Particle::initMomentum() ...@@ -112,8 +107,6 @@ void Particle::initMomentum()
} }
} }
Particle::Particle(ParticleImage *momentum, ParticleImage *position, std::map<Player, std::shared_ptr<QPlayer>> players) Particle::Particle(ParticleImage *momentum, ParticleImage *position, std::map<Player, std::shared_ptr<QPlayer>> players)
: m_bufMomentumRepresentation{momentum} : m_bufMomentumRepresentation{momentum}
, m_bufPositionRepresentation{position} , m_bufPositionRepresentation{position}
...@@ -172,10 +165,8 @@ const double pyAt(int iy) ...@@ -172,10 +165,8 @@ const double pyAt(int iy)
} }
constexpr double dt = 0.15; constexpr double dt = 0.15;
void Particle::manipulateParticleInPosition(int indexFrom, int indexTo) void Particle::manipulateParticleInPosition(int indexFrom, int indexTo)
{ {
sumAtInit = 0;
auto pOneX = m_players[Player::One]->getPosition().x; auto pOneX = m_players[Player::One]->getPosition().x;
auto pTwoX = m_players[Player::Two]->getPosition().x; auto pTwoX = m_players[Player::Two]->getPosition().x;
float sumScorePlayerOne = 0.0; float sumScorePlayerOne = 0.0;
...@@ -204,11 +195,11 @@ void Particle::manipulateParticleInPosition(int indexFrom, int indexTo) ...@@ -204,11 +195,11 @@ void Particle::manipulateParticleInPosition(int indexFrom, int indexTo)
double playerOneBat = batPotential(x, y, m_players[Player::One]->getPosition()); double playerOneBat = batPotential(x, y, m_players[Player::One]->getPosition());
double playerTwoBat = batPotential(x, y, m_players[Player::Two]->getPosition()); double playerTwoBat = batPotential(x, y, m_players[Player::Two]->getPosition());
double horizontalBorders = sqr(y) * sqr(y) * sqr(y) * sqr(y) * 0.002; double horizontalBorders = sqr(y) * sqr(y) * sqr(y) * sqr(y) * 0.01;
std::complex<double> tmp = m_psi[index] * exp(-Ci * dt / hbar * (playerOneBat + playerTwoBat + horizontalBorders)); std::complex<double> tmp = m_psi[index] * exp(-Ci * dt / hbar * (playerOneBat + playerTwoBat + horizontalBorders));
m_psi[index] = tmp; m_psi[index] = tmp;
m_bufPositionRepresentation->updateBuffer(index, tmp * 125.0, (playerOneBat + playerTwoBat + horizontalBorders)*200); m_bufPositionRepresentation->updateBuffer(index, tmp * 125.0, (playerOneBat + playerTwoBat + horizontalBorders) * 150);
} }
m_players[Player::One]->addScore(sumScorePlayerOne); m_players[Player::One]->addScore(sumScorePlayerOne);
m_players[Player::Two]->addScore(sumScorePlayerTwo); m_players[Player::Two]->addScore(sumScorePlayerTwo);
...@@ -229,11 +220,14 @@ void Particle::moveStep(int indexFrom, int indexTo) ...@@ -229,11 +220,14 @@ void Particle::moveStep(int indexFrom, int indexTo)
void Particle::propagate() void Particle::propagate()
{ {
std::cout << std::endl; for (auto &player : m_players)
constexpr int threadCount = 8; {
Profiler p {"propagate", Verbose::True}; player.second->update(dt);
}
constexpr int threadCount = 4;
Profiler p {"propagate"};
{ {
Profiler manipulation {"manipulation", Verbose::True}; Profiler manipulation {"manipulation"};
std::vector<std::thread> threads; std::vector<std::thread> threads;
for (int i = 0; i < threadCount; i++) for (int i = 0; i < threadCount; i++)
{ {
...@@ -245,11 +239,11 @@ void Particle::propagate() ...@@ -245,11 +239,11 @@ void Particle::propagate()
} }
} }
{ {
Profiler f {"fourier_forward", Verbose::True}; Profiler f {"fourier_forward"};
fftw_execute (m_planForward); // transform into momentum repr. fftw_execute (m_planForward); // transform into momentum repr.
} }
{ {
Profiler move {"move", Verbose::True}; Profiler move {"move"};
std::vector<std::thread> threads; std::vector<std::thread> threads;
for (int i = 0; i < threadCount; i++) for (int i = 0; i < threadCount; i++)
{ {
...@@ -261,11 +255,11 @@ void Particle::propagate() ...@@ -261,11 +255,11 @@ void Particle::propagate()
} }
} }
{ {
Profiler image {"image", Verbose::True}; Profiler image {"image"};
updateMomentumImage(); //momentum updateMomentumImage(); //momentum
} }
{ {
Profiler f {"fourier_backward", Verbose::True}; Profiler f {"fourier_backward"};
fftw_execute(m_planBackward); // transform into position repr. fftw_execute(m_planBackward); // transform into position repr.
} }
} }
...@@ -297,7 +291,7 @@ void Particle::updateMomentumImage() ...@@ -297,7 +291,7 @@ void Particle::updateMomentumImage()
px = x + QPong::arrayWidth / 2; px = x + QPong::arrayWidth / 2;
} }
constexpr double scale = 15580.0;; constexpr double scale = 55580.0;;
auto array_index = y * QPong::arrayWidth + x; auto array_index = y * QPong::arrayWidth + x;
auto momentum_index = py * QPong::arrayWidth + px; auto momentum_index = py * QPong::arrayWidth + px;
m_bufMomentumRepresentation->updateBuffer(array_index, (m_psi[momentum_index] * scale), 0.0); m_bufMomentumRepresentation->updateBuffer(array_index, (m_psi[momentum_index] * scale), 0.0);
......
...@@ -14,14 +14,6 @@ Profiler::Profiler(const char* name) ...@@ -14,14 +14,6 @@ Profiler::Profiler(const char* name)
m_startTimepoint = std::chrono::high_resolution_clock::now(); m_startTimepoint = std::chrono::high_resolution_clock::now();
} }
Profiler::Profiler(const char* name, Verbose v)
: m_verbose {v}
, m_name {name}
, m_stopped {false}
{
m_startTimepoint = std::chrono::high_resolution_clock::now();
}
Profiler::~Profiler() Profiler::~Profiler()
{ {
if (!m_stopped) if (!m_stopped)
......
...@@ -22,7 +22,6 @@ class Profiler ...@@ -22,7 +22,6 @@ class Profiler
public: public:
Profiler(const char* name); Profiler(const char* name);
Profiler(const char* name, Verbose v);
~Profiler(); ~Profiler();
long stop(); long stop();
......
...@@ -17,10 +17,10 @@ QPlayer::QPlayer(Player pl, Position pos) ...@@ -17,10 +17,10 @@ QPlayer::QPlayer(Player pl, Position pos)
} }
void QPlayer::update() void QPlayer::update(double dt)
{ {
constexpr double negativeAccelScale = 1.5; constexpr double negativeAccelScale = 1.5;
m_y += m_vy; m_y += (m_vy * dt * 4);
if (m_vy > 0.0) if (m_vy > 0.0)
{ {
...@@ -60,7 +60,7 @@ void QPlayer::move(Direction direction) ...@@ -60,7 +60,7 @@ void QPlayer::move(Direction direction)
break; break;
} }
constexpr double maxSpeedScale = 33; constexpr double maxSpeedScale = 28;
if (m_vy > speedStepSize * maxSpeedScale) if (m_vy > speedStepSize * maxSpeedScale)
{ {
m_vy = speedStepSize * maxSpeedScale; m_vy = speedStepSize * maxSpeedScale;
......
...@@ -31,7 +31,7 @@ class QPlayer ...@@ -31,7 +31,7 @@ class QPlayer
{ {
public: public:
QPlayer(Player pl, Position pos); QPlayer(Player pl, Position pos);
void update(); void update(double dt);
void move(Direction d); void move(Direction d);
float getScore(); float getScore();
void addScore(float score); void addScore(float score);
......
...@@ -23,11 +23,6 @@ void QWindow::simulation() ...@@ -23,11 +23,6 @@ void QWindow::simulation()
{ {
auto start = std::chrono::system_clock::now(); auto start = std::chrono::system_clock::now();
for (auto player : m_players)
{
player.second->update();
}
m_particle->propagate(); m_particle->propagate();
propRate = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now() - start).count(); propRate = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now() - start).count();
...@@ -46,7 +41,7 @@ void QWindow::simulation() ...@@ -46,7 +41,7 @@ void QWindow::simulation()
// Limit the speed of the simulation. // Limit the speed of the simulation.
auto dt = std::chrono::system_clock::now() - start; auto dt = std::chrono::system_clock::now() - start;
auto dtMillis = std::chrono::duration_cast<std::chrono::milliseconds>(dt).count(); auto dtMillis = std::chrono::duration_cast<std::chrono::milliseconds>(dt).count();
constexpr int propTime = 10; constexpr int propTime = 6;
if (dtMillis < propTime) if (dtMillis < propTime)
{ {
std::this_thread::sleep_for(std::chrono::milliseconds(propTime - dtMillis)); std::this_thread::sleep_for(std::chrono::milliseconds(propTime - dtMillis));
...@@ -144,7 +139,6 @@ void QWindow::updateGui() ...@@ -144,7 +139,6 @@ void QWindow::updateGui()
ss << "image update rate: "; ss << "image update rate: ";
ss << 1000 / renderRate; ss << 1000 / renderRate;
m_renderRate.set_text(ss.str()); m_renderRate.set_text(ss.str());
ss = std::stringstream(); ss = std::stringstream();
ss << "simulation rate: "; ss << "simulation rate: ";
ss << 1000 / propRate; ss << 1000 / propRate;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment