Browse Source

took care of the dos file format on polylight* files and untabified

Asad M. Zaman 21 years ago
parent
commit
9b3a2b9f98

+ 3 - 3
panda/src/pgraph/polylightEffect.I

@@ -115,8 +115,8 @@ remove_light(const string &lightname) {
 INLINE bool PolylightEffect::
 INLINE bool PolylightEffect::
 remove_all() {
 remove_all() {
   LIGHTGROUP::const_iterator light_iter;
   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);
     _lightgroup.erase(lightname);
   }
   }
   return true;
   return true;
@@ -156,7 +156,7 @@ get_weight() const {
 //               _contribution_type is a string that controls how
 //               _contribution_type is a string that controls how
 //               this division occurs.
 //               this division occurs.
 //               "proximal" : A light only contributes if the node 
 //               "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
 //               "all" : All lights added to the effect are used in
 //               division irrespective of their light volumes
 //               division irrespective of their light volumes
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////

+ 85 - 85
panda/src/pgraph/polylightEffect.cxx

@@ -42,94 +42,94 @@ make() {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: PolylightEffect::do_poly_light
 //     Function: PolylightEffect::do_poly_light
 //       Access: Public
 //       Access: Public
-//  Description: Gets the node's position and based on distance from 
+//  Description: Gets the node's position and based on distance from
 //  lights in the lightgroup calculates the color to be modulated in
 //  lights in the lightgroup calculates the color to be modulated in
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 CPT(RenderAttrib) PolylightEffect::
 CPT(RenderAttrib) PolylightEffect::
 do_poly_light(const CullTraverserData *data, const TransformState *node_transform) const {
 do_poly_light(const CullTraverserData *data, const TransformState *node_transform) const {
   float r,g,b; // To hold the color calculation
   float r,g,b; // To hold the color calculation
   float dist; // To calculate the distance of each light from the node
   float dist; // To calculate the distance of each light from the node
-  float light_scale = 1.0; // Variable to calculate attenuation 
+  float light_scale = 1.0; // Variable to calculate attenuation
   float fd; // Variable for quadratic attenuation
   float fd; // Variable for quadratic attenuation
   float Rcollect = 0.0,Gcollect = 0.0,Bcollect = 0.0; // Color variables
   float Rcollect = 0.0,Gcollect = 0.0,Bcollect = 0.0; // Color variables
   int num_lights = 0; // Keep track of number of lights for division
   int num_lights = 0; // Keep track of number of lights for division
   r = 0.0;
   r = 0.0;
   g = 0.0;
   g = 0.0;
   b = 0.0;
   b = 0.0;
-  LIGHTGROUP::const_iterator light_iter; 
+  LIGHTGROUP::const_iterator light_iter;
   // Cycle through all the lights in this effect's lightgroup
   // 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();
-	  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;
-  
+  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));
   return ColorScaleAttrib::make(LVecBase4f(r,g,b,1.0));
 }
 }
 
 
@@ -155,21 +155,21 @@ compare_to_impl(const RenderEffect *other) const {
   DCAST_INTO_R(ta, other, 0);
   DCAST_INTO_R(ta, other, 0);
 
 
   if (_enabled != ta->_enabled) {
   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) {
   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;
   return 0;
 }
 }
 
 

+ 8 - 8
panda/src/pgraph/polylightEffect.h

@@ -20,7 +20,7 @@
 #define POLYLIGHTEFFECT_H
 #define POLYLIGHTEFFECT_H
 
 
 #include "pandabase.h"
 #include "pandabase.h"
-
+
 
 
 #include "renderEffect.h"
 #include "renderEffect.h"
 #include "luse.h"
 #include "luse.h"
@@ -33,16 +33,16 @@
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //       Class : PolylightEffect
 //       Class : PolylightEffect
 // Description : A PolylightEffect can be used on a node to define a
 // Description : A PolylightEffect can be used on a node to define a
