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


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

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


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

示例1: 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

示例2: onPolyhedronChanged

void Scene::onPolyhedronChanged()
{
    // Update Polyhedron
    auto symbol = "#" + wild::conversion_cast<std::string>(wild::mod(_index, 80) + 1);

    _pgeometry->setSymbol(symbol);
    _pgeometry->setFaceMask(static_cast<osgKaleido::PolyhedronGeometry::FaceMask>(_faces));

    auto polyhedron = _pgeometry->getOrCreatePolyhedron();

    OSG_INFO << polyhedron->getName() << " (" << polyhedron->getDualName() << "*)" << std::endl;
    OSG_INFO << polyhedron->getWythoffSymbol() << std::endl;
    OSG_INFO << polyhedron->getVertexConfiguration() << std::endl;
    OSG_INFO << polyhedron->getVertexCount() << std::endl;
    OSG_INFO << polyhedron->getFaceCount() << std::endl;

    // Update Vertices
    osg::ref_ptr<osg::Vec3Array> vertices = osgKaleido::createVertexArray(*polyhedron);

    auto stateSet = _vgeode->getOrCreateStateSet();
    auto offsets = stateSet->getUniform("offsets");

    copy(offsets, vertices, osg::Vec3());

    // Update Text
    _text->setText(polyhedron->getName() + "\n" + polyhedron->getWythoffSymbol());
}
开发者ID:kloffy,项目名称:osgKaleido,代码行数:27,代码来源:osgkaleidoviewer.cpp

示例3: processLoadedModel

void processLoadedModel(osg::ref_ptr<osg::Node>& loadedModel, int optimizer_options, const std::string& cursorFileName)
{
    if (!loadedModel) return;

#if !defined(OSG_GLES2_AVAILABLE) && !defined(OSG_GL3_AVAILABLE)

    // add back in enabling of the GL_ALPHA_TEST to get around the core OSG no longer setting it by default for opaque bins.
    // the alpha test is required for the volume rendering alpha clipping to work.
    loadedModel->getOrCreateStateSet()->setMode(GL_ALPHA_TEST, osg::StateAttribute::ON);
#endif

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

    if (!cursorFileName.empty())
    {
        osg::ref_ptr<osg::Group> group = new osg::Group;
        group->addChild(loadedModel.get());

        OSG_NOTICE<<"Creating Cursor"<<std::endl;
        group->addChild(new osgPresentation::Cursor(cursorFileName, 20.0f));

        loadedModel = group;
    }
}
开发者ID:ChrisWC,项目名称:osg,代码行数:26,代码来源:present3D.cpp

示例4: __drawCoordinateMask

//***********************************************************
//FUNCTION:
void CPickNode::__drawCoordinateMask(const osg::Vec3f& vOrigin, float vLength, osg::ref_ptr<osg::Geode>& vMaskNode)
{
	osg::ref_ptr<osg::Geometry> MakGeom = new osg::Geometry();
	osg::ref_ptr<osg::Vec3Array> MaskVert = new osg::Vec3Array();

	for (unsigned int i=1; i<=10; i++)
	{
		float Offfset = vLength / 10.0 * i;
		MaskVert->push_back(osg::Vec3(vOrigin.x()+Offfset, vOrigin.y(), vOrigin.z()));
		MaskVert->push_back(osg::Vec3(vOrigin.x(), vOrigin.y()+Offfset, vOrigin.z()));
		MaskVert->push_back(osg::Vec3(vOrigin.x(), vOrigin.y(), vOrigin.z()+Offfset));
	}
	osg::ref_ptr<osg::Vec4Array> ColorArray = new osg::Vec4Array;
	ColorArray->push_back(osg::Vec4(1.0, 1.0, 1.0, 1.0));

	MakGeom->setVertexArray(MaskVert.get());
	MakGeom->setColorArray(ColorArray);
	MakGeom->setColorBinding(osg::Geometry::BIND_OVERALL);

	MakGeom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::POINTS, 0, 30));
	vMaskNode->addDrawable(MakGeom.get());

	osg::ref_ptr<osg::Point> PointSize = new osg::Point(5.0);
	osg::ref_ptr<osg::StateSet> PointStateSet = vMaskNode->getOrCreateStateSet();
	PointStateSet->setAttribute(PointSize);
}
开发者ID:KevinGuo0211,项目名称:OSG,代码行数:28,代码来源:PickNode.cpp

