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


C++ Geode::addDrawable方法代码示例

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


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

示例1: fontName

AppState::AppState(osgViewer::Viewer* viewer_)
    : displayScene(true), invertRange(true), currentConfig(0),
      viewer(viewer_), zNear(0.03125)
{
    sw = new Switch;
    string fontName("fonts/arial.ttf");
    // Text description of current config
    configText = new osgText::Text;
    configText->setDataVariance(Object::DYNAMIC);
    configText->setFont(fontName);
    configText->setPosition(Vec3(50.0f, 50.0f, 0.0f));
    configText->setColor(Vec4(1.0, 1.0, 1.0, 1.0));
    Geode* textGeode = new Geode;
    textGeode->addDrawable(configText.get());
    // Text for the near plane distance
    zNearText = new osgText::Text;
    zNearText->setDataVariance(Object::DYNAMIC);
    zNearText->setFont(fontName);
    zNearText->setPosition(Vec3(1230.0f, 50.0f, 0.0f));
    zNearText->setColor(Vec4(1.0, 1.0, 1.0, 1.0));
    zNearText->setAlignment(osgText::Text::RIGHT_BASE_LINE);
    textGeode->addDrawable(zNearText.get());
    // Projection that lets the text be placed in pixels.
    textProjection = new Projection;
    textProjection->setMatrix(Matrix::ortho2D(0,1280,0,1024));
    textProjection->addChild(textGeode);
    // "texture not available" text displayed when the user trys to
    // display the depth texture while multisampling.
    osgText::Text* noCanDo = new osgText::Text;
    noCanDo->setFont(fontName);
    noCanDo->setPosition(Vec3(512.0f, 384.0f, 0.0f));
    noCanDo->setColor(Vec4(1.0, 0.0, 0.0, 1.0));
    noCanDo->setText("not available");
    textNotAvailable = new Geode;
    textNotAvailable->addDrawable(noCanDo);
    textProjection->addChild(textNotAvailable.get());
    // Is the depth test inverted?
    osgText::Text* inverted = new osgText::Text;
    inverted->setFont(fontName);
    inverted->setPosition(Vec3(512.0f, 50.0f, 0.0f));
    inverted->setColor(Vec4(1.0, 1.0, 1.0, 1.0));
    inverted->setText("inverted depth test");
    textInverted = new Geode;
    textInverted->addDrawable(inverted);
    textInverted->setNodeMask(~0u);
    textProjection->addChild(textInverted.get());
    textProjection->getOrCreateStateSet()->setRenderBinDetails(11, "RenderBin");
}
开发者ID:AndreyIstomin,项目名称:osg,代码行数:48,代码来源:osgfpdepth.cpp

示例2:

/***************************************************************
* Function: createText()
***************************************************************/
Geode *CAVEGroupReferenceAxis::createText3D(osgText::Text3D **text)
{
    Geode *textGeode = new Geode;
    *text = new osgText::Text3D;
    textGeode->addDrawable(*text);

    (*text)->setFont(CAVEGeode::getDataDir() + "Fonts/TN.ttf");
    (*text)->setCharacterSize(gCharSize, 0.7);
    (*text)->setCharacterDepth(gCharDepth);
    (*text)->setPosition(Vec3(0, 0, 0));
    (*text)->setAlignment(osgText::Text3D::CENTER_BOTTOM);
    (*text)->setDrawMode(osgText::Text3D::TEXT);
    (*text)->setAxisAlignment(osgText::Text3D::XZ_PLANE);
    (*text)->setRenderMode(osgText::Text3D::PER_GLYPH);
    (*text)->setText("");

    Material *material = new Material;
    material->setDiffuse(Material::FRONT_AND_BACK, Vec4(0, 1, 0, 1));
    material->setAmbient(Material::FRONT_AND_BACK, Vec4(0, 1, 0, 1));
    material->setAlpha(Material::FRONT_AND_BACK, 1.0f);

    StateSet *stateset = textGeode->getOrCreateStateSet();
    stateset->setAttributeAndModes(material, StateAttribute::OVERRIDE | StateAttribute::ON);
    stateset->setMode(GL_BLEND, StateAttribute::OVERRIDE | StateAttribute::ON );
    stateset->setRenderingHint(StateSet::TRANSPARENT_BIN);

    return textGeode;
}
开发者ID:aprudhomme,项目名称:calvr_plugins,代码行数:31,代码来源:CAVEGroupReference.cpp

