對glClipPlane平面方程參數的求解

來源:互聯網
上載者:User

    glClipPlane對裁剪frustum還是很管用的,可進一步定義視圖體的範圍。裁剪平面由方程Ax+By+Cz+D=0確定。所有滿足[A B C D]M-1[Xe Ye Ze We]T>0的人眼座標[Xe Ye Ze We]的點都位於該平面定義的半空間中,而該半空間以外的所有點都被裁剪掉——摘自Redbook。

    在我之前寫的reflection就可以用此函數裁剪掉穿過floor的物體,那時還不知道如何確定方程的參數,現在有法子了呵呵。聲明,網上找的。

void findPlane(GLfloat plane[4], CVector3D& p1, CVector3D& p2, CVector3D& p3)
{

/* Need 2 vectors to find cross product. */
 CVector3D vec1, vec2;
 vec1.SetValue(p2.dx-p1.dx, p2.dy-p1.dy, p2.dz-p1.dz);
 vec2.SetValue(p3.dx-p1.dx, p3.dy-p1.dy, p3.dz-p1.dz);

/* find cross product to get A, B, and C of plane equation */

 plane[A] = vec1.dy * vec2.dz - vec1.dz * vec2.dy;
 plane[B] = -(vec1.dx * vec2.dz - vec1.dz * vec2.dx);
 plane[C] = vec1.dx * vec2.dy - vec1.dy * vec2.dx;
 plane[D] = -(plane[0]*p1.dx + plane[1]*p1.dy + plane[2]*p1.dz);

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.