fixed the flicker bug where colors would snap suddenly

This commit is contained in:
Asad M. Zaman 2004-09-09 19:26:55 +00:00
parent 7ff0b84f6a
commit 459cd34f31
2 changed files with 17 additions and 15 deletions

View File

@ -155,7 +155,7 @@ do_poly_light(const CullTraverserData *data, const TransformState *node_transfor
dist = xz.length(); // this does not count height difference 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() << "light's position = " << light->get_pos() << endl;
pgraph_cat.debug() << "relative position = " << point << endl; pgraph_cat.debug() << "relative position = " << point << endl;
pgraph_cat.debug() << "effect center = " << _effect_center << 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; r = Rcollect / num_lights;
g = Gcollect / num_lights; g = Gcollect / num_lights;
b = Bcollect / 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)); return ColorScaleAttrib::make(LVecBase4f(r, g, b, 1.0));

View File

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