Debian Codegraph @

lib/database/src/so/nodes/SoPointLight.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 | SoPointLight
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/elements/SoLightAttenuationElement.h>
58 #include <Inventor/nodes/SoPointLight.h>
59
60 SO_NODE_SOURCE(SoPointLight);
61
62 ////////////////////////////////////////////////////////////////////////
63 //
64 // Description:
65 // Constructor
66 //
67 // Use: public
68
69 SoPointLight::SoPointLight()
70 //
71 ////////////////////////////////////////////////////////////////////////
72 {
73 SO_NODE_CONSTRUCTOR(SoPointLight);
74 SO_NODE_ADD_FIELD(location, (0.0, 0.0, 1.0));
75 isBuiltIn = TRUE;
76 }
77
78 ////////////////////////////////////////////////////////////////////////
79 //
80 // Description:
81 // Destructor
82 //
83 // Use: private
84
85 SoPointLight::~SoPointLight()
86 //
87 ////////////////////////////////////////////////////////////////////////
88 {
89 }
90
91 ////////////////////////////////////////////////////////////////////////
92 //
93 // Description:
94 // Creates a light source during rendering.
95 //
96 // Use: extender
97
98 void
99 SoPointLight::GLRender(SoGLRenderAction *action)
100 //
101 ////////////////////////////////////////////////////////////////////////
102 {
103 int32_t id;
104
105 // Don't turn light on if it's off
106 if (! on.getValue())
107 return;
108
109 // Get a new light id to use for this light
110 id = SoGLLightIdElement::increment(action->getState());
111
112 // Element is being overridden or we have too many sources for GL
113 // to handle? Skip the whole deal.
114 if (id < 0)
115 return;
116
117 //
118 // Create a new source and send it to GL. The SoGLLightIdElement
119 // has already enabled the light.
120 //
121
122 SbVec3f v3;
123 SbVec4f v4;
124
125 id = GL_LIGHT0 + id;
126
127 // RGBA intensities of source are the product of the color and
128 // intensity, with 1.0 alpha
129 v3 = intensity.getValue() * color.getValue();
130 v4.setValue(v3[0], v3[1], v3[2], 1.0);
131
132 glLightfv((GLenum) id, GL_AMBIENT, SbVec4f(0.0, 0.0, 0.0, 1.0).getValue());
133 glLightfv((GLenum) id, GL_DIFFUSE, v4.getValue());
134 glLightfv((GLenum) id, GL_SPECULAR, v4.getValue());
135
136 // Set position
137 v3 = location.getValue();
138 v4.setValue(v3[0], v3[1], v3[2], 1.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 is accessed from the state
146 const SbVec3f &atten = SoLightAttenuationElement::get(action->getState());
147 glLightf((GLenum) id, GL_CONSTANT_ATTENUATION, atten[2]);
148 glLightf((GLenum) id, GL_LINEAR_ATTENUATION, atten[1]);
149 glLightf((GLenum) id, GL_QUADRATIC_ATTENUATION, atten[0]);
150 }