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
|
#include "StdAfx.h"
#include "T2WeatherFilter.h"
T2WeatherFilter::T2WeatherFilter() {
mCurrentWeather = WeatherCode_0;
mPhase = 2;
SetWeather(WeatherCode_0);
}
T2WeatherFilter::~T2WeatherFilter() {
}
void T2WeatherFilter::SetWeather(WeatherCode weather) {
mLastChange = GetTickCount();
mTimeSinceLastChange = mLastChange;
mNextWeather = weather;
mLightningTime = -1;
}
void T2WeatherFilter::ColorFilter(RGBQUAD* rgb) {
if (mCurrentWeather == WeatherCode_1)
RainyFilter(mTimeSinceLastChange, rgb);
else if (mCurrentWeather == WeatherCode_2)
SnowyFilter(mTimeSinceLastChange, rgb);
else
ClearFilter(mTimeSinceLastChange, rgb);
}
void T2WeatherFilter::ClearFilter(unsigned long time, RGBQUAD* rgb) {
}
void T2WeatherFilter::RainyFilter(unsigned long time, RGBQUAD* rgb) {
if (mLightningTime <= time && time <= (mLightningTime + 200)) {
RGBQUAD c;
c.rgbRed = 240;
c.rgbGreen = 240;
c.rgbBlue = 128;
ColorBlend(40, rgb, &c);
} else {
RGBQUAD c;
c.rgbRed = (rgb->rgbRed * 500) / 1000;
c.rgbGreen = (rgb->rgbGreen * 500) / 1000;
c.rgbBlue = (rgb->rgbBlue * 600) / 1000;
ColorFade(time, rgb, &c);
}
}
void T2WeatherFilter::SnowyFilter(unsigned long time, RGBQUAD* rgb) {
RGBQUAD c;
c.rgbRed = ((rgb->rgbRed + ((255 - rgb->rgbRed) * 500) / 1000) * 800) / 1000;
c.rgbGreen = ((rgb->rgbGreen + ((255 - rgb->rgbGreen) * 500) / 1000) * 800) / 1000;
c.rgbBlue = ((rgb->rgbBlue + ((255 - rgb->rgbBlue) * 500) / 1000) * 800) / 1000;
ColorFade(time, rgb, &c);
}
void T2WeatherFilter::ColorFade(unsigned long time, RGBQUAD* a, RGBQUAD* b) {
if ((mPhase == 1) && (time <= 2500)) {
a->rgbRed = (a->rgbRed * (2500 - time) + b->rgbRed * time) / 2500;
a->rgbGreen = (a->rgbGreen * (2500 - time) + b->rgbGreen * time) / 2500;
a->rgbBlue = (a->rgbBlue * (2500 - time) + b->rgbBlue * time) / 2500;
} else if ((mPhase == 3) && (time <= 2500)) {
a->rgbRed = (b->rgbRed * (2500 - time) + a->rgbRed * time) / 2500;
a->rgbGreen = (b->rgbGreen * (2500 - time) + a->rgbGreen * time) / 2500;
a->rgbBlue = (b->rgbBlue * (2500 - time) + a->rgbBlue * time) / 2500;
} else {
*a = *b;
}
}
void T2WeatherFilter::SkyColorFilter(RGBQUAD* rgb) {
if (mCurrentWeather == WeatherCode_1)
RainySkyFilter(mTimeSinceLastChange, rgb);
else if (mCurrentWeather == WeatherCode_2)
SnowySkyFilter(mTimeSinceLastChange, rgb);
else
ClearSkyFilter(mTimeSinceLastChange, rgb);
}
void T2WeatherFilter::ClearSkyFilter(unsigned long time, RGBQUAD* rgb) {
}
void T2WeatherFilter::RainySkyFilter(unsigned long time, RGBQUAD* rgb) {
if (time >= 1800 && time <= 1900) {
RGBQUAD c;
c.rgbRed = 240;
c.rgbGreen = 240;
c.rgbBlue = 128;
ColorBlend(15, rgb, &c);
mLightningTime = rand() % 15000 + 8000;
} else if (mLightningTime <= time && time <= (mLightningTime + 200)) {
RGBQUAD c;
c.rgbRed = 240;
c.rgbGreen = 240;
c.rgbBlue = 128;
ColorBlend(30, rgb, &c);
mLightningTime += rand() % 15000 + 8000;
} else {
int x = ((rgb->rgbRed * 33) + (rgb->rgbGreen * 42) + (rgb->rgbBlue * 25)) / 100;
RGBQUAD c;
c.rgbRed = (x * 128) / 255;
c.rgbGreen = (x * 128) / 255;
c.rgbBlue = (x * 140) / 255;
ColorFade(time, rgb, &c);
}
}
void T2WeatherFilter::SnowySkyFilter(unsigned long time, RGBQUAD* rgb) {
#pragma var_order(g, r, z, b, c)
int z = ((rgb->rgbRed * 33) + (rgb->rgbGreen * 42) + (rgb->rgbBlue * 25)) / 100;
int r = (((z * 180) / 255) & 255) + 80;
int g = (((z * 180) / 255) & 255) + 80;
int b = (((z * 180) / 255) & 255) + 80;
RGBQUAD c;
c.rgbRed = (r <= 255) ? r : 255;
c.rgbGreen = (g <= 255) ? g : 255;
c.rgbBlue = (b <= 255) ? b : 255;
ColorFade(time, rgb, &c);
}
void T2WeatherFilter::ColorBlend(int factor, RGBQUAD* a, RGBQUAD* b) {
a->rgbRed = (a->rgbRed * (100 - factor) + b->rgbRed * factor) / 100;
a->rgbGreen = (a->rgbGreen * (100 - factor) + b->rgbGreen * factor) / 100;
a->rgbBlue = (a->rgbBlue * (100 - factor) + b->rgbBlue * factor) / 100;
}
void T2WeatherFilter::Tick() {
mTimeSinceLastChange = GetTickCount() - mLastChange;
if ((mPhase == 2) && (mCurrentWeather != mNextWeather)) {
mPhase = 3;
mLastChange = GetTickCount();
}
if ((mPhase == 1) && ((mTimeSinceLastChange >= 2500) || (mCurrentWeather == WeatherCode_0))) {
mPhase = 2;
mLastChange = GetTickCount();
}
if ((mPhase == 3) && ((mTimeSinceLastChange >= 2500) || (mCurrentWeather == WeatherCode_0))) {
mPhase = 1;
mCurrentWeather = mNextWeather;
mLastChange = GetTickCount();
}
}
|