-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
glut_232.h
131 lines (114 loc) · 3.48 KB
/
glut_232.h
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
#ifndef GLUT_232_H
#define GLUT_232_H
#include <vector>
#if defined (GLEW_SUPPORT)
#include "GL/glew.h"
#endif // GLEW_SUPPORT
#if defined (ACE_WIN32) || defined (ACE_WIN64)
#include "gl/GL.h"
#else
#include "GL/gl.h"
#endif // ACE_WIN32 || ACE_WIN64
#include "common_tools.h"
#include "engine_common.h"
//////////////////////////////////////////
class object
{
public:
object ()
: dist_ (Common_Tools::getRandomNumber (150.0f, 300.0f))
, x_ (Common_Tools::getRandomNumber (0.0f, dist_))
, y_ (0.0f)
, a_ (0.0f)
, range_ (Common_Tools::getRandomNumber (-20.0f, 50.0f))
, c_ (Common_Tools::getRandomNumber (0.5f, 15.0f))
, e_ (Common_Tools::getRandomNumber (0.0f, 255.0f))
, xSpeed_ (Common_Tools::getRandomNumber (0.1f, 0.4f))
, ySpeed_ (Common_Tools::getRandomNumber (0.02f, 0.04f))
, rot_ (Common_Tools::getRandomNumber (0.0f, 2.0f * static_cast<float> (M_PI)))
, r_ (static_cast<uint8_t> (Common_Tools::getRandomNumber (0, 255)))
, g_ (static_cast<uint8_t> (Common_Tools::getRandomNumber (0, 255)))
, b_ (static_cast<uint8_t> (Common_Tools::getRandomNumber (0, 255)))
, s_ (1.0f)
, r2_ (0.0f)
{}
void move ()
{
x_ += xSpeed_;
y_ = range_ * std::sin (x_ * ySpeed_);
s_ += 0.002f;
}
void show ()
{
glPushMatrix ();
glRotatef (rot_ * 180.0f / static_cast<float> (M_PI), 0.0f, 0.0f, 1.0f);
for (int i2 = 0; i2 < 50; ++i2)
{
// draw (filled) circle
glColor4ub (r_, g_, 255, 206 + i2);
glBegin (GL_TRIANGLE_FAN);
float x1 = x_ + i2 * xSpeed_;
float y1 = range_ * std::sin ((x_ + i2 * xSpeed_) * ySpeed_);
float r = r2_ / 50.0f * i2 * s_;
glVertex2f (x1, y1);
for (float angle = 0.0f; angle < 2.0f * static_cast<float> (M_PI) + 0.2f; angle += 0.2f)
{
float x2 = x1 + std::sin (angle) * r;
float y2 = y1 + std::cos (angle) * r;
glVertex2f (x2, y2);
} // end FOR
glEnd ();
if (x_ + i2 * xSpeed_ > dist_)
{
x_ = -50.0f * xSpeed_;
dist_ = Common_Tools::getRandomNumber (200.0f, 300.0f);
r_ = static_cast<uint8_t> (Common_Tools::getRandomNumber (0, 255));
g_ = static_cast<uint8_t> (Common_Tools::getRandomNumber (0, 255));
b_ = static_cast<uint8_t> (Common_Tools::getRandomNumber (0, 255));
s_ = 1.0f;
} // end IF
if (x_ + i2 * xSpeed_ < 0.0f)
r2_ = 0.0f;
else
r2_ = c_ * std::sin (i2 / 50.0f * static_cast<float> (M_PI)) + 1.0f;
} // end FOR
glPopMatrix ();
}
float dist_;
float x_;
float y_;
float a_;
float range_;
float c_;
float e_;
float xSpeed_;
float ySpeed_;
float rot_;
uint8_t r_;
uint8_t g_;
uint8_t b_;
float s_;
float r2_;
};
//////////////////////////////////////////
// GLUT routines
void engine_glut_232_reshape (int, int);
void engine_glut_232_key (unsigned char, int, int);
void engine_glut_232_key_special (int, int, int);
void engine_glut_232_menu (int);
void engine_glut_232_mouse_button (int, int, int, int);
void engine_glut_232_mouse_move (int, int);
void engine_glut_232_timer (int);
void engine_glut_232_draw (void);
void engine_glut_232_idle (void);
void engine_glut_232_visible (int);
struct Engine_OpenGL_GLUT_232_CBData
{
//
std::vector<object> objects;
// menu
bool wireframe;
// camera
struct Engine_GL_Camera camera;
};
#endif // GLUT_232_H