Debian Codegraph @

lib/database/src/so/nodes/SoDirectionalLight.c++

raw
1 /*
2 *
3 * Copyright (C) 2000 Silicon Graphics, Inc. All Rights Reserved.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * Further, this software is distributed without any warranty that it is
16 * free of the rightful claim of any third person regarding infringement
17 * or the like. Any license provided herein, whether implied or
18 * otherwise, applies only to this software file. Patent licenses, if
19 * any, provided herein do not apply to combinations of this program with
20 * other software, or any other product whatsoever.
21 *
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with this library; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 *
26 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
27 * Mountain View, CA 94043, or:
28 *
29 * http://www.sgi.com
30 *
31 * For further information regarding this notice, see:
32 *
33 * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
34 *
35 */
36
37 /*
38 * Copyright (C) 1990,91 Silicon Graphics, Inc.
39 *
40 _______________________________________________________________________
41 ______________ S I L I C O N G R A P H I C S I N C . ____________
42 |
43 | $Revision: 1.1.1.1 $
44 |
45 | Classes:
46 | SoDirectionalLight
47 |
48 | Author(s) : Paul S. Strauss
49 |
50 ______________ S I L I C O N G R A P H I C S I N C . ____________
51 _______________________________________________________________________
52 */
53
54 #include <GL/gl.h>
55 #include <Inventor/actions/SoGLRenderAction.h>
56 #include <Inventor/elements/SoGLLightIdElement.h>
57 #include <Inventor/nodes/SoDirectionalLight.h>
58
59 SO_NODE_SOURCE(SoDirectionalLight);
60
61 ////////////////////////////////////////////////////////////////////////
62 //
63 // Description:
64 // Constructor
65 //
66 // Use: public
67
68 SoDirectionalLight::SoDirectionalLight()
69 //
70 ////////////////////////////////////////////////////////////////////////
71 {
72 SO_NODE_CONSTRUCTOR(SoDirectionalLight);
73 SO_NODE_ADD_FIELD(direction, (0.0, 0.0, -1.0));
74 isBuiltIn = TRUE;
75 }
76
77 ////////////////////////////////////////////////////////////////////////
78 //
79 // Description:
80 // Destructor
81 //
82 // Use: private
83
84 SoDirectionalLight::~SoDirectionalLight()
85 //
86 ////////////////////////////////////////////////////////////////////////
87 {
88 }
89
90 ////////////////////////////////////////////////////////////////////////
91 //
92 // Description:
93 // Creates a light source during rendering.
94 //
95 // Use: extender
96
97 void
98 SoDirectionalLight::GLRender(SoGLRenderAction *action)
99 //
100 ////////////////////////////////////////////////////////////////////////
101 {
102 int32_t id;
103
104 // Don't turn light on if it's off
105 if (! on.getValue())
106 return;
107
108 // Get a new light id to use for this light
109 id = SoGLLightIdElement::increment(action->getState());
110
111 // Element is being overridden or we have too many sources for GL
112 // to handle? Skip the whole deal.
113 if (id < 0)
114 return;
115
116 //
117 // Create a new source and send it to GL. The SoGLLightIdElement
118 // has already enabled the light.
119 //
120
121 SbVec3f v3;
122 SbVec4f v4;
123
124 id = GL_LIGHT0 + id;
125
126 // RGBA intensities of source are the product of the color and
127 // intensity, with 1.0 alpha
128 v3 = intensity.getValue() * color.getValue();
129 v4.setValue(v3[0], v3[1], v3[2], 1.0);
130
131 glLightfv((GLenum) id, GL_AMBIENT, SbVec4f(0.0, 0.0, 0.0, 1.0).getValue());
132 glLightfv((GLenum) id, GL_DIFFUSE, v4.getValue());
133 glLightfv((GLenum) id, GL_SPECULAR, v4.getValue());
134
135 // "Position" is the direction vector negated with a 0.0 w
136 // component. Yet another GL peccadillo.
137 v3 = direction.getValue();
138 v4.setValue(-v3[0], -v3[1], -v3[2], 0.0);
139 glLightfv((GLenum) id, GL_POSITION, v4.getValue());
140
141 // Make sure no spotlight stuff is on
142 glLightf((GLenum) id, GL_SPOT_EXPONENT, 0.0);
143 glLightf((GLenum) id, GL_SPOT_CUTOFF, 180.0);
144
145 // Attenuation does not matter for directional sources.
146 }