示例3: createTextureQuad

Geode* createTextureQuad(Texture2D *texture)
{
    Vec3Array *vertices = new Vec3Array;
    vertices->push_back(Vec3(-1.0, -1.0, 0.0));
    vertices->push_back(Vec3(1.0, -1.0, 0.0));
    vertices->push_back(Vec3(1.0, 1.0, 0.0));
    vertices->push_back(Vec3(-1.0, 1.0, 0.0));

    Vec2Array *texcoord = new Vec2Array;
    texcoord->push_back(Vec2(0.0, 0.0));
    texcoord->push_back(Vec2(1.0, 0.0));
    texcoord->push_back(Vec2(1.0, 1.0));
    texcoord->push_back(Vec2(0.0, 1.0));

    Geometry *geom = new Geometry;
    geom->setVertexArray(vertices);
    geom->setTexCoordArray(0, texcoord);
    geom->addPrimitiveSet(new DrawArrays(GL_QUADS, 0, 4));

    Geode *geode = new Geode;
    geode->addDrawable(geom);
    geode->getOrCreateStateSet()->setTextureAttributeAndModes(0, texture, StateAttribute::ON);

    return geode;
}
开发者ID:AndreyIstomin,项目名称:osg,代码行数:25,代码来源:osgfpdepth.cpp

示例4: buildDrawable

void _dwobj::buildDrawable(Group *grp, const osgDB::ReaderWriter::Options *options)
{  // current DWobject complete; make a drawable, and add it to a osg::Group
    if (nfaces>0) {
        if (themat->isType(dwmaterial::PointLight) || themat->isType(dwmaterial::SpotLight)) {
            Vec4 pos;
            pos.set(0.0f,0.0f,0.0f,0.0f);
            for (int i=0; i<nverts; i++) {
                pos[0]+=verts[i].x();
                pos[1]+=verts[i].y();
                pos[2]+=verts[i].z();
            }
            pos/=nverts;
            pos[3]=1.0f;
            LightSource *ls=themat->makeLight(pos);
            grp->addChild(ls);
        } else {
            Geode *geode = new Geode;
            int nfnvf=0; // number of vertices for faces plus holes
            int i; // a general counter
            for (i=0; i<nfaces; i++) { // for each face
                faces[i].setnorm(verts); // set its normal and any hole normals
                nfnvf+=faces[i].getallverts(); // get total vertices in object, defines dimensions of NEW arrays
            }


            GLUtesselator* ts=gluNewTess();
            gluTessCallback(ts, GLU_TESS_BEGIN, (GLU_TESS_CALLBACK) myFaceBegin);
            gluTessCallback(ts, GLU_TESS_VERTEX, (GLU_TESS_CALLBACK) myVertex);
            gluTessCallback(ts, GLU_TESS_END, (GLU_TESS_CALLBACK) myFaceEnd);
            gluTessCallback(ts, GLU_TESS_ERROR, (GLU_TESS_CALLBACK) error);
            gluTessCallback(ts, GLU_TESS_COMBINE_DATA, (GLU_TESS_CALLBACK) combineCallback);
            //  for (int nvf=0; nvf<6; nvf++) { // for each length of face
            // for Geometry we dont need to collect prim types individually
            //     prd.setmode(nvf , nfnvf); // filter out only this type of tessellated face
            prd=new prims;
            prd->settmat(tmat.get());
            osg::Geometry *gset = new osg::Geometry;
            prd->setGeometry(gset);
            StateSet *dstate=themat->make(options);
            gset->setStateSet( dstate );
            grp->addChild( geode ); // add to the world outside
            geode->addDrawable(gset);

            // each face adds a primitive to the geometry, after it is tessellated
            for (i=0; i<nfaces; i++) { // for each face, collect up
                prd->tessellate(faces[i],verts, themat, ts, this);
            }
            for (i=0; i<nopens; i++) { // for each hole, join up front & back with Quads
                if (fc1 && fc2) {
                    faces[fc1[i]].link(openings[i*2], &faces[fc2[i]],openings[i*2+1],verts, themat);
                }
            } // for each opening
            prd->buildGeometry();
        gluDeleteTess(ts);
        delete prd;
        }
    } // nfaces>0
    verts.clear();
}
开发者ID:Kurdakov,项目名称:emscripten_OSG,代码行数:59,代码来源:ReaderWriterDW.cpp

