Пример #1
0
ParticleSystem::ParticleSystem( osg::ref_ptr< osg::Group > root )
    : root( root )
{
    // Create and initialize a particle system
    dustParticleSystem = new osgParticle::ParticleSystem;

    // Set the attributes 'texture', 'emmisive' and 'lighting'
    dustParticleSystem->setDefaultAttributes(
        "../content/sangre2.tga",
        true, false);

    // Since the particle system is derived from the class Drawable, we can create
    // add it to the scene as a child of a geode
    geode = new osg::Geode;

    root->addChild(geode);
    geode->addDrawable(dustParticleSystem);

    // Add an 'updater' to help per-frame management
    dustSystemUpdater = new osgParticle::ParticleSystemUpdater;

    // Associate this updater with our particle system
    dustSystemUpdater->addParticleSystem(dustParticleSystem);
    // add the updater node to the scene graph
    root->addChild(dustSystemUpdater);

    // Create a partical to be used by our particle system and define a few
    // of its properties
    osgParticle::Particle smokeParticle;
    smokeParticle.setSizeRange(osgParticle::rangef(0.1,40.0)); // meters

    smokeParticle.setLifeTime(1); // seconds
    smokeParticle.setMass(0.01); // in kilograms
    // Make this our particle system's default particle
    dustParticleSystem->setDefaultParticleTemplate(smokeParticle);

    /* Modular Program */

    // Create a modular program and attach it to our particle system
    osgParticle::ModularProgram *moveDustInAir = new osgParticle::ModularProgram;
    moveDustInAir->setParticleSystem(dustParticleSystem);

    // Create an operator that simulates gravity, adjust it and add it to our program
    osgParticle::AccelOperator *accelUp = new osgParticle::AccelOperator;
    accelUp->setToGravity(-1); // scale factor for normal acceleration due to gravity.
    moveDustInAir->addOperator(accelUp);

    // Add an operator to our program to calculate the friction of air.
    osgParticle::FluidFrictionOperator *airFriction = new osgParticle::FluidFrictionOperator;
    airFriction->setFluidToAir();

    //airFriction->setFluidDensity(1.2929/*air*/*5.0f);
    moveDustInAir->addOperator(airFriction);

    // Finally, add the program to the scene
    root->addChild(moveDustInAir);


}
Пример #2
0
void myInitOGLFun()
{
	initOSG();

	osg::ref_ptr<osg::Node>            mModel;
	osg::ref_ptr<osg::MatrixTransform> mModelTrans;

	mSceneTrans		= new osg::MatrixTransform();
	mModelTrans		= new osg::MatrixTransform();

	//rotate osg coordinate system to match sgct
	mModelTrans->preMult(osg::Matrix::rotate(glm::radians(-90.0f),
                                            1.0f, 0.0f, 0.0f));

	mRootNode->addChild( mSceneTrans.get() );
	mSceneTrans->addChild( mModelTrans.get() );

	sgct::MessageHandler::instance()->print("Loading model '../SharedResources/airplane.ive'...\n");
	mModel = osgDB::readNodeFile("../SharedResources/airplane.ive");

	if ( mModel.valid() )
	{
		sgct::MessageHandler::instance()->print("Model loaded successfully!\n");
		mModelTrans->addChild(mModel.get());

		//get the bounding box
		osg::ComputeBoundsVisitor cbv;
		osg::BoundingBox &bb(cbv.getBoundingBox());
		mModel->accept( cbv );

		osg::Vec3f tmpVec;
		tmpVec = bb.center();

		//scale to fit model and translate model center to origin
		mModelTrans->postMult(osg::Matrix::translate( -tmpVec ) );
		mModelTrans->postMult(osg::Matrix::scale( 1.0f/bb.radius(), 1.0f/bb.radius(), 1.0f/bb.radius() ));

		sgct::MessageHandler::instance()->print("Model bounding sphere center:\tx=%f\ty=%f\tz=%f\n", tmpVec[0], tmpVec[1], tmpVec[2] );
		sgct::MessageHandler::instance()->print("Model bounding sphere radius:\t%f\n", bb.radius() );

		//disable face culling
		mModel->getOrCreateStateSet()->setMode( GL_CULL_FACE,
			osg::StateAttribute::OFF | osg::StateAttribute::OVERRIDE);
	}
	else
		sgct::MessageHandler::instance()->print("Failed to read model!\n");

	setupLightSource();
}
Пример #3
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;
}
void StimulusCylinderGrating_centered_bw::post_init(bool slave)
{

    init_cyl(_cyl);

    _virtual_world->addChild( _cyl.geode.get() );
}
Пример #5
0
void initTransforms(osg::ref_ptr<osg::MatrixTransform> transforms[3][3][3], osg::ref_ptr<CubeCreator> cubeCreator,
        osg::ref_ptr<osg::Group> root, osg::ref_ptr<osg::Geode> geode[3][3][3])
{
  
    float a = 0.0f;
    for (int i=0; i<3; i++)
    {
      for (int j=0; j<3; j++)
      {
         for (int k=0; k<3; k++)
         {
            transforms[i][j][k] = cubeCreator->createCube(geode[i][j][k], a, i,j,k);
         }
      }
    }
    for (int i=0; i<3; i++)
    {
      for (int j= 0; j<3; j++)
      {
         for (int k=0; k<3; k++)
         {
           root->addChild( transforms[i][j][k].get());
         }
      }
    }

}
Пример #6
0
void RefosgLOD::addChild(osg::Object *child) {
	{osg::StateSet *cobj = dynamic_cast<osg::StateSet *>(child);
	if (cobj != 0) {
		_object->setStateSet(cobj);
		return;
	}}
	{NodeCallback *cobj = dynamic_cast<NodeCallback *>(child);
	if (cobj != 0) {
		_object->setCullCallback(cobj);
		return;
	}}
	{NodeCallback *cobj = dynamic_cast<NodeCallback *>(child);
	if (cobj != 0) {
		_object->setUpdateCallback(cobj);
		return;
	}}
	{NodeCallback *cobj = dynamic_cast<NodeCallback *>(child);
	if (cobj != 0) {
		_object->setEventCallback(cobj);
		return;
	}}
	{Node *cobj = dynamic_cast<Node *>(child);
	if (cobj != 0) {
		_object->addChild(cobj);
		return;
	}}
	throw InvalidTypeException();
}
Пример #7
0
void Stimulus3DShaderDemo::post_init(bool slave) {
    osg::ref_ptr<osg::Node> drawn_geometry_node = load_osg_file("Stimulus3DShaderDemo.osg");

    osg::StateSet* state = drawn_geometry_node->getOrCreateStateSet();
    state->setMode(GL_LIGHTING,osg::StateAttribute::OFF);

    osg::Program* AltitudeProgram;
    osg::Shader*  AltitudeVertObj;
    osg::Shader*  AltitudeFragObj;

    AltitudeProgram = new osg::Program;
    AltitudeProgram->setName( "altitude" );
    AltitudeVertObj = new osg::Shader( osg::Shader::VERTEX );
    AltitudeFragObj = new osg::Shader( osg::Shader::FRAGMENT );
    AltitudeProgram->addShader( AltitudeFragObj );
    AltitudeProgram->addShader( AltitudeVertObj );

    load_shader_source( AltitudeVertObj, "rainbow.vert" );
    load_shader_source( AltitudeFragObj, "rainbow.frag" );

    state->setAttributeAndModes(AltitudeProgram, osg::StateAttribute::ON);
    example_param_uniform = new osg::Uniform( osg::Uniform::FLOAT, "example_param" );
    state->addUniform( example_param_uniform );

    _group = new osg::Group;
    _group->addChild(drawn_geometry_node);
    _group->setName("Stimulus3DShaderDemo._group");

    _slave = slave;
    {
      Poco::NamedMutex::ScopedLock lock(_memlock);
      *_mem.begin() = 'a';
    }
}
void OsgPrismatic::CreatePrismaticGraphics(float fltBoxSize, float fltRadius, 
                                           osg::ref_ptr<osg::MatrixTransform> osgJointMT, OsgPrismaticLimit *lpUpperLimit, 
                                           OsgPrismaticLimit *lpLowerLimit, OsgPrismaticLimit *lpPosFlap)
{
	lpUpperLimit->SetupLimitGraphics(fltBoxSize, fltRadius);
	lpLowerLimit->SetupLimitGraphics(fltBoxSize, fltRadius);
	lpPosFlap->SetupLimitGraphics(fltBoxSize, fltRadius);
        
	osgJointMT->addChild(lpUpperLimit->BoxMT());
	osgJointMT->addChild(lpUpperLimit->CylinderMT());

	osgJointMT->addChild(lpLowerLimit->BoxMT());
	osgJointMT->addChild(lpLowerLimit->CylinderMT());

	osgJointMT->addChild(lpPosFlap->BoxMT());
}
Пример #9
0
void OccluderEventHandler::endOccluder()
{
    if (_convexPlanarOccluder.valid()) 
    {
        if (_convexPlanarOccluder->getOccluder().getVertexList().size()>=3)
        {
            osg::OccluderNode* occluderNode = new osg::OccluderNode;
            occluderNode->setOccluder(_convexPlanarOccluder.get());

            if (!_occluders.valid())
            {
                _occluders = new osg::Group;
                if (rootNode()) rootNode()->addChild(_occluders.get());
            }
            _occluders->addChild(occluderNode);

            std::cout<<"created occluder"<<std::endl;
        }
        else
        {
            std::cout<<"Occluder requires at least 3 points to create occluder."<<std::endl;
        }
    }
    else
    {
        std::cout<<"No occluder points to create occluder with."<<std::endl;
    }
    
    // reset current occluder.
    _convexPlanarOccluder = NULL;
}
Пример #10
0
void SlideEventHandler::set(FileList fileList, osg::Switch* sw, float offsetX, float offsetY, osg::TexMat* texmatLeft, osg::TexMat* texmatRight, float radius, float height, float length, float timePerSlide, bool autoSteppingActive)
{
    _switch = sw;
    _switch->setUpdateCallback(this);
    _fileList=FileList(fileList);

    osg::ref_ptr<osg::Group> imageGroup = loadImages(fileList[0],fileList[1],texmatLeft,texmatRight, radius,  height, length);
    if (imageGroup.get())_switch->addChild(imageGroup.get());

    _texmatLeft = texmatLeft;
    _texmatRight = texmatRight;

    _radius=radius;
    _height=height;
    _length=length;

    _timePerSlide = timePerSlide;
    _autoSteppingActive = autoSteppingActive;

    _initSeperationX = offsetX;
    _currentSeperationX = _initSeperationX;

    _initSeperationY = offsetY;
    _currentSeperationY = _initSeperationY;

    initTexMatrices();
}
Пример #11
0
Player::Player(std::string _name, osg::Vec3f _pos, float _colRad, int _hp, osg::ref_ptr<osg::MatrixTransform> _scene, int _bridgeModel)
{
	initTransform();
	rigidBodyRadius = _colRad;
	pos = _pos;
	setName(_name);
	setHP(_hp);
	setMaxHP(_hp);

	_scene->addChild(playerTransform);
	playerTransform->postMult(osg::Matrix::translate(pos));


	healthbarTransform->postMult(osg::Matrix::rotate(-PI / 8, 1.0f, 0.0f, 0.0f));

	bridgeTransform->postMult(osg::Matrix::rotate(PI + PI / 4.0, 1.0, 0.0, 0.0));
	//bridgeTransform->postMult(osg::Matrix::scale(0.1f, 0.1f, 0.1f));

	if (_bridgeModel == 1) {
		bridge = GameObject((std::string)("Kommandobryggan"), osg::Vec3f(0, 0, 0), 0, 100000, (std::string)("models/kurvbrygga_lasselagom.ive"), bridgeTransform, 100000);
		bridgeTransform->postMult(osg::Matrix::translate(0.0f, 3.5f, 0.0f));
	}
	if (_bridgeModel == 2) {
		bridge = GameObject((std::string)("Kommandobryggan"), osg::Vec3f(0, 0, 0), 0, 100000, (std::string)("models/kurvbrygga_lasselagom.ive"), bridgeTransform, 100000);
		bridgeTransform->postMult(osg::Matrix::translate(0.0f, 2.5f, 0.0f));
	}
	if (_bridgeModel == 3) {
		bridge = GameObject((std::string)("Kommandobryggan"), osg::Vec3f(0, 0, 0), 0, 100000, (std::string)("models/kurvbrygga_lassesmal.ive"), bridgeTransform, 100000);
		bridgeTransform->postMult(osg::Matrix::translate(0.0f, 3.5f, 0.0f));
	}
	if (_bridgeModel == 4) {
		bridge = GameObject((std::string)("Kommandobryggan"), osg::Vec3f(0, 0, 0), 0, 100000, (std::string)("models/kurvbrygga_lassesmal.ive"), bridgeTransform, 100000);
		bridgeTransform->postMult(osg::Matrix::translate(0.0f, 2.5f, 0.0f));
	}
}
Пример #12
0
void setupLightSource()
{
	osg::Light * light0 = new osg::Light;
	osg::Light * light1 = new osg::Light;
	osg::LightSource* lightSource0 = new osg::LightSource;
	osg::LightSource* lightSource1 = new osg::LightSource;

	light0->setLightNum( 0 );
	light0->setPosition( osg::Vec4( 5.0f, 5.0f, 10.0f, 1.0f ) );
	light0->setAmbient( osg::Vec4( 0.3f, 0.3f, 0.3f, 1.0f ) );
	light0->setDiffuse( osg::Vec4( 0.8f, 0.8f, 0.8f, 1.0f ) );
	light0->setSpecular( osg::Vec4( 0.1f, 0.1f, 0.1f, 1.0f ) );
	light0->setConstantAttenuation( 1.0f );

	lightSource0->setLight( light0 );
    lightSource0->setLocalStateSetModes( osg::StateAttribute::ON );
	lightSource0->setStateSetModes( *(mRootNode->getOrCreateStateSet()), osg::StateAttribute::ON );

	light1->setLightNum( 1 );
	light1->setPosition( osg::Vec4( -5.0f, -2.0f, 10.0f, 1.0f ) );
	light1->setAmbient( osg::Vec4( 0.2f, 0.2f, 0.2f, 1.0f ) );
	light1->setDiffuse( osg::Vec4( 0.5f, 0.5f, 0.5f, 1.0f ) );
	light1->setSpecular( osg::Vec4( 0.2f, 0.2f, 0.2f, 1.0f ) );
	light1->setConstantAttenuation( 1.0f );

	lightSource1->setLight( light1 );
    lightSource1->setLocalStateSetModes( osg::StateAttribute::ON );
	lightSource1->setStateSetModes( *(mRootNode->getOrCreateStateSet()), osg::StateAttribute::ON );

	mRootNode->addChild( lightSource0 );
	mRootNode->addChild( lightSource1 );
}
Пример #13
0
void add_skybox_to_node(osg::ref_ptr<osg::ClearNode> mynode,
			std::string posx_fname,
			std::string negx_fname,
			std::string posy_fname,
			std::string negy_fname,
			std::string posz_fname,
			std::string negz_fname
			)
{

    osg::StateSet* stateset = new osg::StateSet();

    osg::TexEnv* te = new osg::TexEnv;
    te->setMode(osg::TexEnv::REPLACE);
    stateset->setTextureAttributeAndModes(0, te, osg::StateAttribute::ON);

    osg::TexGen *tg = new osg::TexGen;
    tg->setMode(osg::TexGen::NORMAL_MAP);
    stateset->setTextureAttributeAndModes(0, tg, osg::StateAttribute::ON);

    osg::TexMat *tm = new osg::TexMat;
    stateset->setTextureAttribute(0, tm);

    osg::TextureCubeMap* skymap = readCubeMap(posx_fname,
					      negx_fname,
					      posy_fname,
					      negy_fname,
					      posz_fname,
					      negz_fname);

    stateset->setTextureAttributeAndModes(0, skymap, osg::StateAttribute::ON);

    stateset->setMode( GL_LIGHTING, osg::StateAttribute::OFF );
    stateset->setMode( GL_CULL_FACE, osg::StateAttribute::OFF );

    // clear the depth to the far plane.
    osg::Depth* depth = new osg::Depth;
    depth->setFunction(osg::Depth::ALWAYS);
    depth->setRange(1.0,1.0);   
    stateset->setAttributeAndModes(depth, osg::StateAttribute::ON );

    stateset->setRenderBinDetails(-1,"RenderBin");

    osg::ref_ptr<osg::Drawable> drawable = new osg::ShapeDrawable( new osg::Sphere(osg::Vec3(0.0f,0.0f,0.0f),500));

    osg::ref_ptr<osg::Geode> geode = new osg::Geode();
    geode->setCullingActive(false);
    geode->setStateSet( stateset );
    geode->addDrawable(drawable.get());

    osg::ref_ptr<osg::Transform> transform = new MoveEarthySkyWithEyePointTransform();
    transform->setCullingActive(false);
    transform->addChild(geode.get());

//  mynode.setRequiresClear(false);
    mynode->setCullCallback(new TexMatCallback(*tm));
    mynode->addChild(transform.get());
}
void creerLeSol(vector<GLfloat> coordonnees,osg::ref_ptr<osg::Group> noeudAAjouter) {
	osg::ref_ptr<osg::MatrixTransform> mModel = new osg::MatrixTransform();

	mModel->preMult( osg::Matrix::translate(coordonnees[0], coordonnees[1], coordonnees[2]));
	mModel->preMult( osg::Matrix::rotate( gmtl::Math::deg2Rad( -90.0f), 1.0f, 0.0f, 0.0f) );

	noeudAAjouter->addChild(mModel);
	mModel->addChild(ImmeubleAvecFenetre::route.get());
}
void ImmeubleAvecFenetre::placeNodeLampadaire(osg::ref_ptr<osg::Node> element,vector<GLfloat> coordonnees,osg::ref_ptr<osg::Group> noeudAAjouter,float rotationY) {
	osg::ref_ptr<osg::MatrixTransform> mModel = new osg::MatrixTransform();

	mModel->preMult( osg::Matrix::translate(coordonnees[0], coordonnees[1], coordonnees[2]));
	mModel->preMult( osg::Matrix::rotate( gmtl::Math::deg2Rad( -90.0f ), 1.0f, 0.0f, 0.0f) );
	mModel->preMult( osg::Matrix::rotate( gmtl::Math::deg2Rad( rotationY ), 0.0f, 0.0f, 1.0f) );
	noeudAAjouter->addChild(mModel);
	mModel->addChild(element.get());
}
Пример #16
0
void setLightSource(osg::ref_ptr<osg::Group> root)
{
    osg::ref_ptr<osg::LightSource> ls = new osg::LightSource();
    ls->getLight()->setPosition(osg::Vec4(5.0f,5.0f,5.0f,0.0f));
    ls->getLight()->setAmbient(osg::Vec4(1.2,1.2,1.2,1.2));
    ls->getLight()->setSpecular(osg::Vec4(1.2,1.2,1.2,1.2));
    ls->getLight()->setLinearAttenuation(1.0f);
    root->addChild(ls.get());

}
Пример #17
0
void startApplication()
{
	startMenu->hideAll();	
	
	osg::ref_ptr<osg::Node> groundRoot = genWorld(filename);
	root->addChild(groundRoot);

	osg::ref_ptr<FirstPersonController> controller = new FirstPersonController(&viewer);
    	viewer.setCameraManipulator(controller);

	// Add main HUD
    	mainHud = new hud(&viewer);
    	root->addChild(mainHud->_camera);

	// Set user position (aka camera)
	    osg::Vec3d eye( 0.0, -1.0, 0.0 );
	    osg::Vec3d center( 0.0, 0.0, 0.0 );
	    osg::Vec3d up( 0.0, 0.0, 90.0 );

	    viewer.getCameraManipulator()->setHomePosition(eye, center, up);
	    viewer.home();
}
GameObject::GameObject(std::string _name, osg::Vec3f _pos, float _colRad, int _hp, std::string _model, osg::ref_ptr<osg::MatrixTransform> _scene, int _id)
{
    initTransform();
    setVel(0.0);
    setDir(osg::Vec3f(0.0f, 0.0f, 1.0f));
    setOrientation(osg::Quat(0.0f, 0.0f, 0.0f, 1.0f));
    rigidBodyRadius = _colRad;
    translate(_pos);
    setName(_name);
    setHP(_hp);
    setDescr((std::string)("hej"));
    _scene->addChild(getTrans());
    setID(_id);
    setModel(_model);
}
Пример #19
0
osg::Switch* KeyboardModel::addKey(osg::Vec3& pos, int key,const std::string& text,float width, float height)
{

    osg::Geode* geodeUp = new osg::Geode;
    {
        osgText::Text* textUp = new osgText::Text;
        textUp->setFont("fonts/arial.ttf");
        textUp->setColor(osg::Vec4(1.0f,1.0f,1.0f,1.0f));
        textUp->setCharacterSize(height);
        textUp->setPosition(pos);
        textUp->setDrawMode(osgText::Text::TEXT/*|osgText::Text::BOUNDINGBOX*/);
        textUp->setAlignment(osgText::Text::LEFT_CENTER);
        textUp->setAxisAlignment(osgText::Text::XZ_PLANE);
        textUp->setText(text);
        
        geodeUp->addDrawable(textUp);
    }
    
    osg::Geode* geodeDown = new osg::Geode;
    {
        osgText::Text* textDown = new osgText::Text;
        textDown->setFont("fonts/arial.ttf");
        textDown->setColor(osg::Vec4(1.0f,0.0f,1.0f,1.0f));
        textDown->setCharacterSize(height);
        textDown->setPosition(pos);
        textDown->setDrawMode(osgText::Text::TEXT/*||osgText::Text::BOUNDINGBOX*/);
        textDown->setAlignment(osgText::Text::LEFT_CENTER);
        textDown->setAxisAlignment(osgText::Text::XZ_PLANE);
        textDown->setText(text);
        
        geodeDown->addDrawable(textDown);
    }

    osg::Switch* model = new osg::Switch;
    model->addChild(geodeUp,true);
    model->addChild(geodeDown,false);
    
    _scene->addChild(model);

    _keyModelMap[key] = model;
    
    pos.x() += width;
    
    return model;
    
}
Пример #20
0
EnemyShip::EnemyShip(std::string _name, osg::Vec3f _pos, float _colRad, std::string _model, osg::ref_ptr<osg::MatrixTransform> _scene, int _hp, int _id)
{
	initTransform();
	setVel(0.0);
	setDir(osg::Vec3f(0.0f, 0.0f, 1.0f));	//Not used
	setOrientation(osg::Quat(0.0f, 0.0f, 1.0f, 0.0f));
	setColRad(_colRad);
	setHP(_hp);
	translate(_pos);
	setName(_name);
	setDescr((std::string)("hej"));
	_scene->addChild(getTrans());
	setID(_id);
	setModel(_model);

	attackCooldown = 10;
	homingMissileAttackCooldown = 40;
}
// insert a sphere in the scene with desired position, radius and reflectance properties
void addSimpleObject(osg::ref_ptr<osg::Group> root, osg::Vec3 position, float radius, float reflectance) {
    // create the drawable
    osg::ref_ptr<osg::Drawable> drawable = new osg::ShapeDrawable(new osg::Sphere(position, radius));

    // create the stateset and add the uniform
    osg::ref_ptr<osg::StateSet> stateset = new osg::StateSet();
    stateset->addUniform(new osg::Uniform("reflectance", reflectance));

    // add the stateset to the drawable
    drawable->setStateSet(stateset);

    if(!root->getNumChildren()) {
        osg::ref_ptr<osg::Geode> geode = new osg::Geode();
        root->addChild(geode);
    }

    root->getChild(0)->asGeode()->addDrawable(drawable);
}
    void onClick( Control* control, int mouseButtonMask ) {
        
        //Remove the add point handler if it's valid
        if (s_addPointHandler.valid())
        {            
            osgEarth::removeEventHandler( s_viewer, s_addPointHandler.get() );
            s_addPointHandler = NULL;
        }        

        if (!s_editor.valid())
        {            
            Style style = s_featureNode->getStyle();
            style.getOrCreate<LineSymbol>()->stroke()->stipple() = 0x00FF;            
            s_featureNode->setStyle( style );            
            s_editor = new FeatureEditor( s_featureNode );
            s_root->addChild( s_editor.get() );            
        }
    }    
