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