本文整理汇总了C++中TriangleMesh::add_triangle方法的典型用法代码示例。如果您正苦于以下问题:C++ TriangleMesh::add_triangle方法的具体用法?C++ TriangleMesh::add_triangle怎么用?C++ TriangleMesh::add_triangle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TriangleMesh
的用法示例。
在下文中一共展示了TriangleMesh::add_triangle方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: read
//.........这里部分代码省略.........
}
tgl.push_back(Tuple3ui(sploosh::Int(ts0[0])-1,
sploosh::Int(ts1[0])-1,
sploosh::Int(ts2[0])-1));
if ( ts0.size() > 2 )
tNml.push_back(Tuple3ui(sploosh::Int(ts0[2])-1,
sploosh::Int(ts1[2])-1,
sploosh::Int(ts2[2])-1));
}
fin.getline(text, 1024);
++ l;
}
fin.close();
/* No triangles at all */
if ( tgl.empty() ) printf("THERE IS NO TRIANGLE MESHS AT ALL!\n");
/* Centerize the objects */
if ( centerize )
{
D3DXVECTOR3 maxPt(
-std::numeric_limits<float>::infinity(),
-std::numeric_limits<float>::infinity(),
-std::numeric_limits<float>::infinity()),
minPt(
std::numeric_limits<float>::infinity(),
std::numeric_limits<float>::infinity(),
std::numeric_limits<float>::infinity());
for(size_t i = 0;i < vtx.size();++ i)
{
maxPt.x = max(vtx[i].x, maxPt.x);
maxPt.y = max(vtx[i].y, maxPt.y);
maxPt.z = max(vtx[i].z, maxPt.z);
minPt.x = min(vtx[i].x, minPt.x);
minPt.y = min(vtx[i].y, minPt.y);
minPt.z = min(vtx[i].z, minPt.z);
}
D3DXVECTOR3 center = (maxPt + minPt) * 0.5;
for(size_t i = 0;i < vtx.size();++ i)
vtx[i] -= center;
}
if ( nml.empty() )
{
nml.resize(vtx.size());
for(size_t i = 0;i < tgl.size();++ i)
{
D3DXVECTOR3 v0 = vtx[tgl[i][0]];
D3DXVECTOR3 v1 = vtx[tgl[i][1]];
D3DXVECTOR3 v2 = vtx[tgl[i][2]];
D3DXVECTOR3 e0 = v1 - v0;
D3DXVECTOR3 e1 = v2 - v0;
D3DXVECTOR3 norm;
D3DXVec3Cross(&norm, &e0, &e1);
nml[tgl[i][0]] += norm;
nml[tgl[i][1]] += norm;
nml[tgl[i][2]] += norm;
}
for(size_t i = 0;i < nml.size();++ i)
{
if(D3DXVec3LengthSq(&nml[i]) == 0) nml[i] = D3DXVECTOR3(0, 1, 0);
D3DXVec3Normalize(&nml[i], &nml[i]);
}
for(size_t i = 0;i < vtx.size();++ i)
mesh.add_vertex_normal(vtx[i], nml[i]);
}
else
{
vector<D3DXVECTOR3> nmlmap(vtx.size(), D3DXVECTOR3(0,0,0));
for(size_t i = 0;i < tgl.size();++ i)
{
nmlmap[tgl[i][0]] += nml[tNml[i][0]];
nmlmap[tgl[i][1]] += nml[tNml[i][1]];
nmlmap[tgl[i][2]] += nml[tNml[i][2]];
}
for(size_t i = 0;i < vtx.size();++ i) {
D3DXVec3Normalize(&nmlmap[i], &nmlmap[i]);
mesh.add_vertex_normal(vtx[i], nmlmap[i]);
}
}
if ( reversetglrot )
for(size_t i = 0;i < tgl.size();++ i)
mesh.add_triangle(tgl[i][0], tgl[i][2], tgl[i][1]);
else
for(size_t i = 0;i < tgl.size();++ i)
mesh.add_triangle(tgl[i][0], tgl[i][1], tgl[i][2]);
return 0;
}