]> git.mxchange.org Git - flightgear.git/blob - src/Time/light.hxx
Migrate FlightGear code to use "#include SG_GL*" defined in
[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  - curt@me.umn.edu
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., 675 Mass Ave, Cambridge, MA 02139, 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 #ifdef HAVE_WINDOWS_H
38 #  include <windows.h>
39 #endif
40
41 #include <simgear/compiler.h>
42
43 #include SG_GL_H
44
45 #include <plib/sg.h>                    // plib include
46
47 #include <simgear/structure/subsystem_mgr.hxx>
48 #include <simgear/math/interpolater.hxx>
49 #include <simgear/math/point3d.hxx>
50
51
52 // Define a structure containing the global lighting parameters
53 class FGLight : public SGSubsystem
54 {
55
56 private:
57
58     /*
59      * Lighting look up tables (based on sun angle with local horizon)
60      */
61     SGInterpTable *_ambient_tbl, *_diffuse_tbl, *_specular_tbl;
62     SGInterpTable *_sky_tbl;
63
64     /**
65      * position of the sun and moon in various forms
66      */
67
68     // in geocentric coordinates
69     double _sun_lon, _sun_gc_lat;
70     double _moon_lon, _moon_gc_lat;
71
72     // in cartesian coordiantes
73     Point3D _sunpos, _moonpos;
74
75     // (in view coordinates)
76     sgVec4 _sun_vec, _moon_vec;
77
78     // inverse (in view coordinates)
79     sgVec4 _sun_vec_inv, _moon_vec_inv;
80
81     // the angle between the celestial object and the local horizontal
82     // (in radians)
83     double _sun_angle, _moon_angle;
84     double _prev_sun_angle;
85
86     // the rotation around our vertical axis of the sun (relative to
87     // due south with positive numbers going in the counter clockwise
88     // direction.)  This is the direction we'd need to face if we
89     // wanted to travel towards celestial object.
90     double _sun_rotation, _moon_rotation;
91
92     /**
93      * Derived lighting values
94      */
95
96     // ambient, diffuse and specular component
97     GLfloat _scene_ambient[4];
98     GLfloat _scene_diffuse[4];
99     GLfloat _scene_specular[4];
100
101     // clear sky, fog and cloud color
102     GLfloat _sky_color[4];
103     GLfloat _fog_color[4];
104     GLfloat _cloud_color[4];
105
106     // clear sky and fog color adjusted for sunset effects
107     GLfloat _adj_fog_color[4];
108     GLfloat _adj_sky_color[4];
109
110     double _dt_total;
111
112     void update_sky_color ();
113     void update_adj_fog_color ();
114
115 public:
116
117     FGLight ();
118     virtual ~FGLight ();
119
120     virtual void init ();
121     virtual void reinit ();
122     virtual void bind ();
123     virtual void unbind ();
124     virtual void update ( double dt );
125
126
127     // Color related functions
128
129     inline float *scene_ambient () const { return (float *)_scene_ambient; }
130     inline float *scene_diffuse () const { return (float *)_scene_diffuse; }
131     inline float *scene_specular () const { return (float *)_scene_specular; }
132
133     inline float *sky_color () const { return (float *)_sky_color; }
134     inline float *cloud_color () const { return (float *)_cloud_color; }
135     inline float *adj_fog_color () const { return (float *)_adj_fog_color; }
136
137
138     // Sun related functions
139
140     inline double get_sun_angle () const { return _sun_angle; }
141     inline void set_sun_angle (double a) { _sun_angle = a; }
142
143     inline double get_sun_rotation () const { return _sun_rotation; }
144     inline void set_sun_rotation (double r) { _sun_rotation = r; }
145
146     inline double get_sun_lon () const { return _sun_lon; }
147     inline void set_sun_lon (double l) { _sun_lon = l; }
148
149     inline double get_sun_gc_lat () const { return _sun_gc_lat; }
150     inline void set_sun_gc_lat (double l) { _sun_gc_lat = l; }
151
152     inline Point3D get_sunpos () const { return _sunpos; }
153     inline void set_sunpos (Point3D p) { _sunpos = p; }
154
155     inline float *sun_vec () const { return (float *)_sun_vec; }
156     inline float *sun_vec_inv () const { return (float *)_sun_vec_inv; }
157
158
159     // Moon related functions
160
161     inline double get_moon_angle () const { return _moon_angle; }
162     inline void set_moon_angle (double a) { _moon_angle = a; }
163
164     inline double get_moon_rotation () const { return _moon_rotation; }
165     inline void set_moon_rotation (double r) { _moon_rotation = r; }
166
167     inline double get_moon_lon () const { return _moon_lon; }
168     inline void set_moon_lon (double l) { _moon_lon = l; }
169
170     inline double get_moon_gc_lat () const { return _moon_gc_lat; }
171     inline void set_moon_gc_lat (double l) { _moon_gc_lat = l; }
172
173     inline Point3D get_moonpos () const { return _moonpos; }
174     inline void set_moonpos (Point3D p) { _moonpos = p; }
175
176     inline float *moon_vec () const { return (float *)_moon_vec; }
177     inline float *moon_vec_inv () const { return (float *)_moon_vec_inv; }
178 };
179
180 #endif // _LIGHT_HXX
181