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