src/gl/partrenderer.h

Sat, 29 Feb 2020 23:51:03 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Sat, 29 Feb 2020 23:51:03 +0200
changeset 65
87c906545fc3
parent 61
4585d8d7a7ec
child 66
77c819262b7a
permissions
-rw-r--r--

document the grid snapping transformations

#pragma once
#include <QOpenGLWidget>
#include <QOpenGLFunctions>
#include <QQuaternion>
#include <QOpenGLVertexArrayObject>
#include <QOpenGLBuffer>
#include <QOpenGLShader>
#include <QOpenGLShaderProgram>
#include <glm/glm.hpp>
#include "main.h"
#include "gl/common.h"
#include "gl/compiler.h"

class PartRenderer : public QOpenGLWidget, protected QOpenGLFunctions
{
	Q_OBJECT
public:
	PartRenderer(
		Model* model,
		DocumentManager* documents,
		const ldraw::ColorTable& colorTable,
		QWidget* parent = nullptr);
	~PartRenderer() override;
	void setRenderPreferences(const gl::RenderPreferences& newPreferences);
protected:
	ldraw::Id pick(const QPoint& where);
	void initializeGL() override;
	void resizeGL(int width, int height) override;
	void paintGL() override;
	void mouseMoveEvent(QMouseEvent* event) override;
	void wheelEvent(QWheelEvent* event) override;
	Model* const model;
	DocumentManager* const documents;
	const ldraw::ColorTable& colorTable;
	gl::Compiler* const compiler;
	ldraw::Id highlighted = ldraw::NULL_ID;
	std::optional<glm::vec3> screenToModelCoordinates(const QPoint& point, const geom::Plane& plane);
	QPointF modelToScreenCoordinates(const glm::vec3& point);
	glm::vec3 unproject(const glm::vec3& win);
	glm::mat4 projectionMatrix;
	glm::mat4 viewMatrix;
	glm::mat4 modelMatrix;
	glm::vec4 viewportVector;
	glm::quat modelQuaternion;
	QPoint lastMousePosition;
	gl::RenderPreferences renderPreferences;
signals:
	void projectionMatrixChanged();
	void modelMatrixChanged();
	void viewMatrixChanged();
	void renderPreferencesChanged();
private:
	void setFragmentStyle(gl::FragmentStyle fragStyle);
	void renderAllArrays();
	void renderScene();
	void updateViewMatrix();
	void updateModelMatrix();
	void setupBackgroundColor();
	static constexpr double MIN_ZOOM = 0.0;
	static constexpr double MAX_ZOOM = 3.0;
	double zoom = 1.0;
	bool initialized = false;
	void renderVao(const gl::ArrayClass arrayClass);
	void checkForGLErrors();
};

mercurial