本文整理汇总了C++中MeshPtr::addTriangle方法的典型用法代码示例。如果您正苦于以下问题:C++ MeshPtr::addTriangle方法的具体用法?C++ MeshPtr::addTriangle怎么用?C++ MeshPtr::addTriangle使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MeshPtr
的用法示例。
在下文中一共展示了MeshPtr::addTriangle方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: sphere
MeshPtr Mesh::sphere( float radius, int nSubdivsU, int nSubdivsV, vec3_t center, float uMin, float uMax, float vMin, float vMax )
{
MeshPtr m = MeshPtr( new Mesh() );
float dPhi = MATH_2PIf/nSubdivsU;
float dTheta = MATH_PIf/nSubdivsV;
float theta, phi;
std::vector<Mesh::PointHandle> points;
// y
for (theta=MATH_PIf/2.0f+dTheta;theta<=(3.0f*MATH_PIf)/2.0f-dTheta;theta+=dTheta)
{
vec3_t p;
float y = sin(theta);
// x-z
phi = 0.0f;
for( int j = 0; j<nSubdivsU; ++j )
{
p.x = cos(theta) * cos(phi);
p.y = y;
p.z = cos(theta) * sin(phi);
p = p*radius + center;
points.push_back( m->addPoint(p) );
phi+=dPhi;
}
}
Mesh::PointHandle pole1 = m->addPoint( math::Vec3f(0.0f, 1.0f, 0.0f)*radius + center );
Mesh::PointHandle pole2 = m->addPoint( math::Vec3f(0.0f, -1.0f, 0.0f)*radius + center );
points.push_back(pole1);
points.push_back(pole2);
// add faces
for( int j=0; j<nSubdivsV-3;++j )
{
int offset = j*(nSubdivsU);
int i = 0;
for( i=0; i<nSubdivsU-1; ++i )
{
m->addTriangle(points[offset+i+1], points[offset+i + nSubdivsU], points[offset+i]);
m->addTriangle(points[offset+i+1], points[offset+i+nSubdivsU+1], points[offset+i + nSubdivsU]);
}
m->addTriangle(points[offset+0],points[offset+i + nSubdivsU],points[offset+i]);
m->addTriangle(points[offset],points[offset + nSubdivsU],points[offset+i + nSubdivsU]);
}
for( int i=0; i<nSubdivsU-1; ++i )
{
m->addTriangle(points[i+1], points[i],pole1);
m->addTriangle(points[nSubdivsU*(nSubdivsV-3)+i], points[nSubdivsU*(nSubdivsV-3)+i+1], pole2);
}
m->addTriangle(points[0], points[nSubdivsU-1], pole1);
m->addTriangle(points[nSubdivsV*(nSubdivsV-2)-1], points[nSubdivsU*(nSubdivsV-3)], pole2);
return m;
}