#include "StdAfx.h" #include "T2DayLightFilter.h" #include T2DayLightFilter::T2DayLightFilter() { mBaseCol.rgbRed = 0; mBaseCol.rgbGreen = 0; mBaseCol.rgbBlue = 0; mTime = 0; } T2DayLightFilter::~T2DayLightFilter() { } void T2DayLightFilter::SetTime(int t1, int t2) { #pragma var_order(base, low, high, time, midpoint) double time; double base = (sin(2.0 * (3.141592 * (t1 / 1000.0))) * 8.0) + 500.0; double midpoint = 1000.0 - base; double low = midpoint / 2.0; double high = 1000.0 - (midpoint / 2.0); if (t2 < low) { time = -90.0 * cos((3.141592 * (t2 / (midpoint / 2.0))) / 2.0); } else if (t2 < high) { time = 90.0 * sin(3.141592 * ((t2 - low) / base)); } else { time = -90.0 * sin((3.141592 * ((t2 - high) / (midpoint / 2.0))) / 2.0); } if (time < 0.0) { mTime = -int(-time + 0.5); } else { mTime = int(time + 0.5); } if (mTime > 90) mTime = 90; if (mTime < -90) mTime = -90; while (mTime < 0) mTime += 360; while (mTime >= 360) mTime -= 360; CalcDayLightColor(&mBaseCol); } void T2DayLightFilter::RefractionColor(RGBQUAD* rgb) { rgb->rgbRed = (mBaseCol.rgbRed * rgb->rgbRed) / 255; rgb->rgbGreen = (mBaseCol.rgbGreen * rgb->rgbGreen) / 255; rgb->rgbBlue = (mBaseCol.rgbBlue * rgb->rgbBlue) / 255; } void T2DayLightFilter::CalcDayLightColor(RGBQUAD* rgb) { #pragma var_order(outB, outR, base, tint1, tint2, outG) double base = (0.5 * sin((3.141592 * mTime) / 180.0)) + 0.5; if (base < 0.0) base = 0.0; double outR = base; double outG = base; double outB = base; double tint1 = 1.1 * sin((3.141592 * mTime) / 180.0); if (tint1 > 1.0) tint1 = 1.0; else if (tint1 < 0.1) tint1 = 0.1; outG *= 1.0 - (0.8 * (1.0 - tint1)); outB *= tint1; outR += 0.4; outG += 0.4; outB += 0.4; double tint2 = 0.2 + (outR * 0.35) + (outG * 0.45) + (outB * 0.2); if (tint2 > 1.0) tint2 = 1.0; outR *= tint2; outG *= 1.0 - (0.7 * (1.0 - tint2)); outR = min(max(outR, 0.0), 1.0); outG = min(max(outG, 0.0), 1.0); outB = min(max(outB, 0.0), 1.0); rgb->rgbRed = 255.0 * outR; rgb->rgbGreen = 255.0 * outG; rgb->rgbBlue = 255.0 * outB; } void T2DayLightFilter::SkyColor(RGBQUAD* rgb) { #pragma var_order(outB, outR, inG, outG, inB, inR) double inR = mBaseCol.rgbRed / 255.0; double inG = mBaseCol.rgbGreen / 255.0; double inB = mBaseCol.rgbBlue / 255.0; double outR = inR; double outG = inG; double outB = inB; outR *= (rgb->rgbRed / 255.0); outG *= (rgb->rgbGreen / 255.0); outB *= (rgb->rgbBlue / 255.0); outR = (0.45 * outR) + (0.55 * inR); outG = (0.6 * outG) + (0.4 * inG); outB = (0.6 * outB) + (0.4 * inB); rgb->rgbRed = 255.0 * outR; rgb->rgbGreen = 255.0 * outG; rgb->rgbBlue = 255.0 * outB; }