Example #1
0
/**
  Run the dynamics for a cycle.
*/
void run( Real dt ) {

    // fetch the command in the buffer
    //get_command();

    #ifdef USE_OSG
    if (ONSCREEN_RENDER)
    {
      if (viewer.done())
        return;
      viewer.frame();
    }
    #endif

    // Note: research how the original driver sets up all the parameters that
    // drive step size.  sim->step(dt) is not sufficient in and of itself so
    // there must be another or more parameters that manipulate this state info
    //sim->step( dt );
    // step the sim forward
    STEP_SIZE = dt;
    step((void*) &sim);

    // publish any state change
    //publish_state();

    //#ifdef USE_OSG
    //usleep(DYNAMICS_FREQ);
    //#endif

}
Example #2
0
int main(int argc, char** argv)
{
	viewer.setSceneData(root.get());
	filename = argv[1];	
	
	startMenu = new StartMenu(&viewer, startApplication);
	root->addChild(startMenu->_camera);


	if(root.valid())
	{	
		
		//viewer.setCameraManipulator(new osgGA::TrackballManipulator());
		viewer.realize();
	
		while(!viewer.done())
		{
			viewer.frame();
			//update();
		}
	}
	else
	{
		std::cout << "Invalid Graph!" << std::endl;
	}
	
	return 0;
}
Example #3
0
// Step the dynamics forward
    void step( const Real &dt ) {

#ifdef USE_OSG
        if( ONSCREEN_RENDER ) {
            if( viewer.done( ) ) return;
            viewer.frame( );
        }
#endif

        // step the sim forward
        STEP_SIZE = dt;
        step( (void*) &sim );
    }
