Panda3D
polylightNode.I
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file polylightNode.I
10  * @author sshodhan
11  * @date 2004-06-02
12  */
13 
14 /**
15  * Returns true if the two lights are equivalent that is, all their properties
16  * are same
17  */
18 INLINE bool PolylightNode::
19 operator == (const PolylightNode &other) const {
20  return (compare_to(other) == 0);
21 }
22 
23 /**
24  * Returns true if the two lights are not equivalent.
25  */
26 INLINE bool PolylightNode::
27 operator != (const PolylightNode &other) const {
28  return (compare_to(other) != 0);
29 }
30 
31 /**
32  * Returns true if this PolylightNode sorts before the other one, false
33  * otherwise. The sorting order of two nonequivalent PolylightNodes is
34  * consistent but undefined, and is useful only for storing PolylightNodes in
35  * a sorted container like an STL set.
36  */
37 INLINE bool PolylightNode::
38 operator < (const PolylightNode &other) const {
39  return (compare_to(other) < 0);
40 }
41 
42 /**
43  * Is this light is enabled/disabled?
44  */
45 INLINE bool PolylightNode::
46 is_enabled() const {
47  return _enabled;
48 }
49 
50 /**
51  * Enable this light
52  */
53 INLINE void PolylightNode::
55  _enabled=true;
56 }
57 
58 /**
59  * Disable this light
60  */
61 INLINE void PolylightNode::
63  _enabled=false;
64 }
65 
66 /**
67  * Set this light's position
68  */
69 INLINE void PolylightNode::
70 set_pos(const LPoint3 &position) {
71  _position = position;
72 }
73 
74 /**
75  * Set this light's position
76  */
77 INLINE void PolylightNode::
78 set_pos(PN_stdfloat x, PN_stdfloat y, PN_stdfloat z){
79  _position[0]=x;
80  _position[1]=y;
81  _position[2]=z;
82 }
83 
84 /**
85  * Returns position as a LPoint3
86  */
87 INLINE LPoint3 PolylightNode::
88 get_pos() const {
89  return _position;
90 }
91 
92 /**
93  * Set radius of the spherical light volume
94  */
95 INLINE void PolylightNode::
96 set_radius(PN_stdfloat r){
97  _radius=r;
98 }
99 
100 /**
101  * Get radius of the spherical light volume
102  */
103 INLINE PN_stdfloat PolylightNode::
104 get_radius() const {
105  return _radius;
106 }
107 
108 /**
109  * Set ALINEAR or AQUADRATIC attenuation
110  */
111 INLINE bool PolylightNode::
112 set_attenuation(PolylightNode::Attenuation_Type type){
113  nassertr(type == ALINEAR || type == AQUADRATIC,false);
114  _attenuation_type=type;
115  return true;
116 
117 }
118 
119 /**
120  * Get "linear" or "quadratic" attenuation type
121  */
122 INLINE PolylightNode::Attenuation_Type PolylightNode::
124  return _attenuation_type;
125 }
126 
127 /**
128  * Set the quadratic attenuation factor a0 fd = 1 / ( a0 + a1*distance +
129  * a2*distance*distance)
130  */
131 INLINE void PolylightNode::
132 set_a0(PN_stdfloat a0){
133  _a0=a0;
134 }
135 
136 /**
137  * Set the quadratic attenuation factor a1 fd = 1 / ( a0 + a1*distance +
138  * a2*distance*distance)
139  */
140 INLINE void PolylightNode::
141 set_a1(PN_stdfloat a1){
142  _a1=a1;
143 }
144 
145 /**
146  * Set the quadratic attenuation factor a2 fd = 1 / ( a0 + a1*distance +
147  * a2*distance*distance)
148  */
149 INLINE void PolylightNode::
150 set_a2(PN_stdfloat a2){
151  _a2=a2;
152 }
153 
154 /**
155  * Get the quadratic attenuation factor a0 fd = 1 / ( a0 + a1*distance +
156  * a2*distance*distance)
157  */
158 INLINE PN_stdfloat PolylightNode::
159 get_a0() const {
160  return _a0;
161 }
162 
163 /**
164  * Get the quadratic attenuation factor a1 fd = 1 / ( a0 + a1*distance +
165  * a2*distance*distance)
166  */
167 INLINE PN_stdfloat PolylightNode::
168 get_a1() const {
169  return _a1;
170 }
171 
172 /**
173  * Get the quadratic attenuation factor a2 fd = 1 / ( a0 + a1*distance +
174  * a2*distance*distance)
175  */
176 INLINE PN_stdfloat PolylightNode::
177 get_a2() const {
178  return _a2;
179 }
180 
181 /**
182  * Set flickering to true so at every loop this light's color is varied based
183  * on flicker_type
184  */
185 INLINE void PolylightNode::
187  _flickering=true;
188 }
189 
190 /**
191  * Turn flickering off
192  */
193 INLINE void PolylightNode::
195  _flickering=false;
196 }
197 
198 /**
199  * Check is this light is flickering
200  */
201 INLINE bool PolylightNode::
202 is_flickering() const {
203  return _flickering;
204 }
205 
206 /**
207  * Flicker type can be FRANDOM or FSIN At a later point there might be a
208  * FCUSTOM Custom flicker will be a set of fix points recorded by animating
209  * the light's intensity
210  */
211 INLINE bool PolylightNode::
212 set_flicker_type(PolylightNode::Flicker_Type type){
213  nassertr(type == FRANDOM || type == FSIN,false);
214 
215  _flicker_type=type;
216  return true;
217 }
218 
219 /**
220  * Returns FRANDOM or FSIN
221  */
222 INLINE PolylightNode::Flicker_Type PolylightNode::
224  return _flicker_type;
225 }
226 
227 /**
228  * Set the offset value for the random and sin flicker variations... used to
229  * tweak the flicker This value is added to the variation
230  */
231 INLINE void PolylightNode::
232 set_offset(PN_stdfloat offset){
233  _offset=offset;
234 }
235 
236 /**
237  * Get the offset value for the random and sin flicker variations
238  */
239 INLINE PN_stdfloat PolylightNode::
240 get_offset() const {
241  return _offset;
242 }
243 
244 /**
245  * Set the scale value for the random and sin flicker variations... used to
246  * tweak the flicker This value is multiplied with the variation
247  */
248 INLINE void PolylightNode::
249 set_scale(PN_stdfloat scale){
250  _scale=scale;
251 }
252 
253 /**
254  * Get the scale value for the random and sin flicker variations
255  */
256 INLINE PN_stdfloat PolylightNode::
257 get_scale() const {
258  return _scale;
259 }
260 
261 /**
262  * Set the step size for the sin function in flicker This is the increment
263  * size for the value supplied to the sin function
264  */
265 INLINE void PolylightNode::
266 set_step_size(PN_stdfloat step){
267  _step_size=step;
268 }
269 
270 /**
271  * Get the step size for the sin function in flicker This is the increment
272  * size for the value supplied to the sin function
273  */
274 INLINE PN_stdfloat PolylightNode::
275 get_step_size() const {
276  return _step_size;
277 }
278 
279 /**
280  * Set the light's color...
281  */
282 INLINE void PolylightNode::
283 set_color(const LColor &color) {
284  // PandaNode::set_attrib(ColorAttrib::make_flat(color));
285  _color = color;
286 }
287 
288 /**
289  * Set the light's color... 3 floats between 0 and 1
290  */
291 INLINE void PolylightNode::
292 set_color(PN_stdfloat r, PN_stdfloat g, PN_stdfloat b) {
293  /*
294  LColor color;
295  color[0] = r;
296  color[1] = g;
297  color[2] = b;
298  color[3] = 1.0;
299  PandaNode::set_attrib(ColorAttrib::make_flat(color));
300  */
301  _color[0] = r;
302  _color[1] = g;
303  _color[2] = b;
304  _color[3] = 1.0;
305 }
306 
307 /**
308  * Returns the light's color as LColor
309  */
310 INLINE LColor PolylightNode::
311 get_color() const {
312  return _color;
313 }
314 
315 /**
316  * This differs from get_color in that when applying the light color we need
317  * to make sure that a color flattening external to the PolylightNode is not
318  * ignored.
319  */
320 INLINE LColor PolylightNode::
322 
323  const RenderAttrib *attrib =
324  PandaNode::get_attrib(ColorAttrib::get_class_type());
325  if (attrib != nullptr) {
326  const ColorAttrib *ca = DCAST(ColorAttrib, attrib);
327  if (ca->get_color_type() == ColorAttrib::T_flat) {
328  return ca->get_color();
329  }
330  }
331 
332  return _color;
333 
334 }
335 
336 
337 /**
338  * Set frequency of sin flicker
339  */
340 INLINE void PolylightNode::
341 set_freq(PN_stdfloat f) {
342  _sin_freq=f;
343 }
344 
345 /**
346  * Get frequency of sin flicker
347  */
348 INLINE PN_stdfloat PolylightNode::
349 get_freq() const {
350  return _sin_freq;
351 }
void set_a2(PN_stdfloat a2)
Set the quadratic attenuation factor a2 fd = 1 / ( a0 + a1*distance + a2*distance*distance)
void set_a0(PN_stdfloat a0)
Set the quadratic attenuation factor a0 fd = 1 / ( a0 + a1*distance + a2*distance*distance)
This is the base class for a number of render attributes (other than transform) that may be set on sc...
Definition: renderAttrib.h:51
PN_stdfloat get_a2() const
Get the quadratic attenuation factor a2 fd = 1 / ( a0 + a1*distance + a2*distance*distance)
PN_stdfloat get_a0() const
Get the quadratic attenuation factor a0 fd = 1 / ( a0 + a1*distance + a2*distance*distance)
bool set_flicker_type(Flicker_Type type)
Flicker type can be FRANDOM or FSIN At a later point there might be a FCUSTOM Custom flicker will be ...
PN_stdfloat get_radius() const
Get radius of the spherical light volume.
void set_freq(PN_stdfloat f)
Set frequency of sin flicker.
PN_stdfloat get_offset() const
Get the offset value for the random and sin flicker variations.
get_color
If the type is T_flat or T_off, this returns the color that will be applied to geometry.
Definition: colorAttrib.h:47
int compare_to(const PolylightNode &other) const
Returns a number less than zero if this PolylightNode sorts before the other one, greater than zero i...
void disable()
Disable this light.
Definition: polylightNode.I:62
void set_radius(PN_stdfloat r)
Set radius of the spherical light volume.
Definition: polylightNode.I:96
Attenuation_Type get_attenuation() const
Get "linear" or "quadratic" attenuation type.
bool is_enabled() const
Is this light is enabled/disabled?
Definition: polylightNode.I:46
PN_stdfloat get_step_size() const
Get the step size for the sin function in flicker This is the increment size for the value supplied t...
void set_pos(const LPoint3 &position)
Set this light's position.
Definition: polylightNode.I:70
void set_step_size(PN_stdfloat step)
Set the step size for the sin function in flicker This is the increment size for the value supplied t...
bool operator==(const PolylightNode &other) const
Returns true if the two lights are equivalent that is, all their properties are same.
Definition: polylightNode.I:19
LPoint3 get_pos() const
Returns position as a LPoint3.
Definition: polylightNode.I:88
bool operator !=(const PolylightNode &other) const
Returns true if the two lights are not equivalent.
Definition: polylightNode.I:27
PN_stdfloat get_freq() const
Get frequency of sin flicker.
bool operator<(const PolylightNode &other) const
Returns true if this PolylightNode sorts before the other one, false otherwise.
Definition: polylightNode.I:38
void flicker_on()
Set flickering to true so at every loop this light's color is varied based on flicker_type.
void flicker_off()
Turn flickering off.
bool set_attenuation(Attenuation_Type type)
Set ALINEAR or AQUADRATIC attenuation.
A PolylightNode.
Definition: polylightNode.h:29
bool is_flickering() const
Check is this light is flickering.
void set_a1(PN_stdfloat a1)
Set the quadratic attenuation factor a1 fd = 1 / ( a0 + a1*distance + a2*distance*distance)
PN_stdfloat get_a1() const
Get the quadratic attenuation factor a1 fd = 1 / ( a0 + a1*distance + a2*distance*distance)
void set_offset(PN_stdfloat offset)
Set the offset value for the random and sin flicker variations...
void set_scale(PN_stdfloat scale)
Set the scale value for the random and sin flicker variations...
PN_stdfloat get_scale() const
Get the scale value for the random and sin flicker variations.
Indicates what color should be applied to renderable geometry.
Definition: colorAttrib.h:27
void set_color(const LColor &color)
Set the light's color...
void enable()
Enable this light.
Definition: polylightNode.I:54
get_color_type
Returns the type of color specified by this ColorAttrib.
Definition: colorAttrib.h:46
Flicker_Type get_flicker_type() const
Returns FRANDOM or FSIN.
LColor get_color_scenegraph() const
This differs from get_color in that when applying the light color we need to make sure that a color f...
LColor get_color() const
Returns the light's color as LColor.