RayZaler 0.1
The free opto-mechanical simulation framework
GLRenderEngine.h
1//
2// Copyright (c) 2024 Gonzalo José Carracedo Carballal
3//
4// This program is free software: you can redistribute it and/or modify
5// it under the terms of the GNU Lesser General Public License as
6// published by the Free Software Foundation, either version 3 of the
7// License, or (at your option) any later version.
8//
9// This program is distributed in the hope that it will be useful, but
10// WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU Lesser General Public License for more details.
13//
14// You should have received a copy of the GNU Lesser General Public
15// License along with this program. If not, see
16// <http://www.gnu.org/licenses/>
17//
18
19#ifndef _GL_RENDER_ENGINE_H
20#define _GL_RENDER_ENGINE_H
21
22#include "IncrementalRotation.h"
23#include <GLHelpers.h>
24#include <list>
25
26namespace RZ {
27 class GLModel;
28 class Element;
29
31 Real zoomLevel = 1;
32 Real center[2] = {0, 0};
33 Real width, height;
34 IncrementalRotation rotation;
35 IncrementalRotation screenRotation;
36
37 void zoom(Real delta);
38 void incAzEl(Real deltaAz, Real deltaEl);
39 void roll(Real delta);
40 void move(Real deltaX, Real deltaY);
41
42 void setScreenGeom(Real width, Real height);
43 void setZoom(Real delta);
44 void zoomToBox(ReferenceFrame const &ref, Vec3 const &p1, Vec3 const &p2);
45 void setCenter(Real, Real);
46 void setRotation(Real, Real, Real, Real);
47 void setRotation(Vec3 const &, Real);
48 void setRotation(Matrix3 const &);
49 void setScreenRotation(IncrementalRotation const &);
50 void rotateRelative(Vec3 const &, Real);
51 void configureViewPort(unsigned int width, unsigned int height) const;
52 void configureOrientation(bool translate = true) const;
53
54 void screenToWorld(Real &wX, Real &wY, Real sX, Real sY) const;
55 void worldToScreen(Real &sX, Real &sY, Real wX, Real wY) const;
56
57 bool screenToFrame(Vec3 &, ReferenceFrame const &, Real sX, Real sY) const;
58 bool worldToFrame(Vec3 &, ReferenceFrame const &, Real wX, Real wY) const;
59
60 void frameToWorld(Real &wX, Real &wY, ReferenceFrame const &, Vec3 const &) const;
61 void frameToScreen(Real &sX, Real &sY, ReferenceFrame const &, Vec3 const &) const;
62
63 };
64
66 GLGrid m_xyCoarseGrid;
67 GLGrid m_xyMediumGrid;
68 GLGrid m_xyFineGrid;
69 GLText m_glGridText;
70 unsigned m_divs = 0;
71 GLfloat m_step = 0;
72 GLfloat m_color[3] = {1, 1, 1};
73
74 public:
76
77 void display();
78
79 void setColor(GLfloat, GLfloat, GLfloat);
80 void setColor(Vec3 const &);
81 void setColor(const GLfloat *);
82 void setGridText(std::string const &);
83 void setGridStep(Real step);
84 void setGridDivs(unsigned int num);
85 void setThickness(unsigned);
86 void highlight(Real, Real);
87 };
88
89 struct GLFrameGrid {
90 const ReferenceFrame *frame = nullptr; // Borrowed
91 GLHelperGrid grid;
92 };
93
95 GLModel *m_model = nullptr; // Borrowed
96 Real m_axisZoom = 1.;
97 GLCurrentView m_view;
98 GLReferenceFrame m_glAxes;
99 std::list<GLFrameGrid> m_grids;
100
101 protected:
102 void setOrientationAndCenter(RZ::Matrix3 const &R, RZ::Vec3 const &O);
103 void drawCornerAxes();
104 void drawGrids();
105
106 public:
107 GLCurrentView *view();
108 GLFrameGrid *addGrid(std::string const &, ReferenceFrame const *frame);
109
110 void setModel(GLModel *);
111
112 GLModel *model() const;
113
114 void setAxesZoom(Real);
115 void zoom(Real delta);
116 void zoomToBox(ReferenceFrame const &ref, Vec3 const &p1, Vec3 const &p2);
117 void incAzEl(Real deltaAz, Real deltaEl);
118 void roll(Real delta);
119 void move(Real deltaX, Real deltaY);
120
121 void setZoom(Real delta);
122 void setCenter(Real, Real);
123 void setRotation(Real, Real, Real, Real);
124 void setView(GLCurrentView const *);
125 };
126}
127
128#endif // _GL_RENDER_ENGINE_H
129
Definition: GLHelpers.h:588
Definition: GLRenderEngine.h:65
Definition: GLModel.h:37
Definition: GLHelpers.h:495
Definition: GLRenderEngine.h:94
Definition: GLHelpers.h:555
Definition: IncrementalRotation.h:25
Definition: ReferenceFrame.h:59
Definition: GLRenderEngine.h:30
Definition: GLRenderEngine.h:89
Definition: Matrix.h:48
Definition: Vector.h:66