]> git.mxchange.org Git - flightgear.git/blob - Time/light.hxx
Tweaked FDM interface.
[flightgear.git] / 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     // Derived lighting values
85
86     // ambient component
87     GLfloat scene_ambient[3];
88
89     // diffuse component
90     GLfloat scene_diffuse[3];
91
92     // fog color
93     GLfloat fog_color[4];
94
95     // fog color adjusted for sunset effects
96     GLfloat adj_fog_color[4];
97
98     // clear screen color
99     GLfloat sky_color[4];
100
101     // Constructor
102     fgLIGHT( void );
103
104     // initialize lighting tables
105     void Init( void );
106
107     // update lighting parameters based on current sun position
108     void Update( void);
109
110     // calculate fog color adjusted for sunrise/sunset effects
111     void UpdateAdjFog( void );
112
113     // Destructor
114     ~fgLIGHT( void );
115 };
116
117
118 // Global shared light parameter structure
119 extern fgLIGHT cur_light_params;
120
121
122 #endif // _LIGHT_HXX
123
124
125 // $Log$
126 // Revision 1.8  1998/10/16 00:56:10  curt
127 // Converted to Point3D class.
128 //
129 // Revision 1.7  1998/08/29 13:11:33  curt
130 // Bernie Bright writes:
131 //   I've created some new classes to enable pointers-to-functions and
132 //   pointers-to-class-methods to be treated like objects.  These objects
133 //   can be registered with fgEVENT_MGR.
134 //
135 //   File "Include/fg_callback.hxx" contains the callback class defns.
136 //
137 //   Modified fgEVENT and fgEVENT_MGR to use the callback classes.  Also
138 //   some minor tweaks to STL usage.
139 //
140 //   Added file "Include/fg_stl_config.h" to deal with STL portability
141 //   issues.  I've added an initial config for egcs (and probably gcc-2.8.x).
142 //   I don't have access to Visual C++ so I've left that for someone else.
143 //   This file is influenced by the stl_config.h file delivered with egcs.
144 //
145 //   Added "Include/auto_ptr.hxx" which contains an implementation of the
146 //   STL auto_ptr class which is not provided in all STL implementations
147 //   and is needed to use the callback classes.
148 //
149 //   Deleted fgLightUpdate() which was just a wrapper to call
150 //   fgLIGHT::Update().
151 //
152 //   Modified fg_init.cxx to register two method callbacks in place of the
153 //   old wrapper functions.
154 //
155 // Revision 1.6  1998/07/22 21:45:39  curt
156 // fg_time.cxx: Removed call to ctime() in a printf() which should be harmless
157 //   but seems to be triggering a bug.
158 // light.cxx: Added code to adjust fog color based on sunrise/sunset effects
159 //   and view orientation.  This is an attempt to match the fog color to the
160 //   sky color in the center of the screen.  You see discrepancies at the
161 //   edges, but what else can be done?
162 // sunpos.cxx: Caculate local direction to sun here.  (what compass direction
163 //   do we need to face to point directly at sun)
164 //
165 // Revision 1.5  1998/07/08 14:48:39  curt
166 // polar3d.h renamed to polar3d.hxx
167 //
168 // Revision 1.4  1998/05/20 20:54:17  curt
169 // Converted fgLIGHT to a C++ class.
170 //
171 // Revision 1.3  1998/05/02 01:53:18  curt
172 // Fine tuning mktime() support because of varying behavior on different
173 // platforms.
174 //
175 // Revision 1.2  1998/04/24 00:52:31  curt
176 // Wrapped "#include <config.h>" in "#ifdef HAVE_CONFIG_H"
177 // Fog color fixes.
178 // Separated out lighting calcs into their own file.
179 //
180 // Revision 1.1  1998/04/22 13:24:06  curt
181 // C++ - ifiing the code a bit.
182 // Starting to reorginize some of the lighting calcs to use a table lookup.
183 //
184 //