mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-03 08:55:22 +01:00
9c1a6445aa
Step 4 of docs/world-format-eu07.md, its second part. On a curved body the sun and the moon are worked out for the latitude and longitude of the camera (sky.cameraplace, on by default, as settled in #516; off keeps 52 N 19 E). The sky and the weather take the sun in the local axes at the camera; after them the direction of the sun light is turned into the axes of the world, which it shades and casts its shadows in. The sun, the moon and the stars are drawn with the view turned to the local axes. On the plane, the only body loaded today, nothing is turned or moved.
118 lines
3.2 KiB
C++
118 lines
3.2 KiB
C++
/*
|
|
This Source Code Form is subject to the
|
|
terms of the Mozilla Public License, v.
|
|
2.0. If a copy of the MPL was not
|
|
distributed with this file, You can
|
|
obtain one at
|
|
http://mozilla.org/MPL/2.0/.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include "environment/sky.h"
|
|
#include "environment/sun.h"
|
|
#include "environment/moon.h"
|
|
#include "environment/stars.h"
|
|
#include "environment/skydome.h"
|
|
#include "environment/weather.h"
|
|
#include "rendering/precipitation.h"
|
|
#include "audio/sound.h"
|
|
|
|
#include <array>
|
|
|
|
class opengl46_renderer;
|
|
|
|
// wrapper for environment elements -- sky, sun, stars, clouds etc
|
|
class world_environment {
|
|
|
|
friend opengl46_renderer;
|
|
|
|
public:
|
|
// methods
|
|
void init();
|
|
void update();
|
|
void update_precipitation();
|
|
void update_moon();
|
|
void time( int const Hour = -1, int const Minute = -1, int const Second = -1 );
|
|
// switches between static and dynamic daylight calculation
|
|
void on_daylight_change();
|
|
// calculates current season of the year based on set simulation date
|
|
void compute_season( int const Yearday );
|
|
// calculates current weather
|
|
void compute_weather() const;
|
|
// data access
|
|
inline auto const &
|
|
sun() const {
|
|
return m_sun; }
|
|
inline auto const &
|
|
moon() const {
|
|
return m_moon; }
|
|
inline auto const &
|
|
light_intensity() const {
|
|
return m_lightintensity; }
|
|
inline auto const &
|
|
skydome() const {
|
|
return m_skydome; }
|
|
inline auto &
|
|
skydome() {
|
|
return m_skydome; }
|
|
inline auto const &
|
|
precipitation() const {
|
|
return m_precipitation; }
|
|
inline auto const &
|
|
wind() const {
|
|
return m_wind.vector; }
|
|
inline auto const &
|
|
wind_azimuth() const {
|
|
return m_wind.azimuth; }
|
|
// the wind as it blows and as it is about to change, for a snapshot of the simulation, which puts it back:
|
|
// azimuth and its change, velocity and its change, the time to the next change, the vector
|
|
std::array<float, 8>
|
|
wind_state() const;
|
|
void
|
|
wind_state( std::array<float, 8> const &State );
|
|
// clouds, fog and precipitation of the scenery, see environment/weather.h
|
|
inline auto const &
|
|
weather() const {
|
|
return m_weather; }
|
|
inline auto &
|
|
weather() {
|
|
return m_weather; }
|
|
|
|
private:
|
|
// types
|
|
struct basic_wind {
|
|
// internal state data
|
|
float azimuth;
|
|
float azimuth_change;
|
|
float velocity;
|
|
float velocity_change;
|
|
float change_time;
|
|
// output
|
|
glm::vec3 vector;
|
|
};
|
|
// methods
|
|
void update_wind();
|
|
// members
|
|
CSkyDome m_skydome;
|
|
cStars m_stars;
|
|
cSun m_sun;
|
|
cMoon m_moon;
|
|
// the sun and the moon are worked out for the place of the camera on a curved body (sky.cameraplace)
|
|
bool m_observer_at_camera { false };
|
|
float m_lightintensity { 1.f };
|
|
TSky m_clouds;
|
|
basic_precipitation m_precipitation;
|
|
sound_source m_rainsound { sound_placement::external, -1 };
|
|
basic_wind m_wind;
|
|
world_weather m_weather;
|
|
};
|
|
|
|
namespace simulation {
|
|
|
|
extern world_environment Environment;
|
|
|
|
} // simulation
|
|
|
|
//---------------------------------------------------------------------------
|