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


C++ Vec3Array类代码示例

本文整理汇总了C++中Vec3Array的典型用法代码示例。如果您正苦于以下问题:C++ Vec3Array类的具体用法?C++ Vec3Array怎么用?C++ Vec3Array使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

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

示例2: Geometry

/** This creates the wireframe PickBox around the widget.
  Volume vertex names:
  <PRE>
      4____ 7        y
     /___ /|         |
   0|   3| |         |___x
    | 5  | /6       /
    |/___|/        z
    1    2
  </PRE>
*/
Geometry *PickBox::createWireframe(const Vec4 &color)
{
    Geometry *geom = new Geometry();

    updateVertices(geom);

    // Set colors:
    Vec4Array *colors = new Vec4Array();
    colors->push_back(color);
    geom->setColorArray(colors);
    geom->setColorBinding(Geometry::BIND_OVERALL);

    // Set normals:
    Vec3Array *normals = new Vec3Array();
    normals->push_back(Vec3(0.0f, 0.0f, 1.0f));
    geom->setNormalArray(normals);
    geom->setNormalBinding(Geometry::BIND_OVERALL);

    // This time we simply use primitive, and hardwire the number of coords
    // to use since we know up front:
    geom->addPrimitiveSet(new DrawArrays(PrimitiveSet::LINES, 0, 24));

    geom->setUseDisplayList(false); // allow dynamic changes

    return geom;
}
开发者ID:nixz,项目名称:covise,代码行数:37,代码来源:PickBox.cpp

示例3: initBaseGeometry

/***************************************************************
* Function: initBaseGeometry()
***************************************************************/
void CAVEGeodeSnapWireframeCone::initBaseGeometry()
{
    Vec3Array* vertices = new Vec3Array;
    float rad = 1.0f, height = 1.0f, intvl = M_PI * 2 / gMinFanSegments;

    // BaseGeometry contains (gMinFanSegments * 2) vertices
    for (int i = 0; i < gMinFanSegments; i++) 
    {
        vertices->push_back(Vec3(rad * cos(i * intvl), rad * sin(i * intvl), height));
    }
    for (int i = 0; i < gMinFanSegments; i++) 
    {
        vertices->push_back(Vec3(rad * cos(i * intvl), rad * sin(i * intvl), 0));
    }
    mBaseGeometry->setVertexArray(vertices);

    DrawElementsUInt* topEdges = new DrawElementsUInt(PrimitiveSet::LINE_STRIP, 0);
    DrawElementsUInt* bottomEdges = new DrawElementsUInt(PrimitiveSet::LINE_STRIP, 0);
    DrawElementsUInt* sideEdges = new DrawElementsUInt(PrimitiveSet::LINES, 0);
    for (int i = 0; i < gMinFanSegments; i++)
    {
        topEdges->push_back(i);
        bottomEdges->push_back(i + gMinFanSegments);
        sideEdges->push_back(i);
        sideEdges->push_back(i + gMinFanSegments);
    }
    topEdges->push_back(0);
    bottomEdges->push_back(gMinFanSegments);

    mBaseGeometry->addPrimitiveSet(topEdges);
    mBaseGeometry->addPrimitiveSet(bottomEdges);
    mBaseGeometry->addPrimitiveSet(sideEdges);
}
开发者ID:CalVR,项目名称:calvr_plugins,代码行数:36,代码来源:CAVEGeodeSnapWireframe.cpp

示例4: getNumDrawables

bool Object3D::findNearestVertex(Vec3f point, std::pair<unsigned int, Vec3f>& foundVertex)
{
    bool found = false;
    unsigned int nbDrawables = getNumDrawables();
    Vec3Array *vertexArray = NULL;
    double distMin = 100.0;
    double dist;

    for(unsigned int i=0; i<nbDrawables; i++)
    {
        vertexArray = getVertexList(i);
        if(vertexArray)
        {
            std::vector<Vec3>::iterator itr;
            for (itr=vertexArray->begin(); itr != vertexArray->end(); ++itr)
            {
                dist = Util::computeDist(*itr, point);
                if(dist < distMin)
                {
                    distMin = dist;
                    foundVertex = std::make_pair(i, *itr);
                    found = true;
                }
            }
        }
    }

    return found;
}
开发者ID:ConfusedReality,项目名称:pkg_augmented-reality_polAR,代码行数:29,代码来源:Object3D.cpp

