2012-01-07 16:53:23 +00:00
# include "formsky.h"
# include "tools.h"
# include <QColor>
# include <QSlider>
# include <math.h>
# include "../lib_paysages/sky.h"
2012-01-24 13:16:20 +00:00
# include "../lib_paysages/scenery.h"
# include "../lib_paysages/renderer.h"
2012-01-07 16:53:23 +00:00
static SkyDefinition _definition ;
/**************** Previews ****************/
2012-02-21 13:41:02 +00:00
class PreviewSkyEast : public BasePreview
2012-01-07 16:53:23 +00:00
{
public :
2012-02-12 17:26:17 +00:00
PreviewSkyEast ( QWidget * parent ) :
2012-02-21 13:41:02 +00:00
BasePreview ( parent )
2012-01-07 16:53:23 +00:00
{
2012-01-29 21:45:58 +00:00
_renderer = rendererCreate ( ) ;
2012-01-25 22:32:06 +00:00
_preview_definition = skyCreateDefinition ( ) ;
2012-04-12 20:02:31 +00:00
configScaling ( 0.5 , 5.0 , 0.5 , 2.5 ) ;
2012-01-07 16:53:23 +00:00
}
protected :
2012-06-17 09:40:40 +00:00
QColor getColor ( double x , double y )
2012-01-07 16:53:23 +00:00
{
2012-06-08 19:06:16 +00:00
y - = 100.0 * scaling ;
2012-06-08 12:28:46 +00:00
if ( y > 0.0 )
{
return QColor ( 0 , 0 , 0 ) ;
}
else
{
Vector3 eye = { 0.0 , 0.0 , 0.0 } ;
Vector3 look ;
2012-01-07 16:53:23 +00:00
2012-06-08 12:28:46 +00:00
look . x = 1.0 ;
look . y = - y ;
look . z = x ;
2012-01-16 21:29:21 +00:00
2012-06-08 12:28:46 +00:00
return colorToQColor ( skyGetColor ( & _preview_definition , & _renderer , eye , look ) ) ;
}
2012-01-25 22:32:06 +00:00
}
void updateData ( )
{
skyCopyDefinition ( & _definition , & _preview_definition ) ;
2012-01-16 21:29:21 +00:00
}
2012-01-24 13:16:20 +00:00
private :
Renderer _renderer ;
2012-01-25 22:32:06 +00:00
SkyDefinition _preview_definition ;
2012-01-16 21:29:21 +00:00
} ;
2012-02-21 13:41:02 +00:00
class PreviewSkyWest : public BasePreview
2012-01-16 21:29:21 +00:00
{
public :
2012-02-12 17:26:17 +00:00
PreviewSkyWest ( QWidget * parent ) :
2012-02-21 13:41:02 +00:00
BasePreview ( parent )
2012-01-16 21:29:21 +00:00
{
2012-01-29 21:45:58 +00:00
_renderer = rendererCreate ( ) ;
2012-01-25 22:32:06 +00:00
_preview_definition = skyCreateDefinition ( ) ;
2012-04-12 20:02:31 +00:00
configScaling ( 0.5 , 5.0 , 0.5 , 2.5 ) ;
2012-01-16 21:29:21 +00:00
}
protected :
2012-06-17 09:40:40 +00:00
QColor getColor ( double x , double y )
2012-01-16 21:29:21 +00:00
{
2012-06-08 19:06:16 +00:00
y - = 100.0 * scaling ;
2012-06-08 12:28:46 +00:00
if ( y > 0.0 )
{
return QColor ( 0 , 0 , 0 ) ;
}
else
{
Vector3 eye = { 0.0 , 0.0 , 0.0 } ;
Vector3 look ;
2012-01-16 21:29:21 +00:00
2012-06-08 12:28:46 +00:00
look . x = - 1.0 ;
look . y = - y ;
look . z = - x ;
2012-01-07 16:53:23 +00:00
2012-06-08 12:28:46 +00:00
return colorToQColor ( skyGetColor ( & _preview_definition , & _renderer , eye , look ) ) ;
}
2012-01-25 22:32:06 +00:00
}
void updateData ( )
{
skyCopyDefinition ( & _definition , & _preview_definition ) ;
2012-01-07 16:53:23 +00:00
}
2012-01-24 13:16:20 +00:00
private :
Renderer _renderer ;
2012-01-25 22:32:06 +00:00
SkyDefinition _preview_definition ;
2012-01-07 16:53:23 +00:00
} ;
/**************** Form ****************/
FormSky : : FormSky ( QWidget * parent ) :
BaseForm ( parent )
{
2012-06-23 22:11:25 +00:00
BaseInput * input ;
2012-01-07 16:53:23 +00:00
_definition = skyCreateDefinition ( ) ;
2012-02-12 17:26:17 +00:00
previewWest = new PreviewSkyWest ( this ) ;
2012-02-28 13:45:11 +00:00
addPreview ( previewWest , QString ( tr ( " West preview " ) ) ) ;
2012-02-12 17:26:17 +00:00
previewEast = new PreviewSkyEast ( this ) ;
2012-02-28 13:45:11 +00:00
addPreview ( previewEast , QString ( tr ( " East preview " ) ) ) ;
2012-06-24 12:33:59 +00:00
addInputEnum ( tr ( " Color model " ) , ( int * ) & _definition . model , QStringList ( tr ( " Custom model " ) ) < < tr ( " Rayleigh/Mie scattering " ) < < tr ( " Preetham/Shirley analytic model " ) ) ;
2012-06-25 20:11:15 +00:00
addInputDouble ( tr ( " Day time " ) , & _definition . daytime , 0.14 , 0.86 , 0.002 , 0.1 ) ;
2012-06-22 22:13:55 +00:00
addInputColor ( tr ( " Sun color " ) , & _definition . sun_color ) ;
2012-06-07 19:26:23 +00:00
addInputDouble ( tr ( " Sun radius " ) , & _definition . sun_radius , 0.0 , 0.4 , 0.004 , 0.04 ) ;
addInputDouble ( tr ( " Sun halo radius " ) , & _definition . sun_halo_size , 0.0 , 0.4 , 0.004 , 0.04 ) ;
2012-06-27 12:49:51 +00:00
addInputCurve ( tr ( " Sun halo profile " ) , _definition . sun_halo_profile , 0.0 , 1.0 , 0.0 , 1.0 , tr ( " Distance to center of the sun " ) , tr ( " Light influence (halo opacity) " ) ) ;
2012-06-24 16:04:01 +00:00
addInputDouble ( tr ( " Influence of skydome on lighting " ) , & _definition . dome_lighting , 0.0 , 2.0 , 0.01 , 0.1 ) ;
2012-06-23 22:11:25 +00:00
input = addInputBoolean ( tr ( " Auto colors from daytime " ) , & _definition . model_custom . auto_from_daytime ) ;
input - > setVisibilityCondition ( ( int * ) & _definition . model , SKY_MODEL_CUSTOM ) ;
input = addInputColor ( tr ( " Zenith color " ) , & _definition . model_custom . zenith_color ) ;
input - > setVisibilityCondition ( ( int * ) & _definition . model , SKY_MODEL_CUSTOM ) ;
input = addInputColor ( tr ( " Haze color " ) , & _definition . model_custom . haze_color ) ;
input - > setVisibilityCondition ( ( int * ) & _definition . model , SKY_MODEL_CUSTOM ) ;
input = addInputDouble ( tr ( " Haze height " ) , & _definition . model_custom . haze_height , 0.0 , 1.0 , 0.01 , 0.1 ) ;
input - > setVisibilityCondition ( ( int * ) & _definition . model , SKY_MODEL_CUSTOM ) ;
input = addInputDouble ( tr ( " Haze smoothing " ) , & _definition . model_custom . haze_smoothing , 0.0 , 1.0 , 0.01 , 0.1 ) ;
input - > setVisibilityCondition ( ( int * ) & _definition . model , SKY_MODEL_CUSTOM ) ;
input = addInputDouble ( tr ( " Turbidity " ) , & _definition . model_preetham . turbidity , 1.8 , 6.0 , 0.05 , 0.5 ) ;
input - > setVisibilityCondition ( ( int * ) & _definition . model , SKY_MODEL_PREETHAM ) ;
2012-01-07 16:53:23 +00:00
revertConfig ( ) ;
}
void FormSky : : revertConfig ( )
{
2012-01-24 13:16:20 +00:00
sceneryGetSky ( & _definition ) ;
2012-01-07 16:53:23 +00:00
BaseForm : : revertConfig ( ) ;
}
void FormSky : : applyConfig ( )
{
2012-01-24 13:16:20 +00:00
scenerySetSky ( & _definition ) ;
2012-01-07 16:53:23 +00:00
BaseForm : : applyConfig ( ) ;
}
2012-01-25 22:32:06 +00:00
void FormSky : : configChangeEvent ( )
2012-01-07 16:53:23 +00:00
{
skyValidateDefinition ( & _definition ) ;
2012-01-25 22:32:06 +00:00
BaseForm : : configChangeEvent ( ) ;
2012-01-07 16:53:23 +00:00
}