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


C++ Geometry::setColorBinding方法代码示例

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


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

示例1: createDAIGeometry

void createDAIGeometry( osg::Geometry& geom, int nInstances=1 )
{
    const float halfDimX( .5 );
    const float halfDimZ( .5 );

    osg::Vec3Array* v = new osg::Vec3Array;
    v->resize( 4 );
    geom.setVertexArray( v );

    // Geometry for a single quad.
    (*v)[ 0 ] = osg::Vec3( -halfDimX, 0., 0. );
    (*v)[ 1 ] = osg::Vec3( halfDimX, 0., 0. );
    (*v)[ 2 ] = osg::Vec3( halfDimX, 0., halfDimZ*2.0f );
    (*v)[ 3 ] = osg::Vec3( -halfDimX, 0., halfDimZ*2.0f );


	// create color array data (each corner of our triangle will have one color component)
    osg::Vec4Array* pColors = new osg::Vec4Array;
    pColors->push_back( osg::Vec4( 1.0f, 0.0f, 0.0f, 1.0f ) );
    pColors->push_back( osg::Vec4( 0.0f, 1.0f, 0.0f, 1.0f ) );
    pColors->push_back( osg::Vec4( 0.0f, 0.0f, 1.0f, 1.0f ) );
	pColors->push_back( osg::Vec4( 0.0f, 0.0f, 1.0f, 1.0f ) );
    geom.setColorArray( pColors );

	// make sure that our geometry is using one color per vertex
    geom.setColorBinding( osg::Geometry::BIND_PER_VERTEX );

    osg::Vec2Array* pTexCoords = new osg::Vec2Array( 4 );
    (*pTexCoords)[0].set( 0.0f, 0.0f );
    (*pTexCoords)[1].set( 1.0f, 0.0f );
    (*pTexCoords)[2].set( 1.0f, 1.0f );
    (*pTexCoords)[3].set( 0.0f, 1.0f );
    geom.setTexCoordArray( 0, pTexCoords );

    // Use the DrawArraysInstanced PrimitiveSet and tell it to draw 1024 instances.
    geom.addPrimitiveSet( new osg::DrawArrays( GL_QUADS, 0, 4, nInstances ) );
}
开发者ID:Crisium,项目名称:sigmaosg,代码行数:37,代码来源:Grass.cpp

示例2: DrawElementsUInt

	nave(int x,int y, int z, int tamaño)
		{
		pyramidGeode = new osg::Geode();
		pyramidGeometry = new osg::Geometry();
		pyramidGeode->addDrawable(pyramidGeometry);
		
		osg::Vec3Array* pyramidVertices = new osg::Vec3Array;
	
	//0-4
	pyramidVertices->push_back( osg::Vec3(       x,       y,       z) ); // front left
    //1-5
	pyramidVertices->push_back( osg::Vec3(tamaño+x,       y,       z) ); // front right
    //2-6
	pyramidVertices->push_back( osg::Vec3(tamaño+x,tamaño+y,       z) ); // back right
    //3-7
	pyramidVertices->push_back( osg::Vec3(       x,tamaño+y,       z) ); // back left
	//4-0
    pyramidVertices->push_back( osg::Vec3(	     x,		  y,tamaño+z) ); // peak
    //5-1
	pyramidVertices->push_back( osg::Vec3(tamaño+x,       y,tamaño+z) ); // front right
    //6-2
	pyramidVertices->push_back( osg::Vec3(tamaño+x,tamaño+y,tamaño+z) ); // back right
    //7-3
	pyramidVertices->push_back( osg::Vec3(       x,tamaño+y,tamaño+z) ); // back left	
		
	pyramidGeometry->setVertexArray( pyramidVertices );
		
		osg::DrawElementsUInt* pyramidBase =
        new osg::DrawElementsUInt(osg::PrimitiveSet::QUADS, 0);
    pyramidBase->push_back(3);
    pyramidBase->push_back(2);
    pyramidBase->push_back(1);
    pyramidBase->push_back(0);
    pyramidGeometry->addPrimitiveSet(pyramidBase);

	osg::DrawElementsUInt* pyramidTop =
        new osg::DrawElementsUInt(osg::PrimitiveSet::QUADS, 0);
    pyramidTop->push_back(4);
    pyramidTop->push_back(5);
    pyramidTop->push_back(6);
    pyramidTop->push_back(7);
    pyramidGeometry->addPrimitiveSet(pyramidTop);

    //Repeat the same for each of the four sides. Again, vertices are
    //specified in counter-clockwise order.

    osg::DrawElementsUInt* pyramidFaceOne =
        new osg::DrawElementsUInt(osg::PrimitiveSet::QUADS, 0);
    pyramidFaceOne->push_back(0);
    pyramidFaceOne->push_back(1);
	pyramidFaceOne->push_back(5);
    pyramidFaceOne->push_back(4);
	pyramidGeometry->addPrimitiveSet(pyramidFaceOne);

    osg::DrawElementsUInt* pyramidFaceTwo =
        new osg::DrawElementsUInt(osg::PrimitiveSet::QUADS, 0);
    pyramidFaceTwo->push_back(1);
    pyramidFaceTwo->push_back(2);
    pyramidFaceTwo->push_back(6);
	pyramidFaceTwo->push_back(5);
    pyramidGeometry->addPrimitiveSet(pyramidFaceTwo);

    osg::DrawElementsUInt* pyramidFaceThree =
        new osg::DrawElementsUInt(osg::PrimitiveSet::QUADS, 0);
    pyramidFaceThree->push_back(2);
    pyramidFaceThree->push_back(3);
    pyramidFaceThree->push_back(7);
	pyramidFaceThree->push_back(6);
    pyramidGeometry->addPrimitiveSet(pyramidFaceThree);

    osg::DrawElementsUInt* pyramidFaceFour =
        new osg::DrawElementsUInt(osg::PrimitiveSet::QUADS, 0);
    pyramidFaceFour->push_back(3);
    pyramidFaceFour->push_back(0);
    pyramidFaceThree->push_back(4);
	pyramidFaceFour->push_back(7);
    pyramidGeometry->addPrimitiveSet(pyramidFaceFour);

    //Declare and load an array of Vec4 elements to store colors.

    osg::Vec4Array* colors = new osg::Vec4Array;
    colors->push_back(osg::Vec4(0.0f, 0.0f, 0.0f, 1.0f) ); //index 0 red
    colors->push_back(osg::Vec4(0.0f, 0.0f, 0.0f, 1.0f) ); //index 1 green
    colors->push_back(osg::Vec4(0.0f, 0.0f, 0.0f, 1.0f) ); //index 2 blue
    colors->push_back(osg::Vec4(0.0f, 0.0f, 0.0f, 1.0f) ); //index 3 white
    colors->push_back(osg::Vec4(1.0f, 1.0f, 1.0f, 1.0f) ); //index 4 red
	 colors->push_back(osg::Vec4(1.0f, 1.0f, 1.0f, 1.0f) ); //index 4 red
	  colors->push_back(osg::Vec4(1.0f, 1.0f, 1.0f, 1.0f) ); //index 4 red
	   colors->push_back(osg::Vec4(1.0f, 1.0f, 1.0f, 1.0f) ); //index 4 red

    //The next step is to associate the array of colors with the geometry,
    //assign the color indices created above to the geometry and set the
    //binding mode to _PER_VERTEX.

    pyramidGeometry->setColorArray(colors);
    pyramidGeometry->setColorBinding(osg::Geometry::BIND_PER_VERTEX);
	
		};
开发者ID:gayoxo,项目名称:ProyectoIGr,代码行数:98,代码来源:Nave.cpp


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