示例5: setBlending

void myModel::setBlending()
{
    _blendFunc = new osg::BlendFunc;
    _stateset = _model->getOrCreateStateSet();
    _blendFunc->setFunction(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    _stateset->setAttributeAndModes( _blendFunc );
}
开发者ID:wow2006,项目名称:OSG_Book,代码行数:7,代码来源:myProject03.cpp

示例6: __drawCoordinateLine

//***********************************************************
//FUNCTION:
void CPickNode::__drawCoordinateLine(const osg::Vec3f& vOrigin, float vLength, osg::ref_ptr<osg::Geode>& vLineNode)
{
	osg::ref_ptr<osg::Geometry> CoordGeometry = new osg::Geometry();
	osg::ref_ptr<osg::Vec3Array> CoordVertex = new osg::Vec3Array();

	CoordVertex->push_back(vOrigin);
	CoordVertex->push_back(osg::Vec3(vOrigin.x()+vLength, vOrigin.y(), vOrigin.z()));
	CoordVertex->push_back(vOrigin);
	CoordVertex->push_back(osg::Vec3(vOrigin.x(), vOrigin.y()+vLength, vOrigin.z()));
	CoordVertex->push_back(vOrigin);
	CoordVertex->push_back(osg::Vec3(vOrigin.x(), vOrigin.y(), vOrigin.z()+vLength));
	CoordGeometry->setVertexArray(CoordVertex.get());
	CoordGeometry->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINES, 0, 6));

	osg::ref_ptr<osg::Vec4Array> VertColor = new osg::Vec4Array();
	VertColor->push_back(osg::Vec4(1.0, 0.0, 0.0, 1.0));
	VertColor->push_back(osg::Vec4(1.0, 0.0, 0.0, 1.0));
	VertColor->push_back(osg::Vec4(0.0, 1.0, 0.0, 1.0));
	VertColor->push_back(osg::Vec4(0.0, 1.0, 0.0, 1.0));
	VertColor->push_back(osg::Vec4(0.0, 0.0, 1.0, 1.0));
	VertColor->push_back(osg::Vec4(0.0, 0.0, 1.0, 1.0));
	CoordGeometry->setColorArray(VertColor.get());
	CoordGeometry->setColorBinding(osg::Geometry::BIND_PER_VERTEX);

	osg::ref_ptr<osg::LineWidth> LineSize = new osg::LineWidth();
	LineSize->setWidth(5);
	vLineNode->getOrCreateStateSet()->setAttributeAndModes(LineSize.get(), osg::StateAttribute::ON);
	vLineNode->addDrawable(CoordGeometry.get());
}
开发者ID:KevinGuo0211,项目名称:OSG,代码行数:31,代码来源:PickNode.cpp

示例7: onLightModelChanged

void Scene::onLightModelChanged()
{
    auto program = _twoSided ? _twoSidedProgram : _oneSidedProgram;

    auto stateSet = _pgeode->getOrCreateStateSet();
    stateSet->setAttributeAndModes(program, osg::StateAttribute::ON);
}
开发者ID:kloffy,项目名称:osgKaleido,代码行数:7,代码来源:osgkaleidoviewer.cpp

示例8:

osg::ref_ptr<osg::Geode> Sokoban::NodeFactory::setTexture(osg::ref_ptr<osg::Geode> geode, Sokoban::Type type, std::string& texturePath) {
	// create a simple material
	osg::Material *material = new osg::Material();
	if (isAButton(type))
		material->setEmission(osg::Material::FRONT, BUTTON_EMISSION);
	else
		material->setEmission(osg::Material::FRONT, OBJECT_EMISSION);
	// create a texture
	// load image for texture
	osg::ref_ptr<osg::Image> image = osgDB::readImageFile(texturePath);
	if (!image) {
		std::cerr << "Couldn't load texture : " << texturePath <<std::endl;
		return NULL;
	}
	//Create the texture putting the correct option and set the image
	osg::ref_ptr<osg::Texture2D> texture = new osg::Texture2D;
	texture->setDataVariance(osg::Object::DYNAMIC);
	texture->setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR_MIPMAP_LINEAR);
	texture->setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR);
	texture->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP);
	texture->setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP);
	texture->setImage(image);

	// assign the material and texture to the Geode
	osg::ref_ptr<osg::StateSet> stateSet = geode->getOrCreateStateSet();
	stateSet->setAttribute(material);
	stateSet->setMode(GL_LIGHTING,osg::StateAttribute::ON);
	stateSet->setTextureAttributeAndModes(0, texture, osg::StateAttribute::ON);

	return geode;
}
开发者ID:dburihabwa,项目名称:SokobanOSG,代码行数:31,代码来源:NodeFactory.cpp

