Added moon configuration

This commit is contained in:
Michaël Lemaire 2013-12-26 16:55:37 +01:00 committed by Michael Lemaire
parent d2f49a124f
commit c651b436ab
4 changed files with 26 additions and 3 deletions

View file

@ -20,6 +20,9 @@ void AtmosphereDefinition::save(PackStream* stream) const
stream->write(&sun_radius); stream->write(&sun_radius);
stream->write(&dome_lighting); stream->write(&dome_lighting);
stream->write(&humidity); stream->write(&humidity);
stream->write(&moon_radius);
stream->write(&moon_theta);
stream->write(&moon_phi);
} }
void AtmosphereDefinition::load(PackStream* stream) void AtmosphereDefinition::load(PackStream* stream)
@ -31,6 +34,9 @@ void AtmosphereDefinition::load(PackStream* stream)
stream->read(&sun_radius); stream->read(&sun_radius);
stream->read(&dome_lighting); stream->read(&dome_lighting);
stream->read(&humidity); stream->read(&humidity);
stream->read(&moon_radius);
stream->read(&moon_theta);
stream->read(&moon_phi);
validate(); validate();
} }
@ -46,6 +52,9 @@ void AtmosphereDefinition::copy(BaseDefinition* _destination) const
destination->sun_radius = sun_radius; destination->sun_radius = sun_radius;
destination->dome_lighting = dome_lighting; destination->dome_lighting = dome_lighting;
destination->humidity = humidity; destination->humidity = humidity;
destination->moon_radius = moon_radius;
destination->moon_theta = moon_theta;
destination->moon_phi = moon_phi;
destination->validate(); destination->validate();
} }
@ -79,6 +88,9 @@ void AtmosphereDefinition::applyPreset(AtmospherePreset preset)
sun_color.b = 0.9; sun_color.b = 0.9;
sun_color.a = 1.0; sun_color.a = 1.0;
sun_radius = 1.0; sun_radius = 1.0;
moon_radius = 1.0;
moon_theta = 0.3;
moon_phi = 0.5;
humidity = 0.1; humidity = 0.1;
model = ATMOSPHERE_MODEL_BRUNETON; model = ATMOSPHERE_MODEL_BRUNETON;

View file

@ -48,6 +48,10 @@ public:
double sun_radius; double sun_radius;
double dome_lighting; double dome_lighting;
double moon_radius;
double moon_theta;
double moon_phi;
double _daytime; double _daytime;
}; };

View file

@ -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("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("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("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(); revertConfig();
} }

View file

@ -4,6 +4,8 @@
#include "Vector3.h" #include "Vector3.h"
#include "Geometry.h" #include "Geometry.h"
#include "SoftwareRenderer.h" #include "SoftwareRenderer.h"
#include "Scenery.h"
#include "AtmosphereDefinition.h"
#include "SurfaceMaterial.h" #include "SurfaceMaterial.h"
#define WORLD_SCALING 0.05 #define WORLD_SCALING 0.05
@ -27,6 +29,7 @@ void NightSky::update()
const Color NightSky::getColor(double altitude, const Vector3 &direction) const Color NightSky::getColor(double altitude, const Vector3 &direction)
{ {
AtmosphereDefinition* atmosphere = renderer->getScenery()->getAtmosphere();
Color result(0.01, 0.012, 0.03); Color result(0.01, 0.012, 0.03);
Vector3 location(0.0, altitude, 0.0); Vector3 location(0.0, altitude, 0.0);
@ -34,11 +37,12 @@ const Color NightSky::getColor(double altitude, const Vector3 &direction)
// Get stars // Get stars
// Get moon // 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) if (moon_direction.dotProduct(direction) >= 0)
{ {
Vector3 moon_position = moon_direction.scale(MOON_DISTANCE_SCALED); double moon_radius = MOON_RADIUS_SCALED * 5.0 * atmosphere->moon_radius;
double moon_radius = MOON_RADIUS_SCALED * 5.0;
Vector3 hit1, hit2; Vector3 hit1, hit2;
int hits = Geometry::rayIntersectSphere(location, direction, moon_position, moon_radius, &hit1, &hit2); int hits = Geometry::rayIntersectSphere(location, direction, moon_position, moon_radius, &hit1, &hit2);
if (hits > 1) if (hits > 1)