]> git.mxchange.org Git - simgear.git/blob - simgear/scene/tgdb/pt_lights.hxx
431233ceae776a8b81e74eba2cffbc698a26911a
[simgear.git] / simgear / scene / tgdb / pt_lights.hxx
1 // pt_lights.hxx -- build a 'directional' light on the fly
2 //
3 // Written by Curtis Olson, started March 2002.
4 //
5 // Copyright (C) 2002  Curtis L. Olson  - http://www.flightgear.org/~curt
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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20 //
21 // $Id$
22
23
24 #ifndef _SG_PT_LIGHTS_HXX
25 #define _SG_PT_LIGHTS_HXX
26
27
28 #ifndef __cplusplus
29 # error This library requires C++
30 #endif
31
32
33 #include <simgear/compiler.h>
34
35 #include STL_STRING
36 #include <vector>               // STL
37
38 #include <simgear/math/sg_types.hxx>
39 #include <simgear/scene/material/matlib.hxx>
40
41 SG_USING_STD(string);
42 SG_USING_STD(vector);
43
44
45 typedef vector < int > int_list;
46 typedef int_list::iterator int_list_iterator;
47 typedef int_list::const_iterator int_point_list_iterator;
48
49
50 // Generate a directional light.  This routines creates a
51 // 'directional' light that can only be viewed from within 90 degrees
52 // of the specified dir vector.
53
54 // To accomplish this, he routine creates a triangle with the 1st
55 // point coincident with the specified pt and the 2nd and 3rd points
56 // extending upward.  The 1st point is created with an 'alpha' value
57 // of 1 while the 2nd and 3rd points are created with an 'alpha' of
58 // 0.0.
59
60 // If the triangle is drawn in glPolygonMode(GL_FRONT, GL_POINT) mode,
61 // then two important things happen:
62
63 // 1) Only the 3 vertex points are drawn, the 2nd two with an alpha of
64 // 0 so actually only the desired point is rendered.
65
66 // 2) since we are drawing a triangle, back face culling takes care of
67 // eliminating this poing when the view angle relative to dir is
68 // greater than 90 degrees.
69
70 // The final piece of this puzzle is that if we now use environment
71 // mapping on this point, via an appropriate texture we can then
72 // control the intensity and color of the point based on the view
73 // angle relative to 'dir' the optimal view direction of the light
74 // (i.e. the direction the light is pointing.)
75
76 // Yes this get's to be long and convoluted.  If you can suggest a
77 // simpler way, please do! :-)
78
79 osg::Node *SGMakeDirectionalLights( const point_list &nodes,
80                                     const point_list &normals,
81                                     const int_list &pnt_i,
82                                     const int_list &nml_i,
83                                     SGMaterialLib *matlib,
84                                     const string &material,
85                                     const SGVec3d& dup );
86
87 // Specify the way we want to draw directional point lights (assuming the
88 // appropriate extensions are available.)
89
90 void SGConfigureDirectionalLights( bool use_point_sprites,
91                                    bool enhanced_lighting,
92                                    bool distance_attenuation );
93
94
95 #endif // _SG_PT_LIGHTS_HXX