示例5: Vec3Array

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: gl

void DragonBustNode::genBezierSubdivide(Vec3Array g, uint depth, Vec3Array& points)
{
    /*
     * Based on code from "Curved Surfaces Using Bézier Patches"
     * http://www.gamasutra.com/view/feature/131755/curved_surfaces_using_bzier_.php?page=6
     * See: Bibliography.
     */
    if (depth == 0)
    {
        points.push_back(g[0]);
        points.push_back(g[2]);

        return;
    }

    Vec3Array gl(3);
    Vec3Array gr(3);

    gl[0] = g[0];
    gl[1] = (g[0] + g[1]) * 0.5f;
    gr[1] = (g[1] + g[2]) * 0.5f;
    gl[2] = gr[0] = (gl[1] + gr[1]) * 0.5f;
    gr[2] = g[2];

    genBezierSubdivide(gl, --depth, points);
    genBezierSubdivide(gr, depth, points);
}
开发者ID:mattmw,项目名称:charsim,代码行数:27,代码来源:DragonBustNode.cpp

示例7: CPPUNIT_ASSERT

void SWWReaderTest::testBedslopeNormalArray()
{
    CPPUNIT_ASSERT( _sww->isValid() );

    osg::ref_ptr<osg::Vec3Array> actual = _sww->getBedslopeNormalArray();
    CPPUNIT_ASSERT( actual );

    // expected number of bedslope normals
    const size_t nvertices = 24;
    CPPUNIT_ASSERT_EQUAL( actual->size(), nvertices );

    // hard-coded values (bedslope is flat plane)
    using osg::Vec3;
    using osg::Vec3Array;
    Vec3Array *expected = new Vec3Array; 
    expected->assign(24, Vec3( 0.301511, -0.301511, 0.904534 ) );

    for (size_t i=0; i<nvertices; i++)
        CPPUNIT_ASSERT_VEC3_EQUAL( actual->at(i), expected->at(i) );
}
开发者ID:stoiver,项目名称:anuga-viewer,代码行数:20,代码来源:swwreadertest.cpp

示例8: setGlows

Hyperspace::Hyperspace()
{
	setGlows(false);
	//start by creating a bunch of "stars"
	int stars = 2500;
	osg::Geode* geode = new Geode();
	Geometry* geom = new Geometry;
	geode->addDrawable(geom);
	Vec4Array* colors = new Vec4Array();
	colors->push_back(Vec4(1, 1, 1, 1));
	geom->setColorArray(colors);
	geom->setColorBinding(Geometry::BIND_OVERALL);
	Vec3Array* verts = new Vec3Array();
	geom->setVertexArray(verts);
	geom->addPrimitiveSet(new DrawArrays(PrimitiveSet::TRIANGLES, 0, stars*3));
	geom->getOrCreateStateSet()->setMode(GL_LIGHTING, false);
	for(int i  = 0; i < stars; i++)
	{
		float radius = Util::random(10, 150);
		float theta = 6.28 * Util::loggedRandom("Hyperspace theta") / RAND_MAX;
		float s = cosf(theta);
		float c = sinf(theta);
		Vec3 localUp(-s, c, 0);
		float width = Util::random(0.1, 0.25) * radius / 25;;
		float length = Util::random(10, 30) * radius / 20;
		float z = 0;
		Vec3 basePos(c*radius, s*radius, z+length*0.5);
		Vec3 zDir(0, 0, 1);
		verts->push_back(basePos + zDir * length * 0.5 + localUp * width * 0);
//		verts->push_back(basePos + zDir * length * 0.5 - localUp * width * 0.5);
		verts->push_back(basePos - zDir * length * 0.5 - localUp * width * 0.5);
		verts->push_back(basePos - zDir * length * 0.5 + localUp * width * 0.5);
	}
	mPat->setPosition(Vec3(0, 0, -250));
	mPat->addChild(geode);
	mHSTime = -1;
	update(0);
	
}
开发者ID:allegrocm,项目名称:Falcon,代码行数:39,代码来源:Hyperspace.cpp

