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


C++ TriMesh::appendColorRgb方法代码示例

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


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

示例1: generateQuad

BaseMeshRef SimpleMesh::generateQuad(Rectf dimensions,
                                     Rectf uvCoords = Rectf(0.0f, 0.0f, 1.0f,
                                             1.0f)) {

    // cout << "SimpleMesh::GenerateQuad(); dims: " << dimensions
    //     << " uvCoords: " << uvCoords << endl;

    TriMesh mesh;
    mesh.clear();

    // Vertexes
    mesh.appendVertex(Vec3f(dimensions.x1, dimensions.y1, 0));
    mesh.appendVertex(Vec3f(dimensions.x1, dimensions.y2, 0));
    mesh.appendVertex(Vec3f(dimensions.x2, dimensions.y2, 0));
    mesh.appendVertex(Vec3f(dimensions.x2, dimensions.y1, 0));

    // Vertex Colors
    mesh.appendColorRgb(Color(1.0f, 1.0f, 1.0f));
    mesh.appendColorRgb(Color(1.0f, 1.0f, 1.0f));
    mesh.appendColorRgb(Color(1.0f, 1.0f, 1.0f));
    mesh.appendColorRgb(Color(1.0f, 1.0f, 1.0f));

    // Tex coords
    mesh.appendTexCoord(Vec2f(uvCoords.x1, uvCoords.y1));
    mesh.appendTexCoord(Vec2f(uvCoords.x1, uvCoords.y2));
    mesh.appendTexCoord(Vec2f(uvCoords.x2, uvCoords.y2));
    mesh.appendTexCoord(Vec2f(uvCoords.x2, uvCoords.y1));

    int vert0 = mesh.getNumVertices() - 4;
    int vert1 = mesh.getNumVertices() - 1;
    int vert2 = mesh.getNumVertices() - 2;
    int vert3 = mesh.getNumVertices() - 3;

    mesh.appendTriangle(vert0, vert1, vert3);
    mesh.appendTriangle(vert3, vert1, vert2);

    mesh.recalculateNormals();

    SimpleMeshRef meshWrapper = make_shared<SimpleMesh>(mesh);
    meshWrapper->_bounds = mesh.calcBoundingBox();
    return dynamic_pointer_cast<BaseMesh>(meshWrapper);
}
开发者ID:,项目名称:,代码行数:42,代码来源:

示例2: writeColors

// dependent on a change in parameters, write new colors to the TriMesh
void GeoDeVisualizerApp::writeColors()
{
    mTriangles.getColorsRGB().clear();
    vector<Color> colors;
    colors.reserve(mTriangles.getNumTriangles());
    
    DisplayMode mode = (DisplayMode)mCurParams.displayMode;
    switch(mode) {
    case Geography:
        {
            colors = mWorld.mGeoColors;
            break;
        }
    case Colonies:
        {
            colors = mWorld.mGeoColors;
            // add sphere of influence and location
            Colony& colRef = mWorld.mColonies[mCurParams.displayColony];
            mCamVars.sceneRotation.set(getAverageVertex(colRef.mLocation), mCam.getEyePoint());
            for (set<u32>::iterator soiIt = colRef.mSphereInfluence.begin(); soiIt != colRef.mSphereInfluence.end(); ++soiIt) {
                colors[*soiIt] = Color(0.2, 0.2, 0.2);
            }
            colors[colRef.mLocation] = Color(1.0, 0.0, 0.0);
            break;
        }
    case Resources:
        {
            
            vector<u32> activeResIdxs;
            for (u32 i = 0; i < mCurParams.numResources; i++) {
                if (mCurParams.showResources[i]) {
                    activeResIdxs.push_back(i);
                }
            }
            if (activeResIdxs.size() > 0) {
                colors.insert(colors.begin(), mTriangles.getNumTriangles(), Color(0.0, 0.0, 0.0));
            } else {
                colors.insert(colors.begin(), mTriangles.getNumTriangles(), Color(0.2, 0.2, 0.2));
                break;
            }
            float numIndices = activeResIdxs.size();
            for(vector<u32>::iterator idxIt = activeResIdxs.begin(); idxIt != activeResIdxs.end(); ++idxIt) {
                vector<f32>& activeResVals = (mWorld.resources())[*idxIt].mVals;
                vector<Color>::iterator colIt = colors.begin();
                for (vector<f32>::iterator valIt = activeResVals.begin(); valIt != activeResVals.end(); ++valIt) {
                    *colIt += (resourceColors[*idxIt] * (*valIt)) / numIndices;
                    colIt++;
                }
            }
            break;
        }
    case Attributes:
        {
            colors.insert(colors.begin(), mTriangles.getNumTriangles(), Color(0.0, 0.0, 0.0));
            vector<u32> activeAttrIdxs;
            for (u32 i = 0; i < NUM_ATTRIBUTES; i++) {
                if (mCurParams.showAttributes[i]) {
                    activeAttrIdxs.push_back(i);
                }
            }
            if (activeAttrIdxs.size() == 0) {
                colors.clear();
                colors.insert(colors.begin(), mTriangles.getNumTriangles(), Color(0.1, 0.1, 0.1));
                break;
            }
            map<string, Color> attrMap;
            attrMap["wetness"] = Color(0.0, 0.0, 1.0);
            attrMap["temperature"] = Color(1.0, 0.0, 0.0);
            attrMap["elevation"] = Color(0.0, 1.0, 0);
            // iterate through all active indices
            for(vector<u32>::iterator idxIt = activeAttrIdxs.begin(); idxIt != activeAttrIdxs.end(); ++idxIt) {
                Color colorVal = attrMap[mWorld.mAttributes[*idxIt].mName];
                vector<Color>::iterator faceColorIt = colors.begin();
                // iterate through all attribute values
                for (vector<f32>::iterator attrIt = mWorld.mAttributes[*idxIt].mVals.begin(); attrIt != mWorld.mAttributes[*idxIt].mVals.end(); ++attrIt) {
                    *faceColorIt += (colorVal * (*attrIt));
                    faceColorIt++;
                }
            }
            break;
        }
    }
    // triple the colors vector so that triangles show up as solid triangles
    for (vector<Color>::iterator colIt = colors.begin(); colIt != colors.end(); ++colIt) {
        mTriangles.appendColorRgb(*colIt);
        mTriangles.appendColorRgb(*colIt);
        mTriangles.appendColorRgb(*colIt);
    }
    mFrame = mTriangles;
    mFrame.getColorsRGB().clear();
    vector<Color> frameColors(colors.size()*3, Color(0.1, 0.1, 0.1));
    mFrame.appendColorsRgb(frameColors.data(), frameColors.size());
}
开发者ID:nikhilshinday,项目名称:GeoDe,代码行数:94,代码来源:GeoDeVisualizerApp.cpp

