Browse Source

Polylight API changes based on DRose's suggestions

Shalin Shodhan 21 years ago
parent
commit
81e752915a

+ 4 - 3
panda/src/egg2pg/eggLoader.cxx

@@ -1641,9 +1641,10 @@ make_node(EggGroup *egg_group, PandaNode *parent) {
       egg2pg_cat.warning()
         << "Polylight " << egg_group->get_name() << " make_sphere failed!\n";
 	}
-	PolylightNode *pnode = new PolylightNode(egg_group->get_name(),
-	  center[0], center[1], center[2], color[0], color[1], color[2], 
-	  radius, "linear", false, "random");
+	PolylightNode *pnode = new PolylightNode(egg_group->get_name());
+    pnode->set_pos(center);
+    pnode->set_color(color);
+    pnode->set_radius(radius);
     node = pnode;
     
   } else {

+ 36 - 13
panda/src/pgraph/polylightEffect.I

@@ -33,7 +33,8 @@ PolylightEffect() {
 //       Access: Published
 //  Description: Returns state of the effect: enabled/disabled
 ////////////////////////////////////////////////////////////////////
-INLINE bool PolylightEffect::is_enabled() const {
+INLINE bool PolylightEffect::
+is_enabled() const {
   return _enabled;
 }
 
@@ -68,9 +69,9 @@ disable() {
 //               unique name. Returns true if light added
 ////////////////////////////////////////////////////////////////////
 INLINE bool PolylightEffect::
-add_light(string lightname,NodePath *newlight) {
-  nassertr( newlight->node()->is_of_type(PolylightNode::get_class_type()) ,false);
-  nassertr(newlight->node() != (PolylightNode *)NULL,false);
+add_light(const string &lightname, const NodePath &newlight) {
+  nassertr(newlight.node()->is_of_type(PolylightNode::get_class_type()) ,false);
+  nassertr(newlight.node() != (PolylightNode *)NULL,false);
   
   // Check if light name is unique
   if(_lightgroup.find(lightname) != _lightgroup.end()) {
@@ -79,7 +80,7 @@ add_light(string lightname,NodePath *newlight) {
   }
     
   // Add the light
-  pair<string,NodePath *> _light_to_add(lightname, newlight);
+  pair<string,NodePath> _light_to_add(lightname, newlight);
   _lightgroup.insert(_light_to_add);
   return true;
 }
@@ -92,7 +93,7 @@ add_light(string lightname,NodePath *newlight) {
 //               success.
 ////////////////////////////////////////////////////////////////////
 INLINE bool PolylightEffect::
-remove_light(string lightname) {
+remove_light(const string &lightname) {
 
   // Check if light name exists
   if(_lightgroup.find(lightname) == _lightgroup.end()) {
@@ -114,8 +115,8 @@ remove_light(string lightname) {
 INLINE bool PolylightEffect::
 remove_all() {
   LIGHTGROUP::const_iterator light_iter;
-  for (light_iter = _lightgroup.begin(); light_iter != _lightgroup.end(); light_iter++){
-    string lightname = light_iter->first;
+  for (light_iter = _lightgroup.begin(); light_iter != _lightgroup.end(); light_iter++){
+    string lightname = light_iter->first;
     _lightgroup.erase(lightname);
   }
   return true;
@@ -155,13 +156,13 @@ get_weight() const {
 //               _contribution_type is a string that controls how
 //               this division occurs.
 //               "proximal" : A light only contributes if the node 
-//               is inside its volume
+//				 is inside its volume
 //               "all" : All lights added to the effect are used in
 //               division irrespective of their light volumes
 ////////////////////////////////////////////////////////////////////
 INLINE bool PolylightEffect::
-set_contrib(string type) {
-  nassertr(type == "all" || type == "proximal",false);
+set_contrib(PolylightEffect::Contrib_Type type) {
+  nassertr(type == CALL || type == CPROXIMAL,false);
   _contribution_type = type;
   return true;
 }
@@ -169,9 +170,31 @@ set_contrib(string type) {
 ////////////////////////////////////////////////////////////////////
 //     Function: PolylightEffect::get_contrib
 //       Access: Published
-//  Description: Returns a string value "all"/"proximal"
+//  Description: Returns CALL or CPROXIMAL
 ////////////////////////////////////////////////////////////////////
-INLINE string PolylightEffect::
+INLINE PolylightEffect::Contrib_Type PolylightEffect::
 get_contrib() const {
   return _contribution_type;
 }
+
+////////////////////////////////////////////////////////////////////
+//     Function: PolylightEffect::set_effect_center
+//       Access: Published
+//  Description: Set the center point of the effect...generally 0,0,0
+//               and hence the pivot point of the model
+////////////////////////////////////////////////////////////////////
+INLINE void PolylightEffect::
+set_effect_center(LPoint3f effect_center) {
+  _effect_center = effect_center;
+}
+
+
+////////////////////////////////////////////////////////////////////
+//     Function: PolylightEffect::get_effect_center
+//       Access: Published
+//  Description: Return the value of the _effect_center
+////////////////////////////////////////////////////////////////////
+INLINE LPoint3f PolylightEffect::
+get_effect_center() const {
+  return _effect_center;
+}

+ 88 - 81
panda/src/pgraph/polylightEffect.cxx

@@ -20,10 +20,9 @@
 #include "polylightNode.h"
 #include "config_pgraph.h"
 #include "nodePath.h"
-#include "colorScaleAttrib.h"
 #include "pmap.h"
+#include "colorScaleAttrib.h"
 #include <math.h>
-
 TypeHandle PolylightEffect::_type_handle;
 
 ////////////////////////////////////////////////////////////////////
@@ -32,11 +31,12 @@ TypeHandle PolylightEffect::_type_handle;
 //  Description: Constructs a new PolylightEffect object.
 ////////////////////////////////////////////////////////////////////
 CPT(RenderEffect) PolylightEffect::
-make(string contribution_type,float weight) {
+make() {
   PolylightEffect *effect = new PolylightEffect;
   effect->enable();
-  effect->set_contrib(contribution_type);
-  effect->set_weight(weight);
+  effect->set_contrib(CPROXIMAL);
+  effect->set_weight(0.9);
+  effect->_effect_center = LPoint3f(0.0,0.0,0.0);
   return return_new(effect);
 }
 ////////////////////////////////////////////////////////////////////
@@ -49,80 +49,87 @@ CPT(RenderAttrib) PolylightEffect::
 do_poly_light(const CullTraverserData *data, const TransformState *node_transform) const {
   float r,g,b; // To hold the color calculation
   float dist; // To calculate the distance of each light from the node
-  float light_scale; // Variable to calculate attenuation 
+  float light_scale = 1.0; // Variable to calculate attenuation 
   float fd; // Variable for quadratic attenuation
-  float Rcollect=0.0,Gcollect=0.0,Bcollect=0.0; // Color variables
-  int num_lights=0; // Keep track of number of lights for division
+  float Rcollect = 0.0,Gcollect = 0.0,Bcollect = 0.0; // Color variables
+  int num_lights = 0; // Keep track of number of lights for division
   r = 0.0;
   g = 0.0;
   b = 0.0;
   LIGHTGROUP::const_iterator light_iter; 
   // Cycle through all the lights in this effect's lightgroup
-  for (light_iter = _lightgroup.begin(); light_iter != _lightgroup.end(); light_iter++){
-    const PolylightNode *light = DCAST(PolylightNode,light_iter->second->node()); 
-    // light holds the current PolylightNode
-    if(light->is_enabled()) { // if enabled get all the properties
-      float light_radius = light->get_radius();
-      string light_attenuation = light->get_attenuation();
-      float light_a0 = light->get_a0();
-      float light_a1 = light->get_a1();
-      float light_a2 = light->get_a2();
-      if(light_a0 == 0 && light_a1 == 0 && light_a2 == 0) { // To prevent division by zero
-        light_a0 = 1.0;
-      }
-      Colorf light_color;
-      if(light->is_flickering()) { // If flickering, modify color
-        light_color = light->flicker();
-      }
-      else {
-        light_color = light->get_color();
-      }
-    
-      // Calculate the distance of the node from the light
-      dist = light_iter->second->get_distance(data->_node_path.get_node_path());
-
-      if(dist < light_radius) { // If node is in range of this light
-        if(light_attenuation == "linear") {
-          light_scale = (light_radius - dist)/light_radius;
-        }
-        else if(light_attenuation == "quadratic") {
-          fd = 1.0 / (light_a0 + light_a1 * dist + light_a2 * dist * dist);
-          if(fd<1.0) {
-            light_scale=fd;
-          }
-          else {
-            light_scale=1.0;
-          }
-        }
-        // Keep accumulating each lights contribution... we divide by 
-        // number of lights later.
-        Rcollect += light_color[0] * light_scale;
-        Gcollect += light_color[1] * light_scale;
-        Bcollect += light_color[2] * light_scale;
-        num_lights++;
-      } // if dist< radius
-    } // if light is enabled
-  } // for all lights
-  
-
-  if( _contribution_type == "all") {
-    // Sometimes to prevent snapping of color at light volume boundaries
-    // just divide total contribution by all the lights in the effect
-    // whether or not they contribute color
-    num_lights = _lightgroup.size();
-  }
-
-  if(num_lights == 0) {
-    num_lights = 1;
-  }
-  Rcollect /= num_lights;
-  Gcollect /= num_lights;
-  Bcollect /= num_lights;
-
-  r = (1.0 - _weight) + Rcollect * _weight;
-  g = (1.0 - _weight) + Gcollect * _weight;
-  b = (1.0 - _weight) + Bcollect * _weight;
-  
+  for (light_iter = _lightgroup.begin(); light_iter != _lightgroup.end(); light_iter++){
+    const PolylightNode *light = DCAST(PolylightNode,light_iter->second.node()); 
+	// light holds the current PolylightNode
+	if(light->is_enabled()) { // if enabled get all the properties
+	  float light_radius = light->get_radius();
+	  PolylightNode::Attenuation_Type light_attenuation = light->get_attenuation();
+	  float light_a0 = light->get_a0();
+	  float light_a1 = light->get_a1();
+	  float light_a2 = light->get_a2();
+	  if(light_a0 == 0 && light_a1 == 0 && light_a2 == 0) { // To prevent division by zero
+        light_a0 = 1.0;
+	  }
+	  Colorf light_color;
+	  if(light->is_flickering()) { // If flickering, modify color
+	    light_color = light->flicker();
+	  }
+	  else {
+	    light_color = light->get_color();
+	  }
+	
+	  // Calculate the distance of the node from the light
+	  //dist = light_iter->second->get_distance(data->_node_path.get_node_path());
+      const NodePath lightnp = light_iter->second;
+      LPoint3f point = data->_node_path.get_node_path().get_relative_point(lightnp,
+        light->get_pos());
+      dist = (point - _effect_center).length();
+
+	  if(dist < light_radius) { // If node is in range of this light
+        if(light_attenuation == PolylightNode::ALINEAR) {
+		  light_scale = (light_radius - dist)/light_radius;
+	    }
+	    else if(light_attenuation == PolylightNode::AQUADRATIC) {
+	      fd = 1.0 / (light_a0 + light_a1 * dist + light_a2 * dist * dist);
+		  if(fd < 1.0) {
+		    light_scale = fd;
+		  }
+		  else {
+		    light_scale = 1.0;
+		  }
+		}
+        else {
+          light_scale = 1.0;
+        }
+        // Keep accumulating each lights contribution... we divide by 
+		// number of lights later.
+	    Rcollect += light_color[0] * light_scale;
+	    Gcollect += light_color[1] * light_scale;
+	    Bcollect += light_color[2] * light_scale;
+	    num_lights++;
+	  } // if dist< radius
+	} // if light is enabled
+  } // for all lights
+  
+
+  if( _contribution_type == CALL) {
+    // Sometimes to prevent snapping of color at light volume boundaries
+	// just divide total contribution by all the lights in the effect
+	// whether or not they contribute color
+    num_lights = _lightgroup.size();
+  }
+
+  if(num_lights == 0) {
+    num_lights = 1;
+  }
+  Rcollect /= num_lights;
+  Gcollect /= num_lights;
+  Bcollect /= num_lights;
+
+  r = (1.0 - _weight) + Rcollect * _weight;
+  g = (1.0 - _weight) + Gcollect * _weight;
+  b = (1.0 - _weight) + Bcollect * _weight;
+  
   return ColorScaleAttrib::make(LVecBase4f(r,g,b,1.0));
 }
 
@@ -148,20 +155,20 @@ compare_to_impl(const RenderEffect *other) const {
   DCAST_INTO_R(ta, other, 0);
 
   if (_enabled != ta->_enabled) {
-      return _enabled ? 1 : -1;
+	  return _enabled ? 1 : -1;
   }
 
-  if (_contribution_type != ta->_contribution_type) {
-    return _contribution_type < ta->_contribution_type ? -1 : 1;
-  }
+  if (_contribution_type != ta->_contribution_type) {
+    return _contribution_type < ta->_contribution_type ? -1 : 1;
+  }
  
   if (_weight != ta->_weight) {
-    return _weight < ta->_weight ? -1 :1;
+	return _weight < ta->_weight ? -1 :1;
   }
 
-  if (_lightgroup != ta->_lightgroup) {
-    return _lightgroup < ta->_lightgroup ? -1 : 1;
-  }
+  if (_lightgroup != ta->_lightgroup) {
+    return _lightgroup < ta->_lightgroup ? -1 : 1;
+  }
  
   return 0;
 }

+ 19 - 13
panda/src/pgraph/polylightEffect.h

@@ -20,7 +20,7 @@
 #define POLYLIGHTEFFECT_H
 
 #include "pandabase.h"
-
+
 
 #include "renderEffect.h"
 #include "luse.h"
@@ -33,10 +33,10 @@
 ////////////////////////////////////////////////////////////////////
 //       Class : PolylightEffect
 // Description : A PolylightEffect can be used on a node to define a
-//               LightGroup  for that node. A LightGroup contains 
+//				 LightGroup  for that node. A LightGroup contains 
 //               Polylights which are essentially nodes that add 
-//               color to the polygons of a model based on distance.
-//               PolylightNode is a cheap way to get lighting effects
+//			     color to the polygons of a model based on distance.
+//				 PolylightNode is a cheap way to get lighting effects
 //               specially for night scenes
 ////////////////////////////////////////////////////////////////////
 class EXPCL_PANDA PolylightEffect : public RenderEffect {
@@ -45,32 +45,38 @@ private:
   
 
 PUBLISHED:
-  
-  static CPT(RenderEffect) make(string contribution_type= "proximal", float weight=0.9);
+  enum Contrib_Type {
+    CPROXIMAL,
+    CALL,
+  };
+
+  static CPT(RenderEffect) make();
   INLINE void enable();
   INLINE void disable();
-  INLINE bool add_light(string lightname, NodePath *newlight);
-  INLINE bool remove_light(string lightname);
+  INLINE bool add_light(const string &lightname, const NodePath &newlight);
+  INLINE bool remove_light(const string &lightname);
   INLINE bool remove_all();
   INLINE bool set_weight(float w);
   INLINE float get_weight() const;
-  INLINE bool set_contrib(string type);  
-  INLINE string get_contrib() const;
+  INLINE bool set_contrib(Contrib_Type type);  
+  INLINE Contrib_Type get_contrib() const;
   INLINE bool is_enabled()const;
+  INLINE void set_effect_center(LPoint3f effect_center);
+  INLINE LPoint3f get_effect_center()const;
 
 public:
   CPT(RenderAttrib) do_poly_light(const CullTraverserData *data, const TransformState *node_transform) const;
 
-
 protected:
   virtual int compare_to_impl(const RenderEffect *other) const;
 
 private:
   bool _enabled;
-  string _contribution_type;
+  Contrib_Type _contribution_type;
   float _weight;
-  typedef pmap<string, NodePath *> LIGHTGROUP;
+  typedef pmap<string, NodePath> LIGHTGROUP;
   LIGHTGROUP _lightgroup;
+  LPoint3f _effect_center;
   
 
 public:

+ 89 - 159
panda/src/pgraph/polylightNode.I

@@ -58,7 +58,8 @@ operator < (const PolylightNode &other) const {
 //       Access: Published
 //  Description: Is this light is enabled/disabled?
 ////////////////////////////////////////////////////////////////////
-INLINE bool PolylightNode::is_enabled() const {
+INLINE bool PolylightNode::
+is_enabled() const {
   return _enabled;
 }
 
@@ -67,7 +68,8 @@ INLINE bool PolylightNode::is_enabled() const {
 //       Access: Published
 //  Description: Enable this light
 ////////////////////////////////////////////////////////////////////
-INLINE void PolylightNode::enable(){
+INLINE void PolylightNode::
+enable(){
   _enabled=true;
 }
 
@@ -76,23 +78,32 @@ INLINE void PolylightNode::enable(){
 //       Access: Published
 //  Description: Disable this light
 ////////////////////////////////////////////////////////////////////
-INLINE void PolylightNode::disable(){
+INLINE void PolylightNode::
+disable(){
   _enabled=false;
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: PolylightNode::set_pos
+//       Access: Published
+//  Description: Set this light's position
+////////////////////////////////////////////////////////////////////
+INLINE void PolylightNode::
+set_pos(LVecBase3f position){
+  _position = position;
+}
+
 
 ////////////////////////////////////////////////////////////////////
 //     Function: PolylightNode::set_pos
 //       Access: Published
 //  Description: Set this light's position
 ////////////////////////////////////////////////////////////////////
-INLINE void PolylightNode::set_pos(float x, float y, float z){
-  LVecBase3f position;
-  position[0]=x;
-  position[1]=y;
-  position[2]=z;
-  PandaNode::set_transform(get_transform()->set_pos(position));
-  PandaNode::reset_prev_transform();
+INLINE void PolylightNode::
+set_pos(float x, float y, float z){
+  _position[0]=x;
+  _position[1]=y;
+  _position[2]=z;
 }
 
 ////////////////////////////////////////////////////////////////////
@@ -100,8 +111,9 @@ INLINE void PolylightNode::set_pos(float x, float y, float z){
 //       Access: Published
 //  Description: Returns position as a LPoint3f
 ////////////////////////////////////////////////////////////////////
-INLINE LVecBase3f PolylightNode::get_pos() const {
-  return PandaNode::get_transform()->get_pos();
+INLINE LVecBase3f PolylightNode::
+get_pos() const {
+  return _position;
 }
 
 ////////////////////////////////////////////////////////////////////
@@ -109,7 +121,8 @@ INLINE LVecBase3f PolylightNode::get_pos() const {
 //       Access: Published
 //  Description: Set radius of the spherical light volume
 ////////////////////////////////////////////////////////////////////
-INLINE void PolylightNode::set_radius(float r){
+INLINE void PolylightNode::
+set_radius(float r){
   _radius=r;
 }
 
@@ -118,18 +131,19 @@ INLINE void PolylightNode::set_radius(float r){
 //       Access: Published
 //  Description: Get radius of the spherical light volume
 ////////////////////////////////////////////////////////////////////
-INLINE float PolylightNode::get_radius() const {
+INLINE float PolylightNode::
+get_radius() const {
   return _radius;
 }
 
 ////////////////////////////////////////////////////////////////////
 //     Function: PolylightNode::set_attenuation
 //       Access: Published
-//  Description: Set "linear" or "quadratic" attenuation
+//  Description: Set ALINEAR or AQUADRATIC attenuation
 ////////////////////////////////////////////////////////////////////
-INLINE bool PolylightNode::set_attenuation(string type){
-  nassertr(type == "linear" || type == "quadratic",false);
-    
+INLINE bool PolylightNode::
+set_attenuation(PolylightNode::Attenuation_Type type){
+  nassertr(type == ALINEAR || type == AQUADRATIC,false);
   _attenuation_type=type;
   return true;
   
@@ -140,7 +154,8 @@ INLINE bool PolylightNode::set_attenuation(string type){
 //       Access: Published
 //  Description: Get "linear" or "quadratic" attenuation type
 ////////////////////////////////////////////////////////////////////
-INLINE string PolylightNode::get_attenuation() const {
+INLINE PolylightNode::Attenuation_Type PolylightNode::
+get_attenuation() const {
   return _attenuation_type;
 }
 
@@ -150,7 +165,8 @@ INLINE string PolylightNode::get_attenuation() const {
 //  Description: Set the quadratic attenuation factor a0
 //               fd = 1 / ( a0 + a1*distance + a2*distance*distance)
 ////////////////////////////////////////////////////////////////////
-INLINE void PolylightNode::set_a0(float a0){
+INLINE void PolylightNode::
+set_a0(float a0){
   _a0=a0;
 }
 
@@ -160,7 +176,8 @@ INLINE void PolylightNode::set_a0(float a0){
 //  Description: Set the quadratic attenuation factor a1
 //               fd = 1 / ( a0 + a1*distance + a2*distance*distance)
 ////////////////////////////////////////////////////////////////////
-INLINE void PolylightNode::set_a1(float a1){
+INLINE void PolylightNode::
+set_a1(float a1){
   _a1=a1;
 }
 
@@ -170,7 +187,8 @@ INLINE void PolylightNode::set_a1(float a1){
 //  Description: Set the quadratic attenuation factor a2
 //               fd = 1 / ( a0 + a1*distance + a2*distance*distance)
 ////////////////////////////////////////////////////////////////////
-INLINE void PolylightNode::set_a2(float a2){
+INLINE void PolylightNode::
+set_a2(float a2){
   _a2=a2;
 }
 
@@ -180,7 +198,8 @@ INLINE void PolylightNode::set_a2(float a2){
 //  Description: Get the quadratic attenuation factor a0
 //               fd = 1 / ( a0 + a1*distance + a2*distance*distance)
 ////////////////////////////////////////////////////////////////////
-INLINE float PolylightNode::get_a0() const {
+INLINE float PolylightNode::
+get_a0() const {
   return _a0;
 }
 
@@ -190,7 +209,8 @@ INLINE float PolylightNode::get_a0() const {
 //  Description: Get the quadratic attenuation factor a1
 //               fd = 1 / ( a0 + a1*distance + a2*distance*distance)
 ////////////////////////////////////////////////////////////////////
-INLINE float PolylightNode::get_a1() const {
+INLINE float PolylightNode::
+get_a1() const {
   return _a1;
 }
 
@@ -200,7 +220,8 @@ INLINE float PolylightNode::get_a1() const {
 //  Description: Get the quadratic attenuation factor a2
 //               fd = 1 / ( a0 + a1*distance + a2*distance*distance)
 ////////////////////////////////////////////////////////////////////
-INLINE float PolylightNode::get_a2() const {
+INLINE float PolylightNode::
+get_a2() const {
   return _a2;
 }
 
@@ -210,7 +231,8 @@ INLINE float PolylightNode::get_a2() const {
 //  Description: Set flickering to true so at every loop this light's
 //               color is varied based on flicker_type
 ////////////////////////////////////////////////////////////////////
-INLINE void PolylightNode::flicker_on(){
+INLINE void PolylightNode::
+flicker_on(){
   _flickering=true;
 }
 
@@ -219,7 +241,8 @@ INLINE void PolylightNode::flicker_on(){
 //       Access: Published
 //  Description: Turn flickering off
 ////////////////////////////////////////////////////////////////////
-INLINE void PolylightNode::flicker_off(){
+INLINE void PolylightNode::
+flicker_off(){
   _flickering=false;
 }
 
@@ -228,21 +251,22 @@ INLINE void PolylightNode::flicker_off(){
 //       Access: Published
 //  Description: Check is this light is flickering
 ////////////////////////////////////////////////////////////////////
-INLINE bool PolylightNode::is_flickering() const {
+INLINE bool PolylightNode::
+is_flickering() const {
   return _flickering;
 }
 
 ////////////////////////////////////////////////////////////////////
 //     Function: PolylightNode::set_flicker_type
 //       Access: Published
-//  Description: Flicker type can be "random" or "sin"
-//               At a later point there might be a "custom" 
+//  Description: Flicker type can be FRANDOM or FSIN
+//               At a later point there might be a FCUSTOM
 //               Custom flicker will be a set of fix points recorded
 //               by animating the light's intensity
 ////////////////////////////////////////////////////////////////////
-INLINE bool PolylightNode::set_flicker_type(string type){
-  nassertr(type == "random" || type == "sin",false);
-  
+INLINE bool PolylightNode::
+set_flicker_type(PolylightNode::Flicker_Type type){
+  nassertr(type == FRANDOM || type == FSIN,false);
   
   _flicker_type=type;
   return true;
@@ -251,9 +275,10 @@ INLINE bool PolylightNode::set_flicker_type(string type){
 ////////////////////////////////////////////////////////////////////
 //     Function: PolylightNode::get_flicker_type
 //       Access: Published
-//  Description: Returns "random" or "sin"
+//  Description: Returns FRANDOM or FSIN
 ////////////////////////////////////////////////////////////////////
-INLINE string PolylightNode::get_flicker_type() const {
+INLINE PolylightNode::Flicker_Type PolylightNode::
+get_flicker_type() const {
   return _flicker_type;
 }
 
@@ -264,7 +289,8 @@ INLINE string PolylightNode::get_flicker_type() const {
 //               flicker variations... used to tweak the flicker
 //               This value is added to the variation
 ////////////////////////////////////////////////////////////////////
-INLINE void PolylightNode::set_offset(float offset){
+INLINE void PolylightNode::
+set_offset(float offset){
   _offset=offset;
 }
 
@@ -274,7 +300,8 @@ INLINE void PolylightNode::set_offset(float offset){
 //  Description: Get the offset value for the random and sin
 //               flicker variations
 ////////////////////////////////////////////////////////////////////
-INLINE float PolylightNode::get_offset() const {
+INLINE float PolylightNode::
+get_offset() const {
   return _offset;
 }
 
@@ -285,7 +312,8 @@ INLINE float PolylightNode::get_offset() const {
 //               flicker variations... used to tweak the flicker
 //               This value is multiplied with the variation
 ////////////////////////////////////////////////////////////////////
-INLINE void PolylightNode::set_scale(float scale){
+INLINE void PolylightNode::
+set_scale(float scale){
   _scale=scale;
 }
 
@@ -295,7 +323,8 @@ INLINE void PolylightNode::set_scale(float scale){
 //  Description: Get the scale value for the random and sin
 //               flicker variations
 ////////////////////////////////////////////////////////////////////
-INLINE float PolylightNode::get_scale() const {
+INLINE float PolylightNode::
+get_scale() const {
   return _scale;
 }
 
@@ -306,7 +335,8 @@ INLINE float PolylightNode::get_scale() const {
 //               This is the increment size for the value supplied
 //               to the sin function
 ////////////////////////////////////////////////////////////////////
-INLINE void PolylightNode::set_step_size(float step){
+INLINE void PolylightNode::
+set_step_size(float step){
   _step_size=step;
 }
 
@@ -317,17 +347,28 @@ INLINE void PolylightNode::set_step_size(float step){
 //               This is the increment size for the value supplied
 //               to the sin function
 ////////////////////////////////////////////////////////////////////
-INLINE float PolylightNode::get_step_size() const {
+INLINE float PolylightNode::
+get_step_size() const {
   return _step_size;
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: PolylightNode::set_color
+//       Access: Published
+//  Description: Set the light's color... 
+////////////////////////////////////////////////////////////////////
+INLINE void PolylightNode::
+set_color(Colorf color) {
+  PandaNode::set_attrib(ColorAttrib::make_flat(color));
+}
 
 ////////////////////////////////////////////////////////////////////
 //     Function: PolylightNode::set_color
 //       Access: Published
 //  Description: Set the light's color... 3 floats between 0 and 1
 ////////////////////////////////////////////////////////////////////
-INLINE void PolylightNode::set_color(float r, float g, float b) {
+INLINE void PolylightNode::
+set_color(float r, float g, float b) {
   Colorf color;
   color[0] = r;
   color[1] = g;
@@ -341,7 +382,8 @@ INLINE void PolylightNode::set_color(float r, float g, float b) {
 //       Access: Published
 //  Description: Returns the light's color as Colorf
 ////////////////////////////////////////////////////////////////////
-INLINE Colorf PolylightNode::get_color() const {
+INLINE Colorf PolylightNode::
+get_color() const {
 
   const RenderAttrib *attrib =
     PandaNode::get_attrib(ColorAttrib::get_class_type());
@@ -356,127 +398,14 @@ INLINE Colorf PolylightNode::get_color() const {
  
 }
 
-////////////////////////////////////////////////////////////////////
-//     Function: PolylightNode::set_x
-//       Access: Published
-//  Description: Set light's x position
-////////////////////////////////////////////////////////////////////
-INLINE void PolylightNode::set_x(float x) {
-  LPoint3f pos = get_pos();
-  pos[0] = x;
-  set_pos(pos[0],pos[1],pos[2]);
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: PolylightNode::set_y
-//       Access: Published
-//  Description: Set light's y position
-////////////////////////////////////////////////////////////////////
-INLINE void PolylightNode::set_y(float y) {
-  LPoint3f pos = get_pos();
-  pos[1] = y;
-  set_pos(pos[0],pos[1],pos[2]);
-}
- 
-////////////////////////////////////////////////////////////////////
-//     Function: PolylightNode::set_z
-//       Access: Published
-//  Description: Set light's z position
-////////////////////////////////////////////////////////////////////
-INLINE void PolylightNode::set_z(float z) {
-  LPoint3f pos = get_pos();
-  pos[2] = z;
-  set_pos(pos[0],pos[1],pos[2]);
-}
-/*
-////////////////////////////////////////////////////////////////////
-//     Function: PolylightNode::set_r
-//       Access: Published
-//  Description: Set light's red between 0 and 1
-////////////////////////////////////////////////////////////////////
-INLINE void PolylightNode::set_r(float r) {
-  _color[0]=r;
-}
- 
-////////////////////////////////////////////////////////////////////
-//     Function: PolylightNode::set_g
-//       Access: Published
-//  Description: Set light's green between 0 and 1
-////////////////////////////////////////////////////////////////////
-INLINE void PolylightNode::set_g(float g) {
-  _color[1]=g;
-}
- 
-////////////////////////////////////////////////////////////////////
-//     Function: PolylightNode::set_b
-//       Access: Published
-//  Description: Set light's blue between 0 and 1
-////////////////////////////////////////////////////////////////////
-INLINE void PolylightNode::set_b(float b) {
-  _color[2]=b;
-}
-*/
-////////////////////////////////////////////////////////////////////
-//     Function: PolylightNode::get_x
-//       Access: Published
-//  Description: Get light's x position
-////////////////////////////////////////////////////////////////////
-INLINE float PolylightNode::get_x() const {
-  return get_pos()[0];
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: PolylightNode::get_y
-//       Access: Published
-//  Description: Get light's y position
-////////////////////////////////////////////////////////////////////
-INLINE float PolylightNode::get_y() const {
-  return get_pos()[1];
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: PolylightNode::get_z
-//       Access: Published
-//  Description: Get light's z position
-////////////////////////////////////////////////////////////////////
-INLINE float PolylightNode::get_z() const {
-  return get_pos()[2];
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: PolylightNode::get_r
-//       Access: Published
-//  Description: Get light's red color
-////////////////////////////////////////////////////////////////////
-INLINE float PolylightNode::get_r() const {
-  return get_color()[0];
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: PolylightNode::get_g
-//       Access: Published
-//  Description: Get light's green color
-////////////////////////////////////////////////////////////////////
-INLINE float PolylightNode::get_g() const {
-  return get_color()[1];
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: PolylightNode::get_b
-//       Access: Published
-//  Description: Get light's blue color
-////////////////////////////////////////////////////////////////////
-INLINE float PolylightNode::get_b() const {
-  return get_color()[2];
-}
-
 
 ////////////////////////////////////////////////////////////////////
 //     Function: PolylightNode::set_freq
 //       Access: Published
 //  Description: Set frequency of sin flicker
 ////////////////////////////////////////////////////////////////////
-INLINE void PolylightNode::set_freq(float f) {
+INLINE void PolylightNode::
+set_freq(float f) {
   _sin_freq=f;
 }
 
@@ -485,6 +414,7 @@ INLINE void PolylightNode::set_freq(float f) {
 //       Access: Published
 //  Description: Get frequency of sin flicker
 ////////////////////////////////////////////////////////////////////
-INLINE float PolylightNode::get_freq() const {
+INLINE float PolylightNode::
+get_freq() const {
   return _sin_freq;
 }

+ 40 - 44
panda/src/pgraph/polylightNode.cxx

@@ -37,23 +37,19 @@ TypeHandle PolylightNode::_type_handle;
 //               PolylightNode object.
 ////////////////////////////////////////////////////////////////////
 PolylightNode::
-PolylightNode(const string &name,float x, float y, float z,
-  float r, float g, float b, float radius, string attenuation_type,
-  bool flickering, string flicker_type) :
+PolylightNode(const string &name) :
 PandaNode(name)
 {
   _enabled = true;
-  
-  set_pos(x,y,z);
-  set_color(r,g,b);
- 
-  _radius = radius;
-  set_attenuation(attenuation_type);
+  set_pos(0,0,0);
+  set_color(1,1,1);
+  _radius = 50;
+  set_attenuation(ALINEAR);
   _a0 = 1.0;
   _a1 = 0.1;
   _a2 = 0.01;
-  _flickering = flickering;
-  set_flicker_type(flicker_type);
+  _flickering = true;
+  set_flicker_type(FRANDOM);
   _offset = -0.5;
   _scale = 0.1;
   _step_size = 0.1;
@@ -78,32 +74,32 @@ Colorf PolylightNode::flicker() const {
   r = color[0];
   g = color[1];
   b = color[2];
-  float variation;
+  float variation= 0.0;
   
-  if(_flicker_type == "random") {
+  if(_flicker_type == FRANDOM) {
     //srand((int)ClockObject::get_global_clock()->get_frame_time());
     variation = (rand()%100);// * ClockObject::get_global_clock()->get_dt();
-    variation /= 100.0;
-    //printf("Random Variation: %f\n",variation);
-    variation += _offset;
-    variation *= _scale;
+	variation /= 100.0;
+	//printf("Random Variation: %f\n",variation);
+	variation += _offset;
+	variation *= _scale;
   }
-  else if(_flicker_type == "sin") {
-    double now = ClockObject::get_global_clock()->get_frame_time();
+  else if(_flicker_type == FSIN) {
+	double now = ClockObject::get_global_clock()->get_frame_time();
     variation = sinf(now*_sin_freq);// * ClockObject::get_global_clock()->get_dt();
-    //printf("Variation: %f\n",variation);
-    variation += _offset;
-    variation *= _scale;
+	//printf("Variation: %f\n",variation);
+	variation += _offset;
+	variation *= _scale;
   }
-  else if(_flicker_type == "fixed_point") {
+  else if(_flicker_type == FCUSTOM) {
     // fixed point list of variation values coming soon...
     //double index = (ClockObject::get_global_clock()->get_frame_time() % len(fixed_points)) *  ClockObject::get_global_clock()->get_dt();
-    //index *= _speed;
-    /*if(!(int)index > len(fixed_points) {
-      variation = _fixed_points[(int)index];
-      variation += _offset;
-      variation *= _scale;
-    }*/
+	//index *= _speed;
+	/*if(!(int)index > len(fixed_points) {
+	  variation = _fixed_points[(int)index];
+	  variation += _offset;
+	  variation *= _scale;
+	}*/
   }
   //printf("Variation: %f\n",variation);
   r+=variation;
@@ -130,7 +126,7 @@ Colorf PolylightNode::flicker() const {
 //
 //               Two PolylightNodes are considered equivalent if they
 //               consist of exactly the same properties
-//               Otherwise, they are different; different
+//				 Otherwise, they are different; different
 //               PolylightNodes will be ranked in a consistent but
 //               undefined ordering; the ordering is useful only for
 //               placing the PolylightNodes in a sorted container like an
@@ -140,62 +136,62 @@ int PolylightNode::
 compare_to(const PolylightNode &other) const {
   
   if (_enabled != other._enabled) {
-    return _enabled ? 1 :-1;
+	return _enabled ? 1 :-1;
   }
 
   if (_radius != other._radius) {
-    return _radius < other._radius ? -1 :1;
+	return _radius < other._radius ? -1 :1;
   }
   LVecBase3f position = get_pos();
   LVecBase3f other_position = other.get_pos();
   if (position != other_position) {
-    return position < other_position ? -1 :1;
+	return position < other_position ? -1 :1;
   }
 
   Colorf color = get_color();
   Colorf other_color = other.get_color();
   if (color != other_color) {
-    return color < other_color ? -1 :1;
+	return color < other_color ? -1 :1;
   }
 
   if (_attenuation_type != other._attenuation_type) {
-    return _attenuation_type < other._attenuation_type ? -1 :1;
+	return _attenuation_type < other._attenuation_type ? -1 :1;
   }
 
   if (_a0 != other._a0) {
-    return _a0 < other._a0 ? -1 :1;
+	return _a0 < other._a0 ? -1 :1;
   }
 
   if (_a1 != other._a1) {
-    return _a1 < other._a1 ? -1 :1;
+	return _a1 < other._a1 ? -1 :1;
   }
 
   if (_a2 != other._a2) {
-    return _a2 < other._a2 ? -1 :1;
+	return _a2 < other._a2 ? -1 :1;
   }
 
   if (_flickering != other._flickering) {
-    return _flickering ? 1 :-1;
+	return _flickering ? 1 :-1;
   }
 
   if (_flicker_type != other._flicker_type) {
-    return _flicker_type < other._flicker_type ? -1 :1;
+	return _flicker_type < other._flicker_type ? -1 :1;
   }
 
   if (_offset != other._offset) {
-    return _offset < other._offset ? -1 :1;
+	return _offset < other._offset ? -1 :1;
   }
 
   if (_scale != other._scale) {
-    return _scale < other._scale ? -1 :1;
+	return _scale < other._scale ? -1 :1;
   }
 
   if (_step_size != other._step_size) {
-    return _step_size < other._step_size ? -1 :1;
+	return _step_size < other._step_size ? -1 :1;
   }
 
   if (_sin_freq != other._sin_freq) {
-    return _sin_freq < other._sin_freq ? -1 :1;
+	return _sin_freq < other._sin_freq ? -1 :1;
   }
 
 

+ 31 - 22
panda/src/pgraph/polylightNode.h

@@ -37,20 +37,41 @@ class EXPCL_PANDA PolylightNode : public PandaNode{
 
 
 PUBLISHED:
+  /*
+  // This was the old constructor... interrogate would generate a 
+  // separate wrapper for each parameter... so its better to 
+  // have a simpler constructor and require the programmer
+  // to use set_* methods.
   PolylightNode(const string &name, float x = 0.0, float y = 0.0, float z = 0.0,
-    float r = 1.0, float g = 1.0, float b = 1.0,
-    float radius=50.0, string attenuation_type= "linear",
-    bool flickering =false, string flicker_type="random");
+	float r = 1.0, float g = 1.0, float b = 1.0,
+	float radius=50.0, string attenuation_type= "linear",
+	bool flickering =false, string flicker_type="random");
+  */
+
+  enum Flicker_Type {
+    FRANDOM,
+    FSIN,
+    FCUSTOM,
+  };
+
+  enum Attenuation_Type {
+    ALINEAR,
+    AQUADRATIC,
+  };
+
+  PolylightNode(const string &name);
   INLINE void enable();
   INLINE void disable();
+  INLINE void set_pos(LVecBase3f position);
   INLINE void set_pos(float x,float y, float z);
   INLINE LVecBase3f get_pos() const;
+  INLINE void set_color(Colorf color);
   INLINE void set_color(float r, float g, float b);
   INLINE Colorf get_color() const;
   INLINE void set_radius(float r);
   INLINE float get_radius() const;
-  INLINE bool set_attenuation(string type);
-  INLINE string get_attenuation() const;
+  INLINE bool set_attenuation(Attenuation_Type type);
+  INLINE Attenuation_Type get_attenuation() const;
   INLINE void set_a0(float a0);
   INLINE void set_a1(float a1);
   INLINE void set_a2(float a2);
@@ -60,26 +81,14 @@ PUBLISHED:
   INLINE void flicker_on();
   INLINE void flicker_off();
   INLINE bool is_flickering() const;
-  INLINE bool set_flicker_type(string type);
-  INLINE string get_flicker_type() const;
+  INLINE bool set_flicker_type(Flicker_Type type);
+  INLINE Flicker_Type get_flicker_type() const;
   INLINE void set_offset(float offset);
   INLINE float get_offset() const;
   INLINE void set_scale(float scale);
   INLINE float get_scale() const;
   INLINE void set_step_size(float step) ;
   INLINE float get_step_size() const;
-  INLINE void set_x(float x);
-  INLINE void set_y(float y);
-  INLINE void set_z(float z);
-  //INLINE void set_r(float r);
-  //INLINE void set_g(float g);
-  //INLINE void set_b(float b);
-  INLINE float get_x() const;
-  INLINE float get_y() const;
-  INLINE float get_z() const;
-  INLINE float get_r() const;
-  INLINE float get_g() const;
-  INLINE float get_b() const;
   INLINE void set_freq(float f);
   INLINE float get_freq() const;
 
@@ -97,15 +106,15 @@ public:
   
 private:
   bool _enabled;
-  //LPoint3f _position;
+  LVecBase3f _position;
   //Colorf _color;
   float _radius;
-  string _attenuation_type;
+  Attenuation_Type _attenuation_type;
   float _a0;
   float _a1;
   float _a2;
   bool _flickering;
-  string _flicker_type;
+  Flicker_Type _flicker_type;
   float _offset;
   float _scale;
   float _step_size;