void CPolygon::GetRuleVertex()
{
RuleVertex.Create(1,3);
double x[3],y[3],z[3];
x[1]=Points[1].User3D[0][0]-Points[0].User3D[0][0];
y[1]=Points[1].User3D[0][1]-Points[0].User3D[0][1];
z[1]=Points[1].User3D[0][2]-Points[0].User3D[0][2];
x[2]=Points[PointNum-1].User3D[0][0]-Points[0].User3D[0][0];
y[2]=Points[PointNum-1].User3D[0][1]-Points[0].User3D[0][1];
z[2]=Points[PointNum-1].User3D[0][2]-Points[0].User3D[0][2];
x[0]=y[1]*z[2]-y[2]*z[1];
y[0]=z[1]*x[2]-z[2]*x[1];
z[0]=x[1]*y[2]-x[2]*y[1];
RuleVertex[0][0]=x[0];
RuleVertex[0][1]=y[0];
RuleVertex[0][2]=z[0];
}
然后用法向量和坐标原点到视点的向量相乘,判断是否为背面,判断结果保存在成员变量Back中。
void CPolygon::IfBack(double ViewerX,double ViewerY,double ViewerZ)
{
this->GetRuleVertex();
if((ViewerX*RuleVertex[0][0]+ViewerY*RuleVertex[0][1]+ViewerZ*RuleVertex[0][2])>0)
Back=FALSE;
else
Back=TRUE;
}
上一页 [1] [2] [3] [4] [5] [6] [7] [8] [9] 下一页