-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBarMgr.h
More file actions
171 lines (141 loc) · 3.58 KB
/
BarMgr.h
File metadata and controls
171 lines (141 loc) · 3.58 KB
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/*
* BarMgr.h
*
* Created on: Mar 14, 2013
* Author: CodeArt
*/
#ifndef BARMGR_H_
#define BARMGR_H_
#include <GLES2/gl2.h>
#include <glm/glm.hpp>
#include <vector>
#include <string>
#include "IRender.h"
#include "Shaders.h"
namespace MoGraph
{
/**
* \brief Bar class handles one single bar used by BarMgr for rendering
*/
class scene;
class Bar
{
protected:
float mValue;
glm::vec4 mColor;
public:
/**
* \brief Bar Constructor
*/
Bar() : mValue(1.0f), mColor(1.0f,1.0f,1.0f,1.0f) {}
/**
* \brief setColor, sets the r,g,b,a as float color component for the bar.
* @param r
* @param g
* @param b
* @param a
*/
void setColor(float r,float g,float b, float a) {mColor.x = r; mColor.y = g; mColor.z = b; mColor.w = a;}
/**
* \brief setColor, with glm::vec4 as input.
* @param col
*/
void setColor(glm::vec4 &col) {mColor = col;}
/**
* \brief setValue, bar height value in float
* @param val
*/
void setValue(float val) {mValue = val;}
/**
* \brief getValue, get the bar height value
* @return output height value
*/
float getValue() {return mValue;}
/**
* \brief getColor, get the bar color value
* @return output the bar color
*/
glm::vec4 & getColor() {return mColor;}
};
/**
* \brief BarMgr handles all the bars that are being displayed
* using Render base class for the render calls init() & draw()
*/
class BarMgr : public Render
{
protected:
std::vector<Bar> mBarArray; // question absolute amount of bars or display fromc..to
std::vector<glm::vec3> mVertices;
std::vector<unsigned short> mFaces;
BarShader mShader;
/**
* \brief create3D
* helper function to set the vertex array & index array
* Creates default vertex buffer & index buffer
*/
void create3D(); // create 3D obj. one instance of a cube with origo at bottom with indices
public:
/**
* \brief BarMgr Constructor
* @param scene input reference for the scene
*/
BarMgr(Scene *scene) : Render(scene) {create3D();}
/**
* \brief ~BarMgr Destructor
*/
virtual ~BarMgr() {}
/**
* \brief addBars, set up amount of bars that shall be used for the graph
* @param sz input amount of bars
*/
void addBars(int sz) {mBarArray.resize(sz);}
/**
* \brief addbar, add one bar to the table
* @param bar , adds this bar to the mBarArray table as last entry
*/
void addBar(Bar &bar) {mBarArray.push_back(bar);}
/**
* \brief getBars, get the table of all bars.
* @return
*/
std::vector<Bar> &getBars() {return mBarArray;}
/**
* \brief size, get the bars table size
* @return size of table
*/
int size() {return mBarArray.size();}
/**
* \brief getBar, get a element from the Bars array
* @param i, element index
* @return Bar entry
*/
Bar &getBar(int i) {return mBarArray[i];}
/**
* \brief common vertices used for all bars
* @return vector of vertices
*/
std::vector<glm::vec3>& vertices() {return mVertices;}
/**
* \brief common index table of bars
* @return vector of faces
*/
std::vector<unsigned short>& faces() {return mFaces;}
/**
* \brief getShader,
* @return
*/
BarShader &getShader() {return mShader;}
// virtuals from render class
/**
* \brief init, initiate bar manager class to set up the graph bars
* \note see virtuals from render class
*/
virtual void init();
/**
* \brief draw, render bars on screen
* \note see virtuals from render class
*/
virtual void draw();
};
}
#endif /* BARMGR_H_ */