1998-04-22 13:24:04 +00:00
|
|
|
// light.hxx -- lighting routines
|
|
|
|
//
|
|
|
|
// Written by Curtis Olson, started April 1998.
|
|
|
|
//
|
2004-11-19 22:10:41 +00:00
|
|
|
// Copyright (C) 1998 Curtis L. Olson - http://www.flightgear.org/~curt
|
1998-04-22 13:24:04 +00:00
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License as
|
|
|
|
// published by the Free Software Foundation; either version 2 of the
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful, but
|
|
|
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program; if not, write to the Free Software
|
2006-02-21 01:16:04 +00:00
|
|
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
1998-04-22 13:24:04 +00:00
|
|
|
//
|
|
|
|
// $Id$
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef _LIGHT_HXX
|
|
|
|
#define _LIGHT_HXX
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef __cplusplus
|
|
|
|
# error This library requires C++
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
1998-04-24 00:52:24 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include <config.h>
|
|
|
|
#endif
|
1998-04-22 13:24:04 +00:00
|
|
|
|
2004-11-18 19:53:00 +00:00
|
|
|
#include <simgear/compiler.h>
|
|
|
|
|
2009-11-03 11:41:00 +00:00
|
|
|
#include <simgear/props/props.hxx>
|
2003-09-24 17:20:55 +00:00
|
|
|
#include <simgear/structure/subsystem_mgr.hxx>
|
2000-02-16 23:01:03 +00:00
|
|
|
#include <simgear/math/interpolater.hxx>
|
1998-04-22 13:24:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
// Define a structure containing the global lighting parameters
|
2003-09-24 17:20:55 +00:00
|
|
|
class FGLight : public SGSubsystem
|
2003-09-20 09:38:32 +00:00
|
|
|
{
|
1998-05-20 20:54:16 +00:00
|
|
|
|
2003-09-20 09:38:32 +00:00
|
|
|
private:
|
1998-05-20 20:54:16 +00:00
|
|
|
|
2003-09-20 09:38:32 +00:00
|
|
|
/*
|
|
|
|
* Lighting look up tables (based on sun angle with local horizon)
|
|
|
|
*/
|
|
|
|
SGInterpTable *_ambient_tbl, *_diffuse_tbl, *_specular_tbl;
|
|
|
|
SGInterpTable *_sky_tbl;
|
1998-04-22 13:24:04 +00:00
|
|
|
|
2003-09-20 09:38:32 +00:00
|
|
|
/**
|
|
|
|
* position of the sun and moon in various forms
|
|
|
|
*/
|
1998-04-22 13:24:04 +00:00
|
|
|
|
|
|
|
// in geocentric coordinates
|
2007-01-30 20:14:25 +00:00
|
|
|
double _sun_lon, _sun_lat;
|
2003-09-20 09:38:32 +00:00
|
|
|
double _moon_lon, _moon_gc_lat;
|
1998-04-22 13:24:04 +00:00
|
|
|
|
|
|
|
// (in view coordinates)
|
2006-11-10 05:37:50 +00:00
|
|
|
SGVec4f _sun_vec, _moon_vec;
|
1998-04-22 13:24:04 +00:00
|
|
|
|
|
|
|
// inverse (in view coordinates)
|
2006-11-10 05:37:50 +00:00
|
|
|
SGVec4f _sun_vec_inv, _moon_vec_inv;
|
1998-04-22 13:24:04 +00:00
|
|
|
|
2003-09-20 09:38:32 +00:00
|
|
|
// the angle between the celestial object and the local horizontal
|
|
|
|
// (in radians)
|
|
|
|
double _sun_angle, _moon_angle;
|
|
|
|
double _prev_sun_angle;
|
1998-04-22 13:24:04 +00:00
|
|
|
|
1998-07-22 21:45:37 +00:00
|
|
|
// the rotation around our vertical axis of the sun (relative to
|
|
|
|
// due south with positive numbers going in the counter clockwise
|
|
|
|
// direction.) This is the direction we'd need to face if we
|
2003-09-20 09:38:32 +00:00
|
|
|
// wanted to travel towards celestial object.
|
|
|
|
double _sun_rotation, _moon_rotation;
|
1998-07-22 21:45:37 +00:00
|
|
|
|
2003-09-20 09:38:32 +00:00
|
|
|
/**
|
|
|
|
* Derived lighting values
|
|
|
|
*/
|
1999-03-22 02:08:05 +00:00
|
|
|
|
2003-09-20 09:38:32 +00:00
|
|
|
// ambient, diffuse and specular component
|
2006-11-10 05:37:50 +00:00
|
|
|
SGVec4f _scene_ambient;
|
|
|
|
SGVec4f _scene_diffuse;
|
|
|
|
SGVec4f _scene_specular;
|
2009-11-03 11:41:00 +00:00
|
|
|
SGVec4f _scene_chrome;
|
1999-03-22 02:08:05 +00:00
|
|
|
|
2003-09-20 09:38:32 +00:00
|
|
|
// clear sky, fog and cloud color
|
2006-11-10 05:37:50 +00:00
|
|
|
SGVec4f _sky_color;
|
|
|
|
SGVec4f _fog_color;
|
|
|
|
SGVec4f _cloud_color;
|
1999-03-22 02:08:05 +00:00
|
|
|
|
2003-09-20 09:38:32 +00:00
|
|
|
// clear sky and fog color adjusted for sunset effects
|
2006-11-10 05:37:50 +00:00
|
|
|
SGVec4f _adj_fog_color;
|
|
|
|
SGVec4f _adj_sky_color;
|
2011-06-04 11:11:56 +00:00
|
|
|
|
|
|
|
// input parameters affected by the weather system
|
2010-09-12 09:06:14 +00:00
|
|
|
float _saturation;
|
2011-06-04 11:11:56 +00:00
|
|
|
float _scattering;
|
2011-06-05 08:20:16 +00:00
|
|
|
float _overcast;
|
1999-03-22 02:08:05 +00:00
|
|
|
|
2003-09-20 09:38:32 +00:00
|
|
|
double _dt_total;
|
1999-03-22 02:08:05 +00:00
|
|
|
|
2003-09-20 09:38:32 +00:00
|
|
|
void update_sky_color ();
|
|
|
|
void update_adj_fog_color ();
|
1999-03-22 02:08:05 +00:00
|
|
|
|
2010-07-13 20:50:44 +00:00
|
|
|
void updateSunPos();
|
|
|
|
|
2009-11-03 11:41:00 +00:00
|
|
|
// properties for chrome light; not a tie because I want to fire
|
|
|
|
// property listeners when the values change.
|
|
|
|
SGPropertyNode_ptr _chromeProps[4];
|
2011-10-12 08:17:58 +00:00
|
|
|
|
|
|
|
SGPropertyNode_ptr _sunAngleRad;
|
2003-09-20 09:38:32 +00:00
|
|
|
public:
|
1999-03-22 02:08:05 +00:00
|
|
|
|
2003-09-20 09:38:32 +00:00
|
|
|
FGLight ();
|
|
|
|
virtual ~FGLight ();
|
1998-04-22 13:24:04 +00:00
|
|
|
|
2003-09-20 09:38:32 +00:00
|
|
|
virtual void init ();
|
|
|
|
virtual void reinit ();
|
|
|
|
virtual void bind ();
|
|
|
|
virtual void unbind ();
|
|
|
|
virtual void update ( double dt );
|
1998-04-22 13:24:04 +00:00
|
|
|
|
|
|
|
|
2003-09-20 09:38:32 +00:00
|
|
|
// Color related functions
|
2002-07-21 15:40:51 +00:00
|
|
|
|
2006-11-10 05:37:50 +00:00
|
|
|
inline const SGVec4f& scene_ambient () const { return _scene_ambient; }
|
|
|
|
inline const SGVec4f& scene_diffuse () const { return _scene_diffuse; }
|
|
|
|
inline const SGVec4f& scene_specular () const { return _scene_specular; }
|
2009-11-03 11:41:00 +00:00
|
|
|
inline const SGVec4f& scene_chrome () const { return _scene_chrome; }
|
1998-04-22 13:24:04 +00:00
|
|
|
|
2006-11-10 05:37:50 +00:00
|
|
|
inline const SGVec4f& sky_color () const { return _sky_color; }
|
|
|
|
inline const SGVec4f& cloud_color () const { return _cloud_color; }
|
|
|
|
inline const SGVec4f& adj_fog_color () const { return _adj_fog_color; }
|
2009-04-11 12:28:23 +00:00
|
|
|
inline const SGVec4f& adj_sky_color () const { return _adj_sky_color; }
|
1998-07-22 21:45:37 +00:00
|
|
|
|
2003-09-20 09:38:32 +00:00
|
|
|
// Sun related functions
|
1998-04-22 13:24:04 +00:00
|
|
|
|
2003-09-20 09:38:32 +00:00
|
|
|
inline double get_sun_angle () const { return _sun_angle; }
|
|
|
|
inline void set_sun_angle (double a) { _sun_angle = a; }
|
2003-05-21 17:20:55 +00:00
|
|
|
|
2003-09-20 09:38:32 +00:00
|
|
|
inline double get_sun_rotation () const { return _sun_rotation; }
|
|
|
|
inline void set_sun_rotation (double r) { _sun_rotation = r; }
|
1998-04-22 13:24:04 +00:00
|
|
|
|
2003-09-20 09:38:32 +00:00
|
|
|
inline double get_sun_lon () const { return _sun_lon; }
|
|
|
|
inline void set_sun_lon (double l) { _sun_lon = l; }
|
1998-04-22 13:24:04 +00:00
|
|
|
|
2007-01-30 20:14:25 +00:00
|
|
|
inline double get_sun_lat () const { return _sun_lat; }
|
|
|
|
inline void set_sun_lat (double l) { _sun_lat = l; }
|
1998-04-22 13:24:04 +00:00
|
|
|
|
2006-11-10 05:37:50 +00:00
|
|
|
inline SGVec4f& sun_vec () { return _sun_vec; }
|
|
|
|
inline SGVec4f& sun_vec_inv () { return _sun_vec_inv; }
|
2003-09-20 09:38:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
// Moon related functions
|
|
|
|
|
|
|
|
inline double get_moon_angle () const { return _moon_angle; }
|
|
|
|
inline void set_moon_angle (double a) { _moon_angle = a; }
|
1998-04-22 13:24:04 +00:00
|
|
|
|
2003-09-20 09:38:32 +00:00
|
|
|
inline double get_moon_rotation () const { return _moon_rotation; }
|
|
|
|
inline void set_moon_rotation (double r) { _moon_rotation = r; }
|
1998-04-22 13:24:04 +00:00
|
|
|
|
2003-09-20 09:38:32 +00:00
|
|
|
inline double get_moon_lon () const { return _moon_lon; }
|
|
|
|
inline void set_moon_lon (double l) { _moon_lon = l; }
|
1998-05-20 20:54:16 +00:00
|
|
|
|
2003-09-20 09:38:32 +00:00
|
|
|
inline double get_moon_gc_lat () const { return _moon_gc_lat; }
|
|
|
|
inline void set_moon_gc_lat (double l) { _moon_gc_lat = l; }
|
|
|
|
|
2006-11-10 05:37:50 +00:00
|
|
|
inline const SGVec4f& moon_vec () const { return _moon_vec; }
|
|
|
|
inline const SGVec4f& moon_vec_inv () const { return _moon_vec_inv; }
|
2003-09-20 09:38:32 +00:00
|
|
|
};
|
1998-05-20 20:54:16 +00:00
|
|
|
|
1998-04-22 13:24:04 +00:00
|
|
|
#endif // _LIGHT_HXX
|
2003-09-20 09:38:32 +00:00
|
|
|
|