0
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
| |
#include "stdafx.h"
#include "MotionFilter.h"
#include <GL/glut.h>
#define HIT_RANGE 15
MotionFilter::MotionFilter(){
hitRainDropNum = 0;
}
void MotionFilter::getRgbAt( float x, float y, unsigned char* rgb ){
x = x < 0 ? 0 : x;
x = x > 1 ? 1 : x;
y = y < 0 ? 0 : y;
y = y > 1 ? 1 : y;
int ix = (int)(((float)_cWidth-1)*x);
int iy = (int)(((float)_cHeight-1)*y);
int rowSize = _cWidth * 3;
rgb[0] = btmp[(ix*3)+iy*rowSize];
rgb[1] = btmp[(ix*3)+iy*rowSize+1];
rgb[2] = btmp[(ix*3)+iy*rowSize+2];
}
void MotionFilter::draw(){
glBegin( GL_POLYGON );
glTexCoord2f( 0.0f, 0.0f );
glVertex2f( 0, 768 );
glTexCoord2f( 1.0f, 0.0f );
glVertex2f( 1024, 768 );
glTexCoord2f( 1.0f, 1.0f );
glVertex2f( 1024, 0 );
glTexCoord2f( 0.0f, 1.0f );
glVertex2f( 0,0 );
glEnd();
}
void MotionFilter::shade(){
int i, j;
nlVector* v;
for( i = 0; i < shadeLine.size(); i++ ){
glBegin( GL_LINE_LOOP );
for( j = 0; j < shadeLine[i].size(); j++ ){
v = &shadeLine[i][j];
glVertex2f( v->x, v->y );
}
glEnd();
}
}
void MotionFilter::attach( CellSet* cellset, RainFilter* rfilter ){
int x, y, i, idx;
float lenx, leny, len_a, len_b;
float flow;
unsigned char rgb[3];
Cell *tcell_a, *tcell_b;
RainDrop* rd;
hitRainDropNum = 0;
for( i = 0; i < rfilter->raindrops.size(); i++ ){
rd = &rfilter->raindrops[i];
getRgbAt( rd->xpos/1024, 1-rd->ypos/768, rgb );
flow = 1-(float)rgb[2]/255;
if( flow > 0.04 ){
for( y = 0; y < cellset->hdiv; y++ ){
for( x = 0; x < cellset->wdiv; x++ ){
idx = x+y*cellset->wdiv;
tcell_a = &cellset->cells_a[idx];
tcell_b = &cellset->cells_b[idx];
lenx = (tcell_a->xpos + cellset->xpos) - rd->xpos;
leny = (tcell_a->ypos + cellset->ypos) - rd->ypos;
len_a = sqrt( lenx*lenx+leny*leny );
lenx = (tcell_b->xpos + cellset->xpos) - rd->xpos;
leny = (tcell_b->ypos + cellset->ypos) - rd->ypos;
len_b = sqrt( lenx*lenx+leny*leny );
if( len_a < HIT_RANGE || len_b < HIT_RANGE ){
tcell_a->flow = flow;
tcell_b->flow = flow;
hitRainDropNum++;
}
}
}
rd->init();
}
}
}
void MotionFilter::attach( CellSet* cellset, AirstreamFilter* asfilter ){
int i;
float mpowx = 0;
float mpowy = 0;
nlRectangle* mf;
for( i = 0; i < mfv.size(); i++ ){
mf = &mfv[i];
mpowx += mf->vx;
mpowy += mf->vy;
}
asfilter->as_src.relative_velx = mpowx*7;
asfilter->as_src.relative_vely = mpowy*3;
unsigned char rgb_a[3], rgb_b[3];
float m_a, m_b;
int x, y, idx;
Cell *tcell_a, *tcell_b;
for( y = 0; y < cellset->hdiv; y++ ){
for( x = 0; x < cellset->wdiv; x++ ){
idx = x+y*cellset->wdiv;
tcell_a = &cellset->cells_a[idx];
tcell_b = &cellset->cells_b[idx];
getRgbAt(
(tcell_a->xpos + cellset->xpos)/1024,
1-(tcell_a->ypos + cellset->ypos)/768,
rgb_a
);
m_a = 1-(float)rgb_a[2]/255;
if( m_a > 0.1 ){
tcell_a->nextpow = m_a*2+2;
}
else{
tcell_a->nextpow = 1;
}
getRgbAt(
(tcell_b->xpos + cellset->xpos)/1024,
1-(tcell_b->ypos + cellset->ypos)/768,
rgb_b
);
m_b = 1-(float)rgb_b[2]/255;
if( m_b > 0.1 ){
tcell_b->nextpow = m_b*2+2;
}
else{
tcell_b->nextpow = 1;
}
}
}
}
|