本文整理汇总了C++中Triangle3D::IntersectsXYPlane方法的典型用法代码示例。如果您正苦于以下问题:C++ Triangle3D::IntersectsXYPlane方法的具体用法?C++ Triangle3D::IntersectsXYPlane怎么用?C++ Triangle3D::IntersectsXYPlane使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Triangle3D
的用法示例。
在下文中一共展示了Triangle3D::IntersectsXYPlane方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GenerateSegments
int Slice::GenerateSegments(B9ModelInstance* inputInstance)
{
unsigned int t;
int v1;
int v2;
int cmpcount = 0;//0 or 1 来指示你所寻找的点;
QVector3D* thisvert = NULL;//局部指针进行快速访问顶点
QVector3D* thatvert = NULL;
std::vector<Triangle3D*>* rangedTriangles;
double xdisp;
double ydisp;
double zdisp;
double planefraction;
int intersections = 0;
//Triangle Splitting here:
//Get the right container of triangles and use that as the list
//(we used to use the triList which was O(n^2))
rangedTriangles = inputInstance->GetTrianglesAroundZ(realAltitude);
for(t = 0; t < rangedTriangles->size(); t++)//for each triangle in the model
{
//we want to create a temporary pointer to the currenct triangle
Triangle3D* pTransTri = rangedTriangles->at(t);
//test if the triangle intersects the XY plane of this slice!
if(!pTransTri->IntersectsXYPlane(realAltitude))
{
continue;
}
intersections++;
cmpcount = 0;
//create 1 new segment object for the end result
Segment* seg1 = new Segment;
QVector2D points[2];
for(v1=0;v1<3;v1++)//for 1 or 2 triangle verts ABOVE the plane:
{
thisvert = &pTransTri->vertex[v1];
if(thisvert->z() <= realAltitude)//we only want to compare FROM above the plane by convention (yes this means flush triangles below the plane)
{
continue;
}
for(v2=0; v2<3; v2++)//to every other triangle vert
{
if(v2 == v1)
{continue;}
thatvert = &pTransTri->vertex[v2];
//are both points on the same side of plane?
//if so we dont want to compare
if((thatvert->z() > realAltitude))
{
continue;
}
cmpcount++;
//common
//displacments (final - initial)
xdisp = thatvert->x() - thisvert->x();
ydisp = thatvert->y() - thisvert->y();
zdisp = thatvert->z() - thisvert->z();
planefraction = (thisvert->z() - realAltitude)/fabs(zdisp);//0-1 fraction of where the plane is in relation to the z distance between the 2 verts.
//(0 would be the plane is at the hieght of thisvert)
points[cmpcount-1].setX(thisvert->x() + xdisp*planefraction);
points[cmpcount-1].setY(thisvert->y() + ydisp*planefraction);
}
}
//initiallize the segment.
seg1->normal.setX(pTransTri->normal.x());
seg1->normal.setY(pTransTri->normal.y());
seg1->p1.setX(points[0].x());
seg1->p1.setY(points[0].y());
seg1->p2.setX(points[1].x());
seg1->p2.setY(points[1].y());
seg1->normal.normalize();
seg1->CorrectPointOrder();//to match the normal convention!
AddSegment(seg1);
}
return segmentList.size();
}