Panda3D
 All Classes Functions Variables Enumerations
lightAttrib.I
00001 // Filename: lightAttrib.I
00002 // Created by:  drose (26Mar02)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 
00016 ////////////////////////////////////////////////////////////////////
00017 //     Function: LightAttrib::Constructor
00018 //       Access: Protected
00019 //  Description: Use LightAttrib::make() to construct a new
00020 //               LightAttrib object.
00021 ////////////////////////////////////////////////////////////////////
00022 INLINE LightAttrib::
00023 LightAttrib() {
00024   _off_all_lights = false;
00025 }
00026 
00027 ////////////////////////////////////////////////////////////////////
00028 //     Function: LightAttrib::Copy Constructor
00029 //       Access: Protected
00030 //  Description: Use LightAttrib::make() to construct a new
00031 //               LightAttrib object.  The copy constructor is only
00032 //               defined to facilitate methods like add_on_light().
00033 ////////////////////////////////////////////////////////////////////
00034 INLINE LightAttrib::
00035 LightAttrib(const LightAttrib &copy) :
00036   _on_lights(copy._on_lights),
00037   _off_lights(copy._off_lights),
00038   _off_all_lights(copy._off_all_lights)
00039 {
00040 }
00041 
00042 ////////////////////////////////////////////////////////////////////
00043 //     Function: LightAttrib::get_num_on_lights
00044 //       Access: Published
00045 //  Description: Returns the number of lights that are turned on by
00046 //               the attribute.
00047 ////////////////////////////////////////////////////////////////////
00048 INLINE int LightAttrib::
00049 get_num_on_lights() const {
00050   return _on_lights.size();
00051 }
00052 
00053 ////////////////////////////////////////////////////////////////////
00054 //     Function: LightAttrib::get_on_light
00055 //       Access: Published
00056 //  Description: Returns the nth light turned on by the attribute,
00057 //               sorted in render order.
00058 ////////////////////////////////////////////////////////////////////
00059 INLINE NodePath LightAttrib::
00060 get_on_light(int n) const {
00061   nassertr(n >= 0 && n < (int)_on_lights.size(), NodePath::fail());
00062   return _on_lights[n];
00063 }
00064 
00065 ////////////////////////////////////////////////////////////////////
00066 //     Function: LightAttrib::has_on_light
00067 //       Access: Published
00068 //  Description: Returns true if the indicated light is turned on by
00069 //               the attrib, false otherwise.
00070 ////////////////////////////////////////////////////////////////////
00071 INLINE bool LightAttrib::
00072 has_on_light(const NodePath &light) const {
00073   return _on_lights.find(light) != _on_lights.end();
00074 }
00075 
00076 ////////////////////////////////////////////////////////////////////
00077 //     Function: LightAttrib::get_num_off_lights
00078 //       Access: Published
00079 //  Description: Returns the number of lights that are turned off by
00080 //               the attribute.
00081 ////////////////////////////////////////////////////////////////////
00082 INLINE int LightAttrib::
00083 get_num_off_lights() const {
00084   return _off_lights.size();
00085 }
00086 
00087 ////////////////////////////////////////////////////////////////////
00088 //     Function: LightAttrib::get_off_light
00089 //       Access: Published
00090 //  Description: Returns the nth light turned off by the attribute,
00091 //               sorted in arbitrary (pointer) order.
00092 ////////////////////////////////////////////////////////////////////
00093 INLINE NodePath LightAttrib::
00094 get_off_light(int n) const {
00095   nassertr(n >= 0 && n < (int)_off_lights.size(), NodePath::fail());
00096   return _off_lights[n];
00097 }
00098 
00099 ////////////////////////////////////////////////////////////////////
00100 //     Function: LightAttrib::has_off_light
00101 //       Access: Published
00102 //  Description: Returns true if the indicated light is turned off by
00103 //               the attrib, false otherwise.
00104 ////////////////////////////////////////////////////////////////////
00105 INLINE bool LightAttrib::
00106 has_off_light(const NodePath &light) const {
00107   return _off_lights.find(light) != _off_lights.end() ||
00108     (_off_all_lights && !has_on_light(light));
00109 }
00110 
00111 ////////////////////////////////////////////////////////////////////
00112 //     Function: LightAttrib::has_all_off
00113 //       Access: Published
00114 //  Description: Returns true if this attrib turns off all lights
00115 //               (although it may also turn some on).
00116 ////////////////////////////////////////////////////////////////////
00117 INLINE bool LightAttrib::
00118 has_all_off() const {
00119   return _off_all_lights;
00120 }
00121 
00122 ////////////////////////////////////////////////////////////////////
00123 //     Function: LightAttrib::is_identity
00124 //       Access: Published
00125 //  Description: Returns true if this is an identity attrib: it does
00126 //               not change the set of lights in use.
00127 ////////////////////////////////////////////////////////////////////
00128 INLINE bool LightAttrib::
00129 is_identity() const {
00130   return _on_lights.empty() && _off_lights.empty() && !_off_all_lights;
00131 }
00132 
00133 ////////////////////////////////////////////////////////////////////
00134 //     Function: LightAttrib::check_filtered
00135 //       Access: Private
00136 //  Description: Confirms whether the _filtered table is still valid.
00137 //               It may become invalid if someone calls
00138 //               Light::set_priority().
00139 //
00140 //               If the table is invalid, transparently empties it
00141 //               before returning.
00142 ////////////////////////////////////////////////////////////////////
00143 INLINE void LightAttrib::
00144 check_filtered() const {
00145   if (_sort_seq != Light::get_sort_seq()) {
00146     ((LightAttrib *)this)->sort_on_lights();
00147   }
00148 }
 All Classes Functions Variables Enumerations