示例9: Vec3Array

PositionAttitudeTransform *VideoGeode::createVideoPlane(float sizeX, float sizeY, bool texRepeat)
{
	// vertex array
	Vec3Array *vertexArray = new Vec3Array();
   
   sizeX /= 2.0;
   sizeY /= 2.0;
	
   vertexArray->push_back(Vec3(-sizeX, 0, -sizeY));
	vertexArray->push_back(Vec3(sizeX, 0, -sizeY));
	vertexArray->push_back(Vec3(sizeX, 0, sizeY));
	vertexArray->push_back(Vec3(-sizeX, 0, sizeY));

	
   /*vertexArray->push_back(Vec3(-sizeX, -sizeY, 0));
	vertexArray->push_back(Vec3(sizeX, -sizeY, 0));
	vertexArray->push_back(Vec3(sizeX, sizeY, 0));
	vertexArray->push_back(Vec3(-sizeX, sizeY, 0));*/
   
	// face array
	DrawElementsUInt *faceArray = new DrawElementsUInt(PrimitiveSet::TRIANGLES, 0);
	
	faceArray->push_back(0); // face 1
	faceArray->push_back(1);
	faceArray->push_back(2);
	faceArray->push_back(2); // face 2
	faceArray->push_back(3);
	faceArray->push_back(0);
	
	// normal array
	Vec3Array *normalArray = new Vec3Array();
	normalArray->push_back(Vec3(0, 0, 1));
	
	// normal index
	TemplateIndexArray<unsigned int, Array::UIntArrayType, 24, 4> *normalIndexArray;
	normalIndexArray = new TemplateIndexArray<unsigned int, Array::UIntArrayType, 24, 4>();
	
	normalIndexArray->push_back(0);
	normalIndexArray->push_back(0);
	normalIndexArray->push_back(0);
	normalIndexArray->push_back(0);
	
	// texture coordinates
	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));
	
	Geometry *geometry = new Geometry();
	geometry->setVertexArray(vertexArray);
	geometry->setNormalArray(normalArray);
	geometry->setNormalIndices(normalIndexArray);
	geometry->setNormalBinding(Geometry::BIND_PER_VERTEX);
	geometry->setTexCoordArray(0, texCoords);
	geometry->addPrimitiveSet(faceArray);
	
	Geode *plane = new Geode();
	plane->addDrawable(geometry);
	
	// assign the material to the sphere
	StateSet *planeStateSet = plane->getOrCreateStateSet();
	planeStateSet->ref();
	planeStateSet->setAttribute(_material);
	
   try {
		planeStateSet->setTextureAttributeAndModes(0, createVideoTexture(texRepeat), StateAttribute::ON);
   } catch (char *e) {
      throw e;
   }
	
	PositionAttitudeTransform *planeTransform = new PositionAttitudeTransform();
	planeTransform->addChild(plane);
	return planeTransform;
}
开发者ID:jim-normand,项目名称:NAM,代码行数:75,代码来源:videogeometry.cpp

示例10: Geode