示例3: generateCapsule

void verticesApp::generateCapsule()
{
    
    vector<uint> indices;
    
    double fDeltaRingAngle = (M_PI_2 / mNumRings);
    double fDeltaSegAngle = ((M_PI * 2.0) / mNumSegments);
    
    double sphereRatio = mRadius / (2 * mRadius + mHeight);
    double cylinderRatio = mHeight / (2 * mRadius + mHeight);
    int offset = 0;
    // Top half sphere
    
    // Generate the group of rings for the sphere
    for(unsigned int ring = 0; ring <= mNumRings; ring++ )
    {
        double r0 = mRadius * sinf ( ring * fDeltaRingAngle);
        double y0 = mRadius * cosf (ring * fDeltaRingAngle);
        
        // Generate the group of segments for the current ring
        for(unsigned int seg = 0; seg <= mNumSegments; seg++)
        {
            double x0 = r0 * cosf(seg * fDeltaSegAngle);
            double z0 = r0 * sinf(seg * fDeltaSegAngle);
            
            Vec3f p(x0, 0.5f * mHeight + y0, z0);
            Vec3f n(x0, y0, z0);
            mesh.appendVertex(p);
            mesh.appendNormal(n.normalized());
            mesh.appendTexCoord(Vec2f((double) seg / (double) mNumSegments, (double) ring / (double) mNumRings * sphereRatio));
            mesh.appendColorRgb(Colorf(1.0, 0, 0));
            
            // each vertex (except the last) has six indices pointing to it
            indices.push_back(offset + mNumSegments + 1);
            indices.push_back(offset + mNumSegments);
            indices.push_back(offset);
            indices.push_back(offset + mNumSegments + 1);
            indices.push_back(offset);
            indices.push_back(offset + 1);
            
            offset ++;
        } // end for seg
    } // end for ring
    
    // Cylinder part
    double deltaAngle = ((M_PI * 2.0) / mNumSegments);
    double deltamHeight = mHeight/(double)mNumSegHeight;
    
    for (unsigned short i = 1; i < mNumSegHeight; i++) {
        for (unsigned short j = 0; j<=mNumSegments; j++)
        {
            double x0 = mRadius * cosf(j*deltaAngle);
            double z0 = mRadius * sinf(j*deltaAngle);
            
            Vec3f p(x0, 0.5f*mHeight-i*deltamHeight, z0);
            Vec3f n(x0, 0, z0);
            mesh.appendVertex(p);
            mesh.appendNormal(n.normalized());
            mesh.appendTexCoord(Vec2f(j/(double)mNumSegments, i/(double)mNumSegHeight * cylinderRatio + sphereRatio));
            mesh.appendColorRgb(Colorf(0, 1.0 - (float(j)/float(mNumSegments)), 0));

            
            indices.push_back(offset + mNumSegments + 1);
            indices.push_back(offset + mNumSegments);
            indices.push_back(offset);
            indices.push_back(offset + mNumSegments + 1);
            indices.push_back(offset);
            indices.push_back(offset + 1);
            
            offset ++;
        }
    }

    // Bottom half sphere
    
    // Generate the group of rings for the sphere
    for(unsigned int ring = 0; ring <= mNumRings; ring++)
    {
        double r0 = mRadius * sinf (M_PI_2 + ring * fDeltaRingAngle);
        double y0 =  mRadius * cosf (M_PI_2 + ring * fDeltaRingAngle);
        
        // Generate the group of segments for the current ring
        for(unsigned int seg = 0; seg <= mNumSegments; seg++)
        {
            double x0 = r0 * cosf(seg * fDeltaSegAngle);
            double z0 = r0 * sinf(seg * fDeltaSegAngle);
            
            Vec3f p(x0, -0.5f*mHeight + y0, z0);
            Vec3f n(x0, y0, z0);
            mesh.appendVertex(p);
            mesh.appendNormal(n.normalized());
            mesh.appendTexCoord(Vec2f((double) seg / (double) mNumSegments, (double) ring / (double) mNumRings*sphereRatio + cylinderRatio + sphereRatio));
            mesh.appendColorRgb(Colorf(0, 0, float(ring)/float(mNumRings)));

            
            if (ring != mNumRings) 
            {
                // each vertex (except the last) has six indices pointing to it
                indices.push_back(offset + mNumSegments + 1);
                indices.push_back(offset + mNumSegments);
//.........这里部分代码省略.........
开发者ID:deniskovalev,项目名称:ciResonate,代码行数:101,代码来源:verticesApp.cpp


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