青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

Code Knight

Programming is so cool
隨筆 - 52, 文章 - 0, 評論 - 14, 引用 - 0
數據加載中……

Introduction To Octrees

Introduction


Hidden surface removal is among the biggest problems when writing a 3D engine.

I struggled with it since the very beginning of writing 3D engines and still have no satisfactory solution to it. The ideal visibility detection scheme would allow unlimited data, extremely dynamic worlds and would have zero overdraw. The first 3d engine which implements these three demands still has to be written.

The Z buffer for example allows dynamical worlds and even crossing faces, but it suffers from immense overdraw. The BSP-tree on the other hand, if well implemented, has no overdraw at all but needs that much pre-processing that dynamical worlds are a definite nono.

It wasn't until recently i first heard of the octree, and I must admit i was struck by it's simplicity. I never actually implemented this structure and therefore I will present no pseudo code at all. This explanation is merely an attempt to make it more clear to people who have never heard of it. Besides, if you really understand the structure, then implementation is a piece of cake.


The Octree Structure


Our virtual world or level is actually nothing more then a soup of polygons. Some of you people might have thrown in a couple of curves and voxels but most of it will be polygons. Here it is:



Fig 1. Our little level.


In the picture I just built a simple level containing no more than 250 polys. Now imagine a cube surrounding the world like in the next image:



Fig. 2. Our little level surrounded by a cube.


Now it isn't hard to see that this cube can be divided into eight smaller cubes, hence the name octree. Take a look at this picture:



Fig 3. Our little level with the surrounding cube subdivided.


Call the larger cube the parent and the smaller cubes the children. On their turn subdivide each children into eight smaller cubes, and you will notice we are creating a tree where each node has eight children.

There is still one little problem left. When should we stop dividing cubes into smaller ones? There are two possible solutions. The first one is to stop when a cube has some size smaller then a fixed number. The second one is more common. You might have noticed that every child has less polygons then it's parent. The trick is to stop subdividing when the number of polygons in a cube is smaller then some fixed number.


Creating The Octree


