]> git.mxchange.org Git - flightgear.git/blob - src/Time/light.hxx
Added static port system and a new altimeter model connected to it.
[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/glut.h>
42 #include <GL/gl.h>
43
44 #include <plib/sg.h>                    // plib include
45
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 {
52
53     // Lighting look up tables (based on sun angle with local horizon)
54     SGInterpTable *ambient_tbl;
55     SGInterpTable *diffuse_tbl;
56     SGInterpTable *specular_tbl;
57     SGInterpTable *sky_tbl;
58
59 public:
60
61     ///////////////////////////////////////////////////////////
62     // position of the sun in various forms
63
64     // in geocentric coordinates
65     double sun_lon, sun_gc_lat;
66
67     // in cartesian coordiantes
68     Point3D fg_sunpos;
69
70     // (in view coordinates)
71     sgVec4 sun_vec;
72
73     // inverse (in view coordinates)
74     sgVec4 sun_vec_inv;
75
76     // the angle between the sun and the local horizontal (in radians)
77     double sun_angle;
78
79     // the rotation around our vertical axis of the sun (relative to
80     // due south with positive numbers going in the counter clockwise
81     // direction.)  This is the direction we'd need to face if we
82     // wanted to travel towards the sun.
83     double sun_rotation;
84
85     ///////////////////////////////////////////////////////////
86     // Have the same for the moon. Useful for having some light at night
87     // and stuff. I (Durk) also want to use this for adding similar 
88     // coloring effects to the moon as I did to the sun. 
89     ///////////////////////////////////////////////////////////
90     // position of the moon in various forms
91
92     // in geocentric coordinates
93     double moon_lon, moon_gc_lat;
94
95     // in cartesian coordiantes
96     Point3D fg_moonpos;
97
98     // (in view coordinates)
99     GLfloat moon_vec[4];
100
101     // inverse (in view coordinates)
102     GLfloat moon_vec_inv[4];
103
104     // the angle between the moon and the local horizontal (in radians)
105     double moon_angle;
106
107     // the rotation around our vertical axis of the moon (relative to
108     // due south with positive numbers going in the counter clockwise
109     // direction.)  This is the direction we'd need to face if we
110     // wanted to travel towards the sun.
111     double moon_rotation;
112
113     ///////////////////////////////////////////////////////////
114     // Derived lighting values
115
116     // ambient component
117     GLfloat scene_ambient[4];
118
119     // diffuse component
120     GLfloat scene_diffuse[4];
121
122     // diffuse component
123     GLfloat scene_specular[4];
124
125     // fog color
126     GLfloat fog_color[4];
127
128     // fog color adjusted for sunset effects
129     GLfloat adj_fog_color[4];
130
131     // clear screen color
132     GLfloat sky_color[4];
133
134     // Constructor
135     fgLIGHT( void );
136
137     // initialize lighting tables
138     void Init( void );
139
140     // update lighting parameters based on current sun position
141     void Update( void);
142
143     // calculate fog color adjusted for sunrise/sunset effects
144     void UpdateAdjFog( void );
145
146     // Destructor
147     ~fgLIGHT( void );
148 };
149
150
151 // Global shared light parameter structure
152 extern fgLIGHT cur_light_params;
153
154
155 #endif // _LIGHT_HXX