~ubuntu-branches/debian/jessie/stellarium/jessie

« back to all changes in this revision

Viewing changes to src/skylight.h

Tags: upstream-0.9.0
Import upstream version 0.9.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright (C) 2003 Fabien Chereau
3
 
 *
4
 
 * This program is free software; you can redistribute it and/or
5
 
 * modify it under the terms of the GNU General Public License
6
 
 * as published by the Free Software Foundation; either version 2
7
 
 * of the License, or (at your option) any later version.
8
 
 *
9
 
 * This program is distributed in the hope that it will be useful,
10
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 
 * GNU General Public License for more details.
13
 
 *
14
 
 * You should have received a copy of the GNU General Public License
15
 
 * along with this program; if not, write to the Free Software
16
 
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
17
 
 */
18
 
 
19
 
// Class which computes the daylight sky color
20
 
// Fast implementation of the algorithm from the article
21
 
// "A Practical Analytic Model for Daylight" by A. J. Preetham, Peter Shirley and Brian Smits.
22
 
 
23
 
#ifndef _SKYLIGHT_H_
24
 
#define _SKYLIGHT_H_
25
 
 
26
 
typedef struct {
27
 
        float zenith_angle;     // zenith_angle : angular distance to the zenith in radian
28
 
        float dist_sun;                 // dist_sun     : angular distance to the sun in radian
29
 
        float color[3];                 // 3 component color, can be RGB or CIE color system
30
 
        } skylight_struct;
31
 
 
32
 
typedef struct {
33
 
        float pos[3];                   // Vector to the position (vertical = pos[2])
34
 
        float color[3];                 // 3 component color, can be RGB or CIE color system
35
 
        } skylight_struct2;
36
 
 
37
 
class Skylight
38
 
{
39
 
public:
40
 
    Skylight();
41
 
    virtual ~Skylight();
42
 
        // Set the fixed parameters and precompute what can be
43
 
        // This funtion has to be called once before any call to get_*_value()
44
 
    void set_params(float sun_zenith_angle, float turbidity);
45
 
        // Compute the sky color at the given position in the xyY color system and store it in position.color
46
 
        inline void get_xyY_value(skylight_struct * position);
47
 
        // Return the current zenith color
48
 
        inline void get_zenith_color(float * v) const;
49
 
 
50
 
        // Same functions but in vector mode : faster because prevents extra cosine calculations
51
 
        // The position vectors MUST be normalized, and the vertical z component is the third one
52
 
        void set_paramsv(const float * sun_pos, float turbidity);
53
 
        void get_xyY_valuev(skylight_struct2& position);
54
 
 
55
 
private:
56
 
        float thetas;                   // angular distance between the zenith and the sun in radian
57
 
        float T;                                // Turbidity : i.e. sky "clarity"
58
 
                                                        //  1 : pure air
59
 
                                                        //  2 : exceptionnally clear
60
 
                                                        //  4 : clear
61
 
                                                        //  8 : light haze
62
 
                                                        // 25 : haze
63
 
                                                        // 64 : thin fog
64
 
 
65
 
        // Computed variables depending on the 2 above
66
 
        float zenith_luminance;         // Y color component of the CIE color at zenith (luminance)
67
 
        float zenith_color_x;           // x color component of the CIE color at zenith
68
 
        float zenith_color_y;           // y color component of the CIE color at zenith
69
 
 
70
 
        float eye_lum_conversion;       // luminance conversion for an eye adapted to screen luminance (around 40 cd/m^2)
71
 
 
72
 
        float AY, BY, CY, DY, EY;       // Distribution coefficients for the luminance distribution function
73
 
        float Ax, Bx, Cx, Dx, Ex;       // Distribution coefficients for x distribution function
74
 
        float Ay, By, Cy, Dy, Ey;       // Distribution coefficients for y distribution function
75
 
 
76
 
        float term_x;                           // Precomputed term for x calculation
77
 
        float term_y;                           // Precomputed term for y calculation
78
 
        float term_Y;                           // Precomputed term for luminance calculation
79
 
 
80
 
        float sun_pos[3];
81
 
 
82
 
        // Compute CIE Y (luminance) for zenith in cd/m^2
83
 
        inline void compute_zenith_luminance(void);
84
 
        // Compute CIE x and y color components
85
 
        inline void compute_zenith_color(void);
86
 
        // Compute the luminance distribution coefficients
87
 
        inline void compute_luminance_distribution_coefs(void);
88
 
        // Compute the color distribution coefficients
89
 
        inline void compute_color_distribution_coefs(void);
90
 
 
91
 
};
92
 
 
93
 
#endif // _SKYLIGHT_H_