osg::Node *JTOpenPlugin::createShape(JtkShape *partShape, const char *objName)
{
    //cout << "JtkSHAPE\n";

    Geode *geode = new Geode();
    ref_ptr<Geometry> geom = new Geometry();
    StateSet *geoState = geode->getOrCreateStateSet();
    Vec3Array *vert = new Vec3Array;
    Vec3Array *normalArray = new Vec3Array();
    Vec3Array *colorArray = new Vec3Array();
    Vec2Array *tcArray = new Vec2Array();

    DrawArrayLengths *primitives = NULL;
    if (partShape->typeID() == JtkEntity::JtkPOLYGONSET)
    {
        primitives = new DrawArrayLengths(PrimitiveSet::POLYGON);
    }
    else if (partShape->typeID() == JtkEntity::JtkLINESTRIPSET)
    {
        primitives = new DrawArrayLengths(PrimitiveSet::LINE_STRIP);
    }
    else if (partShape->typeID() == JtkEntity::JtkTRISTRIPSET)
    {
        primitives = new DrawArrayLengths(PrimitiveSet::TRIANGLE_STRIP);
    }
    else
    {
        cerr << "unknown partShape->typeID " << partShape->typeID() << endl;
    }
    geode->setName(objName);
    if (primitives)
    {
        for (int set = 0; set < partShape->numOfSets(); set++)
        {
            float *vertex = NULL,
                  *normal = NULL,
                  *color = NULL,
                  *texture = NULL;
            int vertexCount = -1,
                normCount = -1,
                colorCount = -1,
                textCount = -1;

            partShape->getInternal(vertex, vertexCount, normal, normCount,
                                   color, colorCount, texture, textCount, set);

            primitives->push_back(vertexCount);

            // backFaceCulling nur dann, wenn es im CoviseConfig enabled ist
            /*if(backFaceCulling && (mask & Viewer::MASK_SOLID))
         {
         CullFace *cullFace = new CullFace();        // da viele Modelle backface Culling nicht vertragen (nicht richtig modelliert sind)
         cullFace->setMode(CullFace::BACK);
         geoState->setAttributeAndModes(cullFace, StateAttribute::ON);
         }

         // already done in updateMaterial()
         #if 0
         if(Blended)
         {
         BlendFunc *blendFunc = new BlendFunc();
         blendFunc->setFunction(BlendFunc::SRC_ALPHA, BlendFunc::ONE_MINUS_SRC_ALPHA);
         geoState->setAttributeAndModes(blendFunc, StateAttribute::ON);
         #if 1
         AlphaFunc *alphaFunc = new AlphaFunc();
         alphaFunc->setFunction(AlphaFunc::ALWAYS,1.0);
         geoState->setAttributeAndModes(alphaFunc, StateAttribute::OFF);
         #endif
         }
         #endif
         #ifdef HAVE_OSGNV
         if((strncmp(d_currentObject->node->name(),"combineTextures",15)==0)||(strncmp(objName,"combineTextures",15)==0))
         {
         geoState->setAttributeAndModes(combineTextures.get(), StateAttribute::ON);
         }
         if((strncmp(d_currentObject->node->name(),"combineEnvTextures",15)==0)||(strncmp(objName,"combineEnvTextures",15)==0))
         {
         geoState->setAttributeAndModes(combineEnvTextures.get(), StateAttribute::ON);
         }
         #endif*/

            if (vertex && (vertexCount > 0))
            {
                for (int elems = 0; elems < vertexCount; elems++)
                {
                    vert->push_back(Vec3(vertex[elems * 3 + 0], vertex[elems * 3 + 1], vertex[elems * 3 + 2]));
                }
                JtkEntityFactory::deleteMemory(vertex);
            }

            if (normal && (normCount > 0))
            {
                for (int elems = 0; elems < normCount; elems++)
                {
                    normalArray->push_back(Vec3(normal[elems * 3 + 0], normal[elems * 3 + 1], normal[elems * 3 + 2]));
                }
                if (normCount == vertexCount)
                {
                }
                else
//.........这里部分代码省略.........
开发者ID:nixz,项目名称:covise,代码行数:101,代码来源:JTOpenPlugin.cpp

示例11: v

void Normals::MakeNormalsVisitor::apply( Geode &geode )
{
    for( unsigned int i = 0; i < geode.getNumDrawables(); i++ )
    {
        Geometry *geom = dynamic_cast<Geometry *>(geode.getDrawable(i));
        if( geom )
        {
            if (geom->containsDeprecatedData()) geom->fixDeprecatedData();
            
            Vec3Array *coords   = dynamic_cast<Vec3Array*>(geom->getVertexArray());
            if( coords == 0L )
                continue;

            Vec3Array *normals  = dynamic_cast<Vec3Array*>(geom->getNormalArray());
            if( normals == 0L )
                continue;

            Geometry::AttributeBinding binding = geom->getNormalBinding();
            if( binding == Geometry::BIND_OFF )
                continue;

            if( binding == Geometry::BIND_OVERALL )
            {
                Vec3 v(0,0,0);
                Vec3 n = normals->front();

                Vec3Array::iterator coord_index = coords->begin();
                while( coord_index != coords->end() )
                  v += *(coord_index++) * _mat;
                v /= (float)(coords->size());

                n *= _normal_scale;
                _local_coords->push_back( v );
                _local_coords->push_back( (v + n));
            }
            else // BIND_PER_PRIMITIVE_SET, BIND_PER_VERTEX
            {
                Geometry::PrimitiveSetList& primitiveSets = geom->getPrimitiveSetList();
                Geometry::PrimitiveSetList::iterator itr;

                Vec3Array::iterator coord_index   = coords->begin();
                Vec3Array::iterator normals_index = normals->begin();

                for(itr=primitiveSets.begin(); itr!=primitiveSets.end(); ++itr)
                {
#ifdef DEBUG
                    _printPrimitiveType( (*itr).get() );
#endif
                    if( binding == Geometry::BIND_PER_PRIMITIVE_SET )
                    {
                        Vec3 v(0,0,0);
                        Vec3 n = *(normals_index++);
                        int ni = (*itr)->getNumIndices();
                        for( int i = 0; i < ni; i++ )
                            v += *(coord_index++) * _mat;
                        v /= (float)(ni);

                        n *= _normal_scale;
                        _local_coords->push_back( v );
                        _local_coords->push_back( (v + n));
                    }
                    else
                    {
                        switch((*itr)->getMode())
                        {
                            case(PrimitiveSet::TRIANGLES):
                            {
                                for( unsigned int j = 0; j < (*itr)->getNumPrimitives(); j++ )
                                {
                                    _processPrimitive( 3, coord_index, normals_index, binding );
                                    coord_index += 3;
                                    normals_index+=3;
                                }
                                break;
                            }
                            case(PrimitiveSet::TRIANGLE_STRIP):
                            {
                                for( unsigned int j = 0; j < (*itr)->getNumIndices()-2; j++ )
                                {
                                    _processPrimitive( 3, coord_index, normals_index, binding );
                                    coord_index++;
                                    normals_index++;
                                }
                                coord_index += 2;
                                if( binding == Geometry::BIND_PER_VERTEX )
                                    normals_index += 2;
                                break;
                            }
                            case(PrimitiveSet::TRIANGLE_FAN):
                                break;

                            case(PrimitiveSet::QUADS):
                            {
                                for( unsigned int j = 0; j < (*itr)->getNumPrimitives(); j++ )
                                {
                                    _processPrimitive( 4, coord_index, normals_index, binding );
                                    coord_index += 4;
                                    normals_index +=4;
                                }
                                break;
//.........这里部分代码省略.........
开发者ID:amhagan,项目名称:osg,代码行数:101,代码来源:Normals.cpp

示例12: sqrt

/***************************************************************
* Function: resize()
***************************************************************/
void CAVEGeodeSnapWireframeCone::resize(osg::Vec3 &gridVect)
{
    // calculate rounded vector
    float height = mScaleVect.z(), 
          rad = sqrt(mScaleVect.x() * mScaleVect.x() + mScaleVect.y() * mScaleVect.y());
    int hSeg, radSeg, fanSeg, hDir = 1;
    if (height < 0) 
    { 
        height = -height;  
        hDir = -1; 
    }

    hSeg = (int)(abs((int)(height / mSnappingUnitDist)) + 0.5);
    radSeg = (int)(abs((int)(rad / mSnappingUnitDist)) + 0.5);
    fanSeg = (int)(abs((int)(rad * M_PI * 2 / mSnappingUnitDist)) + 0.5);

    if (fanSeg < gMinFanSegments) 
        fanSeg = gMinFanSegments;

    float intvl = M_PI * 2 / fanSeg;
    height = hSeg * mSnappingUnitDist;
    rad = radSeg * mSnappingUnitDist;
    gridVect = Vec3(radSeg, 0, hSeg * hDir);

    mDiagonalVect = Vec3(rad, rad, height * hDir);

    gCurFanSegments = 10;//fanSeg;	// update number of fan segment, this parameter is passed to 'CAVEGeodeShape'

    // update 'mSnapwireGeometry' geometry, do not use 'mBaseGeometry' anymore
    if (mBaseGeometry)
    {
        removeDrawable(mBaseGeometry);
        mBaseGeometry = NULL;
    }
    if (mSnapwireGeometry) 
        removeDrawable(mSnapwireGeometry);

    mSnapwireGeometry = new Geometry();
    Vec3Array* snapvertices = new Vec3Array;
    int vertoffset = 0;

    // create vertical edges, cap radiating edges and ring strips on side surface
    for (int i = 0; i <= hSeg; i++)
    {
        for (int j = 0; j < fanSeg; j++)
        {
            float theta = j * intvl;
            snapvertices->push_back(mInitPosition + Vec3(rad * cos(theta), rad * sin(theta), i * mSnappingUnitDist * hDir));
        }
    }
    snapvertices->push_back(mInitPosition);
    snapvertices->push_back(mInitPosition + Vec3(0, 0, height * hDir));

    for (int i = 0; i <= hSeg; i++)
    {
        DrawElementsUInt* sideRingStrip = new DrawElementsUInt(PrimitiveSet::LINE_STRIP, 0);
        for (int j = 0; j < fanSeg; j++) 
        {
            sideRingStrip->push_back(vertoffset + i * fanSeg + j);
        }
        sideRingStrip->push_back(vertoffset + i * fanSeg);
        mSnapwireGeometry->addPrimitiveSet(sideRingStrip);
    }
    DrawElementsUInt* sideVerticalEdges = new DrawElementsUInt(PrimitiveSet::LINES, 0);
    DrawElementsUInt* capRadiatingEdges = new DrawElementsUInt(PrimitiveSet::LINES, 0);

    for (int j = 0; j < fanSeg; j++)
    {
        sideVerticalEdges->push_back(vertoffset + j);
        sideVerticalEdges->push_back(vertoffset + j + fanSeg * hSeg);

        capRadiatingEdges->push_back((hSeg + 1) * fanSeg);
        capRadiatingEdges->push_back(vertoffset + j);
        capRadiatingEdges->push_back((hSeg + 1) * fanSeg + 1);
        capRadiatingEdges->push_back(vertoffset + j + fanSeg * hSeg);
    }
    mSnapwireGeometry->addPrimitiveSet(sideVerticalEdges);
    mSnapwireGeometry->addPrimitiveSet(capRadiatingEdges);
    vertoffset += (hSeg + 1) * fanSeg + 2;

    // create ring strips on two caps
    for (int i = 1; i < radSeg; i++)
    {
        float r = i * mSnappingUnitDist;
        for (int j = 0; j < fanSeg; j++)
        {
            float theta = j * intvl;
            snapvertices->push_back(mInitPosition + Vec3(r * cos(theta), r * sin(theta), height * hDir));
            snapvertices->push_back(mInitPosition + Vec3(r * cos(theta), r * sin(theta), 0));
        }
    }

    for (int i = 1; i < radSeg; i++)
    {
        DrawElementsUInt* topRingStrip = new DrawElementsUInt(PrimitiveSet::LINE_STRIP, 0);
        DrawElementsUInt* bottomRingStrip = new DrawElementsUInt(PrimitiveSet::LINE_STRIP, 0);

//.........这里部分代码省略.........
开发者ID:CalVR,项目名称:calvr_plugins,代码行数:101,代码来源:CAVEGeodeSnapWireframe.cpp

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

示例14: Vec4

/***************************************************************
* Function: resize()
***************************************************************/
void CAVEGeodeSnapWireframeLine::resize(osg::Vec3 &gridVect)
{
    /*
    Material* material = new Material;
    material->setAmbient(Material::FRONT_AND_BACK, Vec4(0.0, 1.0, 0.0, 1.0));
    material->setDiffuse(Material::FRONT_AND_BACK, Vec4(1.0, 1.0, 0.0, 1.0));
    material->setSpecular(Material::FRONT_AND_BACK, osg::Vec4( 1.f, 1.f, 1.f, 1.0f));
    material->setAlpha(Material::FRONT_AND_BACK, 1.f);

    StateSet* stateset = new StateSet();
    stateset->setAttributeAndModes(material, StateAttribute::OVERRIDE | StateAttribute::ON);
    setStateSet(stateset);
    */
    
    // calculate grid vector 
    float snapUnitX, snapUnitY, snapUnitZ;
    snapUnitX = snapUnitY = snapUnitZ = mSnappingUnitDist;
    if (mScaleVect.x() < 0) 
        snapUnitX = -mSnappingUnitDist;
    if (mScaleVect.y() < 0) 
        snapUnitY = -mSnappingUnitDist;
    if (mScaleVect.z() < 0) 
        snapUnitZ = -mSnappingUnitDist;
    int xSeg = (int)(abs((int)((mScaleVect.x() + 0.5 * snapUnitX) / mSnappingUnitDist)));
    int ySeg = (int)(abs((int)((mScaleVect.y() + 0.5 * snapUnitY) / mSnappingUnitDist)));
    int zSeg = (int)(abs((int)((mScaleVect.z() + 0.5 * snapUnitZ) / mSnappingUnitDist)));

    Vec3 roundedVect;
    roundedVect.x() = xSeg * snapUnitX;		gridVect.x() = roundedVect.x() / mSnappingUnitDist;
    roundedVect.y() = ySeg * snapUnitY;		gridVect.y() = roundedVect.y() / mSnappingUnitDist;
    roundedVect.z() = zSeg * snapUnitZ;		gridVect.z() = roundedVect.z() / mSnappingUnitDist;
    mDiagonalVect = roundedVect;

    // update box corners in 'mBaseGeometry'
    float xMin, yMin, zMin, xMax, yMax, zMax;
    xMin = mInitPosition.x();	xMax = xMin + roundedVect.x();
    yMin = mInitPosition.y();	yMax = yMin + roundedVect.y();
    zMin = mInitPosition.z();	zMax = zMin + roundedVect.z();

    Array* baseVertArray = mBaseGeometry->getVertexArray();
    if (baseVertArray->getType() == Array::Vec3ArrayType)
    {
        Vec3* vertexArrayDataPtr = (Vec3*) (baseVertArray->getDataPointer());
        vertexArrayDataPtr[0] = Vec3(xMax, yMax, zMax);
        vertexArrayDataPtr[1] = Vec3(xMin, yMax, zMax);
        vertexArrayDataPtr[2] = Vec3(xMin, yMin, zMax);
        vertexArrayDataPtr[3] = Vec3(xMax, yMin, zMax);
        vertexArrayDataPtr[4] = Vec3(xMax, yMax, zMin);
        vertexArrayDataPtr[5] = Vec3(xMin, yMax, zMin);
        vertexArrayDataPtr[6] = Vec3(xMin, yMin, zMin);
        vertexArrayDataPtr[7] = Vec3(xMax, yMin, zMin);
    }
    mBaseGeometry->dirtyDisplayList();
    mBaseGeometry->dirtyBound();

    // update snapping wire geometry
    if (mSnapwireGeometry) 
        removeDrawable(mSnapwireGeometry);

    mSnapwireGeometry = new Geometry();
    Vec3Array* snapvertices = new Vec3Array;
    int vertoffset = 0;
    if (xSeg > 1)	// (xSeg - 1) * 4 vertices
    {
        for (int i = 1; i <= xSeg - 1; i++)
        {
            snapvertices->push_back(Vec3(xMin + i * snapUnitX, yMin, zMin));
            snapvertices->push_back(Vec3(xMin + i * snapUnitX, yMax, zMin));
            snapvertices->push_back(Vec3(xMin + i * snapUnitX, yMax, zMax));
            snapvertices->push_back(Vec3(xMin + i * snapUnitX, yMin, zMax));

            DrawElementsUInt* edges = new DrawElementsUInt(PrimitiveSet::LINE_STRIP, 0);
            edges->push_back(vertoffset + (i-1)*4);
            edges->push_back(vertoffset + (i-1)*4 + 1);
            edges->push_back(vertoffset + (i-1)*4 + 2);
            edges->push_back(vertoffset + (i-1)*4 + 3);
            edges->push_back(vertoffset + (i-1)*4);
            mSnapwireGeometry->addPrimitiveSet(edges);
        }
        vertoffset += (xSeg - 1) * 4;
    }
    if (ySeg > 1)	// (ySeg - 1) * 4 vertices
    {
        for (int i = 1; i <= ySeg - 1; i++)
        {
            snapvertices->push_back(Vec3(xMin, yMin + i * snapUnitY, zMin));
            snapvertices->push_back(Vec3(xMax, yMin + i * snapUnitY, zMin));
            snapvertices->push_back(Vec3(xMax, yMin + i * snapUnitY, zMax));
            snapvertices->push_back(Vec3(xMin, yMin + i * snapUnitY, zMax));

            DrawElementsUInt* edges = new DrawElementsUInt(PrimitiveSet::LINE_STRIP, 0);
            edges->push_back(vertoffset + (i-1)*4);
            edges->push_back(vertoffset + (i-1)*4 + 1);
            edges->push_back(vertoffset + (i-1)*4 + 2);
            edges->push_back(vertoffset + (i-1)*4 + 3);
            edges->push_back(vertoffset + (i-1)*4);
            mSnapwireGeometry->addPrimitiveSet(edges);
//.........这里部分代码省略.........
开发者ID:CalVR,项目名称:calvr_plugins,代码行数:101,代码来源:CAVEGeodeSnapWireframe.cpp

示例15: V_RETURN


//.........这里部分代码省略.........

	GLuint *pIndices = QSE_NEW GLuint[m_sides * 2 * 3];

	GLuint *current = pIndices;
	for (DWORD i = 0; i<m_sides; i++)
	{
		// Triangle #1  ACB
		*(current) = GLuint(i * 4);
		*(current + 1) = GLuint(i * 4 + 2);
		*(current + 2) = GLuint(i * 4 + 1);

		// Triangle #2  BCD
		*(current + 3) = GLuint(i * 4 + 1);
		*(current + 4) = GLuint(i * 4 + 2);
		*(current + 5) = GLuint(i * 4 + 3);
		current += 6;
	}

	data.mIndices = GLUFArrToVec(pIndices, m_sides * 2 * 3);
	
	//now the indicies
	/*glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_IndexBuffer);
	glBufferStorage(GL_ELEMENT_ARRAY_BUFFER, m_sides * 2 * 3 * sizeof(GLfloat), m_IndexBufferData.data(), GL_STATIC_DRAW);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
	SAFE_DELETE_ARRAY(pIndices);

	//buffer the data
	m_pVertexArray.BufferData(mPositionLoc, data.mPositions.size(), &data.mPositions[0]);
	m_pVertexArray.BufferData(mUVLoc, data.mUVCoords.size(), &data.mPositions[0]);
	m_pVertexArray.BufferIndices(pIndices, m_sides * 2 * 3);
	*/

	
	Vec3Array verts;
	float val = 1.0f;


	float depth = val;
	m_sides = 6;

	//float N = 1.0f / sqrt(3.0f);

	//north
	/*verts.push_back(glm::vec3(-val, -val, depth));
	verts.push_back(glm::vec3(val, -val, depth));
	verts.push_back(glm::vec3(val, val, depth));
	verts.push_back(glm::vec3(-val, val, depth));
	
	//uvws.push_back(glm::vec3(-N, -N, N));
	//uvws.push_back(glm::vec3(N, -N, N));
	//uvws.push_back(glm::vec3(N, N, N));
	//uvws.push_back(glm::vec3(-N, N, N));

	//south
	verts.push_back(glm::vec3(val, -val, -depth));
	verts.push_back(glm::vec3(-val, -val, -depth));
	verts.push_back(glm::vec3(-val, val, -depth));
	verts.push_back(glm::vec3(val, val, -depth));

	//uvws.push_back(glm::vec3(N, -N, -N));
	//uvws.push_back(glm::vec3(-N, -N, -N));
	//uvws.push_back(glm::vec3(-N, N, -N));
	//uvws.push_back(glm::vec3(N, N, -N));


	//east
开发者ID:KevinMackenzie,项目名称:AmberRabbit,代码行数:67,代码来源:Sky.cpp


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