From c651b436ab816335a5fee76ca890dce64d795666 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Lemaire?= Date: Thu, 26 Dec 2013 16:55:37 +0100 Subject: [PATCH] Added moon configuration --- src/definition/AtmosphereDefinition.cpp | 12 ++++++++++++ src/definition/AtmosphereDefinition.h | 4 ++++ src/interface/desktop/formatmosphere.cpp | 3 +++ src/render/software/NightSky.cpp | 10 +++++++--- 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/definition/AtmosphereDefinition.cpp b/src/definition/AtmosphereDefinition.cpp index c6dc88f..50c22d9 100644 --- a/src/definition/AtmosphereDefinition.cpp +++ b/src/definition/AtmosphereDefinition.cpp @@ -20,6 +20,9 @@ void AtmosphereDefinition::save(PackStream* stream) const stream->write(&sun_radius); stream->write(&dome_lighting); stream->write(&humidity); + stream->write(&moon_radius); + stream->write(&moon_theta); + stream->write(&moon_phi); } void AtmosphereDefinition::load(PackStream* stream) @@ -31,6 +34,9 @@ void AtmosphereDefinition::load(PackStream* stream) stream->read(&sun_radius); stream->read(&dome_lighting); stream->read(&humidity); + stream->read(&moon_radius); + stream->read(&moon_theta); + stream->read(&moon_phi); validate(); } @@ -46,6 +52,9 @@ void AtmosphereDefinition::copy(BaseDefinition* _destination) const destination->sun_radius = sun_radius; destination->dome_lighting = dome_lighting; destination->humidity = humidity; + destination->moon_radius = moon_radius; + destination->moon_theta = moon_theta; + destination->moon_phi = moon_phi; destination->validate(); } @@ -79,6 +88,9 @@ void AtmosphereDefinition::applyPreset(AtmospherePreset preset) sun_color.b = 0.9; sun_color.a = 1.0; sun_radius = 1.0; + moon_radius = 1.0; + moon_theta = 0.3; + moon_phi = 0.5; humidity = 0.1; model = ATMOSPHERE_MODEL_BRUNETON; diff --git a/src/definition/AtmosphereDefinition.h b/src/definition/AtmosphereDefinition.h index ae3a635..19d1a0b 100644 --- a/src/definition/AtmosphereDefinition.h +++ b/src/definition/AtmosphereDefinition.h @@ -48,6 +48,10 @@ public: double sun_radius; double dome_lighting; + double moon_radius; + double moon_theta; + double moon_phi; + double _daytime; }; diff --git a/src/interface/desktop/formatmosphere.cpp b/src/interface/desktop/formatmosphere.cpp index 6a1519f..37abd33 100644 --- a/src/interface/desktop/formatmosphere.cpp +++ b/src/interface/desktop/formatmosphere.cpp @@ -42,6 +42,9 @@ FormAtmosphere::FormAtmosphere(QWidget *parent): addInputDouble(tr("Sun radius"), &_definition->sun_radius, 0.0, 5.0, 0.05, 0.5); //addInputDouble(tr("Influence of skydome on lighting"), &_definition->dome_lighting, 0.0, 2.0, 0.01, 0.1); addInputDouble(tr("Humidity"), &_definition->humidity, 0.0, 1.0, 0.01, 0.1); + addInputDouble(tr("Moon radius"), &_definition->moon_radius, 0.5, 3.0, 0.03, 0.3); + addInputDouble(tr("Moon location (horizontal)"), &_definition->moon_phi, 0.0, M_PI * 2.0, 0.05, 0.5); + addInputDouble(tr("Moon location (vertical)"), &_definition->moon_theta, -0.1, M_PI * 0.5, 0.02, 0.2); revertConfig(); } diff --git a/src/render/software/NightSky.cpp b/src/render/software/NightSky.cpp index 8376ab5..dc6cd3e 100644 --- a/src/render/software/NightSky.cpp +++ b/src/render/software/NightSky.cpp @@ -4,6 +4,8 @@ #include "Vector3.h" #include "Geometry.h" #include "SoftwareRenderer.h" +#include "Scenery.h" +#include "AtmosphereDefinition.h" #include "SurfaceMaterial.h" #define WORLD_SCALING 0.05 @@ -27,6 +29,7 @@ void NightSky::update() const Color NightSky::getColor(double altitude, const Vector3 &direction) { + AtmosphereDefinition* atmosphere = renderer->getScenery()->getAtmosphere(); Color result(0.01, 0.012, 0.03); Vector3 location(0.0, altitude, 0.0); @@ -34,11 +37,12 @@ const Color NightSky::getColor(double altitude, const Vector3 &direction) // Get stars // Get moon - Vector3 moon_direction = Vector3(0.9, 0.5, -0.6).normalize(); + VectorSpherical moon_location_s = {MOON_DISTANCE_SCALED, atmosphere->moon_theta, -atmosphere->moon_phi}; + Vector3 moon_position(moon_location_s); + Vector3 moon_direction = moon_position.normalize(); if (moon_direction.dotProduct(direction) >= 0) { - Vector3 moon_position = moon_direction.scale(MOON_DISTANCE_SCALED); - double moon_radius = MOON_RADIUS_SCALED * 5.0; + double moon_radius = MOON_RADIUS_SCALED * 5.0 * atmosphere->moon_radius; Vector3 hit1, hit2; int hits = Geometry::rayIntersectSphere(location, direction, moon_position, moon_radius, &hit1, &hit2); if (hits > 1)