]> git.mxchange.org Git - flightgear.git/blobdiff - src/Time/light.hxx
#346 related: missing status message for property server
[flightgear.git] / src / Time / light.hxx
index ac7449b3936a9fa6e4946de22d45383d093877e8..1880c3deab0a3cf9fa34b95e39b23a0c9f5dc105 100644 (file)
@@ -2,7 +2,7 @@
 //
 // Written by Curtis Olson, started April 1998.
 //
-// Copyright (C) 1998  Curtis L. Olson  - curt@me.umn.edu
+// Copyright (C) 1998  Curtis L. Olson  - http://www.flightgear.org/~curt
 //
 // This program is free software; you can redistribute it and/or
 // modify it under the terms of the GNU General Public License as
@@ -16,7 +16,7 @@
 //
 // You should have received a copy of the GNU General Public License
 // along with this program; if not, write to the Free Software
-// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 //
 // $Id$
 
 #  include <config.h>
 #endif
 
-#ifdef HAVE_WINDOWS_H
-#  include <windows.h>
-#endif
-
-#include <GL/glut.h>
-#include <simgear/xgl.h>
+#include <simgear/compiler.h>
 
-#include <plib/sg.h>                   // plib include
-
-#include <simgear/interpolater.hxx>
-#include <simgear/point3d.hxx>
+#include <simgear/props/props.hxx>
+#include <simgear/structure/subsystem_mgr.hxx>
+#include <simgear/math/interpolater.hxx>
 
 
 // Define a structure containing the global lighting parameters
-class fgLIGHT {
+class FGLight : public SGSubsystem
+{
 
-    // Lighting look up tables (based on sun angle with local horizon)
-    fgINTERPTABLE *ambient_tbl;
-    fgINTERPTABLE *diffuse_tbl;
-    fgINTERPTABLE *sky_tbl;
+private:
 
-public:
+    /*
+     * Lighting look up tables (based on sun angle with local horizon)
+     */
+    SGInterpTable *_ambient_tbl, *_diffuse_tbl, *_specular_tbl;
+    SGInterpTable *_sky_tbl;
 
-    ///////////////////////////////////////////////////////////
-    // position of the sun in various forms
+    /**
+     * position of the sun and moon in various forms
+     */
 
     // in geocentric coordinates
-    double sun_lon, sun_gc_lat;
-
-    // in cartesian coordiantes
-    Point3D fg_sunpos;
+    double _sun_lon, _sun_lat;
+    double _moon_lon, _moon_gc_lat;
 
     // (in view coordinates)
-    sgVec4 sun_vec;
+    SGVec4f _sun_vec, _moon_vec;
 
     // inverse (in view coordinates)
-    sgVec4 sun_vec_inv;
+    SGVec4f _sun_vec_inv, _moon_vec_inv;
 
-    // the angle between the sun and the local horizontal (in radians)
-    double sun_angle;
+    // the angle between the celestial object and the local horizontal
+    // (in radians)
+    double _sun_angle, _moon_angle;
+    double _prev_sun_angle;
 
     // 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
-    // wanted to travel towards the sun.
-    double sun_rotation;
-
-    ///////////////////////////////////////////////////////////
-    // Have the same for the moon. Useful for having some light at night
-    // and stuff. I (Durk) also want to use this for adding similar 
-    // coloring effects to the moon as I did to the sun. 
-    ///////////////////////////////////////////////////////////
-    // position of the moon in various forms
-
-    // in geocentric coordinates
-    double moon_lon, moon_gc_lat;
+    // wanted to travel towards celestial object.
+    double _sun_rotation, _moon_rotation;
+
+    /**
+     * Derived lighting values
+     */
+
+    // ambient, diffuse and specular component
+    SGVec4f _scene_ambient;
+    SGVec4f _scene_diffuse;
+    SGVec4f _scene_specular;
+    SGVec4f _scene_chrome;
+
+    // clear sky, fog and cloud color
+    SGVec4f _sky_color;
+    SGVec4f _fog_color;
+    SGVec4f _cloud_color;
+
+    // clear sky and fog color adjusted for sunset effects
+    SGVec4f _adj_fog_color;
+    SGVec4f _adj_sky_color;
+
+    // input parameters affected by the weather system
+    float _saturation;
+    float _scattering;
+    float _overcast;
+
+    double _dt_total;
+
+    void update_sky_color ();
+    void update_adj_fog_color ();
+
+    void updateSunPos();
+    
+    // properties for chrome light; not a tie because I want to fire
+    // property listeners when the values change.
+    SGPropertyNode_ptr _chromeProps[4];
+public:
 
-    // in cartesian coordiantes
-    Point3D fg_moonpos;
+    FGLight ();
+    virtual ~FGLight ();
 
-    // (in view coordinates)
-    GLfloat moon_vec[4];
+    virtual void init ();
+    virtual void reinit ();
+    virtual void bind ();
+    virtual void unbind ();
+    virtual void update ( double dt );
 
-    // inverse (in view coordinates)
-    GLfloat moon_vec_inv[4];
 
-    // the angle between the moon and the local horizontal (in radians)
-    double moon_angle;
+    // Color related functions
 
-    // the rotation around our vertical axis of the moon (relative to
-    // due south with positive numbers going in the counter clockwise
-    // direction.)  This is the direction we'd need to face if we
-    // wanted to travel towards the sun.
-    double moon_rotation;
+    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; }
+    inline const SGVec4f& scene_chrome () const { return _scene_chrome; }
 
-    ///////////////////////////////////////////////////////////
-    // Derived lighting values
+    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; }
+    inline const SGVec4f& adj_sky_color () const { return _adj_sky_color; }
 