Trees are recursion, recursion is trees. It is as simple as that. If you have a correct definition of you cubeNode it is very easy to create an octree recursively. First of all you check all polygons against the boundarys of the cube. This is very simple cause these boundaries are all axis aligned. This means that the cube has six plane equations, which are:

  • 1. X = Q.X
  • 2. Y = Q.Y
  • 3. Z = Q.Z

  • 4. X = Q.X + cubeSize
  • 5. Y = Q.Y + cubeSize
  • 6. Z = Q.Z + cubeSize

    Where Q is the position of one corner of the cube. This are very easy equations and the all parent polygons can very easily be checked against them.

    It could occur that a polygon crosses a cube boundary. Again two possible solution are at hand. First of all we could clip the polygon against the cube, which is simple, because of the axis aligned boundarys. On the other hand we could put the polygon in all cubes it is in. This means that some cubes can contain the same polygons. In order to prevent us from drawing one poly more than one time we should have a flag on each polygon which will be set if the poly is drawn for the first time.

    The implementation of an octree is very straight forward. I haven't done it myself yet, but I will soon. It is all matter of recursion. In order to construct a tree, the first thing you should think of is recursion. Whether we are talking about binary trees, quad trees or octrees, it doesnt matter, just build the darn thing recursively. So have a class definition of one cubeNode and put the creation of the tree in it's constructor. In this constructor you will call the constructor itself for smaller cubes.


  • The Purpose Of The Octree


    An octree is actually nothing more then a data structure. It can be used for very different things. It is not only handy for visibility detection but also for collision detection, realtime shadows and many more things. The most important thing to understand about octrees is that if a parent is not important then it's children aren't either. Let's makes this a little bit more clear with an example.

    We will do this in 2d, which therefore resembles a quadtree, but with some imagination it can very easily be extended to 3d. Here we test the cubes (squares) against the viewing frustrum. Take a look at the next picture:



    Fig 4. An octree from the top and a viewing frustrum.


    In this picture a colored square that has one color was dumped without checking it?s children. As you can see some squares had to be checked all the way to the final node, but some large squares could be dumped at once. The colored squares are the ones that are outside the viewing frustrum and the greyscale ones are the one inside the viewing frustrum. As you can see this is actually a worst case scenario because the viewing frustrum crosses the middle of the surrounding square and therefore all the four children have to be checked.

    You could also apply the octree to many other things. Collision detection for example. Just check in which cube your bounding sphere or box is and you will only have to check against those faces. There are many more examples.


    Conclusion


    There is already a lot written about octrees. I tried to give my view on them in the hope somebody might read this. As you can see octrees are way easier to implement than BSP-trees (although some disagree) while offering a better structure. The main point about an octrees is that when a parent is discarded so are it's children. Actually that is all there is to it.

    Code clean, play Goldeneye and go vegetarian.

    Jaap Suter a.k.a .........

    譯文:
    1、引言Introduction
      隱面移除是寫3D引擎時候最大的問題之一。
      Hidden surface removal is among the biggest problems when writing a 3D engine.

      在我寫3D引擎的開始階段就開始和它斗爭并且一直沒有滿意的解決方法。理想的可見檢測方案應當做到允許(使用)無限的數據、大動態的世界和零重畫。第一流的3D引擎一直在追求實現這3個要求。
      I struggled with it since the very beginning of writing 3D engines and still have no satisfactory solution to it. The ideal visibility detection scheme would allow unlimited data, extremely dynamic worlds and would have zero overdraw. The first 3d engine which implements these three demands still has to be written.

      Z buffer允許動態世界以及即使是交叉的面,但是得忍受大量的重畫。另一方面,BSP樹如果能夠被很好的實現,可以避免重畫,但是它需要大量的預處理計算而且不適合動態世界。
      The Z buffer for example allows dynamical worlds and even crossing faces, but it suffers from immense overdraw. The BSP-tree on the other hand, if well implemented, has no overdraw at all but needs that much pre-processing that dynamical worlds are a definite nono.

      直到最近我第一次聽說了八叉樹(Octree),我必須承認我被它的簡易性“狠狠地打了一下兒”。我從來沒有真正地去實現這個結構,因此我不會去實現一些代碼。這個解釋只是想讓從沒有聽說過八叉樹的人感到更清晰易懂。如果你真的了解了這個結構(Octree),實現它只是一個小意思。
      It wasn't until recently i first heard of the octree, and I must admit i was struck by it's simplicity. I never actually implemented this structure and therefore I will present no pseudo code at all. This explanation is merely an attempt to make it more clear to people who have never heard of it. Besides, if you really understand the structure, then implementation is a piece of cake.

    2、八叉樹的結構The Octree Structure
      我們的實際‘世界’或者說是關卡只不過是一些多邊形。你們或許在其中加入了一些曲面(Curves)和Voxels(地形實現方法的一種),但是大多數也都是多邊形。
      Our virtual world or level is actually nothing more then a soup of polygons. Some of you people might have thrown in a couple of curves and voxels but most of it will be polygons. Here it is:

    圖1

      圖1:我們設計的小型關卡。
      Fig 1. Our little level.

      在這張圖片中我建立了一個不超過250個多邊形的‘關卡’。現在想象有一個包圍了這個世界的立方體,像下一張圖片那樣。
      In the picture I just built a simple level containing no more than 250 polys. Now imagine a cube surrounding the world like in the next image:

    圖2

      圖2:我們設計的關卡被一個立方體所包圍著。
      Fig. 2. Our little level surrounded by a cube.

      現在不難看出這個立方體可以被八等分為八個小些的立方體,所以才叫八叉樹。看看這張圖:
      Now it isn't hard to see that this cube can be divided into eight smaller cubes, hence the name octree. Take a look at this picture:

    圖3

      圖3:對圍繞著關卡的立方體進行細分。
      Fig 3. Our little level with the surrounding cube subdivided.

      大點兒的這個立方體被叫做‘父親’小些的立方體叫做‘孩子’。處理每個‘孩子’的時候,再為更小的八個立方體,你會發現我們在創建一個每個節點有八個子節點(孩子)的樹。
      Call the larger cube the parent and the smaller cubes the children. On their turn subdivide each children into eight smaller cubes, and you will notice we are creating a tree where each node has eight children.

      還有一個小問題。什么時候我們該結束細分的過程呢?有兩個可行的解決方法。第一個是當一個立方體的尺寸已經比一個預定的固定值小的時候。第二個更普通。你可以注意到每個‘孩子’都比他的‘父親’有更少的多邊形。這就是說:當一個立方體包含的多邊形數量比一個預定的固定值少的時候停止細分。
      There is still one little problem left. When should we stop dividing cubes into smaller ones? There are two possible solutions. The first one is to stop when a cube has some size smaller then a fixed number. The second one is more common. You might have noticed that every child has less polygons then it's parent. The trick is to stop subdividing when the number of polygons in a cube is smaller then some fixed number.

    3、創建八叉樹Creating The Octree
      樹是遞歸的,遞歸的是樹。就那么簡單。如果你正確的定義了你的立方體節點,那么遞歸地創建一個八叉樹是很容易的。首先,檢查所有的多邊形(多邊形上位置最外面的點作為)立方體的邊界。這很簡單因為所有邊界都是和坐標軸對其的。這意味著立方體有六個平面方程,分別是:
      Trees are recursion, recursion is trees. It is as simple as that. If you have a correct definition of you cubeNode it is very easy to create an octree recursively. First of all you check all polygons against the boundarys of the cube. This is very simple cause these boundaries are all axis aligned. This means that the cube has six plane equations, which are:
    • 1. X = Q.X
    • 2. Y = Q.Y
    • 3. Z = Q.Z

    • 4. X = Q.X + cubeSize
    • 5. Y = Q.Y + cubeSize
    • 6. Z = Q.Z + cubeSize
      在這里Q是立方體一個頂角的位置。這是個很簡單的方程,而且所有的父親多邊形可以容易地用這些方程來檢測。
      WhereQ is the position of one corner of the cube. This are very easy equations and the all parent polygons can very easily be checked against them.

      一個多邊形穿過了一個立方體邊界這樣的事情是會發生的。再一次,有兩個解決方案可用。首先我們可以沿著立方體剪切這個多邊形,這也是很簡單的,因為(立方體的)邊界是與坐標軸對齊的。還有,我們可以把一個多邊形放在所有它所在的立方體里面。這就意味著一些立方體可能包含著同一個多邊形。為了防止重畫一個多邊形,我們應當在每一個多邊形上做一個標記,當多邊形第一次被畫的時候,設置這個標記(當然畫之前也要檢查這個標記啦,不過肯定影響效率。
      It could occur that a polygon crosses a cube boundary. Again two possible solution are at hand. First of all we could clip the polygon against the cube, which is simple, because of the axis aligned boundarys. On the other hand we could put the polygon in all cubes it is in. This means that some cubes can contain the same polygons. In order to prevent us from drawing one poly more than one time we should have a flag on each polygon which will be set if the poly is drawn for the first time.

      實現一個八叉樹是很簡單明了的事情,我還沒有自己做過,但是我不久會做的。只不過是遞歸而已。為了構造一個樹,第一件你該想的事情就是遞歸。不管我們討論的是二叉、四叉還是八叉樹,都沒有區別,都是遞歸的方法。所以定義一個立方體節點的類,在構造函數里面寫上創建樹的代碼。在這個構造函數里面,你會調用到更小立方體的構造函數。
      The implementation of an octree is very straight forward. I haven't done it myself yet, but I will soon. It is all matter of recursion. In order to construct a tree, the first thing you should think of is recursion. Whether we are talking about binary trees, quad trees or octrees, it doesnt matter, just build the darn thing recursively. So have a class definition of one cubeNode and put the creation of the tree in it's constructor. In this constructor you will call the constructor itself for smaller cubes.

    4、八叉樹的用途The Purpose Of The Octree
      一個八叉樹實際上就是一個數據結構。它可以用做不同的事情。不僅僅對于‘可見檢測’來說很方便,還有實時陰影以及其它方面。理解八叉樹過程中最重要的事情是:如果一個‘父親’節點是‘沒用’的,那么他的‘孩子’節點也同樣。讓我們舉個例子讓它更清楚。
      An octree is actually nothing more then a data structure. It can be used for very different things. It is not only handy for visibility detection but also for collision detection, realtime shadows and many more things. The most important thing to understand about octrees is that if a parent is not important then it's children aren't either. Let's makes this a little bit more clear with an example.

      我們用2D來表示它,這樣就很像一個四叉樹,但是想象一下它也可以很容易的擴展到3D上。在這里我們沿著視錐(viewing frustrum)檢測立方體(正方形)。
      We will do this in 2d, which therefore resembles a quadtree, but with some imagination it can very easily be extended to 3d. Here we test the cubes (squares) against the viewing frustrum. Take a look at the next picture:

    圖4

      圖4:頂部視錐內的八叉樹。
      Fig 4. An octree from the top and a viewing frustrum.

      在這個圖片中,彩色的正方形是沒有(沒必要)檢測它的‘孩子’的。就像你看到的那樣一些正方形(灰色的一些)被檢測直到最終節點,但是一些大的正方形只被涂了一種顏色。那些彩色的正方形就是超出了視錐范圍的,灰色的是在視錐范圍內的。就像你看到的那樣,這確實是最糟糕的一種情況,因為視錐穿過了包圍正方形的中央,所以所有的四個‘孩子’都得被檢測。
      In this picture a colored square that has one color was dumped without checking it抯 children. As you can see some squares had to be checked all the way to the final node, but some large squares could be dumped at once. The colored squares are the ones that are outside the viewing frustrum and the greyscale ones are the one inside the viewing frustrum. As you can see this is actually a worst case scenario because the viewing frustrum crosses the middle of the surrounding square and therefore all the four children have to be checked.

      你可以應用八叉樹到很多別的地方。例如碰撞檢測。只檢查你的碰撞球或者碰撞盒子所在的立方體,而且只需要檢測那些面。還有更多的例子。
      You could also apply the octree to many other things. Collision detection for example. Just check in which cube your bounding sphere or box is and you will only have to check against those faces. There are many more examples.

    5、結論Conclusion
      關于八叉樹已經寫了很多了。我設法表述自己對它的看法,并且希望有人會讀到它。就像你看到的那樣,當提供好的結構的時候,八叉樹比BSP樹更容易實現(有人持異議)。主要的一點是:當一個‘父親’節點被丟棄的時候,他的‘孩子’節點也同樣被丟棄。實際上這就是全部。
      There is already a lot written about octrees. I tried to give my view on them in the hope somebody might read this. As you can see octrees are way easier to implement than BSP-trees (although some disagree) while offering a better structure. The main point about an octrees is that when a parent is discarded so are it's children. Actually that is all there is to it.
      Code clean, play Goldeneye and go vegetarian. Jaap Suter a.k.a .........

    posted on 2010-02-23 21:18 Code Knight 閱讀(477) 評論(0)  編輯 收藏 引用 所屬分類: 圖形學

    青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            欧美激情精品久久久久久变态| 亚洲高清视频在线| 久久国产乱子精品免费女| 一本综合久久| 亚洲女女女同性video| 亚洲在线成人| 欧美伊人久久久久久久久影院| 久久福利资源站| 美女日韩欧美| 欧美午夜国产| 亚洲一区在线观看视频| 国产一区二区三区久久 | 亚洲精品免费在线播放| 最近中文字幕mv在线一区二区三区四区| 亚洲高清三级视频| 亚洲小少妇裸体bbw| 欧美在线高清视频| 欧美韩日精品| 国产婷婷一区二区| 99热精品在线观看| 久久久午夜电影| 亚洲日本电影在线| 性做久久久久久久久| 欧美激情免费观看| 国产一区二区电影在线观看| 亚洲精品视频在线播放| 久久国产一区二区| 99视频精品全国免费| 久久综合99re88久久爱| 国产精品裸体一区二区三区| 亚洲国产美女| 久久久www| 亚洲性感激情| 欧美亚一区二区| 亚洲精品国精品久久99热| 久久成人精品一区二区三区| 日韩视频在线播放| 欧美成人免费在线| 狠狠色综合色区| 欧美一区二区三区视频在线观看 | 美女图片一区二区| 国产一区亚洲| 欧美影院成人| 中文亚洲欧美| 欧美日韩国产一区精品一区| 亚洲日本激情| 欧美激情片在线观看| 久久国产日韩| 国产亚洲综合精品| 久久国产精品99国产精| 亚洲香蕉成视频在线观看 | 亚洲高清不卡在线| 久久婷婷国产麻豆91天堂| 午夜精品久久久久| 国产精品资源| 欧美一级专区免费大片| 亚洲永久在线| 国产亚洲成年网址在线观看| 久久精品国产亚洲精品| 欧美亚洲一区三区| 亚洲女人天堂成人av在线| 亚洲激情成人网| 久久久久久久久伊人| 亚洲欧美bt| 国产亚洲激情视频在线| 久久精品首页| 久久综合影视| 日韩亚洲在线观看| 一本一本久久| 国产视频欧美视频| 免费亚洲婷婷| 欧美精品亚洲一区二区在线播放| 一区二区精品在线| 亚洲一区二区少妇| 国内成人精品视频| 亚洲第一天堂av| 欧美日韩在线免费| 欧美一级淫片播放口| 久久精品日韩| 日韩一区二区精品葵司在线| 日韩一级不卡| 国产在线日韩| 亚洲国产成人91精品| 国产精品va在线播放| 久久乐国产精品| 欧美激情精品久久久久久蜜臀| 亚洲尤物视频在线| 久久亚洲春色中文字幕| 一区二区欧美日韩| 亚洲欧美日产图| 亚洲欧洲一区二区三区久久| 99国产精品久久久| 激情文学综合丁香| 日韩午夜三级在线| 一区二区在线视频观看| 99v久久综合狠狠综合久久| 国产午夜精品理论片a级大结局 | 亚洲精品日韩在线观看| 亚洲午夜视频在线观看| 亚洲国产日韩欧美在线图片| 亚洲午夜久久久| 亚洲精品女人| 久久免费的精品国产v∧| 亚洲一区二区欧美| 美日韩精品免费观看视频| 午夜精品成人在线视频| 美日韩精品视频| 久久精品国产精品亚洲精品| 欧美精品久久久久久久久久| 久久久www| 国产精品外国| 99re66热这里只有精品4| 在线日韩精品视频| 午夜一级久久| 午夜国产精品影院在线观看| 欧美成人一区在线| 校园春色国产精品| 欧美成人69| 免费亚洲电影在线观看| 亚洲综合首页| 日韩网站在线| 在线观看亚洲专区| 性欧美8khd高清极品| 亚洲一区二区精品| 欧美激情一区| 欧美激情视频一区二区三区免费| 狠狠色丁香婷婷综合| 亚洲综合色婷婷| 性欧美在线看片a免费观看| 欧美日韩一区二区三区| 亚洲国产精品一区二区www在线 | 欧美韩日视频| 亚洲国产成人在线播放| 亚洲丁香婷深爱综合| 久久国产精品毛片| 久久久www成人免费精品| 国内精品视频一区| 性做久久久久久久免费看| 久久精品一区蜜桃臀影院 | 亚洲国产岛国毛片在线| 久久深夜福利免费观看| 久久人人超碰| 亚洲电影免费观看高清完整版在线观看| 欧美在线视频二区| 久久综合伊人| 亚洲精品久久7777| 欧美日韩成人免费| 亚洲女人天堂av| 久久人人超碰| 日韩视频―中文字幕| 欧美日韩免费| 亚洲午夜影视影院在线观看| 性做久久久久久| 激情丁香综合| 欧美高清在线一区| 亚洲视频1区2区| 久久久人成影片一区二区三区观看| 精品99一区二区| 欧美激情在线播放| 亚洲专区一区二区三区| 久久综合久久美利坚合众国| 最新国产乱人伦偷精品免费网站| 欧美人成网站| 香蕉久久夜色精品国产| 欧美jjzz| 亚洲欧美日韩国产另类专区| 狠狠v欧美v日韩v亚洲ⅴ| 欧美不卡激情三级在线观看| 夜夜嗨av一区二区三区网页 | aⅴ色国产欧美| 欧美在线免费视屏| 亚洲福利视频一区| 国产精品亚洲综合久久| 欧美v日韩v国产v| 午夜精品理论片| 亚洲日韩视频| 久久精品国产免费观看| 亚洲精品女人| 国产一区亚洲| 欧美日韩中文在线| 久久久久久噜噜噜久久久精品| 99re66热这里只有精品4| 久久阴道视频| 午夜亚洲伦理| 一区二区三区精品视频| 在线观看欧美| 亚洲午夜极品| 国产精品xxxav免费视频| 久久久精品欧美丰满| 亚洲午夜久久久| 亚洲国产日韩综合一区| 久久国产一区二区三区| 夜夜嗨av色一区二区不卡| 影音先锋亚洲电影| 国产欧美日韩一区二区三区在线观看 | 亚洲视频中文| 亚洲精品一区二区三区四区高清| 精品不卡一区| 韩国三级在线一区| 国产亚洲免费的视频看|