Пример #23
0
osg::ref_ptr<osg::Node> RobotModel::makeOsg2(KDL::Segment kdl_seg, urdf::Link urdf_link, osg::ref_ptr<osg::Group> root){
    osg::ref_ptr<OSGSegment> seg = osg::ref_ptr<OSGSegment>(new OSGSegment(kdl_seg));
    root->addChild(seg->toTipOsg_);

    //Attach one visual to joint
    if (urdf_link.visual_array.size() == 0)
    {
        boost::shared_ptr<urdf::Visual> visual = urdf_link.visual;
        seg->attachVisual(visual, rootPrefix);
    }
    //Attach several visuals to joint
    else
    {
         std::vector<boost::shared_ptr<urdf::Visual> > visual_array = urdf_link.visual_array;
         seg->attachVisuals(visual_array, rootPrefix);
    }

    return seg->getGroup();
}
Пример #24
0
osg::Node* CreateScene()
{
	pGroup = new osg::Group;
	
	osg::Geode* pGeode1 = new osg::Geode();
	pGroup->addChild( pGeode1 );	
	osg::Geode* pGeode2 = new osg::Geode();
	pGroup->addChild( pGeode2 );	
	osg::Geode* pGeode3 = new osg::Geode();
	pGroup->addChild( pGeode3 );	
	osg::Geode* pGeode4 = new osg::Geode();
	pGroup->addChild( pGeode4 );	
	osg::Geode* pGeode5 = new osg::Geode();
	pGroup->addChild( pGeode5 );	

	// we create the simplest form of shapes in OpenSceneGraph
    pGeode1->addDrawable( new osg::ShapeDrawable( new osg::Sphere(osg::Vec3(0.0f,0.0f,0.0f),0.5f) ) );
    pGeode2->addDrawable( new osg::ShapeDrawable( new osg::Box(osg::Vec3(2.0f,0.0f,0.0f),2.0f) ) );
    pGeode3->addDrawable( new osg::ShapeDrawable( new osg::Cone(osg::Vec3(4.0f,0.0f,0.0f),0.5f,3.0f) ) );
    pGeode4->addDrawable( new osg::ShapeDrawable( new osg::Cylinder(osg::Vec3(6.0f,0.0f,0.5f),0.5f,3.0f) ) );
    pGeode5->addDrawable( new osg::ShapeDrawable( new osg::Capsule(osg::Vec3(8.0f,0.0f,1.0f),0.5f,3.0f) ) );

	// create dummy sphere, so we can see where the collision should take place
	CSulGeodeSphere* pSphere = new CSulGeodeSphere( radius, osg::Vec3( 0, 0, 0 ) );

	mt = new osg::MatrixTransform;
	mt->addChild( pSphere );
	pGG->addChild( mt );
	updateTransform();

	// test collision
	g_pSI = new CSulSphereIntersector;
	pGG->addChild( g_pSI->enableDebug() );
	g_iv = new osgUtil::IntersectionVisitor;
	g_iv->setIntersector( g_pSI );

	g_pSI->setRadius( radius );
	g_pSI->setPosition( pos );

	testCol();

	return pGroup;
}
    void onClick( Control* control, int mouseButtonMask ) {
        
        //Remove the add point handler if it's valid
        if (s_addPointHandler.valid())
        {            
            osgEarth::removeEventHandler( s_viewer, s_addPointHandler.get() );
            s_addPointHandler = NULL;
        }        

        if (!s_editor.valid() && s_activeFeature.valid())
        {
            Style* style = _featureGraph->getStyles()->getDefaultStyle();
            if ( style )
            {
                style->get<LineSymbol>()->stroke()->stipple() = 0x00FF;
                _featureGraph->dirty();
            }
            s_editor = new FeatureEditor(s_activeFeature.get(), s_source.get(), s_mapNode.get());
            s_root->addChild( s_editor.get() );
        }
    }
