Panda3D
 All Classes Functions Variables Enumerations
lightAttrib.I
1 // Filename: lightAttrib.I
2 // Created by: drose (26Mar02)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 
16 ////////////////////////////////////////////////////////////////////
17 // Function: LightAttrib::Constructor
18 // Access: Protected
19 // Description: Use LightAttrib::make() to construct a new
20 // LightAttrib object.
21 ////////////////////////////////////////////////////////////////////
22 INLINE LightAttrib::
23 LightAttrib() {
24  _off_all_lights = false;
25 }
26 
27 ////////////////////////////////////////////////////////////////////
28 // Function: LightAttrib::Copy Constructor
29 // Access: Protected
30 // Description: Use LightAttrib::make() to construct a new
31 // LightAttrib object. The copy constructor is only
32 // defined to facilitate methods like add_on_light().
33 ////////////////////////////////////////////////////////////////////
34 INLINE LightAttrib::
35 LightAttrib(const LightAttrib &copy) :
36  _on_lights(copy._on_lights),
37  _off_lights(copy._off_lights),
38  _off_all_lights(copy._off_all_lights)
39 {
40 }
41 
42 ////////////////////////////////////////////////////////////////////
43 // Function: LightAttrib::get_num_on_lights
44 // Access: Published
45 // Description: Returns the number of lights that are turned on by
46 // the attribute.
47 ////////////////////////////////////////////////////////////////////
48 INLINE int LightAttrib::
50  return _on_lights.size();
51 }
52 
53 ////////////////////////////////////////////////////////////////////
54 // Function: LightAttrib::get_on_light
55 // Access: Published
56 // Description: Returns the nth light turned on by the attribute,
57 // sorted in render order.
58 ////////////////////////////////////////////////////////////////////
60 get_on_light(int n) const {
61  nassertr(n >= 0 && n < (int)_on_lights.size(), NodePath::fail());
62  return _on_lights[n];
63 }
64 
65 ////////////////////////////////////////////////////////////////////
66 // Function: LightAttrib::has_on_light
67 // Access: Published
68 // Description: Returns true if the indicated light is turned on by
69 // the attrib, false otherwise.
70 ////////////////////////////////////////////////////////////////////
71 INLINE bool LightAttrib::
72 has_on_light(const NodePath &light) const {
73  return _on_lights.find(light) != _on_lights.end();
74 }
75 
76 ////////////////////////////////////////////////////////////////////
77 // Function: LightAttrib::get_num_off_lights
78 // Access: Published
79 // Description: Returns the number of lights that are turned off by
80 // the attribute.
81 ////////////////////////////////////////////////////////////////////
82 INLINE int LightAttrib::
84  return _off_lights.size();
85 }
86 
87 ////////////////////////////////////////////////////////////////////
88 // Function: LightAttrib::get_off_light
89 // Access: Published
90 // Description: Returns the nth light turned off by the attribute,
91 // sorted in arbitrary (pointer) order.
92 ////////////////////////////////////////////////////////////////////
94 get_off_light(int n) const {
95  nassertr(n >= 0 && n < (int)_off_lights.size(), NodePath::fail());
96  return _off_lights[n];
97 }
98 
99 ////////////////////////////////////////////////////////////////////
100 // Function: LightAttrib::has_off_light
101 // Access: Published
102 // Description: Returns true if the indicated light is turned off by
103 // the attrib, false otherwise.
104 ////////////////////////////////////////////////////////////////////
105 INLINE bool LightAttrib::
106 has_off_light(const NodePath &light) const {
107  return _off_lights.find(light) != _off_lights.end() ||
108  (_off_all_lights && !has_on_light(light));
109 }
110 
111 ////////////////////////////////////////////////////////////////////
112 // Function: LightAttrib::has_all_off
113 // Access: Published
114 // Description: Returns true if this attrib turns off all lights
115 // (although it may also turn some on).
116 ////////////////////////////////////////////////////////////////////
117 INLINE bool LightAttrib::
118 has_all_off() const {
119  return _off_all_lights;
120 }
121 
122 ////////////////////////////////////////////////////////////////////
123 // Function: LightAttrib::is_identity
124 // Access: Published
125 // Description: Returns true if this is an identity attrib: it does
126 // not change the set of lights in use.
127 ////////////////////////////////////////////////////////////////////
128 INLINE bool LightAttrib::
129 is_identity() const {
130  return _on_lights.empty() && _off_lights.empty() && !_off_all_lights;
131 }
132 
133 ////////////////////////////////////////////////////////////////////
134 // Function: LightAttrib::check_filtered
135 // Access: Private
136 // Description: Confirms whether the _filtered table is still valid.
137 // It may become invalid if someone calls
138 // Light::set_priority().
139 //
140 // If the table is invalid, transparently empties it
141 // before returning.
142 ////////////////////////////////////////////////////////////////////
143 INLINE void LightAttrib::
144 check_filtered() const {
145  if (_sort_seq != Light::get_sort_seq()) {
146  ((LightAttrib *)this)->sort_on_lights();
147  }
148 }
NodePath get_off_light(int n) const
Returns the nth light turned off by the attribute, sorted in arbitrary (pointer) order.
Definition: lightAttrib.I:94
bool empty() const
Returns true if the ordered vector is empty, false otherwise.
iterator_0 end()
Returns the iterator that marks the end of the ordered vector.
bool has_on_light(const NodePath &light) const
Returns true if the indicated light is turned on by the attrib, false otherwise.
Definition: lightAttrib.I:72
bool has_off_light(const NodePath &light) const
Returns true if the indicated light is turned off by the attrib, false otherwise. ...
Definition: lightAttrib.I:106
static NodePath fail()
Creates a NodePath with the ET_fail error type set.
Definition: nodePath.I:185
bool is_identity() const
Returns true if this is an identity attrib: it does not change the set of lights in use...
Definition: lightAttrib.I:129
static UpdateSeq get_sort_seq()
Returns a global sequence number that is incremented any time any Light in the world changes sort or ...
Definition: light.I:132
int get_num_on_lights() const
Returns the number of lights that are turned on by the attribute.
Definition: lightAttrib.I:49
size_type_0 size() const
Returns the number of elements in the ordered vector.
bool has_all_off() const
Returns true if this attrib turns off all lights (although it may also turn some on).
Definition: lightAttrib.I:118
NodePath get_on_light(int n) const
Returns the nth light turned on by the attribute, sorted in render order.
Definition: lightAttrib.I:60
int get_num_off_lights() const
Returns the number of lights that are turned off by the attribute.
Definition: lightAttrib.I:83
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition: nodePath.h:165
Indicates which set of lights should be considered &quot;on&quot; to illuminate geometry at this level and belo...
Definition: lightAttrib.h:33