-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathOGLScreen.h
More file actions
209 lines (158 loc) · 5.41 KB
/
OGLScreen.h
File metadata and controls
209 lines (158 loc) · 5.41 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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/*
* OGLScreen.h
*
* Created on: Oct 13, 2011
* Author: iraklis
*/
#include <NativeUI/Widgets.h>
#include <GLES/gl.h>
#include "HTMLScreen.h"
// Namespaces we want to access.
using namespace MAUtil; // Class Moblet
using namespace NativeUI; // WebView widget.
#ifndef OGLSCREEN_H_
#define OGLSCREEN_H_
class HTMLScreen;
//A struct that describes a single particle
typedef struct particle{
bool alive; //Whether the particle exists or not
int addTime; //The time that the particle was created
//Position vector
float x;
float y;
float z;
//Velocity vector
float xv;
float yv;
float zv;
};
class OGLScreen : public Screen,
public GLViewListener,
public SensorListener,
public TimerListener,
public ButtonListener
{
public:
OGLScreen(MAHandle particleImage);
~OGLScreen();
/**
* This method creates the user interface of the screen
*/
void createUI();
/**
* This method is called when the GLView has been initialized
* and it's ready to accept OpenGL commands
* @param glView The GLView that was initialized
*/
virtual void glViewReady(GLView* glView);
/**
* This method initializes the parameters of the environment that
* the particles live in, and also sets the screen that handles communication
* with JavaScript
* @param htmlScreen The screen that handles the JavaScript code
* @param maxParticles The maximum number of particles that will be rendered
* @param particleLifetime How long a particle will exists after it's creation
* @param gravityScale How strong is the gravity
* @param screenWidth The width of the area that willbe used for rendering
* @param screenHeight The height of the area that willbe used for rendering
*
*/
void initVariables(HTMLScreen *htmlScreen,int maxParticles, int particleLifetime,
float gravityScale, int screenWidth, int screenHeight);
/**
* This method will initialize the particle texture
*/
void createTexture();
/**
* This method will initialize the OpenGL viewport to fill the GLView,
* And set the coordinate system to the specified size
* @param width The width of the coordinate system
* @param height The height of the coordinate system
*/
void setViewport(int width, int height);
/**
* This method will initialize the OpenGL to the parameters
* that are needed by our particular animation
*/
void initGL();
/**
* This method handles button clicks that this screen manages.
* @param button The button that was clicked
*/
virtual void buttonClicked(Widget* button);
/**
* This method calculates the new position of the particles
* and renders a frame each time it's called.
* @currentTime the current animation time
*/
void draw(int currentTime);
/**
* This method renders the particles on the screen
*/
void renderParticleObject();
/**
* Tell the screen whether it should render the animation or not
* @param render The state of rendering.
*/
void shouldRender(bool render);
/**
* This method is called whenever the timer is fired,
* and controls the animation
*/
virtual void runTimerEvent();
/**
* This method handles accelerometer events
* @param a A struct containing the accelerometer info
*/
virtual void sensorEvent(MASensor a);
/**
* This method adds a new particle to the rendering with the specified parameters
* @param x The horizontal position of the particle.
* @param y The vertical position of the particle.
* @param z The height of the particle.
* @param xv The particle's velocity on the x axis
* @param yv The particle's velocity on the y axis
* @param zv The particle's velocity on the z axis
*/
void addNewParticles(float x, float y, float z,
float xv, float yv, float zv, int flow);
/**
* Checks for particles past their lifetime, and removes them
* @currentTime the current animation time
*/
void removeOldParticles(int currentTime);
/**
* This method enables or disables the Increase flow button
* @state The new state of the button
*/
void enableAddButton(bool state);
/**
* This method enables or disables the Decrease flow button
* @state The new state of the button
*/
void enableRemoveButton(bool state);
private:
Button* mAddButton; //Increase flow
Button* mRemoveButton; //Decrease flow
HTMLScreen *mHTMLScreen; //The screen that handles communication with JS
MAHandle mParticleImageHandle; //The image resource for particles
GLuint mParticleTexture; //The particle texture used by OpenGL
bool mGLViewInitialized; //Initialization flag for the GLView wiget
bool mVariablesInitialized; //Initialization flag for the animation parameters
bool mEnvironmentInitialized; //Initialization flag for rendering
Label* mFPSLabel; //A label for showing the frame rate
Label* mFlowLabel; //A label for showing the flow rate
GLView* mGLView; //The widget that renders the frames
particle* mParticles; //The list of particles
bool mShouldRender; //The state of rendering
int mPrevTime; //The previous time that a frame was rendered
int mTotalTime; //Used to average the FPS value for several frames
int mFrameCounter; //Used to count when it needs to update the FPS
float ax, ay, az; //The gravity vector
int MAX_PARTICLES; //The maximum number of partiles
int PARTICLE_LIFETIME; //The lifetime of each partile, in milliseconds
float GRAVITY_SCALE; //The strenght of gravity
int SCREN_WIDTH; //The width of the screen
int SCREEN_HEIGHT; //The height of the screen
};
#endif /* OGLSCREEN_H_ */