1998-04-22 13:24:04 +00:00
|
|
|
// light.hxx -- lighting routines
|
|
|
|
//
|
|
|
|
// Written by Curtis Olson, started April 1998.
|
|
|
|
//
|
|
|
|
// Copyright (C) 1998 Curtis L. Olson - curt@me.umn.edu
|
|
|
|
//
|
|
|
|
// 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
|
|
|
|
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
//
|
|
|
|
// $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
|
|
|
|
|
|
|
#ifdef HAVE_WINDOWS_H
|
|
|
|
# include <windows.h>
|
|
|
|
#endif
|
|
|
|
|
2002-12-10 20:50:48 +00:00
|
|
|
#include GLUT_H
|
1998-04-22 13:24:04 +00:00
|
|
|
|
2000-02-04 22:50:04 +00:00
|
|
|
#include <plib/sg.h> // plib include
|
1999-10-03 18:49:39 +00:00
|
|
|
|
2000-02-16 23:01:03 +00:00
|
|
|
#include <simgear/math/interpolater.hxx>
|
|
|
|
#include <simgear/math/point3d.hxx>
|
1998-04-22 13:24:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
// Define a structure containing the global lighting parameters
|
1998-05-20 20:54:16 +00:00
|
|
|
class fgLIGHT {
|
|
|
|
|
|
|
|
// Lighting look up tables (based on sun angle with local horizon)
|
2001-03-14 07:25:14 +00:00
|
|
|
SGInterpTable *ambient_tbl;
|
|
|
|
SGInterpTable *diffuse_tbl;
|
2002-07-21 15:40:51 +00:00
|
|
|
SGInterpTable *specular_tbl;
|
2001-03-14 07:25:14 +00:00
|
|
|
SGInterpTable *sky_tbl;
|
1998-05-20 20:54:16 +00:00
|
|
|
|
|
|
|
public:
|
1998-04-22 13:24:04 +00:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
// position of the sun in various forms
|
|
|
|
|
|
|
|
// in geocentric coordinates
|
|
|
|
double sun_lon, sun_gc_lat;
|
|
|
|
|
|
|
|
// in cartesian coordiantes
|
1998-10-16 00:51:46 +00:00
|
|
|
Point3D fg_sunpos;
|
1998-04-22 13:24:04 +00:00
|
|
|
|
|
|
|
// (in view coordinates)
|
1999-10-03 18:49:39 +00:00
|
|
|
sgVec4 sun_vec;
|
1998-04-22 13:24:04 +00:00
|
|
|
|
|
|
|
// inverse (in view coordinates)
|
1999-10-03 18:49:39 +00:00
|
|
|
sgVec4 sun_vec_inv;
|
1998-04-22 13:24:04 +00:00
|
|
|
|
1998-07-22 21:45:37 +00:00
|
|
|
// the angle between the sun and the local horizontal (in radians)
|
1998-04-22 13:24:04 +00:00
|
|
|
double sun_angle;
|
|
|
|
|
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
|
|
|
|
// wanted to travel towards the sun.
|
|
|
|
double sun_rotation;
|
|
|
|
|
1999-03-22 02:08:05 +00:00
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
// 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;
|
|
|
|
|
|
|
|
// in cartesian coordiantes
|
|
|
|
Point3D fg_moonpos;
|
|
|
|
|
|
|
|
// (in view coordinates)
|
|
|
|
GLfloat moon_vec[4];
|
|
|
|
|
|
|
|
// inverse (in view coordinates)
|
|
|
|
GLfloat moon_vec_inv[4];
|
|
|
|
|
|
|
|
// the angle between the moon and the local horizontal (in radians)
|
|
|
|
double moon_angle;
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
1998-04-22 13:24:04 +00:00
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
// Derived lighting values
|
|
|
|
|
|
|
|
// ambient component
|
2000-05-27 06:40:55 +00:00
|
|
|
GLfloat scene_ambient[4];
|
1998-04-22 13:24:04 +00:00
|
|
|
|
|
|
|
// diffuse component
|
2000-05-27 06:40:55 +00:00
|
|
|
GLfloat scene_diffuse[4];
|
1998-04-22 13:24:04 +00:00
|
|
|
|
2002-07-21 15:40:51 +00:00
|
|
|
// diffuse component
|
|
|
|
GLfloat scene_specular[4];
|
|
|
|
|
1998-04-22 13:24:04 +00:00
|
|
|
// fog color
|
|
|
|
GLfloat fog_color[4];
|
|
|
|
|
1998-07-22 21:45:37 +00:00
|
|
|
// fog color adjusted for sunset effects
|
|
|
|
GLfloat adj_fog_color[4];
|
|
|
|
|
1998-04-22 13:24:04 +00:00
|
|
|
// clear screen color
|
|
|
|
GLfloat sky_color[4];
|
|
|
|
|
1998-05-20 20:54:16 +00:00
|
|
|
// Constructor
|
|
|
|
fgLIGHT( void );
|
1998-04-22 13:24:04 +00:00
|
|
|
|
1998-05-20 20:54:16 +00:00
|
|
|
// initialize lighting tables
|
|
|
|
void Init( void );
|
1998-04-22 13:24:04 +00:00
|
|
|
|
1998-05-20 20:54:16 +00:00
|
|
|
// update lighting parameters based on current sun position
|
|
|
|
void Update( void);
|
1998-04-22 13:24:04 +00:00
|
|
|
|
1998-07-22 21:45:37 +00:00
|
|
|
// calculate fog color adjusted for sunrise/sunset effects
|
|
|
|
void UpdateAdjFog( void );
|
|
|
|
|
1998-05-20 20:54:16 +00:00
|
|
|
// Destructor
|
|
|
|
~fgLIGHT( void );
|
|
|
|
};
|
1998-04-22 13:24:04 +00:00
|
|
|
|
|
|
|
|
1998-05-20 20:54:16 +00:00
|
|
|
// Global shared light parameter structure
|
|
|
|
extern fgLIGHT cur_light_params;
|
|
|
|
|
|
|
|
|
1998-04-22 13:24:04 +00:00
|
|
|
#endif // _LIGHT_HXX
|