Browse Source

fixed the flicker bug where colors would snap suddenly

Asad M. Zaman 21 years ago
parent
commit
459cd34f31
2 changed files with 17 additions and 15 deletions
  1. 2 2
      panda/src/pgraph/polylightEffect.cxx
  2. 15 13
      panda/src/pgraph/polylightNode.cxx

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

@@ -155,7 +155,7 @@ do_poly_light(const CullTraverserData *data, const TransformState *node_transfor
         dist = xz.length(); // this does not count height difference
       }
 
-      if (dist < light_radius) { // If node is in range of this light
+      if (dist <= light_radius) { // If node is in range of this light
         pgraph_cat.debug() << "light's position = " << light->get_pos() << endl;
         pgraph_cat.debug() << "relative position = " << point << endl;
         pgraph_cat.debug() << "effect center = " << _effect_center << endl;
@@ -222,7 +222,7 @@ do_poly_light(const CullTraverserData *data, const TransformState *node_transfor
     r = Rcollect / num_lights;
     g = Gcollect / num_lights;
     b = Bcollect / num_lights;
-    pgraph_cat.debug() << "r = " << r << ";g = " << g << ";b = " << b << endl;
+    pgraph_cat.info() << "r=" << r << "; g=" << g << "; b=" << b << endl;
   }
 
   return ColorScaleAttrib::make(LVecBase4f(r, g, b, 1.0));

+ 15 - 13
panda/src/pgraph/polylightNode.cxx

@@ -69,27 +69,25 @@ PandaNode(name)
 Colorf PolylightNode::flicker() const {
   float r,g,b;
 
-  Colorf color;
-  color = get_color();
-  //color = get_color_scenegraph();
+  float variation= 0.0;
+  Colorf color = get_color();  //color = get_color_scenegraph();
+
   r = color[0];
   g = color[1];
   b = color[2];
-  float variation= 0.0;
   
   if (_flicker_type == FRANDOM) {
     //srand((int)ClockObject::get_global_clock()->get_frame_time());
-    variation = (rand()%100);// * ClockObject::get_global_clock()->get_dt();
+    variation = (rand()%100);  // a value between 0-99
     variation /= 100.0;
-    //printf("Random Variation: %f\n",variation);
-    //variation += _offset;
-    variation *= _scale;
+    pgraph_cat.info() << "Random Variation: " << variation << endl;
   } 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;
+    variation = sinf(now*_sin_freq);
+    pgraph_cat.info() << "Variation: " << variation << endl;
+    // can't use negative variation, so make it positive
+    if (variation < 0.0)
+      variation *= -1.0;
   } 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();
@@ -100,6 +98,10 @@ Colorf PolylightNode::flicker() const {
         variation *= _scale;
       }*/
   }
+  
+  //variation += _offset;
+  variation *= _scale;
+
   //printf("Variation: %f\n",variation);
   r+=variation;
   g+=variation;
@@ -112,7 +114,7 @@ Colorf PolylightNode::flicker() const {
     b = color[2];
   }
   */
-  //printf("Color R:%f G:%f B:%f\n",r,g,b);
+  pgraph_cat.debug() << "Color R:" << r << "; G:" << g << "; B:" << b << endl;
   return Colorf(r,g,b,1.0);
 }