本文整理汇总了C++中MeshBuilder::addVertex方法的典型用法代码示例。如果您正苦于以下问题:C++ MeshBuilder::addVertex方法的具体用法?C++ MeshBuilder::addVertex怎么用?C++ MeshBuilder::addVertex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MeshBuilder
的用法示例。
在下文中一共展示了MeshBuilder::addVertex方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: createPlane
int Object::createPlane( Material* mat , float w , float h , float* color , float xTile , float yTile ,
Vector3 const& normal , Vector3 const& alignDir , Vector3 const& offset , bool invYDir )
{
Vector3 yLen = normal.cross( alignDir );
assert( yLen.length2() > 1e-4 );
yLen.normalize();
Vector3 xLen = yLen.cross( normal );
xLen *= 0.5f * w;
yLen *= 0.5f * h;
if ( invYDir )
yLen = -yLen;
Vector3 n = normal;
n.normalize();
int texLen = 2;
VertexType type = ( color ) ? CFVT_XYZ_N_CF1 : CFVT_XYZ_N;
//VertexType type = ( color ) ? CFVT_XYZ_CF1 : CFVT_XYZ;
MeshBuilder builder = MeshBuilder( type | CFVF_TEX1( 2 ) );
if ( color )
builder.setColor( color );
builder.setNormal( n );
builder.reserveVexterBuffer( 4 );
builder.reserveIndexBuffer( 12 );
builder.setPosition( offset - xLen - yLen );
builder.setTexCoord( 0 , 0 , 0 );
builder.addVertex();
builder.setPosition( offset + xLen - yLen );
builder.setTexCoord( 0 ,xTile, 0 );
builder.addVertex();
builder.setPosition( offset + xLen + yLen );
builder.setTexCoord( 0 , xTile , yTile );
builder.addVertex();
builder.setPosition( offset - xLen + yLen );
builder.setTexCoord( 0 , 0 , yTile );
builder.addVertex();
builder.addQuad( 0 , 1 , 2 , 3 );
return builder.createIndexTrangle( this , mat );
}
示例2: buildSquare
// Builds one square
void buildSquare(Object &object, const GLfloat side, MeshBuilder & builder) {
builder.addVertex(-side, -side, 0); // bottom left
builder.addVertex(side, -side, 0); // bottom right
builder.addVertex(-side, side, 0); // top left
builder.addVertex(side, side, 0); // top right
builder.addFace(0, 2, 3); // First triangle : top left
builder.addFace(0, 1, 3); // Second triangle : bottom right
vector<unsigned int> indices;
vector<Vector3f> vertices;
vector<Vector3f> normals;
vector<UV> uvs;
builder.unpack(indices, vertices, normals, uvs);
// Sends the data into buffers on the GPU
object.sendPrimitives(vertices, indices);
}
示例3: test
static int test()
{
MeshBuilder mesh;
Vertex* v[4];
int i;
for ( i = 0 ; i < 4 ; ++i ) // 0 1
v[i] = mesh.addVertex(); // 3 2
Polygon* a = mesh.addPolygon();
a->addVertex( v[0] );
a->addVertex( v[1] );
a->addVertex( v[2] );
Polygon* b = mesh.addPolygon();
b->addVertex( v[0] );
b->addVertex( v[2] );
b->addVertex( v[3] );
VertexMap* vmap = mesh.addVertexMap( 2, "TXUV", VertexMapFormat::VERTEXMAP_TEXCOORD );
float uv[4][2] = { {0, 0}, {1,0}, {1,1}, {0,1} };
vmap->addValue( v[2]->index(), uv[2], 2 );
vmap->addValue( v[1]->index(), uv[1], 2 );
vmap->addValue( v[3]->index(), uv[3], 2 );
vmap->addValue( v[0]->index(), uv[0], 2 );
v[1] = a->getVertex(1)->clone();
a->setVertex( 1, v[1] );
assert( mesh.vertices() == 5 );
float uv1[4][2];
memset( uv1, 0, sizeof(uv1) );
for ( i = 0 ; i < 4 ; ++i )
{
vmap->getValue( v[i]->index(), uv1[i], 2 );
assert( !memcmp(uv[i],uv1[i],sizeof(uv[i])) );
}
assert( vmap->dimensions() == 2 );
assert( vmap->name() == "TXUV" );
return 0;
}
示例4: fillModelMesh
static int fillModelMesh( MeshBuilder& builder , mstudiotexture_t& texDesc , short* tri , Vector3 vtxPos[] , uint8* vtxBone )
{
int numTri = 0;
float fs = 1.0f / texDesc.width;
float ft = 1.0f / texDesc.height;
int base = 0;
if ( vtxBone )
{
while (1)
{
short nEle = *(tri++);
if ( nEle == 0)
break;
if ( nEle < 0 )
{
//triangle fan
nEle = -nEle;
builder.setPosition( vtxPos[ tri[0] ] );
builder.setBlendIndices( vtxBone[ tri[0] ] + 1 );
builder.setTexCoord( 0 , fs * tri[2] , ft * tri[3] );
builder.addVertex();
int start = base++;
tri += 4;
builder.setPosition( vtxPos[ tri[0] ] );
builder.setBlendIndices( vtxBone[ tri[0] ] + 1 );
builder.setTexCoord( 0 , fs * tri[2] , ft * tri[3] );
builder.addVertex();
int prev = base++;
tri += 4;
for( int n = 2 ; n < nEle ; ++n )
{
builder.setPosition( vtxPos[ tri[0] ] );
builder.setBlendIndices( vtxBone[ tri[0] ] + 1 );
builder.setTexCoord( 0 , fs * tri[2] , ft * tri[3] );
builder.addVertex();
int cur = base++;
builder.addTriangle( start , cur , prev );
++numTri;
prev = cur;
tri += 4;
}
}
else
{
//triangle strip
builder.setPosition( vtxPos[ tri[0] ] );
builder.setBlendIndices( vtxBone[ tri[0] ] + 1 );
builder.setTexCoord( 0 , fs * tri[2] , ft * tri[3] );
builder.addVertex();
int prev2 = base++;
tri += 4;
builder.setPosition( vtxPos[ tri[0] ] );
builder.setBlendIndices( vtxBone[ tri[0] ] + 1 );
builder.setTexCoord( 0 , fs * tri[2] , ft * tri[3] );
builder.addVertex();
int prev = base++;
tri += 4;
for( int n = 2 ; n < nEle ; ++n )
{
builder.setPosition( vtxPos[ tri[0] ] );
builder.setBlendIndices( vtxBone[ tri[0] ] + 1 );
builder.setTexCoord( 0 , fs * tri[2] , ft * tri[3] );
builder.addVertex();
int cur = base++;
if ( n % 2 == 0 )
builder.addTriangle( prev2 , cur , prev );
else
builder.addTriangle( prev2 , prev , cur );
++numTri;
prev2 = prev;
prev = cur;
tri += 4;
}
}
}
}
else //vtxBone
{
while (1)
{
short nEle = *(tri++);
if ( nEle == 0)
break;
if ( nEle < 0 )
//.........这里部分代码省略.........