Пример #26
0
int main()
{

    osg::ref_ptr< osg::Geode    > pGeoSphere= new osg::Geode();
    osg::ref_ptr< osg::Geometry   > pGeom= new osg::Geometry();

    osg::ref_ptr< osg::Vec3Array > pVertices= new osg::Vec3Array(  3);

    (*pVertices)[ 0].set( 0+ 2, 0- 2, 0);
    (*pVertices)[ 1].set( 0 , 0- 2, 2);
    (*pVertices)[ 2].set( 0, 0- 2, 0);
    pGeom->setVertexArray( pVertices.get() );

    osg::ref_ptr< osg::DrawElementsUInt> pTri= new osg::DrawElementsUInt( osg::PrimitiveSet::TRIANGLES , 0);

    pTri->push_back( 0);
    pTri->push_back( 1);
    pTri->push_back( 2);
    pGeom->addPrimitiveSet( pTri.get());


    pGeoSphere->addDrawable( pGeom.get());


    //g_pRoot->addChild( pGeoSphere.get());//将非dragger的物体加入

    osgViewer::Viewer viewer;

    //cmdManager
    osg::ref_ptr<osgManipulator::CommandManager> cmdMgr = new osgManipulator::CommandManager;

	osg::ref_ptr< osg::Geode    > pGeoSphereDragger= new osg::Geode();
    g_pRoot->addChild(addDraggerToScene( pGeoSphereDragger.get(),cmdMgr,"Translate2DDragger") );

    viewer.setSceneData(  g_pRoot);

    viewer.addEventHandler(new PickModeHandler());

    return viewer.run();  
}
Пример #27
0
void ComputeNode::addComputationResultsRenderTree()
{

    _computationResultsRenderProgram = new osg::Program;

    _vertexShader = osgDB::readRefShaderFile(osg::Shader::VERTEX, _vertexShaderSourcePath);
    _computationResultsRenderProgram->addShader(_vertexShader.get());

    _geometryShader = osgDB::readRefShaderFile(osg::Shader::GEOMETRY, _geometryShaderSourcePath);
    _computationResultsRenderProgram->addShader(_geometryShader.get());

    _fragmentShader = osgDB::readRefShaderFile(osg::Shader::FRAGMENT, _fragmentShaderSourcePath);
    _computationResultsRenderProgram->addShader(_fragmentShader.get());


    _computationResultsRenderProgram->addBindAttribLocation("tex_coords", 1);

    _computationResultsRenderGroup = new osg::Group;
    _computationResultsRenderGroup->setDataVariance(osg::Object::DYNAMIC);
    _computationResultsRenderStateSet = _computationResultsRenderGroup->getOrCreateStateSet();
    _computationResultsRenderStateSet->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);

    osg::PointSprite *sprite = new osg::PointSprite;
    int texture_unit = 0;
    _computationResultsRenderStateSet->setTextureAttributeAndModes(texture_unit, sprite, osg::StateAttribute::ON);
    _computationResultsRenderStateSet->setAttributeAndModes(_computationResultsRenderProgram.get(), osg::StateAttribute::ON);
    _computationResultsRenderStateSet->addUniform(new osg::Uniform("particleTexture", texture_unit));
    _computationResultsRenderStateSet->addUniform(new osg::Uniform("numRows", (int)NUM_ELEMENTS_X));
    _computationResultsRenderStateSet->addUniform(new osg::Uniform("numCols", (int)NUM_ELEMENTS_Y));


    _computationResultsRenderStateSet->setMode(GL_POINT_SMOOTH, osg::StateAttribute::ON);
    _computationResultsRenderStateSet->setMode(GL_VERTEX_PROGRAM_POINT_SIZE_ARB, osg::StateAttribute::ON);
    _computationResultsRenderStateSet->setMode(GL_ALPHA_TEST, osg::StateAttribute::ON);
    _computationResultsRenderStateSet->setMode(GL_LIGHTING, osg::StateAttribute::OFF);

    osg::Texture2D *tex = new osg::Texture2D();

    osg::Image* particleImage = createSpotLightImage(osg::Vec4(1, 0, 0, 1), osg::Vec4(0.5, 0, 0, 0.0), 32, 0.7);
    if (particleImage)
    {
        tex->setImage(particleImage);
    }
    _computationResultsRenderStateSet->setTextureAttributeAndModes(texture_unit, tex, osg::StateAttribute::ON);


    osg::BlendFunc *blend = new osg::BlendFunc;
    if (false) //emissive particles
    {
        blend->setFunction(osg::BlendFunc::SRC_ALPHA, osg::BlendFunc::ONE);
    }
    else
    {
        blend->setFunction(osg::BlendFunc::SRC_ALPHA, osg::BlendFunc::ONE_MINUS_SRC_ALPHA);
    }

    _computationResultsRenderStateSet->setAttributeAndModes(blend, osg::StateAttribute::ON);


    osg::Depth* depth = new osg::Depth;
    depth->setRange(0.0f, 0.0f);
    depth->setFunction(osg::Depth::ALWAYS);
    depth->setWriteMask(false);
    depth->setFunction(osg::Depth::ALWAYS);

    _computationResultsRenderStateSet->setAttributeAndModes(depth, osg::StateAttribute::OFF);


    osg::Geode* particleGeode = new osg::Geode;
    unsigned int numVertices = NUM_ELEMENTS_X*NUM_ELEMENTS_Y;

    osg::Geometry* particleGeometry = new osg::Geometry;
    particleGeometry->setUseDisplayList(false);
    particleGeometry->setUseVertexBufferObjects(true);

    osg::Vec3Array* vertexarray = new osg::Vec3Array;
    osg::Vec2Array* tcoords = new osg::Vec2Array;

    osg::Vec2 bottom_texcoord(0.0f, 0.0f);

    osg::Vec2 dx_texcoord(1.0f / (float)(NUM_ELEMENTS_X), 0.0f);
    osg::Vec2 dy_texcoord(0.0f, 1.0f / (float)(NUM_ELEMENTS_Y));



    for (int i = 0; i < NUM_ELEMENTS_X; i++)
    {
        osg::Vec2 texcoord = bottom_texcoord + dy_texcoord*(float)i;

        for (int j = 0; j < NUM_ELEMENTS_Y; j++)
        {
            vertexarray->push_back(osg::Vec3(texcoord.x(), texcoord.y(), 0.0));
            tcoords->push_back(osg::Vec2(texcoord.x(), texcoord.y()));
            texcoord += dx_texcoord;
        }
    }

    particleGeometry->setVertexArray(vertexarray);
    particleGeometry->addPrimitiveSet(new osg::DrawArrays(GL_POINTS, 0, numVertices));
    particleGeometry->setTexCoordArray(0, tcoords);
    //this glMemoryBarrier thing... not sure if we could better do instanced drawing?  all the data is in Shader Storage Buffer..
    particleGeometry->setVertexAttribArray(1, particleGeometry->getTexCoordArray(0), osg::Array::BIND_PER_VERTEX);

    _computationResultsRenderGroup->addChild(particleGeode);
    particleGeode->addDrawable(particleGeometry);

    addChild(_computationResultsRenderGroup.get());

}
Пример #28
0
    virtual bool handle(const PointerInfo& pointer, const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa)
    {
       // Check if the dragger node is in the nodepath.
       if (!pointer.contains(this)) return false;
       switch (ea.getEventType())
       {
           // Pick start.
       case (osgGA::GUIEventAdapter::PUSH):
           {
               // Get the LocalToWorld matrix for this node and set it for the projector.
              osg::NodePath nodePathToRoot;
              computeNodePathToRoot(*this,nodePathToRoot);
              osg::Matrix localToWorld = osg::computeLocalToWorld(nodePathToRoot);
              _projector->setLocalToWorld(localToWorld);

              //设置点移动平面,点即鼠标与物体交点(世界坐标系),法线为//视线方向
			  //osg::Plane::Plane  ( const Vec3_type &  norm,  const Vec3_type &  point) norm:法线;point:交点

              osg::Plane* pplnPTPush= new osg::Plane( pointer.getEyeDir(),
				  pointer.getLocalIntersectPoint()/** _projector->getLocalToWorld()*/);
              _projector->setPlane( *pplnPTPush);

              if (_projector->project(pointer, _startProjectedPoint))
              {
                  // Generate the motion command.
                  osg::ref_ptr<TranslateInPlaneCommand> cmd = new TranslateInPlaneCommand(_projector->getPlane());

                  cmd->setStage(MotionCommand::START);
                  cmd->setReferencePoint(_startProjectedPoint);
                  cmd->setLocalToWorldAndWorldToLocal(_projector->getLocalToWorld(),_projector->getWorldToLocal());

                  // Dispatch command.
                  if (_commandManager)
                  {
                     _commandManager->addSelectionsToCommand(*cmd, *getParentDragger());
                     _commandManager->dispatch(*cmd);
                  }
              //在该点处添加一个球 
              osg::ref_ptr< osg::Shape> sphere = 
				  new osg::Sphere( _startProjectedPoint* _projector->getLocalToWorld(), 0.08f);
              osg::ref_ptr<osg::ShapeDrawable> sphereDrawable = new osg::ShapeDrawable(sphere);
              osg::ref_ptr<osg::Geode> sphereGeode = new osg::Geode();
              sphereGeode->addDrawable(sphereDrawable);

              g_pRoot->addChild( sphereGeode);

                  // Set color to pick color.
                  setMaterialColor(_pickColor,*this);
                  getOrCreateStateSet()->setAttributeAndModes(_polygonOffset.get(), osg::StateAttribute::ON);

                  aa.requestRedraw();
              }
              return true; 
           }

           // Pick move.
       case (osgGA::GUIEventAdapter::DRAG):
           {
              osg::Vec3d projectedPoint;
              if (_projector->project(pointer, projectedPoint))
              {
                  // Generate the motion command.
                  osg::ref_ptr<TranslateInPlaneCommand> cmd = new TranslateInPlaneCommand(_projector->getPlane());

                  cmd->setStage(MotionCommand::MOVE);
                  cmd->setLocalToWorldAndWorldToLocal(_projector->getLocalToWorld(),_projector->getWorldToLocal());
                  cmd->setTranslation(projectedPoint - _startProjectedPoint);
                  cmd->setReferencePoint(_startProjectedPoint);

                  // Dispatch command.
                  if (_commandManager)
                  {
                     _commandManager->addSelectionsToCommand(*cmd, *getParentDragger());
                     _commandManager->dispatch(*cmd);
                  }

				  osg::ref_ptr< osg::Shape> sphere =
					  new osg::Sphere( projectedPoint* _projector->getLocalToWorld(), 0.08f);
              osg::ref_ptr<osg::ShapeDrawable> sphereDrawable = new osg::ShapeDrawable(sphere);
              osg::ref_ptr<osg::Geode> sphereGeode = new osg::Geode();
              sphereGeode->addDrawable(sphereDrawable);

              g_pRoot->addChild( sphereGeode);

                  aa.requestRedraw();
              }
              return true; 
           }

           // Pick finish.
       case (osgGA::GUIEventAdapter::RELEASE):
           {

               osg::ref_ptr<TranslateInPlaneCommand> cmd = new TranslateInPlaneCommand(_projector->getPlane());

               cmd->setStage(MotionCommand::FINISH);
               cmd->setReferencePoint(_startProjectedPoint);
               cmd->setLocalToWorldAndWorldToLocal(_projector->getLocalToWorld(),_projector->getWorldToLocal());

              // Dispatch command.
              if (_commandManager)
              {
                  _commandManager->addSelectionsToCommand(*cmd, *getParentDragger());
                  _commandManager->dispatch(*cmd);
              }
              // Reset color.
              setMaterialColor(_color,*this);
              getOrCreateStateSet()->removeAttribute(_polygonOffset.get());

              aa.requestRedraw();
              return true;
           }
       default:
           return false;
       }
    }