Example #4
0
/**
  Run the dynamics for a cycle.
*/
void run( void ) {

    // fetch the command in the buffer
    get_command();

    #ifdef USE_OSG
    if (ONSCREEN_RENDER)
    {
      if (viewer.done())
        return;
      viewer.frame();
    }
    #endif

    // step the sim forward
    step((void*) &sim);

    // publish any state change
    publish_state();

    //#ifdef USE_OSG
    //usleep(DYNAMICS_FREQ);
    //#endif
}
Example #5
0
bool ExportHTML::write(osgPresentation::SlideEventHandler* seh, osgViewer::Viewer& viewer, const std::string& filename)
{
    std::string image_basename;
    std::string image_ext;
    std::string html_basename;
    std::string html_ext;

    std::string ext = osgDB::getFileExtension(filename);
    if (ext=="html" || ext=="htm")
    {
        image_basename = osgDB::getNameLessExtension(filename);
        image_ext = ".jpg";
        html_basename = osgDB::getNameLessExtension(filename);
        html_ext = std::string(".")+ext;
    }
    else
    {
        image_basename = osgDB::getNameLessExtension(filename);
        image_ext = ".jpg";
    }
    
    std::cout<<"Writing slides to "<<image_basename<<"_[slidenumber]"<<image_ext<<std::endl;

    osg::ref_ptr<SnapImageDrawCallback> sidc = new SnapImageDrawCallback;

    osgViewer::Viewer::Cameras cameras;
    viewer.getCameras(cameras);

    for(osgViewer::Viewer::Cameras::iterator itr = cameras.begin();
        itr != cameras.end();
        ++itr)
    {
        (*itr)->setPostDrawCallback(sidc.get());
    }

    std::string home_file = createFileName(html_basename, 0, html_ext);

    unsigned int i;
    for(i=0; i<seh->getNumSlides(); ++i)
    {
        std::ostringstream os;
        os << image_basename <<"_"<<i<<image_ext;

        sidc->setFileName(os.str());
        sidc->setSnapImageOnNextFrame(true);

        if (!html_basename.empty())
        {
            std::string htmlFileName = createFileName(html_basename, i, html_ext);

            std::ofstream fout(htmlFileName.c_str());
            if (fout)
            {
                std::string previous_file = i>0 ? createFileName(html_basename,i-1,html_ext) : "";
                std::string next_file = i<seh->getNumSlides()-1 ? createFileName(html_basename,i+1,html_ext) : "";

                std::cout<<"Writing html slides "<<htmlFileName<<std::endl;

                fout<<"<html>"<<std::endl;
                fout<<"<table width=\"100%\">"<<std::endl;
                fout<<"<tr>"<<std::endl;
                if (!previous_file.empty())
                {
                    fout<<"<td align=\"left\" width=\"33%\"><a href=\""<<osgDB::getSimpleFileName(previous_file)<<"\"> Previous </a></td>"<<std::endl;
                }
                else
                {
                    fout<<"<td align=\"left\" width=\"33%\"></td>"<<std::endl;
                }
                if (i != 0)
                {
                    fout<<"<td align=\"center\" width=\"33%\"><a href=\""<<osgDB::getSimpleFileName(home_file)<<"\"> Home </a></td>"<<std::endl;
                }
                else
                {
                    fout<<"<td align=\"center\" width=\"33%\"></td>"<<std::endl;
                }
                if (!next_file.empty())
                {
                    fout<<"<td align=\"right\" width=\"33%\"><a href=\""<<osgDB::getSimpleFileName(next_file)<<"\"> Next </a></td>"<<std::endl;
                }
                else
                {
                    fout<<"<td align=\"right\" width=\"33%\"></td>"<<std::endl;
                }
                fout<<"</tr>"<<std::endl;
                fout<<"</table>"<<std::endl;
                fout<<"<img src=\""<<osgDB::getSimpleFileName(os.str())<<"\">"<<std::endl; 
                fout<<"</html>"<<std::endl;
            }
            else
            {
                std::cout<<"Could not open '"<<filename<<"' for writing."<<std::endl;
            }
        }
        // wait for all cull and draw threads to complete.

        seh->selectSlide(i, osgPresentation::SlideEventHandler::LAST_POSITION);

        // fire off the cull and draw traversals of the scene.
        viewer.frame();
    }
    return true;
}
Example #6
0
int main( int argc, char **argv )
{
	int windowWidth, windowHeight;
	std::string osgEarthFileName = "D:/Dev/csp/csp/examples/cspEarth/data/srtm.earth";

	// use an ArgumentParser object to manage the program arguments.
    osg::ArgumentParser arguments(&argc,argv);

	// Allow a debugger to be attached before the interesting parts start
	if (arguments.read("-p"))
	{
		std::cout << "Attach debugger and press a key..." << std::endl;
		std::getchar();
	}

	// if an .earth file definition was specified, use this one instead of the default
	arguments.read("-file", osgEarthFileName);

	// get screen size
	arguments.read("-window", windowWidth, windowHeight);

	// =====================================================================
	// SETUP
	// Make it possible for this application to locate images bound
	// to textures.
	std::string search_path = ";";
	csp::ospath::addpath(search_path, "./data/images/");
	csp::ospath::addpath(search_path, "./data/models/");
	csp::ObjectModel::setDataFilePathList(search_path);

	// Set paths for shader files.
	Shader::instance()->setShaderPath("./data/shaders/");


	// =====================================================================
	// Manual creation of a object model.
	Ref<ObjectModel> my_model = new ObjectModel();

	// An external is used to handle the path to the scene graph file.
	// It is also ensuring that paths is handled independent on operating
	// system.
	External modelPath;
	modelPath.setSource("industry/refinery_column01/refinery_column01.osg");
	my_model->setModelPath(modelPath);
	my_model->setSmooth(true);

	// Load the model from disc. This will also apply needed shaders.
	// smoothing and more things.
	my_model->loadModel();

	// read osgEarth config file and create the globe
	std::cout << "reading osgEarth config file: " << osgEarthFileName << std::endl;
	osg::ref_ptr<osg::Node> globe = osgDB::readNodeFile(osgEarthFileName);
	osg::ref_ptr<osg::Node> topNode = new osg::Node;

	osg::Group* group = new osg::Group;
	group->setName("root group");

	// =====================================================================
	// construct the viewer
	viewer.addEventHandler(new osgViewer::StatsHandler);
	viewer.addEventHandler(new osgViewer::HelpHandler);
    viewer.addEventHandler(new osgViewer::WindowSizeHandler);
	viewer.addEventHandler(new osgViewer::ScreenCaptureHandler);

	// modify the key mapping of an osg default event handler
	// this is just to demonstrate the principle, no real use case behind it...
	osgViewer::View::EventHandlers eventHandlers = viewer.getEventHandlers();
	// iterate through the viewer's event handlers and modify their default behavior
	for (osgViewer::View::EventHandlers::iterator it = eventHandlers.begin(); it != eventHandlers.end(); ++it)
	{
		// EventHandlers is a list of osgGA::GUIEventHandlers, so RTTI is used to find out the derived class
		if(osgViewer::WindowSizeHandler *winSizeHandler = 
			dynamic_cast<osgViewer::WindowSizeHandler *>(it->get()))
		{
			winSizeHandler->setKeyEventToggleFullscreen(osgGA::GUIEventAdapter::KEY_F2);
		}
	}


	// Create overlay data
	osg::ref_ptr<osg::Geode> statsGeometry = createStatsGeometry();
	group->addChild( statsGeometry );
	
	// add the osgEarth globe to the scene
	group->addChild( globe.get() );
	group->addChild( my_model->getModel().get() );

	//viewer.setSceneData(my_model->getModel().get());
	viewer.setSceneData( group );
	//viewer.setSceneData(globe.get());

	// create camera and context
	setupCameraAndContext( viewer, windowWidth, windowHeight );

	// the overlay geometry is added to an individual camera
	// QUESTION: But why isn't it rendered by the primary cam?!?
	statsCamera->addChild( statsGeometry );

	//viewer.setCameraManipulator(new osgGA::FlightManipulator);

	osgEarth::MapNode* mapNode = osgEarth::MapNode::findMapNode(globe);
    manip = new osgEarthUtil::EarthManipulator();
	manip->setNode(globe);
    if ( mapNode->getMap()->isGeocentric() )
    {
        manip->setHomeViewpoint( 
            osgEarthUtil::Viewpoint( osg::Vec3d( -90, 0, 0 ), 0.0, -90.0, 5e7 ) );
    }
	manip->getSettings()->bindMouseDoubleClick(
		osgEarthUtil::EarthManipulator::ACTION_GOTO, osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON );

	viewer.setCameraManipulator(manip);
	viewer.addEventHandler(new inputHandler());
	// run the viewers frame loop
    viewer.realize();

    // main loop (note, window toolkits which take control over the main loop will require 
	// a window redraw callback containing the code below.)
    while(!viewer.done())
    {
        viewer.frame();
    }
}