1 // light.hxx -- lighting routines
3 // Written by Curtis Olson, started April 1998.
5 // Copyright (C) 1998 Curtis L. Olson - http://www.flightgear.org/~curt
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.
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.
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.
29 # error This library requires C++
41 #include <simgear/compiler.h>
43 #include <simgear/structure/subsystem_mgr.hxx>
44 #include <simgear/math/interpolater.hxx>
45 #include <simgear/math/point3d.hxx>
48 // Define a structure containing the global lighting parameters
49 class FGLight : public SGSubsystem
55 * Lighting look up tables (based on sun angle with local horizon)
57 SGInterpTable *_ambient_tbl, *_diffuse_tbl, *_specular_tbl;
58 SGInterpTable *_sky_tbl;
61 * position of the sun and moon in various forms
64 // in geocentric coordinates
65 double _sun_lon, _sun_lat;
66 double _moon_lon, _moon_gc_lat;
68 // in cartesian coordiantes
69 SGVec3d _sunpos, _moonpos;
71 // (in view coordinates)
72 SGVec4f _sun_vec, _moon_vec;
74 // inverse (in view coordinates)
75 SGVec4f _sun_vec_inv, _moon_vec_inv;
77 // the angle between the celestial object and the local horizontal
79 double _sun_angle, _moon_angle;
80 double _prev_sun_angle;
82 // the rotation around our vertical axis of the sun (relative to
83 // due south with positive numbers going in the counter clockwise
84 // direction.) This is the direction we'd need to face if we
85 // wanted to travel towards celestial object.
86 double _sun_rotation, _moon_rotation;
89 * Derived lighting values
92 // ambient, diffuse and specular component
93 SGVec4f _scene_ambient;
94 SGVec4f _scene_diffuse;
95 SGVec4f _scene_specular;
97 // clear sky, fog and cloud color
100 SGVec4f _cloud_color;
102 // clear sky and fog color adjusted for sunset effects
103 SGVec4f _adj_fog_color;
104 SGVec4f _adj_sky_color;
108 void update_sky_color ();
109 void update_adj_fog_color ();
116 virtual void init ();
117 virtual void reinit ();
118 virtual void bind ();
119 virtual void unbind ();
120 virtual void update ( double dt );
123 // Color related functions
125 inline const SGVec4f& scene_ambient () const { return _scene_ambient; }
126 inline const SGVec4f& scene_diffuse () const { return _scene_diffuse; }
127 inline const SGVec4f& scene_specular () const { return _scene_specular; }
129 inline const SGVec4f& sky_color () const { return _sky_color; }
130 inline const SGVec4f& cloud_color () const { return _cloud_color; }
131 inline const SGVec4f& adj_fog_color () const { return _adj_fog_color; }
134 // Sun related functions
136 inline double get_sun_angle () const { return _sun_angle; }
137 inline void set_sun_angle (double a) { _sun_angle = a; }
139 inline double get_sun_rotation () const { return _sun_rotation; }
140 inline void set_sun_rotation (double r) { _sun_rotation = r; }
142 inline double get_sun_lon () const { return _sun_lon; }
143 inline void set_sun_lon (double l) { _sun_lon = l; }
145 inline double get_sun_lat () const { return _sun_lat; }
146 inline void set_sun_lat (double l) { _sun_lat = l; }
148 inline const SGVec3d& get_sunpos () const { return _sunpos; }
149 inline void set_sunpos (const SGVec3d& p) { _sunpos = p; }
151 inline SGVec4f& sun_vec () { return _sun_vec; }
152 inline SGVec4f& sun_vec_inv () { return _sun_vec_inv; }
155 // Moon related functions
157 inline double get_moon_angle () const { return _moon_angle; }
158 inline void set_moon_angle (double a) { _moon_angle = a; }
160 inline double get_moon_rotation () const { return _moon_rotation; }
161 inline void set_moon_rotation (double r) { _moon_rotation = r; }
163 inline double get_moon_lon () const { return _moon_lon; }
164 inline void set_moon_lon (double l) { _moon_lon = l; }
166 inline double get_moon_gc_lat () const { return _moon_gc_lat; }
167 inline void set_moon_gc_lat (double l) { _moon_gc_lat = l; }
169 inline const SGVec3d& get_moonpos () const { return _moonpos; }
170 inline void set_moonpos (const SGVec3d& p) { _moonpos = p; }
172 inline const SGVec4f& moon_vec () const { return _moon_vec; }
173 inline const SGVec4f& moon_vec_inv () const { return _moon_vec_inv; }