Scanframe Modular Application 0.1.0
Loading...
Searching...
No Matches
Helper.h
Go to the documentation of this file.
1#pragma once
2#include <xgl/Color.h>
3#include <xgl/Dynamic.h>
4#include <xgl/ShaderProgram.h>
6#include <xgl/global.h>
7
8namespace sf::xgl
9{
10
15{
16 public:
20 typedef Matrix44::value_type value_type;
21
25 explicit Helper(ShaderProgram* sp);
26
31 explicit Helper(Dynamic* dynamic = nullptr);
32
38 void setFlags(bool solid, bool paint = false);
39
45 void setCameraAndModelMatrix(const QMatrix4x4& camera, const QMatrix4x4& model);
46
50 bool isSolid() const;
51
55 bool isPainting() const;
56
60 void pushMatrix();
61
65 void popMatrix();
66
71
75 void popCulling();
76
80 Matrix44& matrix();
81
87
93
99 void setColor(const Color& color);
100
106 void setColor(const QColor& color);
107
112 void setColor(float r, float g, float b, float a);
113
118 void setLineWidth(float width = 1.0f);
119
125 void render(VertexArrayBase* object, bool is_model = true);
126
132 void render(const std::function<void()>& callback, bool is_model = true);
133
134 void beginMode(GLenum mode);
135 void endMode();
136 void setNormal(double x, double y, double z);
137 void setVertex(double x, double y, double z);
138 void setVertex(Vector3D vec);
139 void setTexCoord(double x, double y);
140 void drawSphere(double radius, int slices, int stacks);
141 void drawDisk(double innerRadius, double outerRadius, int slices, int loops);
142 void drawCylinder(double baseRadius, double topRadius, double height, int slices, int stacks);
143 void drawPlaneLines(const Vector3D& a, const Vector3D& b, const Vector3D&, const Vector3D& d, int w_lines, int h_lines);
144
150
151 private:
155 ShaderProgram* _shaderProgram;
159 Matrix44 _matrix;
163 Matrix44 _cameraMatrix;
167 Matrix44 _modelMatrix;
171 Color _color;
175 vector3f _normal{0.0f, 0.0f, 0.0f};
179 std::stack<Matrix44> _matrixStack;
183 std::stack<CullingState> _cullingStack;
187 bool _flagPaint{false};
191 bool _flagSolid{false};
195 CullingState _cullingState{cfDisabled};
196
197 Dynamic* _dynamic{nullptr};
198};
199
204{
205 public:
206 explicit ScopedMatrix(Helper& helper);
207
209
210 private:
211 Helper& _helper;
212};
213
218{
219 public:
226 explicit ScopedCulling(Helper& helper, CullingState state = {cfEnabled | cfCCW | cfBackside});
227
232
233 private:
234 Helper& _helper;
235};
236
237}// namespace sf::xgl
238
239// Include all inlined functions and template implementations.
240#include <xgl/Helper.hpp>
Color class used in vertex arrays and has layout of 4 x GLfloat.
Definition Color.h:15
Dynamic object .
Definition Dynamic.h:14
Keeps track of color.
Definition Helper.h:15
void pushMatrix()
Pushes the current matrix to 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 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)
Performs a translation on the current matrix. Compatible with the OpenGL function.
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)
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:20
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.
void popMatrix()
Pops the stored matrix from 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 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.
Easy to use class to enable culling temporarily.
Definition Helper.h:218
~ScopedCulling()
Disables the culling when getting out of scope.
ScopedCulling(Helper &helper, CullingState state={cfEnabled|cfCCW|cfBackside})
Create instance culling front or back of the object.
Pushes and pops a matrix for the scope it is in.
Definition Helper.h:204
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:14
Definition DemoRenderer.h:6
QFlags< ECullingFlag > CullingState
Type to contain bitmapped culling settings.
Definition Types.h:61
@ cfBackside
Definition Types.h:54
@ cfCCW
Definition Types.h:50
@ cfEnabled
Definition Types.h:48
std::array< GLfloat, 3 > vector3f
Type which correspond 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