rendergather / osgocean

Automatically exported from code.google.com/p/osgocean
GNU Lesser General Public License v3.0
0 stars 0 forks source link

FFTOceanSurface::computeNoiseCoords() breaks on large time jumps #23

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Because FFTOceanSurface::computeNoiseCoords() simply keeps increasing a
static (not nice) float (not nice in combination) large time jumps can lead
to an unrecoverable state with not enough precision available in the
counter to provide smooth animation.

Although these time jumps are probably caused by a bug in my application I
still consider osgOcean's behaviour here a bug - locally I added a _time,
added a advanceTime(dt); call to update() and changed the logic to:

void FFTOceanSurface::advanceTime( const double& dt )
{
    float maxLength = 32.f * osg::Vec2f(2.f, 4.f).length();
    float maxTotalTime = maxLength / 2.0;    
    _time += dt * 0.0008;
    _time = fmod(_time, maxTotalTime);
}

osg::Vec3f FFTOceanSurface::computeNoiseCoords(float noiseSize, const
osg::Vec2f& movement, float speed)
{
    float length = noiseSize*movement.length();
    float tileScale = _tileResInv * noiseSize;
    osg::Vec2f velocity = movement * speed / length;
    osg::Vec2f pos = velocity * _time;
    osg::Vec3f x = osg::Vec3f( pos, tileScale );
    return x;
}

... now, due to the copied (from update()) magic constants in advanceTime()
(one obviously needs the largest used values) I realize this might not be
inclusion-worthy, but I don't know how to properly do this as I have no
idea where the magic constants in update() come from in the first place. :-)

Original issue reported on code.google.com by felix.nawothnig on 31 Mar 2010 at 8:57