This repository has been archived on 2020-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
Files
YASMIN/ui/map/Renderable.h
kazu 075d8bb633 a lot!!! of changes
added main menu
added debug display
many debug widgets for plotting live data
worked on android live sensors
added offline-data sensor feeding
some dummy data sensors
worked on the map display
added ui debug for grid-points, particles and weights
added a cool dude to display the estimation
added real filtering based on the Indoor components
c++11 fixes for android compilation
online and offline filtering support
new resampling technique for testing
map loading via dialog
2016-09-16 19:30:04 +02:00

77 lines
1.7 KiB
C++

#ifndef RENDERABLE_H
#define RENDERABLE_H
#include <QOpenGLShaderProgram>
class Renderable {
protected:
QOpenGLShaderProgram program;
public:
/** dtor */
virtual ~Renderable() {;}
/** get the renderable's shader */
QOpenGLShaderProgram& getProgram() {return program;}
/** render the renderable */
void render() {
program.bind();
_render();
}
struct ModelMatrix {
QVector3D pos = QVector3D(0,0,0);
QVector3D rot = QVector3D(0,0,0);
QVector3D scale = QVector3D(1,1,1);
QMatrix4x4 mat;
ModelMatrix() {mat.setToIdentity();}
void update() {
const QVector3D _rot = rot.normalized();
const float rotDeg = rot.length();
mat.setToIdentity();
mat.scale(scale.x(), scale.y(), scale.z());
mat.translate(pos.x(), pos.y(), pos.z());
mat.rotate(rotDeg, _rot.x(), _rot.y(), _rot.z());
}
} modelMatrix;
void setPosition(QVector3D vec) {
modelMatrix.pos = vec * 0.99;
modelMatrix.update();
}
void setPosition(const float x, const float y, const float z) {
setPosition(QVector3D(x,z,y));
}
/** in degrees! */
void setRotation(const float x, const float y, const float z) {
modelMatrix.rot = QVector3D(x,z,y);
modelMatrix.update();
}
virtual void setOutlineOnly(const bool outline) {;}
virtual void initGL() = 0;
virtual void _render() = 0;
protected:
/** helper method to build the shader */
void loadShader(const QString& vertex, const QString& fragment) {
program.removeAllShaders();
if (!program.addShaderFromSourceFile(QOpenGLShader::Vertex, vertex)) {throw "1";}
if (!program.addShaderFromSourceFile(QOpenGLShader::Fragment, fragment)) {throw "2";}
if (!program.link()) {throw "3";}
if (!program.bind()) {throw "4";}
}
};
#endif // RENDERABLE_H