Just My Life & My Work

這篇來講使用二元空間分割樹 (Binary Space Partitioning Tree)如何來畫一個場景,接續我撰寫的二元空間分割樹 (Binary Space Partitioning Tree)

以下是利用BSP tree來畫場景的演算法:

Algorithm backTofrontRender(bspRoot node, viewPoint view)
Input: bspRoot node, the root node of a pre-constructed, pre-sorted
           binary search partition tree, representing the scene to be
           rendered viewpoint v, the (x,y) coordinates of a viewpoint
           in 2D space or the (x,y,z) coordinates of a viewpoint in 3D
           space
Output: a drawing (rendering) of the scene which is represented by the
            binary space partition tree

backToFrontRender(node, view){

   if node is a leaf {
       draw this node to the screen }
   else
   determine on which side of the dividing line the viewpoint is 
      if the viewpoint is in back of the dividing line {
          render(right subnode)
          draw node to screen
          render(left subnode) }
      else the viewpoint is in front of the dividing line so draw
          everything behind that line first
         {  render (left subnode)
            draw node to screen
            render (right subnode) }
}

這是我們最後畫出來的影像。

將平面牆當成一直線。

事先建立好的BSP tree。

由演算法可知,繪圖順序:F2→E→D→B→A→C→G→F1→H。這裡還沒有去除不可見的牆,因此依舊畫不可見的牆,從遠而近畫上去。BSP演算法解決Painter’s Algorithm無法排序交錯幾何的問題,而Z buffer Algorithm可去除不可見的幾何。

參考:Binary Space Partitioning

Comments on: "二元空間分割樹2 (Binary Space Partitioning Tree2)" (1)

  1. 未知 的大頭貼

    […] (Binary space partitioning)和二元空間分割樹2 (Binary space partitioning2),這裡以遊戲設計的角度談兩種方式來做二元空間分割樹:對齊軸 […]

隨意留個言吧:)~

這個網站採用 Akismet 服務減少垃圾留言。進一步了解 Akismet 如何處理網站訪客的留言資料

標籤雲