Scanframe Modular Application 0.1.0
Loading...
Searching...
No Matches
Helper.h
Go to the documentation of this file.
1#pragma once
2#include <stack>
3#include <xgl/Color.h>
4#include <xgl/Dynamic.h>
5#include <xgl/ShaderProgram.h>
7#include <xgl/global.h>
8
9namespace sf::xgl
10{
11
16{
17 public:
21 typedef Matrix44::value_type value_type;
22
26 explicit Helper(ShaderProgram* sp);
27
32 explicit Helper(Dynamic* dynamic = nullptr);
33
39 void setFlags(bool solid, bool paint = false);
40
46 void setCameraAndModelMatrix(const QMatrix4x4& camera, const QMatrix4x4& model);
47
51 bool isSolid() const;
52
56 bool isPainting() const;
57
61 void pushMatrix();
62
66 void popMatrix();
67
72
76 void popCulling();
77
81 Matrix44& matrix();
82
88
94
100
106 void setColor(const Color& color);
107
113 void setColor(const QColor& color);
114
119 void setColor(float r, float g, float b, float a);
120
125 void setLineWidth(float width = 1.0f);
126
132 void render(VertexArrayBase* object, bool is_model = true);
133
139 void render(const std::function<void()>& callback, bool is_model = true);
140
141 void beginMode(GLenum mode);
142 void endMode();
143 void setNormal(double x, double y, double z);
144 void setVertex(double x, double y, double z);
145 void setVertex(Vector3D vec);
146 void setTexCoord(double x, double y);
147 void drawSphere(double radius, int slices, int stacks);
148 void drawDisk(double innerRadius, double outerRadius, int slices, int loops);
149 void drawCylinder(double baseRadius, double topRadius, double height, int slices, int stacks);
150 void drawPlaneLines(const Vector3D& a, const Vector3D& b, const Vector3D&, const Vector3D& d, int w_lines, int h_lines);
151
157
158 private:
162 ShaderProgram* _shaderProgram;
166 Matrix44 _matrix;
170 Matrix44 _cameraMatrix;
174 Matrix44 _modelMatrix;
178 Color _color;
182 vector3f _normal{0.0f, 0.0f, 0.0f};
186 std::stack<Matrix44> _matrixStack;
190 std::stack<CullingState> _cullingStack;
194 bool _flagPaint{false};
198 bool _flagSolid{false};
202 CullingState _cullingState{cfDisabled};
203
204 Dynamic* _dynamic{nullptr};
205};
206
211{
212 public:
213 explicit ScopedMatrix(Helper& helper);
214
216
217 private:
218 Helper& _helper;
219};
220
225{
226 public:
233 explicit ScopedCulling(Helper& helper, CullingState state = {cfEnabled | cfCCW | cfBackside});
234
239
240 private:
241 Helper& _helper;
242};
243
244}// namespace sf::xgl
245
246#ifndef __JETBRAINS_IDE__
247 // Include all inlined functions and template implementations.
248 #include <xgl/Helper.hpp>
249#endif
Color class used in vertex arrays and a layout of 4 x GLfloat.
Definition Color.h:14
Dynamic object .
Definition Dynamic.h:14
Keeps track of color.
Definition Helper.h:16
void pushMatrix()
Pushes the current matrix to the stack.
void setTexCoord(double x, double y)
void setLineWidth(float width=1.0f)
Sets the line width for GL_LINES and GL_LINE_STRIP.
Helper(ShaderProgram *sp)
Create a helper for a shader program.
void setVertex(double x, double y, double z)
void setFlags(bool solid, bool paint=false)
Helper flags which determine how the helper is active.
void translate(value_type x, value_type y, value_type z)
Adds a transformed (no translation) translation vector to the current matrix translation vector....
void setColor(float r, float g, float b, float a)
Sets the current color using the rgba values. Compatible with the OpenGL function glColorXXX.
void setColor(const Color &color)
Sets the current color using a QColor type.
ShaderProgram * shaderProgram()
Gets the Shader program.
void drawCylinder(double baseRadius, double topRadius, double height, int slices, int stacks)
Color & color()
Gets the current color as a reference. Compatible with the OpenGL function glColorXXX.
bool isSolid() const
Gets the solid flag.
void setNormal(double x, double y, double z)
void render(VertexArrayBase *object, bool is_model=true)
Draws the element setting some shader uniforms depending on the given arguments.
Matrix44::value_type value_type
Definition Helper.h:21
void beginMode(GLenum mode)
void pushCulling(CullingState state)
Pushes the current culling settings to stack.
void setVertex(Vector3D vec)
void setCameraAndModelMatrix(const QMatrix4x4 &camera, const QMatrix4x4 &model)
Sets the camera and model matrices which needed for old style OpenGL.
bool isPainting() const
Gets the paint flag.
void setColor(const QColor &color)
Sets the current color using a QColor type. Compatible with the OpenGL function glColorXXX.
void popMatrix()
Pops the stored matrix from the stack.
void drawDisk(double innerRadius, double outerRadius, int slices, int loops)
void render(const std::function< void()> &callback, bool is_model=true)
Sets the tracked state before rendering using the callback.
void popCulling()
Pops the stored culling settings to stack.
Helper(Dynamic *dynamic=nullptr)
Create a helper for a dynamic object which shader program is used to initialize the helper....
void rotate(value_type angle, value_type x, value_type y, value_type z)
Performs a rotation on the current matrix. Compatible with the OpenGL function.
void drawPlaneLines(const Vector3D &a, const Vector3D &b, const Vector3D &, const Vector3D &d, int w_lines, int h_lines)
void drawSphere(double radius, int slices, int stacks)
Matrix44 & matrix()
Gets the current matrix to modify.
Class to enable culling in a particular scope only.
Definition Helper.h:225
~ScopedCulling()
Disables the culling when getting out of scope.
ScopedCulling(Helper &helper, CullingState state={cfEnabled|cfCCW|cfBackside})
Create an instance culling front or back of the object.
Pushes and pops a matrix for the scope it is in.
Definition Helper.h:211
ScopedMatrix(Helper &helper)
Shader program having a default vertex and fragment shader.
Definition ShaderProgram.h:13
Base class for vertex-array derived classes.
Definition VertexArrayBase.h:15
Definition DemoRenderer.h:6
QFlags< ECullingFlag > CullingState
Type to contain bitmapped culling settings.
Definition Types.h:63
@ cfBackside
Definition Types.h:55
@ cfCCW
Definition Types.h:51
@ cfEnabled
Definition Types.h:49
std::array< GLfloat, 3 > vector3f
Type which corresponds with a GLSL type and used to implement Vertex structures.
Definition Types.h:21
#define _XGL_FUNC
Definition xgl/global.h:34
#define _XGL_CLASS
Definition xgl/global.h:35