16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-18 03:09:18 +02:00

support for config-specified day of the year

This commit is contained in:
tmj-fstate
2017-02-18 18:15:39 +01:00
parent 013a6f0559
commit a1942ce771
6 changed files with 33 additions and 16 deletions

View File

@@ -552,18 +552,7 @@ void Global::ConfigParse(cParser &Parser)
std::tm *localtime = std::localtime(&timenow);
Global::fMoveLight = localtime->tm_yday + 1; // numer bieżącego dnia w roku
}
if (fMoveLight > 0.f) // tu jest nadal zwiększone o 1
{ // obliczenie deklinacji wg:
// http://naturalfrequency.com/Tregenza_Sharples/Daylight_Algorithms/algorithm_1_11.htm
// Spencer J W Fourier series representation of the position of the sun Search 2 (5)
// 172 (1971)
Global::fMoveLight =
M_PI / 182.5 * (Global::fMoveLight - 1.0); // numer dnia w postaci kąta
fSunDeclination =
0.006918 - 0.3999120 * std::cos(fMoveLight) + 0.0702570 * std::sin(fMoveLight) -
0.0067580 * std::cos(2 * fMoveLight) + 0.0009070 * std::sin(2 * fMoveLight) -
0.0026970 * std::cos(3 * fMoveLight) + 0.0014800 * std::sin(3 * fMoveLight);
}
// TODO: calculate lights single time here for static setup. or get rid of static setup
}
else if (token == "smoothtraction")
{

View File

@@ -505,6 +505,11 @@ opengl_texture::set_filtering() {
::glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
::glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
if( GLEW_EXT_texture_filter_anisotropic ) {
// anisotropic filtering
::glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 16.0f );
}
bool sharpen{ false };
for( auto const &trait : traits ) {

View File

@@ -1513,14 +1513,14 @@ void TWorld::Update_Lights() {
Global::DayLight.position[2] = position.z;
auto const direction = -1.0 * Sun.getDirection();
Global::DayLight.direction = direction;
auto const intensity = std::min( 2.0f * Sun.getIntensity(), 1.0f );
auto const intensity = std::min( 2.0f * Sun.getIntensity(), 1.25f );
Global::DayLight.diffuse[ 0 ] = 255.0 / 255.0 * intensity;
Global::DayLight.diffuse[ 1 ] = 242.0 / 255.0 * intensity;
Global::DayLight.diffuse[ 2 ] = 231.0 / 255.0 * intensity;
// Global::DayLight.diffuse[ 3 ] = 1.0f;// std::min( 0.15f + intensity, 1.0f );
Global::DayLight.ambient[ 0 ] = 205.0 / 255.0 * intensity * 0.75f;
Global::DayLight.ambient[ 1 ] = 217.0 / 255.0 * intensity * 0.75f;
Global::DayLight.ambient[ 0 ] = 155.0 / 255.0 * intensity * 0.75f;
Global::DayLight.ambient[ 1 ] = 192.0 / 255.0 * intensity * 0.75f;
Global::DayLight.ambient[ 2 ] = 231.0 / 255.0 * intensity * 0.75f;
// Global::DayLight.ambient[ 3 ] = 1.0f;
/*

View File

@@ -67,6 +67,7 @@ cParser::~cParser()
// methods
bool cParser::getTokens(int Count, bool ToLower, const char *Break)
{
tokens.clear(); // emulates old parser behaviour. TODO, TBD: allow manual reset?
/*
if (LoadTraction==true)
trtest="niemaproblema"; //wczytywać

22
sun.cpp
View File

@@ -285,13 +285,33 @@ int cSun::yearday( int Day, const int Month, const int Year ) {
return Day;
}
void cSun::daymonth( WORD &Day, WORD &Month, WORD const Year, WORD const Yearday ) {
WORD daytab[ 2 ][ 13 ] = {
{ 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 },
{ 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 }
};
int leap = ( Year % 4 == 0 ) && ( Year % 100 != 0 ) || ( Year % 400 == 0 );
WORD idx = 1;
while( (idx < 13) && ( Yearday <= daytab[ leap ][ idx ] )) {
++idx;
}
Month = idx + 1;
Day = Yearday - daytab[ leap ][ idx ];
}
// obtains current time for calculations
void
cSun::time( SYSTEMTIME *Time ) {
::GetLocalTime( Time );
// NOTE: we're currently using local time to determine day/month/year
// TODO: enter scenario-defined day/month/year instead.
if( Global::fMoveLight > 0.0 ) {
// TODO: enter scenario-defined day/month/year instead.
daymonth( Time->wDay, Time->wMonth, Time->wYear, static_cast<WORD>(Global::fMoveLight) );
}
Time->wHour = GlobalTime->hh;
Time->wMinute = GlobalTime->mm;
Time->wSecond = std::floor( GlobalTime->mr );

2
sun.h
View File

@@ -54,6 +54,8 @@ protected:
void irradiance();
// calculates day of year from given date
int yearday( int Day, int const Month, int const Year );
// calculates day and month from given day of year
void daymonth( WORD &Day, WORD &Month, WORD const Year, WORD const Yearday );
// obtains current time for calculations
void time( SYSTEMTIME *Time );