Panda3D
 All Classes Functions Variables Enumerations
polylightNode.I
00001 // Filename: PolylightNodeEffect.I
00002 // Created by:  sshodhan (02Jun04)
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 ////////////////////////////////////////////////////////////////////
00018 //     Function: PolylightNode::operator ==
00019 //       Access: Published
00020 //  Description: Returns true if the two lights are equivalent
00021 //               that is, all their properties are same
00022 ////////////////////////////////////////////////////////////////////
00023 INLINE bool PolylightNode::
00024 operator == (const PolylightNode &other) const {
00025   return (compare_to(other) == 0);
00026 }
00027 
00028 ////////////////////////////////////////////////////////////////////
00029 //     Function: PolylightNode::operator !=
00030 //       Access: Published
00031 //  Description: Returns true if the two lights are not equivalent.
00032 ////////////////////////////////////////////////////////////////////
00033 INLINE bool PolylightNode::
00034 operator != (const PolylightNode &other) const {
00035   return (compare_to(other) != 0);
00036 }
00037 
00038 ////////////////////////////////////////////////////////////////////
00039 //     Function: PolylightNode::operator <
00040 //       Access: Published
00041 //  Description: Returns true if this PolylightNode sorts before the other
00042 //               one, false otherwise.  The sorting order of two
00043 //               nonequivalent PolylightNodes is consistent but undefined,
00044 //               and is useful only for storing PolylightNodes in a sorted
00045 //               container like an STL set.
00046 ////////////////////////////////////////////////////////////////////
00047 INLINE bool PolylightNode::
00048 operator < (const PolylightNode &other) const {
00049   return (compare_to(other) < 0);
00050 }
00051 
00052 ////////////////////////////////////////////////////////////////////
00053 //     Function: PolylightNode::is_enabled
00054 //       Access: Published
00055 //  Description: Is this light is enabled/disabled?
00056 ////////////////////////////////////////////////////////////////////
00057 INLINE bool PolylightNode::
00058 is_enabled() const {
00059   return _enabled;
00060 }
00061 
00062 ////////////////////////////////////////////////////////////////////
00063 //     Function: PolylightNode::enable
00064 //       Access: Published
00065 //  Description: Enable this light
00066 ////////////////////////////////////////////////////////////////////
00067 INLINE void PolylightNode::
00068 enable(){
00069   _enabled=true;
00070 }
00071 
00072 ////////////////////////////////////////////////////////////////////
00073 //     Function: PolylightNode::disable
00074 //       Access: Published
00075 //  Description: Disable this light
00076 ////////////////////////////////////////////////////////////////////
00077 INLINE void PolylightNode::
00078 disable(){
00079   _enabled=false;
00080 }
00081 
00082 ////////////////////////////////////////////////////////////////////
00083 //     Function: PolylightNode::set_pos
00084 //       Access: Published
00085 //  Description: Set this light's position
00086 ////////////////////////////////////////////////////////////////////
00087 INLINE void PolylightNode::
00088 set_pos(const LVecBase3 &position){
00089   _position = position;
00090 }
00091 
00092 
00093 ////////////////////////////////////////////////////////////////////
00094 //     Function: PolylightNode::set_pos
00095 //       Access: Published
00096 //  Description: Set this light's position
00097 ////////////////////////////////////////////////////////////////////
00098 INLINE void PolylightNode::
00099 set_pos(PN_stdfloat x, PN_stdfloat y, PN_stdfloat z){
00100   _position[0]=x;
00101   _position[1]=y;
00102   _position[2]=z;
00103 }
00104 
00105 ////////////////////////////////////////////////////////////////////
00106 //     Function: PolylightNode::get_pos
00107 //       Access: Published
00108 //  Description: Returns position as a LPoint3
00109 ////////////////////////////////////////////////////////////////////
00110 INLINE LVecBase3 PolylightNode::
00111 get_pos() const {
00112   return _position;
00113 }
00114 
00115 ////////////////////////////////////////////////////////////////////
00116 //     Function: PolylightNode::set_radius
00117 //       Access: Published
00118 //  Description: Set radius of the spherical light volume
00119 ////////////////////////////////////////////////////////////////////
00120 INLINE void PolylightNode::
00121 set_radius(PN_stdfloat r){
00122   _radius=r;
00123 }
00124 
00125 ////////////////////////////////////////////////////////////////////
00126 //     Function: PolylightNode::get_radius
00127 //       Access: Published
00128 //  Description: Get radius of the spherical light volume
00129 ////////////////////////////////////////////////////////////////////
00130 INLINE PN_stdfloat PolylightNode::
00131 get_radius() const {
00132   return _radius;
00133 }
00134 
00135 ////////////////////////////////////////////////////////////////////
00136 //     Function: PolylightNode::set_attenuation
00137 //       Access: Published
00138 //  Description: Set ALINEAR or AQUADRATIC attenuation
00139 ////////////////////////////////////////////////////////////////////
00140 INLINE bool PolylightNode::
00141 set_attenuation(PolylightNode::Attenuation_Type type){
00142   nassertr(type == ALINEAR || type == AQUADRATIC,false);
00143   _attenuation_type=type;
00144   return true;
00145   
00146 }
00147 
00148 ////////////////////////////////////////////////////////////////////
00149 //     Function: PolylightNode::get_attenuation
00150 //       Access: Published
00151 //  Description: Get "linear" or "quadratic" attenuation type
00152 ////////////////////////////////////////////////////////////////////
00153 INLINE PolylightNode::Attenuation_Type PolylightNode::
00154 get_attenuation() const {
00155   return _attenuation_type;
00156 }
00157 
00158 ////////////////////////////////////////////////////////////////////
00159 //     Function: PolylightNode::set_a0
00160 //       Access: Published
00161 //  Description: Set the quadratic attenuation factor a0
00162 //               fd = 1 / ( a0 + a1*distance + a2*distance*distance)
00163 ////////////////////////////////////////////////////////////////////
00164 INLINE void PolylightNode::
00165 set_a0(PN_stdfloat a0){
00166   _a0=a0;
00167 }
00168 
00169 ////////////////////////////////////////////////////////////////////
00170 //     Function: PolylightNode::set_a1
00171 //       Access: Published
00172 //  Description: Set the quadratic attenuation factor a1
00173 //               fd = 1 / ( a0 + a1*distance + a2*distance*distance)
00174 ////////////////////////////////////////////////////////////////////
00175 INLINE void PolylightNode::
00176 set_a1(PN_stdfloat a1){
00177   _a1=a1;
00178 }
00179 
00180 ////////////////////////////////////////////////////////////////////
00181 //     Function: PolylightNode::set_a2
00182 //       Access: Published
00183 //  Description: Set the quadratic attenuation factor a2
00184 //               fd = 1 / ( a0 + a1*distance + a2*distance*distance)
00185 ////////////////////////////////////////////////////////////////////
00186 INLINE void PolylightNode::
00187 set_a2(PN_stdfloat a2){
00188   _a2=a2;
00189 }
00190 
00191 ////////////////////////////////////////////////////////////////////
00192 //     Function: PolylightNode::get_a0
00193 //       Access: Published
00194 //  Description: Get the quadratic attenuation factor a0
00195 //               fd = 1 / ( a0 + a1*distance + a2*distance*distance)
00196 ////////////////////////////////////////////////////////////////////
00197 INLINE PN_stdfloat PolylightNode::
00198 get_a0() const {
00199   return _a0;
00200 }
00201 
00202 ////////////////////////////////////////////////////////////////////
00203 //     Function: PolylightNode::get_a1
00204 //       Access: Published
00205 //  Description: Get the quadratic attenuation factor a1
00206 //               fd = 1 / ( a0 + a1*distance + a2*distance*distance)
00207 ////////////////////////////////////////////////////////////////////
00208 INLINE PN_stdfloat PolylightNode::
00209 get_a1() const {
00210   return _a1;
00211 }
00212 
00213 ////////////////////////////////////////////////////////////////////
00214 //     Function: PolylightNode::get_a2
00215 //       Access: Published
00216 //  Description: Get the quadratic attenuation factor a2
00217 //               fd = 1 / ( a0 + a1*distance + a2*distance*distance)
00218 ////////////////////////////////////////////////////////////////////
00219 INLINE PN_stdfloat PolylightNode::
00220 get_a2() const {
00221   return _a2;
00222 }
00223 
00224 ////////////////////////////////////////////////////////////////////
00225 //     Function: PolylightNode::flicker_on
00226 //       Access: Published
00227 //  Description: Set flickering to true so at every loop this light's
00228 //               color is varied based on flicker_type
00229 ////////////////////////////////////////////////////////////////////
00230 INLINE void PolylightNode::
00231 flicker_on(){
00232   _flickering=true;
00233 }
00234 
00235 ////////////////////////////////////////////////////////////////////
00236 //     Function: PolylightNode::flicker_off
00237 //       Access: Published
00238 //  Description: Turn flickering off
00239 ////////////////////////////////////////////////////////////////////
00240 INLINE void PolylightNode::
00241 flicker_off(){
00242   _flickering=false;
00243 }
00244 
00245 ////////////////////////////////////////////////////////////////////
00246 //     Function: PolylightNode::is_flickering
00247 //       Access: Published
00248 //  Description: Check is this light is flickering
00249 ////////////////////////////////////////////////////////////////////
00250 INLINE bool PolylightNode::
00251 is_flickering() const {
00252   return _flickering;
00253 }
00254 
00255 ////////////////////////////////////////////////////////////////////
00256 //     Function: PolylightNode::set_flicker_type
00257 //       Access: Published
00258 //  Description: Flicker type can be FRANDOM or FSIN
00259 //               At a later point there might be a FCUSTOM
00260 //               Custom flicker will be a set of fix points recorded
00261 //               by animating the light's intensity
00262 ////////////////////////////////////////////////////////////////////
00263 INLINE bool PolylightNode::
00264 set_flicker_type(PolylightNode::Flicker_Type type){
00265   nassertr(type == FRANDOM || type == FSIN,false);
00266   
00267   _flicker_type=type;
00268   return true;
00269 }
00270 
00271 ////////////////////////////////////////////////////////////////////
00272 //     Function: PolylightNode::get_flicker_type
00273 //       Access: Published
00274 //  Description: Returns FRANDOM or FSIN
00275 ////////////////////////////////////////////////////////////////////
00276 INLINE PolylightNode::Flicker_Type PolylightNode::
00277 get_flicker_type() const {
00278   return _flicker_type;
00279 }
00280 
00281 ////////////////////////////////////////////////////////////////////
00282 //     Function: PolylightNode::set_offset
00283 //       Access: Published
00284 //  Description: Set the offset value for the random and sin
00285 //               flicker variations... used to tweak the flicker
00286 //               This value is added to the variation
00287 ////////////////////////////////////////////////////////////////////
00288 INLINE void PolylightNode::
00289 set_offset(PN_stdfloat offset){
00290   _offset=offset;
00291 }
00292 
00293 ////////////////////////////////////////////////////////////////////
00294 //     Function: PolylightNode::get_offset
00295 //       Access: Published
00296 //  Description: Get the offset value for the random and sin
00297 //               flicker variations
00298 ////////////////////////////////////////////////////////////////////
00299 INLINE PN_stdfloat PolylightNode::
00300 get_offset() const {
00301   return _offset;
00302 }
00303 
00304 ////////////////////////////////////////////////////////////////////
00305 //     Function: PolylightNode::set_scale
00306 //       Access: Published
00307 //  Description: Set the scale value for the random and sin
00308 //               flicker variations... used to tweak the flicker
00309 //               This value is multiplied with the variation
00310 ////////////////////////////////////////////////////////////////////
00311 INLINE void PolylightNode::
00312 set_scale(PN_stdfloat scale){
00313   _scale=scale;
00314 }
00315 
00316 ////////////////////////////////////////////////////////////////////
00317 //     Function: PolylightNode::get_scale
00318 //       Access: Published
00319 //  Description: Get the scale value for the random and sin
00320 //               flicker variations
00321 ////////////////////////////////////////////////////////////////////
00322 INLINE PN_stdfloat PolylightNode::
00323 get_scale() const {
00324   return _scale;
00325 }
00326 
00327 ////////////////////////////////////////////////////////////////////
00328 //     Function: PolylightNode::set_step_size
00329 //       Access: Published
00330 //  Description: Set the step size for the sin function in flicker
00331 //               This is the increment size for the value supplied
00332 //               to the sin function
00333 ////////////////////////////////////////////////////////////////////
00334 INLINE void PolylightNode::
00335 set_step_size(PN_stdfloat step){
00336   _step_size=step;
00337 }
00338 
00339 ////////////////////////////////////////////////////////////////////
00340 //     Function: PolylightNode::get_step_size
00341 //       Access: Published
00342 //  Description: Get the step size for the sin function in flicker
00343 //               This is the increment size for the value supplied
00344 //               to the sin function
00345 ////////////////////////////////////////////////////////////////////
00346 INLINE PN_stdfloat PolylightNode::
00347 get_step_size() const {
00348   return _step_size;
00349 }
00350 
00351 ////////////////////////////////////////////////////////////////////
00352 //     Function: PolylightNode::set_color
00353 //       Access: Published
00354 //  Description: Set the light's color... 
00355 ////////////////////////////////////////////////////////////////////
00356 INLINE void PolylightNode::
00357 set_color(const LColor &color) {
00358   //PandaNode::set_attrib(ColorAttrib::make_flat(color));
00359   _color = color;
00360 }
00361 
00362 ////////////////////////////////////////////////////////////////////
00363 //     Function: PolylightNode::set_color
00364 //       Access: Published
00365 //  Description: Set the light's color... 3 floats between 0 and 1
00366 ////////////////////////////////////////////////////////////////////
00367 INLINE void PolylightNode::
00368 set_color(PN_stdfloat r, PN_stdfloat g, PN_stdfloat b) {
00369   /*
00370   LColor color;
00371   color[0] = r;
00372   color[1] = g;
00373   color[2] = b;
00374   color[3] = 1.0;
00375   PandaNode::set_attrib(ColorAttrib::make_flat(color));
00376   */
00377   _color[0] = r;
00378   _color[1] = g;
00379   _color[2] = b;
00380   _color[3] = 1.0;  
00381 }
00382 
00383 ////////////////////////////////////////////////////////////////////
00384 //     Function: PolylightNode::get_color
00385 //       Access: Published
00386 //  Description: Returns the light's color as LColor
00387 ////////////////////////////////////////////////////////////////////
00388 INLINE LColor PolylightNode::
00389 get_color() const {
00390   return _color;
00391 }
00392 
00393 ////////////////////////////////////////////////////////////////////
00394 //     Function: PolylightNode::get_color_scenegraph
00395 //       Access: Published
00396 //  Description: This differs from get_color in that when applying
00397 //               the light color we need to make sure that a color
00398 //               flattening external to the PolylightNode is not 
00399 //               ignored.
00400 ////////////////////////////////////////////////////////////////////
00401 INLINE LColor PolylightNode::
00402 get_color_scenegraph() const {
00403 
00404   const RenderAttrib *attrib =
00405     PandaNode::get_attrib(ColorAttrib::get_class_type());
00406   if (attrib != (const RenderAttrib *)NULL) {
00407     const ColorAttrib *ca = DCAST(ColorAttrib, attrib);
00408     if (ca->get_color_type() == ColorAttrib::T_flat) {
00409       return ca->get_color();
00410     }
00411   }
00412     
00413   return _color;
00414  
00415 }
00416 
00417 
00418 ////////////////////////////////////////////////////////////////////
00419 //     Function: PolylightNode::set_freq
00420 //       Access: Published
00421 //  Description: Set frequency of sin flicker
00422 ////////////////////////////////////////////////////////////////////
00423 INLINE void PolylightNode::
00424 set_freq(PN_stdfloat f) {
00425   _sin_freq=f;
00426 }
00427 
00428 ////////////////////////////////////////////////////////////////////
00429 //     Function: PolylightNode::get_freq
00430 //       Access: Published
00431 //  Description: Get frequency of sin flicker
00432 ////////////////////////////////////////////////////////////////////
00433 INLINE PN_stdfloat PolylightNode::
00434 get_freq() const {
00435   return _sin_freq;
00436 }
 All Classes Functions Variables Enumerations