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

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個多邊形的‘關卡’?,F在想象有一個包圍了這個世界的立方體,像下一張圖片那樣。
      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 閱讀(475) 評論(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>
            99精品欧美一区| 悠悠资源网亚洲青| 在线一区二区三区四区| 亚洲韩国青草视频| 欧美88av| 中国亚洲黄色| 午夜在线观看欧美| 韩国一区二区三区在线观看| 免费亚洲电影在线| 欧美成人免费全部| 一区二区免费在线播放| 亚洲一区激情| 狠狠色综合网| 亚洲精品女av网站| 欧美日韩美女在线观看| 亚洲午夜极品| 久久精品国产99| 一级成人国产| 欧美在线观看网址综合| 亚洲片在线资源| 亚洲男人的天堂在线aⅴ视频| 狠狠色丁香久久婷婷综合丁香| 欧美激情 亚洲a∨综合| 国产精品乱人伦一区二区 | 欧美日韩另类综合| 欧美一区免费| 欧美/亚洲一区| 午夜日韩在线| 免费国产自线拍一欧美视频| 亚洲欧美日韩精品综合在线观看| 久久激情五月激情| 亚洲一区二区视频在线观看| 久久全国免费视频| 亚洲午夜激情网站| 欧美国产精品一区| 久久gogo国模裸体人体| 欧美激情一区在线观看| 欧美资源在线观看| 欧美三级网址| 亚洲国产精品一区二区www在线| 国产精品自拍在线| 亚洲美女诱惑| 亚洲国产欧美一区二区三区久久 | 亚洲一区观看| 欧美久久久久久久久| 久久亚洲春色中文字幕| 国产精品成人一区二区三区吃奶| 欧美成人精品1314www| 国产欧美一区二区三区久久人妖| 亚洲精品欧美| 日韩午夜激情电影| 麻豆精品精品国产自在97香蕉| 久久aⅴ国产欧美74aaa| 欧美视频三区在线播放| 亚洲黑丝在线| 亚洲日本激情| 欧美大胆成人| 亚洲国产高清在线观看视频| 精品成人a区在线观看| 欧美专区在线| 久久久久久国产精品一区| 国产精品视频xxx| 亚洲一区二区三区三| 亚洲永久在线| 国产精品区二区三区日本| a91a精品视频在线观看| 一本一本久久a久久精品综合妖精 一本一本久久a久久精品综合麻豆 | 久热国产精品视频| 女生裸体视频一区二区三区 | 欧美日韩国产综合网| 亚洲国产精品va在看黑人| 亚洲日本va午夜在线电影| 欧美激情亚洲视频| 亚洲乱码国产乱码精品精| 亚洲欧美日产图| 国产精品一区二区视频| 欧美一区二区三区免费视频| 久久男人资源视频| 亚洲国产成人精品女人久久久| 久久资源av| 亚洲激情一区二区三区| 99亚洲一区二区| 国产精品久久久久久久久动漫| 亚洲欧美国产制服动漫| 久久久久久尹人网香蕉| 亚洲国产欧美一区二区三区丁香婷| 欧美国产精品中文字幕| 国产精品99久久不卡二区| 欧美一区二区三区的| 激情综合久久| 欧美日韩免费一区二区三区视频 | 亚洲国产成人久久综合一区| 亚洲视频大全| 国产三级欧美三级| 美日韩精品视频免费看| 99pao成人国产永久免费视频| 欧美亚洲一区二区三区| 亚洲韩国日本中文字幕| 欧美视频一区二区三区| 久久精品视频免费观看| 亚洲美女在线国产| 你懂的成人av| 性欧美激情精品| 亚洲激情综合| 国产精品永久免费观看| 免费短视频成人日韩| 亚洲欧美美女| 亚洲人成精品久久久久| 久久久欧美精品sm网站| 一区二区三区视频观看| 激情综合网址| 国产精品爽黄69| 欧美成人资源| 久久精品亚洲精品国产欧美kt∨| 亚洲精品乱码久久久久久日本蜜臀 | 国产精品久久久久久久9999| 久久久亚洲综合| 亚洲一区美女视频在线观看免费| 欧美激情精品久久久久久大尺度| 欧美在线视频一区二区| 夜夜爽99久久国产综合精品女不卡| 国产一区二区三区高清在线观看| 欧美三级视频| 欧美 日韩 国产一区二区在线视频 | 一区二区三区高清| 欧美激情一级片一区二区| 久久aⅴ乱码一区二区三区| 亚洲无线观看| 一本色道久久综合狠狠躁篇怎么玩 | 欧美男人的天堂| 美乳少妇欧美精品| 久久久久网址| 久久精品视频免费播放| 欧美中文日韩| 欧美一区二区三区四区在线观看| 国产精品99久久久久久白浆小说| 日韩亚洲欧美精品| 亚洲欧洲精品一区二区三区| 欧美国内亚洲| 亚洲国产精品欧美一二99| 美玉足脚交一区二区三区图片| 久久久久久伊人| 六月天综合网| 欧美丰满高潮xxxx喷水动漫| 免费成人激情视频| 欧美~级网站不卡| 美女爽到呻吟久久久久| 欧美91精品| 亚洲国产成人久久| 9国产精品视频| 午夜精彩视频在线观看不卡 | 欧美日韩日本国产亚洲在线| 欧美裸体一区二区三区| 欧美日韩免费区域视频在线观看| 欧美午夜精品理论片a级大开眼界| 国产精品久久久久久久电影 | 欧美激情第3页| 欧美区一区二| 国产精品va在线播放| 国产精品入口夜色视频大尺度| 国产精品视频一| 精品91在线| 99热在线精品观看| 亚洲欧美日韩精品在线| 老司机一区二区| 91久久精品国产91久久性色| 中文日韩电影网站| 欧美与黑人午夜性猛交久久久| 老司机精品视频一区二区三区| 欧美激情麻豆| 国产欧美日韩91| 亚洲国产精品va在线看黑人动漫| 亚洲免费观看高清完整版在线观看熊| 亚洲五月六月| 久久久www| 亚洲精品资源美女情侣酒店| 校园春色国产精品| 欧美激情第五页| 国产亚洲欧洲997久久综合| 亚洲欧洲一区二区天堂久久| 亚洲欧美日韩国产一区| 欧美大成色www永久网站婷| 一本色道久久综合亚洲精品小说 | 国产永久精品大片wwwapp| 亚洲人午夜精品免费| 久久精品国产96久久久香蕉| 亚洲国产免费| 羞羞视频在线观看欧美| 欧美成人精品h版在线观看| 国产精品揄拍一区二区| 日韩视频在线你懂得| 久久精品动漫| 一本色道综合亚洲| 乱中年女人伦av一区二区| 国产区欧美区日韩区| 一区二区三区日韩精品视频| 欧美a级片网站| 欧美一级电影久久| 国产精品盗摄久久久| 99亚洲一区二区|