lilith3d

 

Engine

Documentation

Notes

Tutorial 4: Weather

  • Weather

This is a very small tutorial. It used to be "Lights and Weather", but lights are currently disabled in Lilith3D. In hopes they will return soon, this is left as a small tutorial.

Tutorial 4: Weather

The weather section starts out with a very useful TimeClock function:

timeClock->CalcCalendarTime( &day, &hour, &minute, &second );

CalcCalendarTime computes the game time in natural units. Handy for a weather system where we want fog in the morning and rain in the evening.

Lilith supports 2 kinds of weather: rain and fog. They can be set independently, but while fog looks fine on its own, usually rain should have a little fog to fill it out. Weather does not change instantly. To set the desired weather, call GetTargetWeather():

Weather* weather = lilith->GetTargetWeather();
...
weather->SetFog( FOG_MAX * Interpolate( (float)FOG_START*60, (float)0.0f,
                                                                            (float)FOG_PEAK*60, (float)1.0,
                                                                            (float)(hour*60+minute) ) );

Note the use of the Interpolate function, provided as a very useful utility method.

Most of the code here just interpolates between times of the day and sets the weather. It is foggy in the morning and rainy in the afternoon. The code is written to never execute more than 1 time per game minute (not real minute). Since the weather can't change instantly there's no point updating every frame.

If you ever need the current actual weather, it can be retrieved (but not changed) with the CurrentWeather() method.

Conclusion

Pretty straightforward code...but makes a great difference in the result!