当前位置: 首页>>代码示例>>C++>>正文


C++ ref_ptr::addChild方法代码示例

本文整理汇总了C++中osg::ref_ptr::addChild方法的典型用法代码示例。如果您正苦于以下问题:C++ ref_ptr::addChild方法的具体用法?C++ ref_ptr::addChild怎么用?C++ ref_ptr::addChild使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在osg::ref_ptr的用法示例。


在下文中一共展示了ref_ptr::addChild方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: root

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);


}
开发者ID:popoca,项目名称:OSG_ShootingGallery,代码行数:59,代码来源:ParticleSystem.cpp

示例2: myInitOGLFun

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();
}
开发者ID:Risca,项目名称:sgct,代码行数:49,代码来源:main.cpp

示例3: main

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;
}
开发者ID:aalviz2,项目名称:learningOSG,代码行数:28,代码来源:vuic.cpp

示例4: post_init

void StimulusCylinderGrating_centered_bw::post_init(bool slave)
{

    init_cyl(_cyl);

    _virtual_world->addChild( _cyl.geode.get() );
}
开发者ID:walste,项目名称:Fish-VR,代码行数:7,代码来源:StimulusCylinderGrating_centered_bw.cpp

示例5: initTransforms

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());
         }
      }
    }

}
开发者ID:ssppkenny,项目名称:osgrubikscube,代码行数:27,代码来源:cube.cpp

示例6: addChild

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();
}
开发者ID:whztt07,项目名称:osgedit,代码行数:28,代码来源:reflect_osg_lod.cpp

示例7: lock

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';
    }
}
开发者ID:FreemooVR,项目名称:FreemooVR,代码行数:34,代码来源:Stimulus3DShaderDemo.cpp

示例8: CreatePrismaticGraphics

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());
}
开发者ID:NeuroRoboticTech,项目名称:AnimatLabPublicSource,代码行数:16,代码来源:OsgPrismatic.cpp

示例9: endOccluder

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;
}
开发者ID:BodyViz,项目名称:osg,代码行数:31,代码来源:osgoccluder.cpp

示例10: set

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();
}
开发者ID:nsmoooose,项目名称:osg,代码行数:27,代码来源:osgstereoimage.cpp

示例11: GameObject

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));
	}
}
开发者ID:flair2005,项目名称:GameOfDomes_domeClient,代码行数:35,代码来源:Player.cpp

示例12: setupLightSource

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 );
}
开发者ID:Risca,项目名称:sgct,代码行数:32,代码来源:main.cpp

示例13: add_skybox_to_node

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());
}
开发者ID:K8H,项目名称:fsee,代码行数:58,代码来源:skybox.cpp

示例14: creerLeSol

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());
}
开发者ID:mapster76,项目名称:FlyThroughACity,代码行数:9,代码来源:ImmeubleAvecFenetre.cpp

示例15: placeNodeLampadaire

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());
}
开发者ID:mapster76,项目名称:FlyThroughACity,代码行数:9,代码来源:ImmeubleAvecFenetre.cpp


注:本文中的osg::ref_ptr::addChild方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。