forked from czajowaty/virtual_monsbaia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSceneGLRenderer.hpp
116 lines (104 loc) · 3.29 KB
/
SceneGLRenderer.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#ifndef SCENEGLRENDERER_HPP
#define SCENEGLRENDERER_HPP
#include "ADScene.hpp"
#include <QOpenGLFunctions>
#include <QOpenGLWidget>
#include <QMatrix4x4>
#include <QOpenGLShaderProgram>
#include <QOpenGLBuffer>
#include <QOpenGLTexture>
#include <QOpenGLVertexArrayObject>
#include <QVector3D>
struct VertexPlain
{
QVector3D pos;
};
struct VertexTextured
{
QVector3D pos;
QVector2D texturePos;
QVector3D texpage;
QVector2D clut;
};
class SceneGLRenderer : public QOpenGLWidget, protected QOpenGLFunctions
{
Q_OBJECT
using Vertex = VertexTextured;
public:
SceneGLRenderer(QWidget* parent = nullptr);
~SceneGLRenderer();
bool isSceneLoaded() const
{ return vramTexture_ != nullptr; }
void loadScene(ADScene const& adScene);
QVector3D const& cameraPosition() const
{ return cameraPosition_; }
QVector3D const& cameraFront() const
{ return cameraFront_; }
float cameraYaw() const
{ return cameraYaw_; }
float cameraPitch() const
{ return cameraPitch_; }
void resetCamera();
void increaseFieldOfView(float change);
void decreaseFieldOfView(float change);
void moveNonRotatedForward(float magnitude);
void moveForward(float magnitude);
void moveNonRotatedBackwards(float magnitude);
void moveBackwards(float magnitude);
void moveNonRotatedLeft(float magnitude);
void moveLeft(float magnitude);
void moveNonRotatedRight(float magnitude);
void moveRight(float magnitude);
void moveNonRotatedUp(float magnitude);
void moveNonRotatedDown(float magnitude);
void rotateYaw(float magnitude);
void rotatePitch(float magnitude);
void toggleDrawOpaques()
{ setDrawOpaques(!drawOpaques_); }
void setDrawOpaques(bool enabled);
void toggleDrawSemiTransparent()
{ setDrawSemiTransparent(!drawSemiTransparent_); }
void setDrawSemiTransparent(bool enabled);
protected:
void initializeGL() override;
void resizeGL(int w, int h) override;
void paintGL() override;
private:
void clear();
Vertex toVertex(
AD::PolygonDescriptor const& polygonDescriptor,
AD::Point3D const& adVertex,
GpuTexCoord const& texCoord);
void prepareBuffers(
QVector<Vertex> const& vertices,
QVector<GLuint> const& opaquePolygonsIndices,
QVector<GLuint> const& semiTransparentPolygonsIndices);
QVector3D cameraRight() const;
void calculateCameraFront();
void updateViewMatrix();
void calculateProjectionMatrix();
float aspectRatio_;
QMatrix4x4 pMatrix_;
QOpenGLShaderProgram shaderProgram_;
QOpenGLVertexArrayObject opaquePolygonsVao_;
QOpenGLVertexArrayObject semiTransparentPolygonsVao_;
QOpenGLBuffer vbo_;
QOpenGLBuffer opaquePolygonsEbo_;
QOpenGLBuffer semiTransparentPolygonsEbo_;
std::unique_ptr<QOpenGLTexture> vramTexture_;
uint32_t opaquePolygonsIndicesNumber_;
uint32_t semiTransparentPolygonsIndicesNumber_;
QMatrix4x4 projectionMatrix_;
int projectionMatrixLocation_;
QMatrix4x4 viewMatrix_;
int viewMatrixLocation_;
float fieldOfView_;
QVector3D cameraPosition_;
QVector3D cameraFront_;
QVector3D cameraUp_;
float cameraYaw_;
float cameraPitch_;
bool drawOpaques_;
bool drawSemiTransparent_;
};
#endif // SCENEGLRENDERER_HPP