花了不少时间去实现了这个功能,大多问题都出现在低级错误,看来以后要提醒十二分精神!错误的原因是:
<span style="color: rgb(255, 255, 255); font-family: Arial; font-size: 14px; line-height: 22px;"> </span>void CTriangle2DUtils::DrawSolidGeneralClipZOrder( D3DXVECTOR3 p0, D3DXVECTOR3 p1, D3DXVECTOR3 p2, int color ) { if (p0.y > p1.y) Math3D::Swap(p0 , p1); if (p0.y > p2.y) Math3D::Swap(p0 , p2); if (p1.y > p2.y) Math3D::Swap(p2 , p1); if (p0.y > BTM_BORDER_SCR || p2.y < TOP_BORDER_SCR || (p0.x < LEFT_BORDER_SCR && p1.x < LEFT_BORDER_SCR && p2.x < LEFT_BORDER_SCR) || (p0.x > RIGHT_BORDER_SCR && p1.x > RIGHT_BORDER_SCR && p2.x > RIGHT_BORDER_SCR) ) return;//在可显区域外 //inv z p0.z = 1.0f / p0.z; p1.z = 1.0f / p1.z; p2.z = 1.0f / p2.z; if (FCMP( p0.x , p1.x ) && FCMP( p1.x, p2.x ) || FCMP( p0.y , p1.y ) && FCMP( p1.y, p2.y ) ) {//绘制退化直线 DrawDeclineClip(p0 , p1, p2 , color); } else if (FCMP( p0.y , p1.y ) ) { CTriangle2DUtils::DrawSolidFlatTopClipZOrder(p0 , p1, p2, color); } else if ( FCMP( p1.y , p2.y ) ) { CTriangle2DUtils::DrawSolidFlatBottomClipZOrder(p0 , p1, p2, color); } else { //had inve z float dzdy = (p2.z - p0.z ) / (p2.y - p0.y); //float newz = dzdy * (p2.y - p0.y) + p0.z;---------------就这里没有改回来导致了z排序错误 float newz = dzdy * (p1.y - p0.y) + p0.z;//应该改成这样--------------- //float newzInv = 1.0f / newz; D3DXVECTOR3 pc( LINE_X_NOF(p0.x, p0.y, p2.x, p2.y, p1.y) , p1.y , newz); CTriangle2DUtils::DrawSolidFlatBottomClipZOrder(p0 , p1, pc, color); CTriangle2DUtils::DrawSolidFlatTopClipZOrder(p1 , pc, p2, color); } }
时间: 2024-10-14 06:44:57