Esempio n. 1
0
void GameOverState::setCallbacks(const std::vector<Callback>& callbacks) {
	for (int i = 0; i < m_gameObjects.size(); i++) {
		if (dynamic_cast<MenuButton*>(m_gameObjects[i])) {
			MenuButton* pButton = dynamic_cast<MenuButton*>(m_gameObjects[i]);
			pButton->setCallback(callbacks[pButton->getCallbackID()]);
		}
	}
}
Esempio n. 2
0
void MenuState::setCallbacks(const std::vector<Callback>&callbacks){
	// go through the game objects
	for (int i = 0; i < m_gameObjectsMenuState.size(); i++)
	{
		// if they are of type MenuButton then assign a callback based on the id passed in from the file
			if (dynamic_cast<MenuButton*>(m_gameObjectsMenuState[i]))
			{
				MenuButton* pButton = dynamic_cast<MenuButton*>(m_gameObjectsMenuState[i]);
				pButton->setCallback(callbacks[pButton->getCallbackID()]);
			}
	}
}
Esempio n. 3
0
bool OsgMovie::init()
{
    std::cerr << "OsgMovie init\n";
    //osg::setNotifyLevel( osg::INFO );

    _loadMenu = new SubMenu("OsgMovie");
    _loadMenu->setCallback(this);
    MenuSystem::instance()->addMenuItem(_loadMenu);

    string configBase = "Plugin.OsgMovie";
    std::vector<std::string> list;

    ConfigManager::getChildren(configBase, list);

    for(int i = 0; i < list.size(); i++)
    {
        MenuButton * button = new MenuButton(list[i]);
        button->setCallback(this);
        _loadMenu->addItem(button);
        _loadButtons.push_back(button);
    }


    configPath = ConfigManager::getEntry("Plugin.OsgMovie.ConfigDir");

    ifstream cfile;
    cfile.open((configPath + "/Init.cfg").c_str(), ios::in);

    if(!cfile.fail())
    {
        string line;
        while(!cfile.eof())
        {
            Matrix m;
            char name[150];
            int stereo;
            cfile >> name;
            if(cfile.eof())
            {
                break;
            }
            cfile >> stereo;
            for(int i = 0; i < 4; i++)
            {
                for(int j = 0; j < 4; j++)
                {
                    cfile >> m(i, j);
                }
            }
            _configMap[string(name)] = std::pair<int, osg::Matrix> (stereo,m);
        }
    }
Esempio n. 4
0
void TextInputPanel::makeNumberRow()
{
    _numberRow = new MenuItemGroup(MenuItemGroup::ROW_LAYOUT);
    addMenuItem(_numberRow);

    MenuButton * mb;
    mb = new MenuButton("1",false);
    mb->setCallback(this);
    _numberRow->addItem(mb);
    mb = new MenuButton("2",false);
    mb->setCallback(this);
    _numberRow->addItem(mb);
    mb = new MenuButton("3",false);
    mb->setCallback(this);
    _numberRow->addItem(mb);
    mb = new MenuButton("4",false);
    mb->setCallback(this);
    _numberRow->addItem(mb);
    mb = new MenuButton("5",false);
    mb->setCallback(this);
    _numberRow->addItem(mb);
    mb = new MenuButton("6",false);
    mb->setCallback(this);
    _numberRow->addItem(mb);
    mb = new MenuButton("7",false);
    mb->setCallback(this);
    _numberRow->addItem(mb);
    mb = new MenuButton("8",false);
    mb->setCallback(this);
    _numberRow->addItem(mb);
    mb = new MenuButton("9",false);
    mb->setCallback(this);
    _numberRow->addItem(mb);
    mb = new MenuButton("0",false);
    mb->setCallback(this);
    _numberRow->addItem(mb);
}
Esempio n. 5
0
bool ImageSequence::init()
{
    _isMenu = new SubMenu("ImageSequence");
    PluginHelper::addRootMenuItem(_isMenu);

    _loadMenu = new SubMenu("Load");
    _isMenu->addItem(_loadMenu);

    std::vector<std::string> tags;
    ConfigManager::getChildren("Plugin.ImageSequence.Files",tags);

    for(int i = 0; i < tags.size(); ++i)
    {
	MenuButton * button = new MenuButton(tags[i]);
	button->setCallback(this);
	_loadMenu->addItem(button);
	_loadButtons.push_back(button);

	SequenceSet * ss = new SequenceSet;
	ss->path = ConfigManager::getEntry("path",std::string("Plugin.ImageSequence.Files.") + tags[i],"");
	ss->start = ConfigManager::getInt("start",std::string("Plugin.ImageSequence.Files.") + tags[i],0);
	ss->frames = ConfigManager::getInt("frames",std::string("Plugin.ImageSequence.Files.") + tags[i],0);
	_sets.push_back(ss);
    }

    int index = ConfigManager::getInt("value","Plugin.ImageSequence.AutoStart",-1);
    if(index >=0 && index < _sets.size())
    {
	_autoStart = true;
	_autoStartIndex = index;
    }
    else
    {
	_autoStart = false;
    }

    _removeButton = new MenuButton("Remove");
    _removeButton->setCallback(this);
    _isMenu->addItem(_removeButton);

    return true;
}
Esempio n. 6
0
void TextInputPanel::addCustomRow(std::vector<std::string> & row)
{
    MenuItemGroup * mig = new MenuItemGroup(MenuItemGroup::ROW_LAYOUT);

    for(int i = 0; i < row.size(); ++i)
    {
	MenuButton * mb = new MenuButton(row[i],false);
	mb->setCallback(this);
	mig->addItem(mb);
    }

    int pos = _rootMenu->getItemPosition(_rowGroup);
    if(pos >= 0)
    {
	_rootMenu->addItem(mig,pos+1);
    }
    else
    {
	_rootMenu->addItem(mig);
    }
}
Esempio n. 7
0
bool OsgMovie::loadFile(std::string filename)
{

    osgDB::Registry::instance()->loadLibrary("osgdb_ffmpeg.so");

    //create shaders for left and right eye (use uniform to set mode, and also set which eye)
    // int eye 0 right eye, 1 left eye
    // mode 0 mono, 1 top down, 2 left right, 3 interlaced (need to complete 3 interlaced)

    /*
        static const char *fragShaderTop = {
    	  "#extension GL_ARB_texture_rectangle : enable\n"
    	  "uniform sampler2DRect movie_texture;\n"
    	  "void main(void)\n"
    	  "{\n"
    	  "    vec2 coord = gl_TexCoord[0].st;\n"
    	  "    ivec2 size = textureSize(movie_texture, 0);\n"
    	  "    coord.t = (size.t * 0.5) + (coord.t * 0.5); \n"
        	  "    gl_FragColor = texture2DRect(movie_texture, coord);\n"
        	  "}\n"
        };

        static const char *fragShaderBottom = {
    	  "#extension GL_ARB_texture_rectangle : enable\n"
    	  "uniform sampler2DRect movie_texture;\n"
    	  "void main(void)\n"
    	  "{\n"
    	  "    vec2 coord = gl_TexCoord[0].st;\n"
    	  "    coord.t = (coord.t * 0.5); \n"
        	  "    gl_FragColor = texture2DRect(movie_texture, coord);\n"
        	  "}\n"
        };

        static const char *fragShaderLeft = {
    	  "#extension GL_ARB_texture_rectangle : enable\n"
    	  "uniform sampler2DRect movie_texture;\n"
    	  "void main(void)\n"
    	  "{\n"
    	  "    vec2 coord = gl_TexCoord[0].st;\n"
    	  "    coord.s = (size.s * 0.5) \n"
        	  "    gl_FragColor = texture2DRect(movie_texture, coord);\n"
        	  "}\n"
        };

        static const char *fragShaderRight = {
    	  "#extension GL_ARB_texture_rectangle : enable\n"
    	  "uniform sampler2DRect movie_texture;\n"
    	  "void main(void)\n"
    	  "{\n"
    	  "    vec2 coord = gl_TexCoord[0].st;\n"
    	  "    ivec2 size = textureSize(movie_texture, 0);\n"
    	  "    coord.s = (size.s * 0.5) + (coord.s * 0.5); \n"
        	  "    gl_FragColor = texture2DRect(movie_texture, coord);\n"
        	  "}\n"
        };

        static const char *fragShaderEven = {
    	  "#extension GL_ARB_texture_rectangle : enable\n"
    	  "uniform sampler2DRect movie_texture;\n"
    	  "void main(void)\n"
    	  "{\n"
    	  "    vec2 coord = gl_TexCoord[0].st;\n"
    	  "    ivec2 size = textureSize(movie_texture, 0); \n"
    	  "    if( findLSB(coord.y) ) \n"
    	  "    coord.s = (size.s * 0.5) + (coord.s * 0.5); \n"
        	  "    gl_FragColor = texture2DRect(movie_texture, coord);\n"
        	  "}\n"
        };
    */
    static const char *fragShader = {
        "#extension GL_ARB_texture_rectangle : enable \n"
        "uniform sampler2DRect movie_texture; \n"
        "uniform int split;\n"
        "uniform int mode;\n"
        "uniform int type;\n"
        "uniform int eye;\n"
        "void main(void)\n"
        "{\n"
        "    vec2 coord = gl_TexCoord[0].st; \n"
        "    ivec2 size = textureSize(movie_texture, 0);\n"
        "	   if( (mode == 0) && split ) \n"
        "    { \n"
        "       if( type == 1 ) \n"
        "            coord.y = (coord.y * 0.5); \n"
        "       else \n"
        "            coord.x = (coord.x * 0.5); \n"
        "    } \n"
        "	   else if( mode == 1) \n"
        "    { \n"
        "        if( type == 1 ) \n"
        "            coord.y = (coord.y * 0.5) + (0.5 * size.y * eye); \n"
        "        else \n"
        "            coord.x = (coord.x * 0.5) + (0.5 * size.x * eye); \n"
        "    } \n"
        "    gl_FragColor = texture2DRect(movie_texture, coord); \n"
        "}\n"
    };


    osg::ref_ptr<osg::MatrixTransform> group = new osg::MatrixTransform;
    osg::ref_ptr<osg::Geode> geodeL = new osg::Geode;
    osg::ref_ptr<osg::Geode> geodeR = new osg::Geode;

    //get state for left geode
    osg::StateSet* stateset = geodeL->getOrCreateStateSet();
    geodeL->setNodeMask(geodeL->getNodeMask() & ~(CULL_MASK_RIGHT));
    stateset->addUniform(new osg::Uniform("eye",0));

    //get state for right geode
    stateset = geodeR->getOrCreateStateSet();
    geodeR->setNodeMask(geodeR->getNodeMask() & ~(CULL_MASK_LEFT));
    geodeR->setNodeMask(geodeR->getNodeMask() & ~(CULL_MASK));
    stateset->addUniform(new osg::Uniform("eye",1));

    group->addChild(geodeR);
    group->addChild(geodeL);

    // add shader to group node
    osg::Program* program = new osg::Program;
    program->addShader(new osg::Shader(osg::Shader::FRAGMENT, fragShader));

    // get name of file
    std::string name(filename);
    size_t found = filename.find_last_of("//");
    if(found != filename.npos)
    {
        name = filename.substr(found + 1,filename.npos);
    }

    // create object to hold movie data
    struct VideoObject * currentobject = new struct VideoObject;
    currentobject->name = name;
    currentobject->stream = NULL;
    currentobject->scene = NULL;
    currentobject->firstPlay = false;
    currentobject->modeUniform = new osg::Uniform("mode",0);
    currentobject->typeUniform = new osg::Uniform("type",0);
    currentobject->splitUniform = new osg::Uniform("split",0);

    // set state parameters
    stateset = group->getOrCreateStateSet();
    stateset->setAttribute(program);
    stateset->addUniform(new osg::Uniform("movie_texture",0));
    stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF);
    stateset->addUniform(currentobject->modeUniform);
    stateset->addUniform(currentobject->typeUniform);
    stateset->addUniform(currentobject->splitUniform);

    osg::Image* image = osgDB::readImageFile(filename.c_str());
    osg::ImageStream* imagestream = dynamic_cast<osg::ImageStream*>(image);
    if (imagestream)
    {
        currentobject->stream = imagestream;
        currentobject->stream->pause();

        osg::ImageStream::AudioStreams& audioStreams = currentobject->stream->getAudioStreams();
        if ( !audioStreams.empty() )
        {
#ifdef FMOD_FOUND
            osg::AudioStream* audioStream = audioStreams[0].get();
            audioStream->setAudioSink(new FmodAudioSink(audioStream));
            currentobject->stream->setVolume(1.0);
#endif
        }
    }

    if (image)
    {
        float width = image->s() * image->getPixelAspectRatio();
        float height = image->t();

        //check the ratio of the image
        float widthFactor = 1.0;
        if( (width / height) > 2.5 )
        {
            widthFactor = 0.5;
            currentobject->splitUniform->set(1); // indicate double image
        }

        osg::ref_ptr<osg::Drawable> drawable = myCreateTexturedQuadGeometry(osg::Vec3(0.0,0.0,0.0), width * widthFactor, height,image);

        if (image->isImageTranslucent())
        {
            drawable->getOrCreateStateSet()->setMode(GL_BLEND, osg::StateAttribute::ON);
            drawable->getOrCreateStateSet()->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
        }

        geodeR->addDrawable(drawable.get());
        geodeL->addDrawable(drawable.get());

        // set bound
        group->dirtyBound();
    }
    else
    {
        printf("Unable to read file\n");
        return false;
    }

    // add stream to the scene
    SceneObject * so = new SceneObject(name,false,false,false,true,true);
    PluginHelper::registerSceneObject(so,"OsgMovie");
    so->addChild(group);
    so->attachToScene();
    so->setNavigationOn(true);
    so->addMoveMenuItem();
    so->addNavigationMenuItem();
    currentobject->scene = so;

    // simple default menu
    MenuCheckbox * mcb = new MenuCheckbox("Play", false); // make toggle button
    mcb->setCallback(this);
    so->addMenuItem(mcb);
    _playMap[currentobject] = mcb;

    MenuButton * mrb = new MenuButton("Restart");
    mrb->setCallback(this);
    so->addMenuItem(mrb);
    _restartMap[currentobject] = mrb;

    MenuCheckbox * scb = new MenuCheckbox("Stereo", false); // make toggle button
    scb->setCallback(this);
    so->addMenuItem(scb);
    _stereoMap[currentobject] = scb;

    MenuCheckbox * tbcb = new MenuCheckbox("TopBottom", false); // make toggle button
    tbcb->setCallback(this);
    so->addMenuItem(tbcb);
    _stereoTypeMap[currentobject] = tbcb;

    MenuRangeValue * ms = new MenuRangeValue("Scale", 0.0, 10.0, 1.0); // make video scale
    ms->setCallback(this);
    so->addMenuItem(ms);
    _scaleMap[currentobject] = ms;

    MenuButton * msab = new MenuButton("Save"); // make position and scale of video
    msab->setCallback(this);
    so->addMenuItem(msab);
    _saveMap[currentobject] = msab;

    MenuButton * mscb = new MenuButton("Load"); // load position of video
    mscb->setCallback(this);
    so->addMenuItem(mscb);
    _loadMap[currentobject] = mscb;

    MenuButton * mb = new MenuButton("Delete");
    mb->setCallback(this);
    so->addMenuItem(mb);
    _deleteMap[currentobject] = mb;

    _loadedVideos.push_back(currentobject);

    return true;
}
Esempio n. 8
0
void TextInputPanel::updateListDisplay()
{
    if(!_searchListGroup)
    {
	_searchListGroup = new MenuItemGroup(MenuItemGroup::COL_LAYOUT,MenuItemGroup::ALIGN_LEFT_INDENT);
	_searchListBar = new MenuBar(osg::Vec4(1.0,1.0,1.0,1.0));
    }

    for(int i = 0; i < _searchListButtons.size(); ++i)
    {
	_searchListGroup->removeItem(_searchListButtons[i]);
    }

    if(_text.empty() || _numDisplayResults <= 0)
    {
	removeMenuItem(_searchListGroup);
	removeMenuItem(_searchListBar);
	return;
    }

    if(!_searchListGroup->getParent())
    {
	/*int pos = _rootMenu->getItemPosition(_textBar);
	if(pos >= 0)
	{
	    _rootMenu->addItem(_searchListGroup,pos+1);
	    _rootMenu->addItem(_searchListBar,pos+2);
	}
	else
	{
	    _rootMenu->addItem(_searchListGroup);
	    _rootMenu->addItem(_searchListBar);
	}*/
	addMenuItem(_searchListBar);
	addMenuItem(_searchListGroup);
    }

    while(_searchListButtons.size() < _numDisplayResults)
    {
	MenuButton * mb = new MenuButton("",false);
	mb->setCallback(this);
	_searchListButtons.push_back(mb);
    }

    std::vector<std::string> resultList;

    for(int i = 0; i < _searchList.size(); ++i)
    {
	if(_searchList[i].size() < _text.size())
	{
	    continue;
	}

	// TODO: for windows use _stricmp
#ifdef WIN32
	if(_strnicmp(_text.c_str(),_searchList[i].c_str(),_text.size()) == 0)
#else
	if(strncasecmp(_text.c_str(),_searchList[i].c_str(),_text.size()) == 0)
#endif
	{
	    resultList.push_back(_searchList[i]);
	    if(resultList.size() == _numDisplayResults)
	    {
		break;
	    }
	}
    }

    if(resultList.size() == 0 || (resultList.size() == 1 && resultList[0] == _text))
    {
	removeMenuItem(_searchListGroup);
	removeMenuItem(_searchListBar);
	return;
    }

    for(int i = 0; i < resultList.size(); ++i)
    {
	_searchListButtons[i]->setText(resultList[i]);
	_searchListGroup->addItem(_searchListButtons[i]);
    }
}
Esempio n. 9
0
void TextInputPanel::makeNumpad()
{
     _rowGroup = new MenuItemGroup(MenuItemGroup::ROW_LAYOUT);
    addMenuItem(_rowGroup);

    MenuItemGroup * tempItem;
    MenuButton * tempButton;

    tempItem = new MenuItemGroup(MenuItemGroup::COL_LAYOUT);
    tempButton = new MenuButton("7",false);
    tempButton->setCallback(this);
    tempItem->addItem(tempButton);
    tempButton = new MenuButton("4",false);
    tempButton->setCallback(this);
    tempItem->addItem(tempButton);
    tempButton = new MenuButton("1",false);
    tempButton->setCallback(this);
    tempItem->addItem(tempButton);
    tempButton = new MenuButton("-",false);
    tempButton->setCallback(this);
    tempItem->addItem(tempButton);
    _rowGroup->addItem(tempItem);
    _colGroups.push_back(tempItem);

    tempItem = new MenuItemGroup(MenuItemGroup::COL_LAYOUT);
    tempButton = new MenuButton("8",false);
    tempButton->setCallback(this);
    tempItem->addItem(tempButton);
    tempButton = new MenuButton("5",false);
    tempButton->setCallback(this);
    tempItem->addItem(tempButton);
    tempButton = new MenuButton("2",false);
    tempButton->setCallback(this);
    tempItem->addItem(tempButton);
    tempButton = new MenuButton("0",false);
    tempButton->setCallback(this);
    tempItem->addItem(tempButton);
    _rowGroup->addItem(tempItem);
    _colGroups.push_back(tempItem);

    tempItem = new MenuItemGroup(MenuItemGroup::COL_LAYOUT);
    tempButton = new MenuButton("9",false);
    tempButton->setCallback(this);
    tempItem->addItem(tempButton);
    tempButton = new MenuButton("6",false);
    tempButton->setCallback(this);
    tempItem->addItem(tempButton);
    tempButton = new MenuButton("3",false);
    tempButton->setCallback(this);
    tempItem->addItem(tempButton);
    tempButton = new MenuButton(".",false);
    tempButton->setCallback(this);
    tempItem->addItem(tempButton);
    _rowGroup->addItem(tempItem);
    _colGroups.push_back(tempItem);
}
Esempio n. 10
0
void TextInputPanel::makeQWERTY()
{
    _rowGroup = new MenuItemGroup(MenuItemGroup::ROW_LAYOUT);
    addMenuItem(_rowGroup);

    MenuItemGroup * tempItem;
    MenuButton * tempButton;

    tempItem = new MenuItemGroup(MenuItemGroup::COL_LAYOUT);
    tempButton = new MenuButton("Q",false);
    tempButton->setCallback(this);
    tempItem->addItem(tempButton);
    tempButton = new MenuButton("A",false);
    tempButton->setCallback(this);
    tempItem->addItem(tempButton);
    tempButton = new MenuButton("Z",false);
    tempButton->setCallback(this);
    tempItem->addItem(tempButton);
    _rowGroup->addItem(tempItem);
    _colGroups.push_back(tempItem);

    tempItem = new MenuItemGroup(MenuItemGroup::COL_LAYOUT);
    tempButton = new MenuButton("W",false);
    tempButton->setCallback(this);
    tempItem->addItem(tempButton);
    tempButton = new MenuButton("S",false);
    tempButton->setCallback(this);
    tempItem->addItem(tempButton);
    tempButton = new MenuButton("X",false);
    tempButton->setCallback(this);
    tempItem->addItem(tempButton);
    _rowGroup->addItem(tempItem);
    _colGroups.push_back(tempItem);

    tempItem = new MenuItemGroup(MenuItemGroup::COL_LAYOUT);
    tempButton = new MenuButton("E",false);
    tempButton->setCallback(this);
    tempItem->addItem(tempButton);
    tempButton = new MenuButton("D",false);
    tempButton->setCallback(this);
    tempItem->addItem(tempButton);
    tempButton = new MenuButton("C",false);
    tempButton->setCallback(this);
    tempItem->addItem(tempButton);
    _rowGroup->addItem(tempItem);
    _colGroups.push_back(tempItem);

    tempItem = new MenuItemGroup(MenuItemGroup::COL_LAYOUT);
    tempButton = new MenuButton("R",false);
    tempButton->setCallback(this);
    tempItem->addItem(tempButton);
    tempButton = new MenuButton("F",false);
    tempButton->setCallback(this);
    tempItem->addItem(tempButton);
    tempButton = new MenuButton("V",false);
    tempButton->setCallback(this);
    tempItem->addItem(tempButton);
    _rowGroup->addItem(tempItem);
    _colGroups.push_back(tempItem);

    tempItem = new MenuItemGroup(MenuItemGroup::COL_LAYOUT);
    tempButton = new MenuButton("T",false);
    tempButton->setCallback(this);
    tempItem->addItem(tempButton);
    tempButton = new MenuButton("G",false);
    tempButton->setCallback(this);
    tempItem->addItem(tempButton);
    tempButton = new MenuButton("B",false);
    tempButton->setCallback(this);
    tempItem->addItem(tempButton);
    _rowGroup->addItem(tempItem);
    _colGroups.push_back(tempItem);

    tempItem = new MenuItemGroup(MenuItemGroup::COL_LAYOUT);
    tempButton = new MenuButton("Y",false);
    tempButton->setCallback(this);
    tempItem->addItem(tempButton);
    tempButton = new MenuButton("H",false);
    tempButton->setCallback(this);
    tempItem->addItem(tempButton);
    tempButton = new MenuButton("N",false);
    tempButton->setCallback(this);
    tempItem->addItem(tempButton);
    _rowGroup->addItem(tempItem);
    _colGroups.push_back(tempItem);

    tempItem = new MenuItemGroup(MenuItemGroup::COL_LAYOUT);
    tempButton = new MenuButton("U",false);
    tempButton->setCallback(this);
    tempItem->addItem(tempButton);
    tempButton = new MenuButton("J",false);
    tempButton->setCallback(this);
    tempItem->addItem(tempButton);
    tempButton = new MenuButton("M",false);
    tempButton->setCallback(this);
    tempItem->addItem(tempButton);
    _rowGroup->addItem(tempItem);
    _colGroups.push_back(tempItem);

    tempItem = new MenuItemGroup(MenuItemGroup::COL_LAYOUT);
    tempButton = new MenuButton("I",false);
    tempButton->setCallback(this);
    tempItem->addItem(tempButton);
    tempButton = new MenuButton("K",false);
    tempButton->setCallback(this);
    tempItem->addItem(tempButton);
    tempButton = new MenuButton(",",false);
    tempButton->setCallback(this);
    tempItem->addItem(tempButton);
    _rowGroup->addItem(tempItem);
    _colGroups.push_back(tempItem);

    tempItem = new MenuItemGroup(MenuItemGroup::COL_LAYOUT);
    tempButton = new MenuButton("O",false);
    tempButton->setCallback(this);
    tempItem->addItem(tempButton);
    tempButton = new MenuButton("L",false);
    tempButton->setCallback(this);
    tempItem->addItem(tempButton);
    tempButton = new MenuButton(".",false);
    tempButton->setCallback(this);
    tempItem->addItem(tempButton);
    _rowGroup->addItem(tempItem);
    _colGroups.push_back(tempItem);

    tempItem = new MenuItemGroup(MenuItemGroup::COL_LAYOUT);
    tempButton = new MenuButton("P",false);
    tempButton->setCallback(this);
    tempItem->addItem(tempButton);
    tempButton = new MenuButton(";",false);
    tempButton->setCallback(this);
    tempItem->addItem(tempButton);
    tempButton = new MenuButton("/",false);
    tempButton->setCallback(this);
    tempItem->addItem(tempButton);
    _rowGroup->addItem(tempItem);
    _colGroups.push_back(tempItem);
}
Esempio n. 11
0
bool SoundPlayer::init()
{ 
    std::cerr << "SoundPlayer init\n";

    MLMenu = new SubMenu("SoundPlayer", "SoundPlayer");
    MLMenu->setCallback(this);

    loadMenu = new SubMenu("Load","Load");
    loadMenu->setCallback(this);
    MLMenu->addItem(loadMenu);

    MenuSystem::instance()->addMenuItem(MLMenu);

    _volumeSlider = new MenuRangeValue("Volume", 0, 1, 0.01);
    _volumeSlider->setCallback(this);
    MLMenu->addItem(_volumeSlider);

    std::string name = ConfigManager::getEntry("Plugin.SoundPlayer.Server.Name");
    std::string synthDir = ConfigManager::getEntry("Plugin.SoundPlayer.Server.SynthDir");
    std::string port = ConfigManager::getEntry("Plugin.SoundPlayer.Server.Port");
    std::string address = ConfigManager::getEntry("Plugin.SoundPlayer.Server.Address");

    if (cvr::ComController::instance()->isMaster())
    {
       // Address and port hacked in - to be fixed 
        _AudioServer = new SCServer(name, "137.110.116.10", "57110", synthDir);
        _AudioServer->dumpOSC(1);
    }
    
    std::string dataDir = ConfigManager::getEntry("Plugin.SoundPlayer.Files");

    std::vector<std::string> filenames;
    ConfigManager::getChildren("Plugin.SoundPlayer.Files", filenames);

    for (int i = 0; i < filenames.size(); ++i)
    {
	std::string name = ConfigManager::getEntry("Plugin.SoundPlayer.Files." + filenames[i]);
        std::string path = dataDir + "/" + name;
        if (cvr::ComController::instance()->isMaster())
        {
	    int outarray [] = {0, 7};
	    Sound * sound = new Sound(_AudioServer, path, outarray, 0);

	    if(sound->isValid())
	    {
		sound->setGain(_volumeSlider->getValue());
		_sounds.push_back(sound);
	    }

	    }
	    else
	    {
	        _sounds.push_back(NULL);
		std::cout << "Unable to load sound " << path << std::endl;
	    }
        

	MenuButton * button = new MenuButton(filenames[i]);
	button->setCallback(this);
	loadMenu->addItem(button);
	_soundButtons.push_back(button);
    }

    std::cerr << "SoundPlayer init done.\n";
    return true;
}
Esempio n. 12
0
bool TourCave::init()
{
    bool found;

    if(ComController::instance()->isMaster())
    {
	_mls = new MultiListenSocket(11011);
	if(!_mls->setup())
	{
	    std::cerr << "Error setting up MultiListen Socket." << std::endl;
	    delete _mls;
	    _mls = NULL;
	}
    }

    std::string name;

    name = ConfigManager::getEntry("name","Plugin.TourCave.BackgroundAudio","NONE",&found);

    if(found)
    {
	_backgroundAudio = new TourAudio;
	_backgroundAudio->name = name;
	_backgroundAudio->loop = ConfigManager::getBool("loop","Plugin.TourCave.BackgroundAudio",false, NULL);
        _backgroundAudio->volume = ConfigManager::getFloat("volume","Plugin.TourCave.BackgroundAudio",1.0);
	_backgroundAudio->started = false;

        if(ComController::instance()->isMaster())
	{
	    //TODO: start?, or wait for some sort of trigger
#ifdef HAS_AUDIO
	    //_am->SendUDP((name + "/Volume").c_str(),"f",1.0 * ta->volume);
	    _am->SendUDP((name + "/Play").c_str(),"i",1);
#endif
	}
    }

    _tourCaveMenu = new SubMenu("TourCave","TourCave");
    PluginHelper::addRootMenuItem(_tourCaveMenu);

    int path;
    int mode = 0;

    std::stringstream ss;
    ss << "Mode" << mode;

    path = ConfigManager::getInt(std::string("Plugin.TourCave.") + ss.str() + ".PathID", 0, &found);
    while(found)
    {
	std::stringstream ss1;
	ss1 << "Mode" << mode;

       float speed = ConfigManager::getFloat("speed",std::string("Plugin.TourCave.") + ss1.str() + ".PathID",1.0);
       _modePathSpeedList.push_back(speed);

	MenuButton * mb = new MenuButton(ss1.str());
	mb->setCallback(this);
	_tourCaveMenu->addItem(mb);
	_modeButtonList.push_back(mb);

	_modePathIDList.push_back(path);

	_modeAudioList.push_back(std::vector<TourAudio*>());
	std::vector<std::string> audioList;
	ConfigManager::getChildren(std::string("Plugin.TourCave.") + ss1.str() + ".Audio", audioList);

	for(int i = 0; i < audioList.size(); i++)
	{
	    std::stringstream entry;
	    entry << "Plugin.TourCave." << ss1.str() << ".Audio." << audioList[i];
	    TourAudio * ta;
	    ta = new TourAudio;
	    ta->name = ConfigManager::getEntry("name",entry.str(),"name");
	    ta->triggerTime = ConfigManager::getFloat("time",entry.str(),0);
	    ta->loop = ConfigManager::getBool("loop",entry.str(),false);
	    ta->started = false;

	    bool usedist;

	    float x,y,z,dist;
	    dist = ConfigManager::getFloat("distance",entry.str(),0,&usedist);
	    if(usedist)
	    {
		ta->distance = dist;
		x = ConfigManager::getFloat("x",entry.str());
		y = ConfigManager::getFloat("y",entry.str());
		z = ConfigManager::getFloat("z",entry.str());
		ta->pos = osg::Vec3(x,y,z);
	    }
	    else
	    {
		ta->distance = 0;
	    }

            std::string s;
	    s = ConfigManager::getEntry("stopLocation",entry.str(),"NEXT");
            if(s == "NEXT")
            {
                ta->sl = NEXT_PATH;
            }
            else
            {
                ta->sl = PATH_END;
            }

            s = ConfigManager::getEntry("stopAction",entry.str(),"STOP");
            if(s == "NOTHING")
            {
                ta->sa = NOTHING;
            }
            else if(s == "PAUSE")
            {
                ta->sa = PAUSE;
            }
            else
            {
                ta->sa = STOP;
            }

            ta->volume = ConfigManager::getFloat("volume",entry.str(),1.0);

	    _modeAudioList[mode].push_back(ta);
	}

	mode++;
	std::stringstream ss2;
	ss2 << "Mode" << mode;

	path = ConfigManager::getInt(std::string("Plugin.TourCave.") + ss2.str() + ".PathID", 0, &found);
    }

    return true;
}
Esempio n. 13
0
bool ModelLoader::init()
{
    std::cerr << "ModelLoader init\n";

    MLMenu = new SubMenu("ModelLoader", "ModelLoader");
    MLMenu->setCallback(this);

    loadMenu = new SubMenu("Load","Load");
    loadMenu->setCallback(this);
    MLMenu->addItem(loadMenu);

    removeButton = new MenuButton("Remove All");
    removeButton->setCallback(this);
    MLMenu->addItem(removeButton);

    vector<string> list;

    string configBase = "Plugin.ModelLoader.Files";

    ConfigManager::getChildren(configBase,list);

    for(int i = 0; i < list.size(); i++)
    {
	MenuButton * button = new MenuButton(list[i]);
	button->setCallback(this);
	menuFileList.push_back(button);

	struct loadinfo * info = new struct loadinfo;
	info->name = list[i];
	info->path = ConfigManager::getEntry("path",configBase + "." + list[i],"");
	info->mask = ConfigManager::getInt("mask",configBase + "." + list[i], 1);
	info->lights = ConfigManager::getInt("lights",configBase + "." + list[i], 1);
	info->backfaceCulling = ConfigManager::getBool("backfaceCulling",configBase + "." + list[i], false);
	info->showBound = ConfigManager::getBool("showBound",configBase + "." + list[i], false);

	models.push_back(info);

	osg::Vec3 center = ConfigManager::getVec3(configBase + "." + list[i]);
	float scale = ConfigManager::getFloat("scale",configBase + "." + list[i],1.0);
	float h,p,r;
	h = ConfigManager::getFloat("h",configBase + "." + list[i],0.0) * M_PI / 180.0;
	p = ConfigManager::getFloat("p",configBase + "." + list[i],0.0) * M_PI / 180.0;
	r = ConfigManager::getFloat("r",configBase + "." + list[i],0.0) * M_PI / 180.0;
	osg::Matrix rot;
	rot.makeRotate(r,osg::Vec3(0,1,0),p,osg::Vec3(1,0,0),h,osg::Vec3(0,0,1));
	osg::Matrix trans;
	trans.makeTranslate(-center);
	osg::Matrix scaleMat;
	scaleMat.makeScale(osg::Vec3(scale,scale,scale));
	_defaultLocInit[info->name] = pair<float, Matrix>(1.0, trans * scaleMat * rot);
    }

    configPath = ConfigManager::getEntry("Plugin.ModelLoader.ConfigDir");

    ifstream cfile;
    cfile.open((configPath + "/Init.cfg").c_str(), ios::in);

    if(!cfile.fail())
    {
	string line;
	while(!cfile.eof())
	{
	    Matrix m;
	    float scale;
	    char name[150];
	    cfile >> name;
	    if(cfile.eof())
	    {
		break;
	    }
	    cfile >> scale;
	    for(int i = 0; i < 4; i++)
	    {
		for(int j = 0; j < 4; j++)
		{
		    cfile >> m(i, j);
		}
	    } 
	    locInit[string(name)] = pair<float, Matrix>(scale, m);
	}
    }
bool PointsWithPans::init()
{

    _pwpMenu = new SubMenu("PointsWithPans");
    PluginHelper::addRootMenuItem(_pwpMenu);

    _setMenu = new SubMenu("Sets");
    _pwpMenu->addItem(_setMenu);

    _removeButton = new MenuButton("Remove");
    _removeButton->setCallback(this);
    _pwpMenu->addItem(_removeButton);

    std::vector<std::string> setTags;
    ConfigManager::getChildren("Plugin.PointsWithPans.Sets",setTags);

    for(int i = 0; i < setTags.size(); i++)
    {
	std::stringstream setss;
	setss << "Plugin.PointsWithPans.Sets." << setTags[i]; 
	PWPSet * set = new PWPSet;
	set->scale = ConfigManager::getFloat("scale",setss.str(),1.0);
	set->pointSize = ConfigManager::getFloat("pointSize",setss.str(),0.005);
	float x,y,z;
	x = ConfigManager::getFloat("x",setss.str(),0);
	y = ConfigManager::getFloat("y",setss.str(),0);
	z = ConfigManager::getFloat("z",setss.str(),0);
	set->offset = osg::Vec3(x,y,z);
	set->file = ConfigManager::getEntry("file",setss.str(),"",NULL);
	set->moveTime = ConfigManager::getFloat("moveTime",setss.str(),4.0);
	set->fadeTime = ConfigManager::getFloat("fadeTime",setss.str(),5.0);
	std::vector<std::string> panTags;
	ConfigManager::getChildren(setss.str(),panTags);
	float radius = ConfigManager::getFloat("sphereRadius",setss.str(),250.0);
	float distance = ConfigManager::getFloat("selectDistance",setss.str(),2500.0);
	for(int j = 0; j < panTags.size(); j++)
	{
	    std::stringstream panss;
	    panss << setss.str() << "." << panTags[j];
	    x = ConfigManager::getFloat("x",panss.str(),0);
	    y = ConfigManager::getFloat("y",panss.str(),0);
	    z = ConfigManager::getFloat("z",panss.str(),0);
	    PWPPan pan;
	    pan.location = osg::Vec3(x,y,z);
	    pan.name = ConfigManager::getEntry("name",panss.str(),"",NULL);
	    pan.rotationOffset = ConfigManager::getFloat("rotationOffset",panss.str(),0);
	    pan.rotationOffset = pan.rotationOffset * M_PI / 180.0;
	    pan.sphereRadius = ConfigManager::getFloat("sphereRadius",panss.str(),radius);
	    pan.selectDistance = ConfigManager::getFloat("selectDistance",panss.str(),distance);
	    pan.textureFile = ConfigManager::getEntry("textureFile",panss.str(),"");
	    set->panList.push_back(pan);
	}
	_setList.push_back(set);
	MenuButton * button = new MenuButton(setTags[i]);
	button->setCallback(this);
	_setMenu->addItem(button);
	_buttonList.push_back(button);
    }

    _activeObject = new PointsObject("Points",true,false,false,true,false);
    PluginHelper::registerSceneObject(_activeObject,"PointsWithPans");

    return true;
}
Esempio n. 15
0
bool PointsOOC::loadFile(std::string filename)
{
    osg::ref_ptr<Node> points = osgDB::readNodeFile(filename);

	if( points.valid() )
	{

        osg::StateSet* state = points->getOrCreateStateSet();

    	// check to make sure that the osga is a point cloud (check for uniform)
		osg::Uniform* pointUniform = state->getUniform("point_size");
    	if( pointUniform != NULL )
    	{

			// check if see if this is the first set to be loaded
			if( _loadedPoints.size() == 0 )
			{
				_startTime = CVRViewer::instance()->getFrameStamp()->getReferenceTime();
				_currentFrame = CVRViewer::instance()->getFrameStamp()->getFrameNumber();
			} 
		
			// get fileName
			std::string name = osgDB::getStrippedName(filename); 

			// add stream to the scene
			SceneObject * so = new SceneObject(name,false,false,false,true,true);
			PluginHelper::registerSceneObject(so,"PointsOOC");
			so->addChild(points.get());
			so->attachToScene();
			so->setNavigationOn(true);
			so->addMoveMenuItem();
			so->addNavigationMenuItem();
		    so->setShowBounds(false);

            // add submenu to control point size options
            SubMenu * sm = new SubMenu("Point Size Options");
            so->addMenuItem(sm);
		    _subMenuMap[so] = sm;

			// add menu items for controlling the points
		    MenuCheckbox * cb = new MenuCheckbox("Show Bounds", false);
		    cb->setCallback(this);
		    so->addMenuItem(cb);
		    _boundsMap[so] = cb;
		    
            cb = new MenuCheckbox("Enable Shader", true);
		    cb->setCallback(this);
		    so->addMenuItem(cb);
		    _shaderMap[so] = cb;
		    
			// get point size
			float shaderSize;
			pointUniform->get(shaderSize);

			// access the alpha
	    	osg::Uniform* alphaUniform = state->getUniform("global_alpha");

            // doesnt exist in table create a new entry
            if( _locInit.find(name) == _locInit.end() )
            {
                Loc l;
                l.pos = osg::Matrix::identity();
                l.pointSize = 1.0;
                l.shaderSize = shaderSize;
                l.shaderEnabled = true;
                l.pointAlpha = 1.0;
                l.pointFunc[0] = 1.0;
                l.pointFunc[1] = 0.05;
                l.pointFunc[2] = 0.0;
                _locInit[name] = l;
            }

            _locInit[name].shaderStateset = state;
            
            // create point stateset
            _locInit[name].pointStateset = new osg::StateSet();

            _locInit[name].pointStateset->setMode(GL_POINT_SMOOTH, osg::StateAttribute::ON);

	    _locInit[name].pointStateset->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
	    _locInit[name].pointStateset->setMode(GL_BLEND, osg::StateAttribute::ON);
	    _locInit[name].pointStateset->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);

            osg::Point* point = new osg::Point;
            point->setDistanceAttenuation(osg::Vec3(_locInit[name].pointFunc[0], _locInit[name].pointFunc[1], _locInit[name].pointFunc[2]));
            point->setSize(_locInit[name].pointSize);
            point->setMinSize(1.0);
            point->setMaxSize(100.0);
            _locInit[name].pointStateset->setAttribute(point);

            osg::PolygonMode *pm = new osg::PolygonMode( osg::PolygonMode::FRONT_AND_BACK, osg::PolygonMode::POINT );
            _locInit[name].pointStateset->setAttribute(pm);

            // read it from the saved file
	    pointUniform->set(_locInit[name].shaderSize);
	    alphaUniform->set(_locInit[name].pointAlpha);

            // point variation
            float variation = _locInit[name].shaderSize * 0.75;

        	MenuRangeValue * mrv = new MenuRangeValue("Point Size Shader", _locInit[name].shaderSize - variation, 
                                                _locInit[name].shaderSize + variation, _locInit[name].shaderSize);
	    	mrv->setCallback(this);
        	_sliderShaderSizeMap[so] = mrv;
	    	
        	mrv = new MenuRangeValue("Point Size", 0.01, 50.0, _locInit[name].pointSize);
            mrv->setCallback(this);
        	_sliderPointSizeMap[so] = mrv;
        	
            mrv = new MenuRangeValue("Point Func", 0.0, 0.9, _locInit[name].pointFunc[1]);
            mrv->setCallback(this);
        	_sliderPointFuncMap[so] = mrv;

			mrv = new MenuRangeValue("Alpha", 0.0, 1.0, _locInit[name].pointAlpha);
	    	mrv->setCallback(this);
        	sm->addItem(mrv);
        	_sliderAlphaMap[so] = mrv;

            // check if shader enabled
            if( !_locInit[name].shaderEnabled )
            {
                _shaderMap[so]->setValue(false);
                points->setStateSet(_locInit[name].pointStateset);

                sm->addItem(_sliderPointSizeMap[so]);
                sm->addItem(_sliderPointFuncMap[so]);
            }
            else
            {
                sm->addItem(_sliderShaderSizeMap[so]);
            }

	    // set default lighting and blend modes
            points->getStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
            points->getStateSet()->setMode(GL_BLEND,osg::StateAttribute::OFF);

            //check pointAlpha
            if( _locInit[name].pointAlpha != 1.0 )
            {
                points->getStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::ON);
                points->getStateSet()->setMode(GL_BLEND,osg::StateAttribute::ON);
                points->getStateSet()->setRenderingHint( osg::StateSet::TRANSPARENT_BIN );
            }

        	bool nav;
        	nav = so->getNavigationOn();
        	so->setNavigationOn(false);

        	so->setTransform(_locInit[name].pos);
        	so->setNavigationOn(nav);

            // add default buttons
			MenuButton* mb = new MenuButton("Save");
	    	mb->setCallback(this);
	    	so->addMenuItem(mb);
	    	_saveMap[so] = mb;			

			mb = new MenuButton("Delete");
	    	mb->setCallback(this);
	    	so->addMenuItem(mb);
	    	_deleteMap[so] = mb;
			
			// to list of objects
			_loadedPoints.push_back(so);

			return true;
		}
	}

    return false;
}
Esempio n. 16
0
// intialize
bool PointsOOC::init()
{
  cerr << "PointsOOC::PointsOOC" << endl;

  // enable osg debugging
  //osg::setNotifyLevel( osg::INFO );
  
  
  _mainMenu = new SubMenu("PointsOOC", "PointsOOC");
  _mainMenu->setCallback(this);

  _loadMenu = new SubMenu("Load","Load");
  _loadMenu->setCallback(this);
  _mainMenu->addItem(_loadMenu);

  _removeButton = new MenuButton("Remove All");
  _removeButton->setCallback(this);
  _mainMenu->addItem(_removeButton);

  MenuSystem::instance()->addMenuItem(_mainMenu);


  vector<string> list;

  string configBase = "Plugin.PointsOOC.Files";

  ConfigManager::getChildren(configBase, list);

  for(int i = 0; i < list.size(); i++)
  {
	MenuButton * button = new MenuButton(list[i]);
	button->setCallback(this);
	_loadMenu->addItem(button);
    _menuFileList.push_back(button);

	std::string path = ConfigManager::getEntry("value", 
        configBase + "." + list[i], "");
    _filePaths.push_back(path);
    //std::cout << path << std::endl;
  }


  // load saved initial scales and locations
  _configPath = ConfigManager::getEntry("Plugin.PointsOOC.ConfigDir");

  ifstream cfile;
  cfile.open((_configPath + "/PointsOOCInit.cfg").c_str(), ios::in);

  if(!cfile.fail())
  {
    string line;
    while(!cfile.eof())
    {

	   Loc l;
       l.pointFunc[0] = 1.0;
       l.pointFunc[1] = 0.0;

       char name[150];
       cfile >> name;
       if(cfile.eof())
       {
         break;
       }
	   cfile >> l.pointSize;
	   cfile >> l.shaderSize;
	   cfile >> l.pointFunc[2];
	   cfile >> l.pointAlpha;
       cfile >> l.shaderEnabled;
       for(int i = 0; i < 4; i++)
       {
         for(int j = 0; j < 4; j++)
         {
           cfile >> l.pos(i, j);
         }
       }

       _locInit[string(name)] = l;
    }
  }