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

basic particle system implementation

This commit is contained in:
tmj-fstate
2019-08-06 14:06:46 +02:00
parent 95aab4b629
commit fbd2ff85fa
17 changed files with 1045 additions and 10 deletions

View File

@@ -11,6 +11,7 @@ http://mozilla.org/MPL/2.0/.
#include "simulationenvironment.h"
#include "Globals.h"
#include "Timer.h"
namespace simulation {
@@ -77,8 +78,14 @@ world_environment::init() {
m_stars.init();
m_clouds.Init();
m_precipitation.init();
m_precipitationsound.deserialize( "rain-sound-loop", sound_type::single );
m_wind = basic_wind{
static_cast<float>( Random( 0, 360 ) ),
static_cast<float>( Random( -5, 5 ) ),
static_cast<float>( Random( -2, 4 ) ),
static_cast<float>( Random( -1, 1 ) ),
static_cast<float>( Random( 5, 20 ) ),
{} };
}
void
@@ -170,6 +177,8 @@ world_environment::update() {
// reduce friction due to snow
Global.FrictionWeatherFactor = 0.75f;
}
update_wind();
}
void
@@ -178,6 +187,33 @@ world_environment::update_precipitation() {
m_precipitation.update();
}
void
world_environment::update_wind() {
auto const timedelta{ static_cast<float>( Timer::GetDeltaTime() ) };
m_wind.change_time -= timedelta;
if( m_wind.change_time < 0 ) {
m_wind.change_time = Random( 5, 30 );
m_wind.azimuth_change = Random( -5, 5 );
m_wind.velocity_change = Random( -1, 1 );
}
// TBD, TODO: wind configuration
m_wind.azimuth = clamp_circular( m_wind.azimuth + m_wind.azimuth_change * timedelta );
// HACK: negative part of range allows for some quiet periods, without active wind
m_wind.velocity = clamp<float>( m_wind.velocity + m_wind.velocity_change * timedelta, -2, 4 );
// convert to force vector
auto const polarangle { glm::radians( 90.f ) }; // theta
auto const azimuthalangle{ glm::radians( m_wind.azimuth ) }; // phi
// convert spherical coordinates to opengl coordinates
m_wind.vector =
std::max( 0.f, m_wind.velocity )
* glm::vec3(
std::sin( polarangle ) * std::sin( azimuthalangle ),
std::cos( polarangle ),
std::sin( polarangle ) * std::cos( azimuthalangle ) * -1 );
}
void
world_environment::time( int const Hour, int const Minute, int const Second ) {