From 459cd34f31709837f74ee39ef7dad9b405539e90 Mon Sep 17 00:00:00 2001 From: "Asad M. Zaman" Date: Thu, 9 Sep 2004 19:26:55 +0000 Subject: [PATCH] fixed the flicker bug where colors would snap suddenly --- panda/src/pgraph/polylightEffect.cxx | 4 ++-- panda/src/pgraph/polylightNode.cxx | 28 +++++++++++++++------------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/panda/src/pgraph/polylightEffect.cxx b/panda/src/pgraph/polylightEffect.cxx index dca7ad7a84..79f2f105dd 100755 --- a/panda/src/pgraph/polylightEffect.cxx +++ b/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)); diff --git a/panda/src/pgraph/polylightNode.cxx b/panda/src/pgraph/polylightNode.cxx index feff3a6d4b..84c2d406c8 100755 --- a/panda/src/pgraph/polylightNode.cxx +++ b/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); }