9
by Nathan Osman
Added bubble class - warning: there seems to be a repaint issue with the plugin although it does not seem to crash anything. |
1 |
#include <math.h> |
2 |
#include <string.h> |
|
3 |
#include "bubble.h" |
|
4 |
||
5 |
#ifndef PI2
|
|
6 |
#define PI2 6.2831853
|
|
7 |
#endif
|
|
8 |
||
9 |
#ifndef HALFPI
|
|
10 |
#define HALFPI 1.57079633
|
|
11 |
#endif
|
|
12 |
||
13 |
#define NUM_DIVISIONS 10
|
|
14 |
||
15 |
Bubble::Bubble() |
|
16 |
: m_vertices(NULL), m_indices(NULL), m_fadein_remaining(0) |
|
17 |
{
|
|
18 |
// Create the rectangle
|
|
19 |
CreateRoundedRectangle(NUM_DIVISIONS, 0.4); |
|
20 |
}
|
|
21 |
||
22 |
Bubble::~Bubble() |
|
23 |
{
|
|
24 |
if(m_vertices) |
|
25 |
delete [] m_vertices; |
|
26 |
if(m_indices) |
|
27 |
delete [] m_indices; |
|
28 |
}
|
|
29 |
||
30 |
void Bubble::CreateRoundedRectangle(int num_divisions, |
|
31 |
float radius) |
|
32 |
{
|
|
33 |
// Calculate some values
|
|
34 |
float circle_offset = 1.0f - radius; |
|
35 |
int total_divisions = (num_divisions + 1) * 4; |
|
36 |
||
37 |
// Storage for the points
|
|
38 |
m_vertices = new GLfloat[(total_divisions + 1) * 2]; |
|
39 |
memset(m_vertices, 0, sizeof(GLfloat) * (total_divisions + 1) * 2); |
|
40 |
||
41 |
// Fill in the quadrants
|
|
42 |
int calc_offset = 0; |
|
43 |
int index_offset = 0; |
|
44 |
for(int i=0;i<=num_divisions;++i,++calc_offset,++index_offset) |
|
45 |
{
|
|
46 |
float f = (float)calc_offset / (float)(num_divisions * 4); |
|
47 |
m_vertices[index_offset * 2] = cos(PI2 * f) * radius + circle_offset; |
|
48 |
m_vertices[index_offset * 2 + 1] = sin(PI2 * f) * radius + circle_offset; |
|
49 |
}
|
|
50 |
calc_offset -= 1; |
|
51 |
for(int i=0;i<=num_divisions;++i,++calc_offset,++index_offset) |
|
52 |
{
|
|
53 |
float f = (float)calc_offset / (float)(num_divisions * 4); |
|
54 |
m_vertices[index_offset * 2] = cos(PI2 * f) * radius - circle_offset; |
|
55 |
m_vertices[index_offset * 2 + 1] = sin(PI2 * f) * radius + circle_offset; |
|
56 |
}
|
|
57 |
calc_offset -= 1; |
|
58 |
for(int i=0;i<=num_divisions;++i,++calc_offset,++index_offset) |
|
59 |
{
|
|
60 |
float f = (float)calc_offset / (float)(num_divisions * 4); |
|
61 |
m_vertices[index_offset * 2] = cos(PI2 * f) * radius - circle_offset; |
|
62 |
m_vertices[index_offset * 2 + 1] = sin(PI2 * f) * radius - circle_offset; |
|
63 |
}
|
|
64 |
calc_offset -= 1; |
|
65 |
for(int i=0;i<=num_divisions;++i,++calc_offset,++index_offset) |
|
66 |
{
|
|
67 |
float f = (float)calc_offset / (float)(num_divisions * 4); |
|
68 |
m_vertices[index_offset * 2] = cos(PI2 * f) * radius + circle_offset; |
|
69 |
m_vertices[index_offset * 2 + 1] = sin(PI2 * f) * radius - circle_offset; |
|
70 |
}
|
|
71 |
||
72 |
// Now create the indices
|
|
73 |
m_indices = new GLuint[total_divisions + 2]; |
|
74 |
||
75 |
m_indices[0] = total_divisions; |
|
76 |
for(int i=1; i<=total_divisions; ++i) |
|
77 |
m_indices[i] = i - 1; |
|
78 |
m_indices[total_divisions + 1] = 0; |
|
79 |
}
|
|
80 |
||
81 |
void Bubble::Render(int ms) |
|
82 |
{
|
|
13
by Nathan Osman
Managed to get a grey rectangle to appear but still problems with repainting. |
83 |
GLfloat verts[] = { -1.0f, 1.0f, 1.0f, 1.0f, 1.0f,-1.0f, -1.0f,-1.0f }; |
84 |
GLuint inds[] = { 0, 1, 2, 3 }; |
|
85 |
||
86 |
glEnable(GL_BLEND); |
|
87 |
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
|
88 |
glColor4f(0.5, 0.5, 0.5, 0.2f); |
|
89 |
glEnableClientState(GL_VERTEX_ARRAY); |
|
90 |
glVertexPointer(2, GL_FLOAT, 0, verts); |
|
91 |
glDrawElements(GL_QUADS, 4, GL_UNSIGNED_INT, inds); |
|
92 |
glDisableClientState(GL_VERTEX_ARRAY); |
|
93 |
glDisable(GL_BLEND); |
|
94 |
||
95 |
/*
|
|
9
by Nathan Osman
Added bubble class - warning: there seems to be a repaint issue with the plugin although it does not seem to crash anything. |
96 |
// Check for a transition
|
97 |
float trans = 1.0f;
|
|
98 |
|
|
99 |
if(m_fadein_remaining > 0)
|
|
100 |
{
|
|
101 |
m_fadein_remaining -= ms;
|
|
102 |
trans = sin((1.0f - (float)m_fadein_remaining / (float)m_fadein_time) * HALFPI);
|
|
103 |
}
|
|
104 |
|
|
105 |
// Set up the matrix
|
|
106 |
glPushMatrix();
|
|
107 |
glScalef(trans * 0.15f + 0.85f, trans * 0.15f + 0.85f, 1.0f);
|
|
108 |
|
|
109 |
// Set up the blending
|
|
110 |
glEnable(GL_BLEND);
|
|
111 |
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
112 |
glColor4f(0.5, 0.5, 0.5, trans * 0.4f);
|
|
113 |
|
|
114 |
// Draw the stuff
|
|
115 |
glEnableClientState(GL_VERTEX_ARRAY);
|
|
116 |
glVertexPointer(2, GL_FLOAT, 0, m_vertices);
|
|
117 |
glDrawElements(GL_TRIANGLE_FAN, (NUM_DIVISIONS + 1) * 4 + 2, GL_UNSIGNED_INT, m_indices);
|
|
118 |
glDisableClientState(GL_VERTEX_ARRAY);
|
|
119 |
|
|
13
by Nathan Osman
Managed to get a grey rectangle to appear but still problems with repainting. |
120 |
glColor4usv(defaultColor);
|
9
by Nathan Osman
Added bubble class - warning: there seems to be a repaint issue with the plugin although it does not seem to crash anything. |
121 |
glDisable(GL_BLEND);
|
122 |
glPopMatrix();
|
|
13
by Nathan Osman
Managed to get a grey rectangle to appear but still problems with repainting. |
123 |
*/
|
9
by Nathan Osman
Added bubble class - warning: there seems to be a repaint issue with the plugin although it does not seem to crash anything. |
124 |
}
|