]> git.mxchange.org Git - flightgear.git/blob - src/Time/light.hxx
Merge branch 'tbm/graphics-bug' into next
[flightgear.git] / src / Time / light.hxx
1 // light.hxx -- lighting routines
2 //
3 // Written by Curtis Olson, started April 1998.
4 //
5 // Copyright (C) 1998  Curtis L. Olson  - http://www.flightgear.org/~curt
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 // General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20 //
21 // $Id$
22
23
24 #ifndef _LIGHT_HXX
25 #define _LIGHT_HXX
26
27
28 #ifndef __cplusplus                                                          
29 # error This library requires C++
30 #endif                                   
31
32
33 #ifdef HAVE_CONFIG_H
34 #  include <config.h>
35 #endif
36
37 #include <simgear/compiler.h>
38
39 #include <simgear/structure/subsystem_mgr.hxx>
40 #include <simgear/math/interpolater.hxx>
41
42
43 // Define a structure containing the global lighting parameters
44 class FGLight : public SGSubsystem
45 {
46
47 private:
48
49     /*
50      * Lighting look up tables (based on sun angle with local horizon)
51      */
52     SGInterpTable *_ambient_tbl, *_diffuse_tbl, *_specular_tbl;
53     SGInterpTable *_sky_tbl;
54
55     /**
56      * position of the sun and moon in various forms
57      */
58
59     // in geocentric coordinates
60     double _sun_lon, _sun_lat;
61     double _moon_lon, _moon_gc_lat;
62
63     // in cartesian coordiantes
64     SGVec3d _sunpos, _moonpos;
65
66     // (in view coordinates)
67     SGVec4f _sun_vec, _moon_vec;
68
69     // inverse (in view coordinates)
70     SGVec4f _sun_vec_inv, _moon_vec_inv;
71
72     // the angle between the celestial object and the local horizontal
73     // (in radians)
74     double _sun_angle, _moon_angle;
75     double _prev_sun_angle;
76
77     // the rotation around our vertical axis of the sun (relative to
78     // due south with positive numbers going in the counter clockwise
79     // direction.)  This is the direction we'd need to face if we
80     // wanted to travel towards celestial object.
81     double _sun_rotation, _moon_rotation;
82
83     /**
84      * Derived lighting values
85      */
86
87     // ambient, diffuse and specular component
88     SGVec4f _scene_ambient;
89     SGVec4f _scene_diffuse;
90     SGVec4f _scene_specular;
91
92     // clear sky, fog and cloud color
93     SGVec4f _sky_color;
94     SGVec4f _fog_color;
95     SGVec4f _cloud_color;
96
97     // clear sky and fog color adjusted for sunset effects
98     SGVec4f _adj_fog_color;
99     SGVec4f _adj_sky_color;
100
101     double _dt_total;
102
103     void update_sky_color ();
104     void update_adj_fog_color ();
105
106 public:
107
108     FGLight ();
109     virtual ~FGLight ();
110
111     virtual void init ();
112     virtual void reinit ();
113     virtual void bind ();
114     virtual void unbind ();
115     virtual void update ( double dt );
116
117
118     // Color related functions
119
120     inline const SGVec4f& scene_ambient () const { return _scene_ambient; }
121     inline const SGVec4f& scene_diffuse () const { return _scene_diffuse; }
122     inline const SGVec4f& scene_specular () const { return _scene_specular; }
123
124     inline const SGVec4f& sky_color () const { return _sky_color; }
125     inline const SGVec4f& cloud_color () const { return _cloud_color; }
126     inline const SGVec4f& adj_fog_color () const { return _adj_fog_color; }
127
128
129     // Sun related functions
130
131     inline double get_sun_angle () const { return _sun_angle; }
132     inline void set_sun_angle (double a) { _sun_angle = a; }
133
134     inline double get_sun_rotation () const { return _sun_rotation; }
135     inline void set_sun_rotation (double r) { _sun_rotation = r; }
136
137     inline double get_sun_lon () const { return _sun_lon; }
138     inline void set_sun_lon (double l) { _sun_lon = l; }
139
140     inline double get_sun_lat () const { return _sun_lat; }
141     inline void set_sun_lat (double l) { _sun_lat = l; }
142
143     inline const SGVec3d& get_sunpos () const { return _sunpos; }
144     inline void set_sunpos (const SGVec3d& p) { _sunpos = p; }
145
146     inline SGVec4f& sun_vec () { return _sun_vec; }
147     inline SGVec4f& sun_vec_inv () { return _sun_vec_inv; }
148
149
150     // Moon related functions
151
152     inline double get_moon_angle () const { return _moon_angle; }
153     inline void set_moon_angle (double a) { _moon_angle = a; }
154
155     inline double get_moon_rotation () const { return _moon_rotation; }
156     inline void set_moon_rotation (double r) { _moon_rotation = r; }
157
158     inline double get_moon_lon () const { return _moon_lon; }
159     inline void set_moon_lon (double l) { _moon_lon = l; }
160
161     inline double get_moon_gc_lat () const { return _moon_gc_lat; }
162     inline void set_moon_gc_lat (double l) { _moon_gc_lat = l; }
163
164     inline const SGVec3d& get_moonpos () const { return _moonpos; }
165     inline void set_moonpos (const SGVec3d& p) { _moonpos = p; }
166
167     inline const SGVec4f& moon_vec () const { return _moon_vec; }
168     inline const SGVec4f& moon_vec_inv () const { return _moon_vec_inv; }
169 };
170
171 #endif // _LIGHT_HXX
172