3 Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #ifndef DAYNIGHTRATIO_HEADER
21 #define DAYNIGHTRATIO_HEADER
23 inline u32 time_to_daynight_ratio(float time_of_day, bool smooth)
25 float t = time_of_day;
27 t += ((int)(-t)/24000)*24000;
29 t -= ((int)(t)/24000)*24000;
44 float lastt = values[0][0];
45 for(u32 i=1; i<sizeof(values)/sizeof(*values); i++){
46 float t0 = values[i][0];
47 float switch_t = (t0 + lastt) / 2;
55 for(u32 i=0; i<sizeof(values)/sizeof(*values); i++){
60 float td0 = values[i][0] - values[i-1][0];
61 float f = (t - values[i-1][0]) / td0;
62 return f * values[i][1] + (1.0 - f) * values[i-1][1];