Пример #29
0
void KeyboardModel::createKeyboard()
{
    _scene = new osg::Group;
    
    osg::Vec3 origin(0.0f,0.0f,0.0f);
    osg::Vec3 pos=origin;
    
    addKey(pos,osgGA::GUIEventAdapter::KEY_Control_L,"Ctrl",2.0f,0.5f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_Super_L,"Super",2.0f,0.5f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_Alt_L,"Alt",2.0f,0.5f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_Space,"Space",3.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_Mode_switch,"Switch",2.0f,0.5f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_Super_R,"Super",2.0f,0.5f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_Menu,"Menu",2.0f,0.5f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_Control_R,"Ctrl",2.0f,0.5f);

    osg::Vec3 middle(pos.x()+1.0f,0.0f,0.0f);
    
    pos.x() = 0.0f;
    pos.z() += 1.0f;

    addKey(pos,osgGA::GUIEventAdapter::KEY_Shift_L,"Shift",2.0f,0.5f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_Backslash,"\\",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_Z,"Z",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_X,"X",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_C,"C",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_V,"V",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_B,"B",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_N,"N",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_M,"M",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_Comma,",",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_Period,".",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_Slash,"/",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_Shift_R,"Shift",2.0f,0.5f);

    pos.x() = 0.0f;
    pos.z() += 1.0f;
    
    addKey(pos,osgGA::GUIEventAdapter::KEY_Caps_Lock,"Caps",2.0f,0.5f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_A,"A",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_S,"S",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_D,"D",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_F,"F",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_G,"G",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_H,"H",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_J,"J",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_K,"K",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_L,"L",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_Semicolon,";",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_Quote,"'",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_Hash,"#",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_Return,"Return",4.0f,0.5f);

    pos.x() = 0.0f;
    pos.z() += 1.0f;
    
    addKey(pos,osgGA::GUIEventAdapter::KEY_Tab,"Tab",2.0f,0.5f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_Q,"Q",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_W,"W",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_E,"E",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_R,"R",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_T,"T",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_Y,"Y",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_U,"U",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_I,"I",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_O,"O",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_P,"P",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_Leftbracket,"[",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_Rightbracket,"]",1.0f,1.0f);

    pos.x() = 0.0f;
    pos.z() += 1.0f;
    
    addKey(pos,osgGA::GUIEventAdapter::KEY_Backquote,"`",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_1,"1",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_2,"2",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_3,"3",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_4,"4",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_5,"5",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_6,"6",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_7,"7",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_8,"8",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_9,"9",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_0,"0",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_Minus,"-",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_Equals,"=",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_BackSpace,"Backspace",3.0f,0.5f);

    pos.x() = 0.0f;
    pos.z() += 1.5f;
    
    float F_height = 0.5f;
    addKey(pos,osgGA::GUIEventAdapter::KEY_Escape,"Esc",2.0f,F_height);
    addKey(pos,osgGA::GUIEventAdapter::KEY_F1,"F1",1.0f,F_height);
    addKey(pos,osgGA::GUIEventAdapter::KEY_F2,"F2",1.0f,F_height);
    addKey(pos,osgGA::GUIEventAdapter::KEY_F3,"F3",1.0f,F_height);
    addKey(pos,osgGA::GUIEventAdapter::KEY_F4,"F4",1.0f,F_height);
    addKey(pos,osgGA::GUIEventAdapter::KEY_F5,"F5",1.0f,F_height);
    addKey(pos,osgGA::GUIEventAdapter::KEY_F6,"F6",1.0f,F_height);
    addKey(pos,osgGA::GUIEventAdapter::KEY_F7,"F7",1.0f,F_height);
    addKey(pos,osgGA::GUIEventAdapter::KEY_F8,"F8",1.0f,F_height);
    addKey(pos,osgGA::GUIEventAdapter::KEY_F9,"F9",1.0f,F_height);
    addKey(pos,osgGA::GUIEventAdapter::KEY_F10,"F10",1.0f,F_height);
    addKey(pos,osgGA::GUIEventAdapter::KEY_F11,"F11",1.0f,F_height);
    addKey(pos,osgGA::GUIEventAdapter::KEY_F12,"F12",1.0f,F_height);


    
    float cursorMoveHeight=0.35f;

    pos = middle;    
    addKey(pos,osgGA::GUIEventAdapter::KEY_Left,"Left",1.0f,cursorMoveHeight);
    osg::Vec3 down = pos;
    addKey(pos,osgGA::GUIEventAdapter::KEY_Down,"Down",1.0f,cursorMoveHeight);
    addKey(pos,osgGA::GUIEventAdapter::KEY_Right,"Right",1.0f,cursorMoveHeight);
    
    osg::Vec3 keypad = pos;
    keypad.x()+=1.0f;

    pos = down;
    pos.z() += 1.0f;
    
    addKey(pos,osgGA::GUIEventAdapter::KEY_Up,"Up",1.0f,cursorMoveHeight);
    

    float homeHeight = 0.35f;
    pos = middle;
    pos.z() += 3.0;    
    addKey(pos,osgGA::GUIEventAdapter::KEY_Delete,"Delete",1.0f,homeHeight);
    addKey(pos,osgGA::GUIEventAdapter::KEY_End,"End",1.0f,homeHeight);
    addKey(pos,osgGA::GUIEventAdapter::KEY_Page_Down,"Page\nDown",1.0f,homeHeight);
    
    pos = middle;
    pos.z() += 4.0;    
    addKey(pos,osgGA::GUIEventAdapter::KEY_Insert,"Insert",1.0f,homeHeight);
    addKey(pos,osgGA::GUIEventAdapter::KEY_Home,"Home",1.0f,homeHeight);
    addKey(pos,osgGA::GUIEventAdapter::KEY_Page_Up,"Page\nUp",1.0f,homeHeight);

    pos = middle;
    pos.z() += 5.5;    
    addKey(pos,osgGA::GUIEventAdapter::KEY_Print,"PrtScrn\nSysRq",1.0f,homeHeight);
    addKey(pos,osgGA::GUIEventAdapter::KEY_Scroll_Lock,"ScrLk",1.0f,homeHeight);
    addKey(pos,osgGA::GUIEventAdapter::KEY_Pause,"Pause\nBreak",1.0f,homeHeight);
    
    

    pos = keypad;
    addKey(pos,osgGA::GUIEventAdapter::KEY_KP_Insert,"0",2.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_KP_Delete,".",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_KP_Enter,"Enter",1.0f,homeHeight);
    
    pos = keypad;
    pos.z() += 1.0f;
    addKey(pos,osgGA::GUIEventAdapter::KEY_KP_End,"1",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_KP_Down,"2",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_KP_Page_Down,"3",1.0f,1.0f);

    pos = keypad;
    pos.z() += 2.0f;
    addKey(pos,osgGA::GUIEventAdapter::KEY_KP_Left,"4",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_KP_Begin,"5",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_KP_Right,"6",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_KP_Add,"+",1.0f,1.0f);

    pos = keypad;
    pos.z() += 3.0f;
    addKey(pos,osgGA::GUIEventAdapter::KEY_KP_Home,"7",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_KP_Up,"8",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_KP_Page_Up,"9",1.0f,1.0f);

    pos = keypad;
    pos.z() += 4.0f;
    addKey(pos,osgGA::GUIEventAdapter::KEY_Num_Lock,"Num\nLock",1.0f,0.3f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_KP_Divide,"/",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_KP_Multiply,"*",1.0f,1.0f);
    addKey(pos,osgGA::GUIEventAdapter::KEY_KP_Subtract,"-",1.0f,1.0f);
    
    float totalWidth = pos.x()-origin.x();
    pos = origin;
    pos.z() += -1.5f;

    osg::Geode* geodeInput = new osg::Geode;
    {
        _inputText = new osgText::Text;
        _inputText->setFont("fonts/arial.ttf");
        _inputText->setColor(osg::Vec4(1.0f,1.0f,0.0f,1.0f));
        _inputText->setCharacterSize(1.0f);
        _inputText->setMaximumWidth(totalWidth);
        _inputText->setPosition(pos);
        _inputText->setDrawMode(osgText::Text::TEXT/*||osgText::Text::BOUNDINGBOX*/);
        _inputText->setAlignment(osgText::Text::BASE_LINE);
        _inputText->setAxisAlignment(osgText::Text::XZ_PLANE);
        _inputText->setDataVariance(osg::Object::DYNAMIC);
        _inputText->setText("Press some keys...");
        
        geodeInput->addDrawable(_inputText.get());
        
        _scene->addChild(geodeInput);
    }

}
Пример #30
0
int main( int argc, char **argv )
{

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

    // set up the usage document, in case we need to print out how to use this program.
    arguments.getApplicationUsage()->setApplicationName(arguments.getApplicationName());
    arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] filename ...");
    arguments.getApplicationUsage()->addCommandLineOption("--image <filename>","Load an image and render it on a quad");
    arguments.getApplicationUsage()->addCommandLineOption("--dem <filename>","Load an image/DEM and render it on a HeightField");
    arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display command line parameters");
    arguments.getApplicationUsage()->addCommandLineOption("--help-env","Display environmental variables available");
    arguments.getApplicationUsage()->addCommandLineOption("--help-keys","Display keyboard & mouse bindings available");
    arguments.getApplicationUsage()->addCommandLineOption("--help-all","Display all command line, env vars and keyboard & mouse bindings.");

    arguments.getApplicationUsage()->addCommandLineOption("--dragger <draggername>","Use the specified dragger for manipulation [TabPlaneDragger, TabPlaneTrackballDragger, TrackballDragger, Translate1DDragger, Translate2DDragger, TranslateAxisDragger, TabBoxDragger, TranslatePlaneDragger, Scale1DDragger, Scale2DDragger, RotateCylinderDragger, RotateSphereDragger]");
    arguments.getApplicationUsage()->addCommandLineOption("--fixedDraggerSize","Fix the size of the dragger geometry in the screen space");

    bool fixedSizeInScreen = false;
    while (arguments.read("--fixedDraggerSize")) { fixedSizeInScreen = true; }


    // construct the viewer.
    osgViewer::Viewer viewer(arguments);

    // add the window size toggle handler
    viewer.addEventHandler(new osgViewer::WindowSizeHandler);

    // get details on keyboard and mouse bindings used by the viewer.
    viewer.getUsage(*arguments.getApplicationUsage());


    if (arguments.read("--test-NodeMask"))
    {
        const osg::ref_ptr<osg::Group> group = new osg::Group();
        group->setNodeMask(0);

        const osg::ref_ptr<osgManipulator::AntiSquish> antiSquish = new osgManipulator::AntiSquish();

        group->addChild(antiSquish.get());

        const osg::ref_ptr<osg::Node> node = new osg::Node();
        node->setInitialBound(osg::BoundingSphere(osg::Vec3(0.0, 0.0, 0.0), 1.0));

        antiSquish->addChild(node.get());

        group->getBound();

        return 1;
    }



    // if user request help write it out to cout.
    bool helpAll = arguments.read("--help-all");
    unsigned int helpType = ((helpAll || arguments.read("-h") || arguments.read("--help"))? osg::ApplicationUsage::COMMAND_LINE_OPTION : 0 ) |
                            ((helpAll ||  arguments.read("--help-env"))? osg::ApplicationUsage::ENVIRONMENTAL_VARIABLE : 0 ) |
                            ((helpAll ||  arguments.read("--help-keys"))? osg::ApplicationUsage::KEYBOARD_MOUSE_BINDING : 0 );
    if (helpType)
    {
        arguments.getApplicationUsage()->write(std::cout, helpType);
        return 1;
    }

    // report any errors if they have occurred when parsing the program arguments.
    if (arguments.errors())
    {
        arguments.writeErrorMessages(std::cout);
        return 1;
    }

    std::string dragger_name = "TabBoxDragger";
    arguments.read("--dragger", dragger_name);

    osg::Timer_t start_tick = osg::Timer::instance()->tick();

    // read the scene from the list of file specified command line args.
    osg::ref_ptr<osg::Node> loadedModel = osgDB::readRefNodeFiles(arguments);

    // if no model has been successfully loaded report failure.
    bool tragger2Scene(true);
    if (!loadedModel)
    {
        //std::cout << arguments.getApplicationName() <<": No data loaded" << std::endl;
        //return 1;
        loadedModel = createDemoScene(fixedSizeInScreen);
        tragger2Scene=false;
    }

    // any option left unread are converted into errors to write out later.
    arguments.reportRemainingOptionsAsUnrecognized();

    // report any errors if they have occurred when parsing the program arguments.
    if (arguments.errors())
    {
        arguments.writeErrorMessages(std::cout);
    }

    osg::Timer_t end_tick = osg::Timer::instance()->tick();

    std::cout << "Time to load = "<<osg::Timer::instance()->delta_s(start_tick,end_tick)<<std::endl;


    // optimize the scene graph, remove redundant nodes and state etc.
    osgUtil::Optimizer optimizer;
    optimizer.optimize(loadedModel);


    // pass the loaded scene graph to the viewer.
    if ( tragger2Scene ) {
        viewer.setSceneData(addDraggerToScene(loadedModel.get(), dragger_name, fixedSizeInScreen));
    } else {
        viewer.setSceneData(loadedModel);
    }


    return viewer.run();
}