示例5: createRectangleWithTexture

Geode* ChessUtils::createRectangleWithTexture(Vec3 centerPosition, Image* image, int width, int height, Vec4 color) {
	int halfWidth = width / 2;
	int halfHeight = height / 2;

	Vec3Array* vertices = new Vec3Array();	
	vertices->push_back(Vec3(centerPosition.x() - halfWidth, centerPosition.y() - halfHeight, centerPosition.z()));
	vertices->push_back(Vec3(centerPosition.x() + halfWidth, centerPosition.y() - halfHeight, centerPosition.z()));
	vertices->push_back(Vec3(centerPosition.x() + halfWidth, centerPosition.y() + halfHeight, centerPosition.z()));
	vertices->push_back(Vec3(centerPosition.x() - halfWidth, centerPosition.y() + halfHeight, centerPosition.z()));

	Vec3Array* normals = new Vec3Array();
	normals->push_back(Vec3(0.0f, 0.0f, 1.0f));

	Vec2Array* texcoords = new Vec2Array();
	texcoords->push_back(Vec2(0.0f, 0.0f));
	texcoords->push_back(Vec2(1.0f, 0.0f));
	texcoords->push_back(Vec2(1.0f, 1.0f));
	texcoords->push_back(Vec2(0.0f, 1.0f));

	Vec4Array* colors = new Vec4Array();
	colors->push_back(color);

	Geometry* quad = new Geometry();
	quad->setVertexArray(vertices);
	quad->setNormalArray(normals);
	quad->setNormalBinding(osg::Geometry::BIND_OVERALL);	
	quad->setColorArray(colors);
	quad->setColorBinding(osg::Geometry::BIND_OVERALL);
	quad->setTexCoordArray(0, texcoords);
	quad->addPrimitiveSet(new osg::DrawArrays(GL_QUADS, 0, 4));

	Texture2D* texture = new Texture2D();
	if (image != NULL) {
		texture->setImage(image);
	}			

	Geode* geode = new Geode();
	geode->addDrawable(quad);

	osg::BlendFunc* blendFunc = new osg::BlendFunc();
	blendFunc->setFunction(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

	osg::TexEnv* blendTexEnv = new osg::TexEnv();
	blendTexEnv->setMode(osg::TexEnv::BLEND);

	osg::StateSet* geodeStateset = geode->getOrCreateStateSet();
	geodeStateset->setAttributeAndModes(blendFunc);
	geodeStateset->setTextureAttribute(0, blendTexEnv);
	geodeStateset->setTextureAttributeAndModes(0, texture);
	geodeStateset->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
	
	return geode;
}
开发者ID:carlosmccosta,项目名称:AR-Chess,代码行数:53,代码来源:ChessUtils.cpp

示例6: boxCenter

Geode *Marker::createBox(Vec4 &color)
{
    Geode *geode = new Geode();

    TessellationHints *hints = new TessellationHints();
    hints->setDetailRatio(0.3f);

    Vec3 boxCenter(0.0f, 0.0f, 0.0f);
    _boxShape = new Box(boxCenter, 1.0f);
    _shapeDrawable = new ShapeDrawable(_boxShape);
    _shapeDrawable->setTessellationHints(hints);
    _shapeDrawable->setColor(color);
    geode->addDrawable(_shapeDrawable);
    _shapeDrawable->setUseDisplayList(false); // allow changes to color and shape
    return geode;
}
开发者ID:nixz,项目名称:covise,代码行数:16,代码来源:Marker.cpp

示例7: sphereCenter

Geode *Marker::createSphere(Vec4 &color)
{
    Geode *geode = new Geode();

    // setDetailRatio is a factor to multiply the default values for
    // numSegments (40) and numRows (10).
    // They won't go below the minimum values of MIN_NUM_SEGMENTS = 5, MIN_NUM_ROWS = 3
    TessellationHints *hints = new TessellationHints();
    hints->setDetailRatio(0.3f);

    Vec3 sphereCenter(0.0f, 0.0f, 0.0f);
    _sphereShape = new Sphere(sphereCenter, 1.0f);
    _shapeDrawable = new ShapeDrawable(_sphereShape);
    _shapeDrawable->setTessellationHints(hints);
    _shapeDrawable->setColor(color);
    geode->addDrawable(_shapeDrawable);
    _shapeDrawable->setUseDisplayList(false); // allow changes to color and shape
    return geode;
}
开发者ID:nixz,项目名称:covise,代码行数:19,代码来源:Marker.cpp

示例8: addDrawable

void World::addDrawable(Drawable::Drawable *drawable,
			 			Transform *transform, std::string name)
{
	// adding all to top-level group for now
	Geode *geo = new Geode;
	geo->addDrawable(drawable);
	if(transform) {
		transform->addChild(geo);
		_root->addChild(transform);
	} else {
		_root->addChild(geo);
	}

	if(!name.empty()) {
		_names[name] = drawable;
	}

	//notifyViews();
}
开发者ID:asandroq,项目名称:orbis,代码行数:19,代码来源:world.cpp

示例9: Geode

PositionAttitudeTransform *VideoGeode::createVideoSphere(float size, bool texRepeat)
{
	Geode *sphere = new Geode();
	sphere->addDrawable(new ShapeDrawable(new Sphere(Vec3(0, 0, 4), size)));
	
	// assign the material to the sphere
	StateSet *sphereStateSet = sphere->getOrCreateStateSet();
	sphereStateSet->ref();
	sphereStateSet->setAttribute(_material);
	
   try {
      sphereStateSet->setTextureAttributeAndModes(0, createVideoTexture(texRepeat), StateAttribute::ON);
   } catch (char *e) {
      throw e;
   }
	
	PositionAttitudeTransform *sphereTransform = new PositionAttitudeTransform();
	sphereTransform->addChild(sphere);
	return sphereTransform;
}
开发者ID:jim-normand,项目名称:NAM,代码行数:20,代码来源:videogeometry.cpp

示例10: Geode

Geode *Marker::createCone(Vec4 &color)
{
    Geode *geode = new Geode();

    // setDetailRatio is a factor to multiply the default values for
    // numSegments (40) and numRows (10).
    // They won't go below the minimum values of MIN_NUM_SEGMENTS = 5, MIN_NUM_ROWS = 3
    TessellationHints *hints = new TessellationHints();
    hints->setDetailRatio(0.3f);

    // Create cone geometry:
    _coneShape = new Cone(Vec3(0, 0, 0), 0.1f, 0.5f); // center, radius, height
    _shapeDrawable = new ShapeDrawable(_coneShape);
    _shapeDrawable->setTessellationHints(hints);
    _shapeDrawable->setColor(color);
    _shapeDrawable->setUseDisplayList(false); // allow changes to color and shape

    geode->addDrawable(_shapeDrawable);
    return geode;
}
开发者ID:nixz,项目名称:covise,代码行数:20,代码来源:Marker.cpp

示例11: CreateBomb

Group* CreateBomb()
{
	MatrixTransform *matrix_trans = new MatrixTransform();
	Matrix *matrix = new Matrix();
	Geode *node = new Geode();
	float radius = 10;

	//创建精细度对象,精细度越高,细分就越多
	osg::TessellationHints* hints = new osg::TessellationHints;
	//设置精细度为0.5f
	hints->setDetailRatio(0.5f);

	//添加一个球体,第一个参数是预定义几何体对象,第二个是精细度,默认为0
	node->addDrawable(new osg::ShapeDrawable(new osg::Sphere(osg::Vec3(0, 100, 300), radius),hints));

	matrix_trans->addChild(node);
	matrix_trans->setUpdateCallback(new BombCallback(Vec3(0,100,300)));
	//matrix_trans->setDataVariance(osg::Object::DYNAMIC);
	return matrix_trans;
}
开发者ID:t3cmax,项目名称:3D1,代码行数:20,代码来源:CreateBomb.cpp

示例12: Widget

TFColorWidget::TFColorWidget(Interaction *interaction, Measure *b, int size)
    : Widget()
    , Events()
{
    _interaction = interaction;

    Geode *geode = new Geode();

    _geom = new Geometry();
    _geom->setUseDisplayList(false);

    _vertices = new Vec3Array();
    _vertices->push_back(Vec3(0, 0, 0));
    _vertices->push_back(Vec3(0, 0, .2));
    _vector = (*_vertices)[1] - (*_vertices)[0];
    _vector.normalize();
    _geom->setVertexArray(_vertices);

    DrawElementsUInt *line = new DrawElementsUInt(osg::PrimitiveSet::LINES, 0);
    line->push_back(0);
    line->push_back(1);
    _geom->addPrimitiveSet(line);

    _colors = new Vec4Array(1);
    (*_colors)[0].set(0.0, 0.0, 0.0, 1.0);
    _geom->setColorArray(_colors);
    _geom->setColorBinding(osg::Geometry::BIND_OVERALL);

    geode->addDrawable(_geom);

    _node->addChild(geode);

    LineWidth *width = new LineWidth();
    width->setWidth(size);
    StateSet *state = _geom->getOrCreateStateSet();
    state->setAttribute(width, osg::StateAttribute::ON);
    state->setMode(GL_LIGHTING, StateAttribute::OFF);

    _interaction->addListener(this, this);
}
开发者ID:nixz,项目名称:covise,代码行数:40,代码来源:TFColorWidget.cpp

示例13: DrawArrayLengths

Geode *ClipPlanePlugin::loadPlane()
{

    // *5---*6---*7
    // |    |    |
    // *3--------*4
    // |    |    |
    // *0---*1---*2

    float w = cover->getSceneSize() * 0.1; // width of plane

    Vec3Array *lineCoords = new Vec3Array(12);
    (*lineCoords)[0].set(-w, -0.01, -w);
    (*lineCoords)[1].set(w, -0.01, -w);
    (*lineCoords)[2].set(-w, -0.01, 0.0f);
    (*lineCoords)[3].set(w, -0.01, 0.0f);
    (*lineCoords)[4].set(-w, -0.01, w);
    (*lineCoords)[5].set(w, -0.01, w);
    (*lineCoords)[6].set(-w, -0.01, -w);
    (*lineCoords)[7].set(-w, -0.01, w);
    (*lineCoords)[8].set(0.0f, -0.01, -w);
    (*lineCoords)[9].set(0.0f, -0.01, w);
    (*lineCoords)[10].set(w, -0.01, -w);
    (*lineCoords)[11].set(w, -0.01, w);

    DrawArrayLengths *primitives = new DrawArrayLengths(PrimitiveSet::LINE_STRIP);
    for (int i = 0; i < 6; i++)
    {
        primitives->push_back(2);
    }

    Vec3Array *lineColors = new Vec3Array(12);
    for (int i = 0; i < 12; i++)
    {
        (*lineColors)[i].set(Vec3(1.0f, 1.0f, 1.0f));
    }

    Geometry *geoset = new Geometry();
    geoset->setVertexArray(lineCoords);
    geoset->addPrimitiveSet(primitives);
    geoset->setColorArray(lineColors);

    Material *mtl = new Material;
    mtl->setColorMode(Material::AMBIENT_AND_DIFFUSE);
    mtl->setAmbient(Material::FRONT_AND_BACK, Vec4(0.2f, 0.2f, 0.2f, 1.0f));
    mtl->setDiffuse(Material::FRONT_AND_BACK, Vec4(0.9f, 0.9f, 0.9f, 1.0f));
    mtl->setSpecular(Material::FRONT_AND_BACK, Vec4(0.9f, 0.9f, 0.9f, 1.0f));
    mtl->setEmission(Material::FRONT_AND_BACK, Vec4(0.0f, 0.0f, 0.0f, 1.0f));
    mtl->setShininess(Material::FRONT_AND_BACK, 16.0f);

    Geode *geode = new Geode;
    geode->setName("ClipPlane");
    geode->addDrawable(geoset);

    StateSet *geostate = geode->getOrCreateStateSet();
    geostate->setAttributeAndModes(mtl, StateAttribute::ON);
    geostate->setMode(GL_LIGHTING, StateAttribute::OFF);
    LineWidth *lineWidth = new LineWidth(3.0);
    geostate->setAttributeAndModes(lineWidth, StateAttribute::ON);
    geode->setStateSet(geostate);

    return geode;
}
开发者ID:dwickeroth,项目名称:covise,代码行数:63,代码来源:ClipPlane.cpp

示例14: createFloorplanGeometry

/***************************************************************
* Function: createFloorplanGeometry()
***************************************************************/
void VirtualScenicHandler::createFloorplanGeometry(const int numPages, 
    CAVEAnimationModeler::ANIMPageEntry **pageEntryArray)
{
    if (numPages <= 0)
    {
        return;
    }

    for (int i = 0; i < numPages; i++)
    {
        // create floorplan geometry
        float length = pageEntryArray[i]->mLength;
        float width = pageEntryArray[i]->mWidth;
        float altitude = pageEntryArray[i]->mAlti;

        Geode *floorplanGeode = new Geode;
        Geometry *floorplanGeometry = new Geometry;

        Vec3Array* vertices = new Vec3Array;
        Vec3Array* normals = new Vec3Array;
        Vec2Array* texcoords = new Vec2Array(4);

        vertices->push_back(Vec3(-length / 2,  width / 2, altitude));	(*texcoords)[0].set(0, 1);
        vertices->push_back(Vec3(-length / 2, -width / 2, altitude));	(*texcoords)[1].set(0, 0);
        vertices->push_back(Vec3( length / 2, -width / 2, altitude));	(*texcoords)[2].set(1, 0);
        vertices->push_back(Vec3( length / 2,  width / 2, altitude));	(*texcoords)[3].set(1, 1);

        for (int k = 0; k < 4; k++) 
        { 
            normals->push_back(Vec3(0, 0, 1));
        }

        DrawElementsUInt* rectangle = new DrawElementsUInt(PrimitiveSet::POLYGON, 0);
        rectangle->push_back(0);	rectangle->push_back(1);
        rectangle->push_back(2);	rectangle->push_back(3);

        floorplanGeometry->addPrimitiveSet(rectangle);
        floorplanGeometry->setVertexArray(vertices);
        floorplanGeometry->setNormalArray(normals);
        floorplanGeometry->setTexCoordArray(0, texcoords);
        floorplanGeometry->setNormalBinding(Geometry::BIND_PER_VERTEX);

        floorplanGeode->addDrawable(floorplanGeometry);
        mFloorplanSwitch->addChild(floorplanGeode);

        /* load floorplan images */
        Material *transmaterial = new Material;
        transmaterial->setDiffuse(Material::FRONT_AND_BACK, Vec4(1, 1, 1, 1));
        transmaterial->setAlpha(Material::FRONT_AND_BACK, 1.0f);

        Image* imgFloorplan = osgDB::readImageFile(pageEntryArray[i]->mTexFilename);

        Texture2D* texFloorplan = new Texture2D(imgFloorplan); 

        StateSet *floorplanStateSet = floorplanGeode->getOrCreateStateSet();
        floorplanStateSet->setTextureAttributeAndModes(0, texFloorplan, StateAttribute::ON);
        floorplanStateSet->setMode(GL_BLEND, StateAttribute::OVERRIDE | StateAttribute::ON );
        floorplanStateSet->setRenderingHint(StateSet::TRANSPARENT_BIN);
        floorplanStateSet->setAttributeAndModes(transmaterial, StateAttribute::OVERRIDE | StateAttribute::ON);
    }
}
开发者ID:Peachychan,项目名称:calvr_plugins,代码行数:64,代码来源:VirtualScenicHandler.cpp

示例15: sizeof


//.........这里部分代码省略.........
        { 0.0, 0.0, 0.15 },
        { 0.0, 0.0, 0.15 },
        { 0.4, 0.4, 0.7 },
        { 0.2, 0.2, 0.6 },
        { 0.1, 0.1, 0.6 },
        { 0.1, 0.1, 0.6 },
        { 0.1, 0.1, 0.6 },
    };
    float x, y, z;
    float alpha, theta;
    float radius = 20.0f;
    int nlev = sizeof( lev )/sizeof(float);

    Geometry *geom = new Geometry;

    Vec3Array& coords = *(new Vec3Array(19*nlev));
    Vec4Array& colors = *(new Vec4Array(19*nlev));
    Vec2Array& tcoords = *(new Vec2Array(19*nlev));
    
    
    int ci = 0;

    for( i = 0; i < nlev; i++ )
    {
        for( j = 0; j <= 18; j++ )
        {
            alpha = osg::DegreesToRadians(lev[i]);
            theta = osg::DegreesToRadians((float)(j*20));

            x = radius * cosf( alpha ) * cosf( theta );
            y = radius * cosf( alpha ) * -sinf( theta );
            z = radius * sinf( alpha );

            coords[ci][0] = x;
            coords[ci][1] = y;
            coords[ci][2] = z;

            colors[ci][0] = cc[i][0];
            colors[ci][1] = cc[i][1];
            colors[ci][2] = cc[i][2];
            colors[ci][3] = 1.0;

            tcoords[ci][0] = (float)j/18.0;
            tcoords[ci][1] = (float)i/(float)(nlev-1);

            ci++;
        }


    }

    for( i = 0; i < nlev-1; i++ )
    {
        DrawElementsUShort* drawElements = new DrawElementsUShort(PrimitiveSet::TRIANGLE_STRIP);
        drawElements->reserve(38);

        for( j = 0; j <= 18; j++ )
        {
            drawElements->push_back((i+1)*19+j);
            drawElements->push_back((i+0)*19+j);
        }

        geom->addPrimitiveSet(drawElements);
    }
    
    geom->setVertexArray( &coords );
    geom->setTexCoordArray( 0, &tcoords );

    geom->setColorArray( &colors );
    geom->setColorBinding( Geometry::BIND_PER_VERTEX );


    Texture2D *tex = new Texture2D;
    tex->setImage(osgDB::readImageFile("Images/white.rgb"));

    StateSet *dstate = new StateSet;

    dstate->setTextureAttributeAndModes(0, tex, StateAttribute::OFF );
    dstate->setTextureAttribute(0, new TexEnv );
    dstate->setMode( GL_LIGHTING, StateAttribute::OFF );
    dstate->setMode( GL_CULL_FACE, StateAttribute::ON );
    

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

    dstate->setRenderBinDetails(-2,"RenderBin");

    geom->setStateSet( dstate );

    Geode *geode = new Geode;
    geode->addDrawable( geom );

    geode->setName( "Sky" );

    return geode;
}
开发者ID:BodyViz,项目名称:osg,代码行数:101,代码来源:sky.cpp


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