<commit_before>#include <osgGA/AnimationPathManipulator>
#include <stdio.h>

using namespace osgGA;

AnimationPathManipulator::AnimationPathManipulator(osg::AnimationPath* animationPath) 
{
    _animationPath = animationPath;
    _timeOffset = 0.0;
    _timeScale = 1.0;
    _isPaused = false;
    
    _realStartOfTimedPeriod = 0.0;
    _animStartOfTimedPeriod = 0.0;
    _numOfFramesSinceStartOfTimedPeriod = -1; // need to init.
}

AnimationPathManipulator::AnimationPathManipulator( const std::string& filename ) 
{
    _animationPath = new osg::AnimationPath;
    _animationPath->setLoopMode(osg::AnimationPath::LOOP);
    _timeOffset = 0.0f;
    _timeScale = 1.0f;
    _isPaused = false;

    FILE *fp = fopen( filename.c_str(), "r" );
    if( fp == NULL )
    {
        osg::notify(osg::WARN) << "AnimationPathManipulator: Cannot open animation path file \"" << filename << "\".\n";
        _valid = false;
        return;
    }
    while( !feof( fp ))
    {
        double time;
            osg::Vec3 position;
            osg::Quat rotation;
        fscanf( fp, "%lf %f %f %f %f %f %f %f\n",
            &time, &position[0], &position[1], &position[2],
            &rotation[0], &rotation[1], &rotation[2], &rotation[3] );

        if( !feof(fp))
                _animationPath->insert(time,osg::AnimationPath::ControlPoint(position,rotation));
    }
    fclose(fp);
}

void AnimationPathManipulator::home(const GUIEventAdapter& ea,GUIActionAdapter&)
{
    if (_animationPath.valid())
    {
        _timeOffset = _animationPath->getFirstTime()-ea.time();
    }
}

void AnimationPathManipulator::init(const GUIEventAdapter& ea,GUIActionAdapter& aa)
{
    home(ea,aa);
}

bool AnimationPathManipulator::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& us)
{
    if( !valid() ) return false;

    us = us;

    bool retval = false;
    switch( ea.getEventType() )
    {
    case GUIEventAdapter::FRAME:
        if( _isPaused )
        {
            handleFrame( _pauseTime );
        }
        else
        {
            handleFrame( ea.time() );
        }
            retval =  true;
        break;
    case GUIEventAdapter::KEYDOWN:
            if (ea.getKey()==' ')
            {
                home(ea,us);
                us.requestRedraw();
                us.requestContinuousUpdate(false);
                return true;
            } 
            else if(ea.getKey() == 'p')
            {
                if( _isPaused )
                {
                    _isPaused = false;
                    _timeOffset -= ea.time() - _pauseTime;
                }
                else
                {
                    _isPaused = true;
                    _pauseTime = ea.time();
                }
                us.requestRedraw();
                us.requestContinuousUpdate(false);<commit_msg>Made the AnimationPathManipulator::home() reset the timming of the animation path so that the timing always starts at the begining of the loop.<commit_after>#include <osgGA/AnimationPathManipulator>
#include <stdio.h>

using namespace osgGA;

AnimationPathManipulator::AnimationPathManipulator(osg::AnimationPath* animationPath) 
{
    _animationPath = animationPath;
    _timeOffset = 0.0;
    _timeScale = 1.0;
    _isPaused = false;
    
    _realStartOfTimedPeriod = 0.0;
    _animStartOfTimedPeriod = 0.0;
    _numOfFramesSinceStartOfTimedPeriod = -1; // need to init.
}

AnimationPathManipulator::AnimationPathManipulator( const std::string& filename ) 
{
    _animationPath = new osg::AnimationPath;
    _animationPath->setLoopMode(osg::AnimationPath::LOOP);
    _timeOffset = 0.0f;
    _timeScale = 1.0f;
    _isPaused = false;

    FILE *fp = fopen( filename.c_str(), "r" );
    if( fp == NULL )
    {
        osg::notify(osg::WARN) << "AnimationPathManipulator: Cannot open animation path file \"" << filename << "\".\n";
        _valid = false;
        return;
    }
    while( !feof( fp ))
    {
        double time;
            osg::Vec3 position;
            osg::Quat rotation;
        fscanf( fp, "%lf %f %f %f %f %f %f %f\n",
            &time, &position[0], &position[1], &position[2],
            &rotation[0], &rotation[1], &rotation[2], &rotation[3] );

        if( !feof(fp))
                _animationPath->insert(time,osg::AnimationPath::ControlPoint(position,rotation));
    }
    fclose(fp);
}

void AnimationPathManipulator::home(const GUIEventAdapter& ea,GUIActionAdapter&)
{
    if (_animationPath.valid())
    {
        _timeOffset = _animationPath->getFirstTime()-ea.time();

    }

    // reset the timing of the animation.
    _numOfFramesSinceStartOfTimedPeriod=-1;
                
}

void AnimationPathManipulator::init(const GUIEventAdapter& ea,GUIActionAdapter& aa)
{
    home(ea,aa);
}

bool AnimationPathManipulator::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& us)
{
    if( !valid() ) return false;

    us = us;

    bool retval = false;
    switch( ea.getEventType() )
    {
    case GUIEventAdapter::FRAME:
        if( _isPaused )
        {
            handleFrame( _pauseTime );
        }
        else
        {
            handleFrame( ea.time() );
        }
            retval =  true;
        break;
    case GUIEventAdapter::KEYDOWN:
            if (ea.getKey()==' ')
            {
                home(ea,us);
                us.requestRedraw();
                us.requestContinuousUpdate(false);
                
                return true;
            } 
            else if(ea.getKey() == 'p')
            {
                if( _isPaused )
                {
                    _isPaused = false;
                    _timeOffset -= ea.time() - _pauseTime;
                }
                else
                {
                    _isPaused = true;
                    _pauseTime = ea.time();
                }
                us.requestRedraw();
                us.requestContinuousUpdate(false);
{'fraction_non_alphanumeric': 0.12126865671641791, 'fraction_numerical': 0.007293080054274084, 'mean_word_length': 1.982802225594335, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4425909', 'n_tokens_mistral': 1899, 'n_tokens_neox': 1811, 'n_words': 347}