示例9:

void CSVRender::Object::setupCommonMarkerState(osg::ref_ptr<osg::Geometry> geometry)
{
    osg::ref_ptr<osg::StateSet> state = geometry->getOrCreateStateSet();
    state->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
    state->setMode(GL_BLEND, osg::StateAttribute::ON);

    state->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
}
开发者ID:Fynjyfun,项目名称:openmw,代码行数:8,代码来源:object.cpp

示例10: setMaterial

void myModel::setMaterial()
{
    _nodess = _model->getOrCreateStateSet();
    _nodeMaterial = new osg::Material;
    _nodeMaterial->setDiffuse( osg::Material::FRONT, osg::Vec4(0.5f,0.5f,0.5f,1.0f));
    _nodeMaterial->setAmbient( osg::Material::FRONT, osg::Vec4(2.0f,0.0f,0.0f,1.0f) );
    _nodeMaterial->setTransparency(osg::Material::FRONT , 0.25f);
    _nodess->setAttribute( _nodeMaterial.get() );
}
开发者ID:wow2006,项目名称:OSG_Book,代码行数:9,代码来源:myProject03.cpp

示例11: createVertexNode

void Scene::createVertexNode()
{
    _vgeode = new osg::Geode;
    _vgeode->setDataVariance(osg::Object::DYNAMIC);

    osg::Vec3f lightDir(1.0f, 1.0f, 1.0f);
    lightDir.normalize();

    auto offsets = new osg::Uniform(osg::Uniform::FLOAT_VEC3, "offsets", Scene::VertexInstances);
    offsets->setDataVariance(osg::Object::DYNAMIC);

    auto stateSet = _vgeode->getOrCreateStateSet();
    stateSet->setAttributeAndModes(_instancedProgram, osg::StateAttribute::ON);
    stateSet->addUniform(new osg::Uniform("ecLightDirection", lightDir));
    stateSet->addUniform(new osg::Uniform("lightColor", osg::Vec3(1.0f, 1.0f, 1.0f)));
    stateSet->addUniform(offsets);

    osg::Vec3 scale(1.0f, 1.0f, 1.0f);
    osg::Vec4 color(0.25f, 0.25f, 0.25f, 1.0f);

    auto vertexMatrix = osg::Matrixf::scale(scale * 0.125f * 0.25f);
    auto normalMatrix = inverseTranspose(vertexMatrix);

    _vgeometry = new osgKaleido::PolyhedronGeometry("#27");
    _vgeometry->setUseDisplayList(false);
    _vgeometry->setUseVertexBufferObjects(true);

    _vgeometry->update(nullptr); // Force geometry generation

    auto vertices = dynamic_cast<osg::Vec3Array*>(_vgeometry->getVertexArray());
    if (vertices != nullptr) {
        transform(*vertices, vertexMatrix);
    }

    auto normals = dynamic_cast<osg::Vec3Array*>(_vgeometry->getNormalArray());
    if (normals != nullptr) {
        transform(*normals, normalMatrix);
    }

    auto colors = dynamic_cast<osg::Vec4Array*>(_vgeometry->getColorArray());
    if (colors != nullptr) {
        fill(*colors, color);
    }

    makeInstanced(_vgeometry, Scene::VertexInstances);

    auto size = 1.0f;
    osg::BoundingBox bb(-size, -size, -size, +size, +size, +size);
    _vgeometry->setInitialBound(bb);

    _vgeode->addDrawable(_vgeometry);

    addChild(_vgeode);
}
开发者ID:kloffy,项目名称:osgKaleido,代码行数:54,代码来源:osgkaleidoviewer.cpp

示例12: myPostSyncPreDrawFun

