Commit 89c808ec authored by Jeff Niu's avatar Jeff Niu

Added display for sam position, velocity, and force

parent 832cda0d
#include <QPainter>
#include <chrono>
#include <sstream>
#include "arrow.h"
#include "renderscene.h"
#include "statsdisplay.h"
#include "../gui/mainwindow.h"
#include "arrow.h"
RenderScene::RenderScene(std::shared_ptr<Simulator> simulator, QWidget *parent)
: QOpenGLWidget(parent),
......@@ -66,6 +66,10 @@ const std::vector<Solenoid> *RenderScene::solenoids() const {
return &m_solenoids;
}
const Sam *RenderScene::sam() const {
return &m_sam;
}
void RenderScene::paintEvent(QPaintEvent *event) {
long long int timeMillis = std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::system_clock::now().time_since_epoch()
......@@ -80,13 +84,9 @@ void RenderScene::paintEvent(QPaintEvent *event) {
solenoid.draw(&painter, event, deltaMillis, 2000);
}
m_sam.draw(&painter, event, deltaMillis, 2000);
std::stringstream ss;
ss << "(" << m_sam.mag().x() << ", " << m_sam.mag().y() << ")";
painter.setPen(Qt::white);
painter.drawText(QPoint(10, 10), QString::fromStdString(ss.str()));
Arrow samForce(this, m_sam.pos(), m_sam.mag());
samForce.draw(&painter, event, deltaMillis, 2000);
StatsDisplay statsDisplay(this);
statsDisplay.draw(&painter, event, deltaMillis, 2000);
painter.end();
}
......@@ -62,6 +62,11 @@ public:
*/
const std::vector<Solenoid> *solenoids() const override;
/**
* @return a pointer to the Sam instance.
*/
const Sam *sam() const override;
/**
* Start the ticker.
*/
......
......@@ -11,6 +11,7 @@
#include "drawable.h"
class Solenoid;
class Sam;
/**
* Base render scene referenced by Drawables to
......@@ -22,6 +23,7 @@ public:
virtual vector2f center() const = 0;
virtual const std::vector<Solenoid> *solenoids() const = 0;
virtual const Sam *sam() const = 0;
};
#endif //MINOTAUR_CPP_RENDERSCENEBASE_H
......@@ -60,6 +60,11 @@ Sam::pos() const {
return m_pos;
}
const typename Sam::vector2f &
Sam::vel() const {
return m_vel;
}
const typename Sam::vector2f &
Sam::mag() const {
return m_mag;
......
......@@ -44,6 +44,11 @@ public:
*/
const vector2f &pos() const;
/**
* @return SAM's current velocity
*/
const vector2f &vel() const;
/**
* @return the current magnetic field magnitude on SAM
*/
......
#include <QPainter>
#include "statsdisplay.h"
#include "sam.h"
StatsDisplay::StatsDisplay(RenderSceneBase *render_scene)
: m_render_scene(render_scene) {}
void StatsDisplay::draw(QPainter *painter, QPaintEvent *, int, float) {
QString pos, vel, mag;
const Sam *sam = m_render_scene->sam();
char format[] = "(%.3g, %.3g)";
pos.sprintf(format, sam->pos().x(), sam->pos().y());
vel.sprintf(format, sam->vel().x(), sam->vel().y());
mag.sprintf(format, sam->mag().x(), sam->mag().y());
painter->setPen(Qt::white);
painter->drawText(5, 15, "Position");
painter->drawText(5, 35, "Velocity");
painter->drawText(5, 55, "Magnetic");
painter->drawText(65, 15, pos);
painter->drawText(65, 35, vel);
painter->drawText(65, 55, mag);
}
#ifndef MINOTAUR_CPP_STATISDISPLAY_H
#define MINOTAUR_CPP_STATISDISPLAY_H
#include "drawable.h"
#include "renderscenebase.h"
class StatsDisplay : public Drawable {
public:
explicit StatsDisplay(RenderSceneBase *render_scene);
void draw(QPainter *painter, QPaintEvent *, int, float) override;
private:
RenderSceneBase *m_render_scene;
};
#endif //MINOTAUR_CPP_STATISDISPLAY_H
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment