Пример #1
0
 void onMapModelChanged( const MapModelChange& change )
 {
     osg::ref_ptr<TerrainEngineNode> safeNode = _node.get();
     if ( safeNode.valid() )
         safeNode->onMapModelChanged( change );
 }
Пример #2
0
 void onMapInfoEstablished( const MapInfo& mapInfo ) {
     _node->onMapInfoEstablished( mapInfo );
 }
Пример #3
0
 void onMapModelChanged( const MapModelChange& change ) {
     _node->onMapModelChanged( change );
 }
Пример #4
0
 void onMapInfoEstablished( const MapInfo& mapInfo )
 {
     osg::ref_ptr<TerrainEngineNode> safeNode = _node.get();
     if ( safeNode.valid() )
         safeNode->onMapInfoEstablished( mapInfo );
 }
Пример #5
0
SlideEventHandler* SlideEventHandler::instance() { return s_seh.get(); }
Пример #6
0
 void onMapModelChanged( const MapModelChange& change )
 {
     osg::ref_ptr<TerrainEngineNode> safeNode;
     if (_node.lock(safeNode))
         safeNode->onMapModelChanged( change );
 }
Пример #7
0
 void onMapInfoEstablished( const MapInfo& mapInfo )
 {
     osg::ref_ptr<TerrainEngineNode> safeNode;
     if (_node.lock(safeNode))
         safeNode->onMapInfoEstablished( mapInfo );
 }