void myPostSyncPreDrawFun()
{
	gEngine->setWireframe(wireframe.getVal());
	gEngine->setDisplayInfoVisibility(info.getVal());
	gEngine->setStatsGraphVisibility(stats.getVal());

	if( takeScreenshot.getVal() )
	{
		gEngine->takeScreenshot();
		takeScreenshot.setVal(false);
	}

	light.getVal() ? mRootNode->getOrCreateStateSet()->setMode( GL_LIGHTING, osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE) :
		mRootNode->getOrCreateStateSet()->setMode( GL_LIGHTING, osg::StateAttribute::OFF | osg::StateAttribute::OVERRIDE);

	mSceneTrans->setMatrix(osg::Matrix::rotate( glm::radians(curr_time.getVal() * 8.0), 0.0, 1.0, 0.0));
	mSceneTrans->postMult(osg::Matrix::translate(0.0, -0.1, dist.getVal()));

	//transform to scene transformation from configuration file
	mSceneTrans->postMult( osg::Matrix( glm::value_ptr( gEngine->getModelMatrix() ) ));

	//update the frame stamp in the viewer to sync all
	//time based events in osg
	mFrameStamp->setFrameNumber( gEngine->getCurrentFrameNumber() );
	mFrameStamp->setReferenceTime( curr_time.getVal() );
	mFrameStamp->setSimulationTime( curr_time.getVal() );
	mViewer->setFrameStamp( mFrameStamp.get() );
	mViewer->advance( curr_time.getVal() ); //update

	//traverse if there are any tasks to do
	if (!mViewer->done())
	{
		mViewer->eventTraversal();
		//update travelsal needed for pagelod object like terrain data etc.
		mViewer->updateTraversal();
	}
}
开发者ID:Risca,项目名称:sgct,代码行数:37,代码来源:main.cpp

示例13: AddHudOverlay

bool ossimPlanetViewer::AddHudOverlay(osg::ref_ptr<osg::Node> hudNode)
{
   bool result =  false;
   if(thePlanet.valid())
   {
      result = true;
      
      hudNode->getOrCreateStateSet()->setRenderBinDetails(11,"RenderBin");
      theHudOverlayList.push_back(hudNode.get());
      
      thePlanet->addChild(hudNode.get());
   }
   
   return result;
}
开发者ID:star-labs,项目名称:star_ossim,代码行数:15,代码来源:ossimPlanetViewer.cpp

示例14: createPolyhedronNode

void Scene::createPolyhedronNode()
{
    _pgeode = new osg::Geode;
    _pgeode->setDataVariance(osg::Object::DYNAMIC);

    osg::Vec3f lightDir(0.0f, 0.0f, 1.0f);
    lightDir.normalize();

    auto stateSet = _pgeode->getOrCreateStateSet();
    stateSet->setAttributeAndModes(_twoSidedProgram, osg::StateAttribute::ON);
    stateSet->addUniform(new osg::Uniform("ecLightDirection", lightDir));
    stateSet->addUniform(new osg::Uniform("lightColor", osg::Vec3(1.0f, 1.0f, 1.0f)));

    _pgeometry = new osgKaleido::PolyhedronGeometry("#27");
    _pgeometry->setUseDisplayList(false);
    _pgeometry->setUseVertexBufferObjects(true);

    _pgeode->addDrawable(_pgeometry);

    addChild(_pgeode);
}
开发者ID:kloffy,项目名称:osgKaleido,代码行数:21,代码来源:osgkaleidoviewer.cpp

示例15: SetupAlfaFunc

void BranchXML::SetupAlfaFunc( osg::ref_ptr< osg::Geode > geode , int iLOD )
{
	//настроить альфа канал

	//получить ссылку на данные ствола
	dataBranch &_data = xmlRoot::Instance().GetDataBranch();

	if ( _data.m_vLOD[ iLOD ].m_fAlphaTestValue > 0.0f)
	{
		//настройка атрибутов состояния LOD ствола
		osg::StateSet* state = geode->getOrCreateStateSet();

		//помечаем объект как имеющий прозрачность
		state->setRenderingHint( osg::StateSet::TRANSPARENT_BIN );

		// Turn on alpha testing
		osg::AlphaFunc* af = new osg::AlphaFunc(
			osg::AlphaFunc::GREATER, _data.m_vLOD[ iLOD ].m_fAlphaTestValue );
		state->setAttributeAndModes( af );
	}
}
开发者ID:wangfeilong321,项目名称:osgtraining,代码行数:21,代码来源:BranchXML.cpp


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