-    // ambient component
-    GLfloat scene_ambient[3];
+    // Sun related functions
 
-    // diffuse component
-    GLfloat scene_diffuse[3];
+    inline double get_sun_angle () const { return _sun_angle; }
+    inline void set_sun_angle (double a) { _sun_angle = a; }
 
-    // fog color
-    GLfloat fog_color[4];
+    inline double get_sun_rotation () const { return _sun_rotation; }
+    inline void set_sun_rotation (double r) { _sun_rotation = r; }
 
-    // fog color adjusted for sunset effects
-    GLfloat adj_fog_color[4];
+    inline double get_sun_lon () const { return _sun_lon; }
+    inline void set_sun_lon (double l) { _sun_lon = l; }
 
-    // clear screen color
-    GLfloat sky_color[4];
+    inline double get_sun_lat () const { return _sun_lat; }
+    inline void set_sun_lat (double l) { _sun_lat = l; }
 
-    // Constructor
-    fgLIGHT( void );
+    inline SGVec4f& sun_vec () { return _sun_vec; }
+    inline SGVec4f& sun_vec_inv () { return _sun_vec_inv; }
 
-    // initialize lighting tables
-    void Init( void );
 
-    // update lighting parameters based on current sun position
-    void Update( void);
+    // Moon related functions
 
-    // calculate fog color adjusted for sunrise/sunset effects
-    void UpdateAdjFog( void );
+    inline double get_moon_angle () const { return _moon_angle; }
+    inline void set_moon_angle (double a) { _moon_angle = a; }
 
-    // Destructor
-    ~fgLIGHT( void );
-};
+    inline double get_moon_rotation () const { return _moon_rotation; }
+    inline void set_moon_rotation (double r) { _moon_rotation = r; }
 
+    inline double get_moon_lon () const { return _moon_lon; }
+    inline void set_moon_lon (double l) { _moon_lon = l; }
 
-// Global shared light parameter structure
-extern fgLIGHT cur_light_params;
+    inline double get_moon_gc_lat () const { return _moon_gc_lat; }
+    inline void set_moon_gc_lat (double l) { _moon_gc_lat = l; }
 
+    inline const SGVec4f& moon_vec () const { return _moon_vec; }
+    inline const SGVec4f& moon_vec_inv () const { return _moon_vec_inv; }
+};
 
 #endif // _LIGHT_HXX
+