Пример #8
0
void SDLAudioSink::play()
{
    if (_started)
    {
        if (_paused)
        {
            SDL_PauseAudio(0);
            _paused = false;
        }
        return;
    }

    _started = true;
    _paused = false;

    osg::notify(osg::NOTICE)<<"SDLAudioSink()::startPlaying()"<<std::endl;

    osg::notify(osg::NOTICE)<<"  audioFrequency()="<<_audioStream->audioFrequency()<<std::endl;
    osg::notify(osg::NOTICE)<<"  audioNbChannels()="<<_audioStream->audioNbChannels()<<std::endl;
    osg::notify(osg::NOTICE)<<"  audioSampleFormat()="<<_audioStream->audioSampleFormat()<<std::endl;



    SDL_AudioSpec specs = { 0 };
    SDL_AudioSpec wanted_specs = { 0 };

    wanted_specs.freq = _audioStream->audioFrequency();
    wanted_specs.channels = _audioStream->audioNbChannels();
    wanted_specs.silence = 0;
    wanted_specs.samples = 1024;
    wanted_specs.callback = soundReadCallback;
    wanted_specs.userdata = this;
    wanted_specs.format = 0;

#if SDL_MAJOR_VERSION>=2
    switch(_audioStream->audioSampleFormat())
    {
        case(osg::AudioStream::SAMPLE_FORMAT_U8):  { wanted_specs.format = AUDIO_U8; OSG_NOTICE<<"    SampleFormat  = SAMPLE_FORMAT_U8"<<std::endl;  break;}
        case(osg::AudioStream::SAMPLE_FORMAT_S16): { wanted_specs.format = AUDIO_S16SYS; OSG_NOTICE<<"    SampleFormat  = SAMPLE_FORMAT_S16"<<std::endl; break; }
        case(osg::AudioStream::SAMPLE_FORMAT_S24): { OSG_NOTICE<<"    SampleFormat  = SAMPLE_FORMAT_S24 NOT Supported by SDL."<<std::endl; break; }
        case(osg::AudioStream::SAMPLE_FORMAT_S32): { wanted_specs.format = AUDIO_S32SYS; OSG_NOTICE<<"    SampleFormat  = SAMPLE_FORMAT_S32"<<std::endl; break; }
        case(osg::AudioStream::SAMPLE_FORMAT_F32): { wanted_specs.format = AUDIO_F32SYS; OSG_NOTICE<<"    SampleFormat  = SAMPLE_FORMAT_F32"<<std::endl; break; }
    }
#else
    switch(_audioStream->audioSampleFormat())
    {
        case(osg::AudioStream::SAMPLE_FORMAT_U8):  { wanted_specs.format = AUDIO_U8; OSG_NOTICE<<"    SampleFormat  = SAMPLE_FORMAT_U8"<<std::endl;  break;}
        case(osg::AudioStream::SAMPLE_FORMAT_S16): { wanted_specs.format = AUDIO_S16SYS; OSG_NOTICE<<"    SampleFormat  = SAMPLE_FORMAT_S16"<<std::endl; break; }
        case(osg::AudioStream::SAMPLE_FORMAT_S24): { OSG_NOTICE<<"    SampleFormat  = SAMPLE_FORMAT_S24 NOT Supported by SDL1.x."<<std::endl; break; }
        case(osg::AudioStream::SAMPLE_FORMAT_S32): { OSG_NOTICE<<"    SampleFormat  = SAMPLE_FORMAT_S32 NOT Supported by SDL1.x"<<std::endl; break; }
        case(osg::AudioStream::SAMPLE_FORMAT_F32): { OSG_NOTICE<<"    SampleFormat  = SAMPLE_FORMAT_F32 NOT Supported by SDL1.x"<<std::endl; break; }
    }
#endif

    if (wanted_specs.format!=0)
    {

        if (SDL_OpenAudio(&wanted_specs, &specs) < 0)
            throw "SDL_OpenAudio() failed (" + std::string(SDL_GetError()) + ")";

        SDL_PauseAudio(0);
    }
    else
    {
        throw "SDL_OpenAudio() does not support audio format";
    }
}
bool MovieEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa, osg::Object*, osg::NodeVisitor* /*nv*/)
{
    switch(ea.getEventType())
    {
        case(osgGA::GUIEventAdapter::MOVE):
        {
            if(_currentImageStream.valid() && (ea.getModKeyMask() & osgGA::GUIEventAdapter::MODKEY_SHIFT))
            {
                float scalar = (ea.getXnormalized()+1) / 2.0;
                _currentImageStream->seek(scalar * _currentImageStream->getLength());
            }
        }
        break;

        case(osgGA::GUIEventAdapter::RELEASE):
        {

            osgViewer::View* view = dynamic_cast<osgViewer::View*>(&aa);
            osgUtil::LineSegmentIntersector::Intersections intersections;
            bool foundIntersection = view==0 ? false : view->computeIntersections(ea, intersections);

            if (foundIntersection)
            {
                // use the nearest intersection
                const osgUtil::LineSegmentIntersector::Intersection& intersection = *(intersections.begin());
                osg::Drawable* drawable = intersection.drawable.get();
                osg::Geometry* geometry = drawable ? drawable->asGeometry() : 0;

                if (geometry) {
                    osg::Texture* tex = geometry->getStateSet() ? dynamic_cast<osg::Texture*>(geometry->getStateSet()->getTextureAttribute(0, osg::StateAttribute::TEXTURE)) : NULL;
                    if (tex) {
                        osg::ImageStream* is = dynamic_cast<osg::ImageStream*>(tex->getImage(0));
                        if (is)
                        {
                            setColor(_currentGeometry.get(), osg::Vec4(0.7, 0.7, 0.7, 1.0));
                            _currentGeometry = geometry;
                            setColor(_currentGeometry.get(), osg::Vec4(1,1,1,1));
                            _currentImageStream = is;

                            if (is->getStatus() == osg::ImageStream::PLAYING)
                            {
                                is->pause();
                            }
                            else
                            {
                                is->play();
                            }

                        }
                    }
                }
            }

            break;
        }
        case(osgGA::GUIEventAdapter::KEYDOWN):
        {
            if (!_currentImageStream.valid())
                return false;

            if (ea.getKey()=='p')
            {
                osg::ImageStream::StreamStatus playToggle = _currentImageStream->getStatus();
                if (playToggle != osg::ImageStream::PLAYING)
                {
                    std::cout<< _currentImageStream.get() << " Play"<<std::endl;
                    _currentImageStream->play();
                }
                else
                {
                    // playing, so pause
                    std::cout<< _currentImageStream.get() << " Pause"<<std::endl;
                    _currentImageStream->pause();
                }
                return true;
            }
            else if (ea.getKey()=='r')
            {
                std::cout<< _currentImageStream.get() << " Restart"<<std::endl;
                _currentImageStream->rewind();
                _currentImageStream->play();
                return true;
            }
            else if (ea.getKey()=='>')
            {
                std::cout << _currentImageStream.get() << " Seeking"<<std::endl;
                _currentImageStream->seek(_currentImageStream->getCurrentTime() + 1.0);

                return true;
            }
            else if (ea.getKey()=='L')
            {
                if ( _currentImageStream->getLoopingMode() == osg::ImageStream::LOOPING)
                {
                    std::cout<< _currentImageStream.get() << " Toggle Looping Off"<<std::endl;
                    _currentImageStream->setLoopingMode( osg::ImageStream::NO_LOOPING );
                }
                else
                {
                    std::cout<< _currentImageStream.get() << " Toggle Looping On"<<std::endl;
                    _currentImageStream->setLoopingMode( osg::ImageStream::LOOPING );
                }
                return true;
            }
            else if (ea.getKey()=='+')
            {
                double tm = _currentImageStream->getTimeMultiplier();
                tm += 0.1;
                _currentImageStream->setTimeMultiplier(tm);
                std::cout << _currentImageStream.get() << " Increase speed rate "<< _currentImageStream->getTimeMultiplier() << std::endl;

                return true;
            }
            else if (ea.getKey()=='-')
            {
                double tm = _currentImageStream->getTimeMultiplier();
                tm -= 0.1;
                _currentImageStream->setTimeMultiplier(tm);
                std::cout << _currentImageStream.get() << " Decrease speed rate "<< _currentImageStream->getTimeMultiplier() << std::endl;

                return true;
            }
            else if (ea.getKey()=='o')
            {
                std::cout<< _currentImageStream.get() << " Frame rate  "<< _currentImageStream->getFrameRate() <<std::endl;

                return true;
            }
            return false;
        }

        default:
            return false;
    }
    return false;
}