-//				 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
+//               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
 //               specially for night scenes
 //               specially for night scenes
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 class EXPCL_PANDA PolylightEffect : public RenderEffect {
 class EXPCL_PANDA PolylightEffect : public RenderEffect {
 private:
 private:
   INLINE PolylightEffect();
   INLINE PolylightEffect();
-  
+
 
 
 PUBLISHED:
 PUBLISHED:
   enum Contrib_Type {
   enum Contrib_Type {
@@ -58,7 +58,7 @@ PUBLISHED:
   INLINE bool remove_all();
   INLINE bool remove_all();
   INLINE bool set_weight(float w);
   INLINE bool set_weight(float w);
   INLINE float get_weight() const;
   INLINE float get_weight() const;
-  INLINE bool set_contrib(Contrib_Type type);  
+  INLINE bool set_contrib(Contrib_Type type);
   INLINE Contrib_Type get_contrib() const;
   INLINE Contrib_Type get_contrib() const;
   INLINE bool is_enabled()const;
   INLINE bool is_enabled()const;
   INLINE void set_effect_center(LPoint3f effect_center);
   INLINE void set_effect_center(LPoint3f effect_center);
@@ -77,7 +77,7 @@ private:
   typedef pmap<string, NodePath> LIGHTGROUP;
   typedef pmap<string, NodePath> LIGHTGROUP;
   LIGHTGROUP _lightgroup;
   LIGHTGROUP _lightgroup;
   LPoint3f _effect_center;
   LPoint3f _effect_center;
-  
+
 
 
 public:
 public:
   static TypeHandle get_class_type() {
   static TypeHandle get_class_type() {

+ 33 - 33
panda/src/pgraph/polylightNode.cxx

@@ -75,37 +75,37 @@ Colorf PolylightNode::flicker() const {
   g = color[1];
   g = color[1];
   b = color[2];
   b = color[2];
   float variation= 0.0;
   float variation= 0.0;
-  
+
   if(_flicker_type == FRANDOM) {
   if(_flicker_type == FRANDOM) {
     //srand((int)ClockObject::get_global_clock()->get_frame_time());
     //srand((int)ClockObject::get_global_clock()->get_frame_time());
     variation = (rand()%100);// * ClockObject::get_global_clock()->get_dt();
     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 == FSIN) {
   else if(_flicker_type == FSIN) {
-	double now = ClockObject::get_global_clock()->get_frame_time();
+    double now = ClockObject::get_global_clock()->get_frame_time();
     variation = sinf(now*_sin_freq);// * ClockObject::get_global_clock()->get_dt();
     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 == FCUSTOM) {
   else if(_flicker_type == FCUSTOM) {
     // fixed point list of variation values coming soon...
     // 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();
     //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);
   //printf("Variation: %f\n",variation);
   r+=variation;
   r+=variation;
   g+=variation;
   g+=variation;
   b+=variation;
   b+=variation;
- 
+
   /* CLAMPING
   /* CLAMPING
   if(fabs(r - color[0]) > 0.5 || fabs(g - color[1]) > 0.5 || fabs(b - color[2]) > 0.5) {
   if(fabs(r - color[0]) > 0.5 || fabs(g - color[1]) > 0.5 || fabs(b - color[2]) > 0.5) {
     r = color[0];
     r = color[0];
@@ -126,7 +126,7 @@ Colorf PolylightNode::flicker() const {
 //
 //
 //               Two PolylightNodes are considered equivalent if they
 //               Two PolylightNodes are considered equivalent if they
 //               consist of exactly the same properties
 //               consist of exactly the same properties
-//				 Otherwise, they are different; different
+//               Otherwise, they are different; different
 //               PolylightNodes will be ranked in a consistent but
 //               PolylightNodes will be ranked in a consistent but
 //               undefined ordering; the ordering is useful only for
 //               undefined ordering; the ordering is useful only for
 //               placing the PolylightNodes in a sorted container like an
 //               placing the PolylightNodes in a sorted container like an
@@ -134,64 +134,64 @@ Colorf PolylightNode::flicker() const {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 int PolylightNode::
 int PolylightNode::
 compare_to(const PolylightNode &other) const {
 compare_to(const PolylightNode &other) const {
-  
+
   if (_enabled != other._enabled) {
   if (_enabled != other._enabled) {
-	return _enabled ? 1 :-1;
+    return _enabled ? 1 :-1;
   }
   }
 
 
   if (_radius != other._radius) {
   if (_radius != other._radius) {
-	return _radius < other._radius ? -1 :1;
+    return _radius < other._radius ? -1 :1;
   }
   }
   LVecBase3f position = get_pos();
   LVecBase3f position = get_pos();
   LVecBase3f other_position = other.get_pos();
   LVecBase3f other_position = other.get_pos();
   if (position != other_position) {
   if (position != other_position) {
-	return position < other_position ? -1 :1;
+    return position < other_position ? -1 :1;
   }
   }
 
 
   Colorf color = get_color();
   Colorf color = get_color();
   Colorf other_color = other.get_color();
   Colorf other_color = other.get_color();
   if (color != other_color) {
   if (color != other_color) {
-	return color < other_color ? -1 :1;
+    return color < other_color ? -1 :1;
   }
   }
 
 
   if (_attenuation_type != other._attenuation_type) {
   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) {
   if (_a0 != other._a0) {
-	return _a0 < other._a0 ? -1 :1;
+    return _a0 < other._a0 ? -1 :1;
   }
   }
 
 
   if (_a1 != other._a1) {
   if (_a1 != other._a1) {
-	return _a1 < other._a1 ? -1 :1;
+    return _a1 < other._a1 ? -1 :1;
   }
   }
 
 
   if (_a2 != other._a2) {
   if (_a2 != other._a2) {
-	return _a2 < other._a2 ? -1 :1;
+    return _a2 < other._a2 ? -1 :1;
   }
   }
 
 
   if (_flickering != other._flickering) {
   if (_flickering != other._flickering) {
-	return _flickering ? 1 :-1;
+    return _flickering ? 1 :-1;
   }
   }
 
 
   if (_flicker_type != other._flicker_type) {
   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) {
   if (_offset != other._offset) {
-	return _offset < other._offset ? -1 :1;
+    return _offset < other._offset ? -1 :1;
   }
   }
 
 
   if (_scale != other._scale) {
   if (_scale != other._scale) {
-	return _scale < other._scale ? -1 :1;
+    return _scale < other._scale ? -1 :1;
   }
   }
 
 
   if (_step_size != other._step_size) {
   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) {
   if (_sin_freq != other._sin_freq) {
-	return _sin_freq < other._sin_freq ? -1 :1;
+    return _sin_freq < other._sin_freq ? -1 :1;
   }
   }
 
 
 
 
@@ -282,7 +282,7 @@ fillin(DatagramIterator &scan, BamReader *manager) {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: PolylightNode::output
 //     Function: PolylightNode::output
 //       Access: Public, Virtual
 //       Access: Public, Virtual
-//  Description: 
+//  Description:
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 void PolylightNode::
 void PolylightNode::
 output(ostream &out) const {
 output(ostream &out) const {

+ 7 - 7
panda/src/pgraph/polylightNode.h

@@ -38,14 +38,14 @@ class EXPCL_PANDA PolylightNode : public PandaNode{
 
 
 PUBLISHED:
 PUBLISHED:
   /*
   /*
-  // This was the old constructor... interrogate would generate a 
-  // separate wrapper for each parameter... so its better to 
+  // 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
   // have a simpler constructor and require the programmer
   // to use set_* methods.
   // to use set_* methods.
   PolylightNode(const string &name, float x = 0.0, float y = 0.0, float z = 0.0,
   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 {
   enum Flicker_Type {
@@ -103,7 +103,7 @@ PUBLISHED:
 public:
 public:
   Colorf flicker() const;
   Colorf flicker() const;
 
 
-  
+
 private:
 private:
   bool _enabled;
   bool _enabled;
   LVecBase3f _position;
   LVecBase3f _position;
@@ -121,7 +121,7 @@ private:
   float _sin_freq;
   float _sin_freq;
   //float _speed;
   //float _speed;
   //float fixed_points
   //float fixed_points
-  
+
 
 
 public:
 public:
   static void register_with_read_factory();
   static void register_with_read_factory();