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

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>
            极品尤物一区二区三区| 久久久欧美一区二区| 国产精品青草久久| 国产精品av久久久久久麻豆网| 欧美黄色免费网站| 欧美成人一区二区三区片免费| 美女免费视频一区| 欧美日本一区二区三区| 国产精品久久久久久久久久久久久| 国产精品美女xx| 国语自产精品视频在线看一大j8 | 玖玖国产精品视频| 欧美ed2k| 一区二区三区日韩欧美| 亚洲免费在线视频一区 二区| 先锋影音久久| 嫩草国产精品入口| 欧美日韩一区二区免费视频| 国产欧美精品一区aⅴ影院| 樱桃国产成人精品视频| 一区二区三区欧美在线观看| 欧美一区二区三区婷婷月色 | 激情久久久久久久| 亚洲欧洲一区| 欧美一区二区视频在线观看| 蜜桃伊人久久| 99精品黄色片免费大全| 欧美在线看片a免费观看| 欧美国产日韩一区二区在线观看 | 久久免费国产精品| 欧美日韩亚洲一区二区三区四区| 国产一二精品视频| 在线一区日本视频| 牛牛影视久久网| 亚洲午夜激情网站| 欧美国产另类| 在线欧美视频| 久久精品噜噜噜成人av农村| 日韩视频在线观看国产| 久久夜色精品国产欧美乱| 国产精品99免视看9| 最新日韩av| 蜜臀久久99精品久久久久久9| 亚洲无毛电影| 欧美日韩国产一区二区三区地区| 伊人精品久久久久7777| 欧美在线视频导航| 亚洲性图久久| 欧美日韩一级大片网址| 亚洲人成艺术| 欧美暴力喷水在线| 久久久精品免费视频| 国产日韩在线不卡| 欧美一级久久久| 一本色道久久综合亚洲精品高清 | 欧美电影在线观看完整版| 国产拍揄自揄精品视频麻豆| 亚洲欧洲av一区二区| 日韩一级精品| 欧美体内she精视频| 亚洲深夜福利网站| 在线视频日韩精品| 国产精品色午夜在线观看| 午夜精品短视频| 亚洲欧美中日韩| 国产亚洲综合精品| 麻豆精品在线观看| 噜噜爱69成人精品| 亚洲国产裸拍裸体视频在线观看乱了中文| 久久精品色图| 久久色在线播放| 亚洲欧洲日产国码二区| 亚洲黄色在线观看| 欧美成人一二三| 99精品国产在热久久下载| 亚洲精品一区中文| 亚洲欧美国产77777| 欧美一区二区在线观看| 国产一区二区三区久久久| 久久久久女教师免费一区| 久久久久久日产精品| 亚洲高清一区二| 欧美激情免费在线| 欧美日韩精品不卡| 欧美专区中文字幕| 免费欧美日韩| 亚洲一区二区高清| 久久激情视频免费观看| 亚洲精品国精品久久99热| 一区二区高清| 黄色欧美日韩| 亚洲人成网站在线观看播放| 欧美日韩一区二区高清| 欧美专区一区二区三区| 男同欧美伦乱| 午夜在线a亚洲v天堂网2018| 久久精品国产清高在天天线| 最新国产拍偷乱拍精品| 亚洲一区欧美二区| 亚洲激情中文1区| 亚洲视频专区在线| 亚洲国产欧美一区二区三区久久 | 欧美视频在线免费看| 久久久精品久久久久| 农夫在线精品视频免费观看| 亚洲欧美在线aaa| 蜜桃久久av一区| 久久国产精品毛片| 欧美日韩中文字幕精品| 欧美69wwwcom| 国产亚洲欧美一区二区| 一区二区国产在线观看| 亚洲经典自拍| 久久国产夜色精品鲁鲁99| 在线亚洲精品| 欧美激情在线播放| 久久成人人人人精品欧| 久久久久久尹人网香蕉| 欧美日韩视频第一区| 免费观看一级特黄欧美大片| 国产精品欧美一区二区三区奶水| 亚洲第一偷拍| 亚洲二区在线视频| 久久不见久久见免费视频1| 亚洲女优在线| 国产精品xxxxx| 99日韩精品| 中文日韩在线视频| 欧美日韩国产页| 亚洲免费成人av| 一个人看的www久久| 猛干欧美女孩| 欧美成人一区在线| 亚洲高清精品中出| 久久精品欧美日韩| 美女视频一区免费观看| 尤物精品在线| 久久夜色精品国产欧美乱极品| 99热免费精品| 在线免费不卡视频| 午夜精品久久久久久99热软件 | 欧美在线免费观看视频| 国产精品日韩专区| 亚洲永久精品大片| 久久精品99国产精品日本| 国产一区二区精品在线观看| 欧美一站二站| 免费看av成人| 亚洲人午夜精品| 欧美激情网友自拍| 日韩一区二区福利| 亚洲午夜在线观看视频在线| 欧美三区在线视频| 亚洲综合精品自拍| 久久久久国产精品厨房| 狠狠综合久久av一区二区小说| 久久黄金**| 亚洲电影欧美电影有声小说| 99re亚洲国产精品| 国产精品久久久久久久午夜| 欧美亚洲在线| 亚洲二区视频| 国产精品99久久久久久www| 国产精品麻豆成人av电影艾秋| 欧美一区二区三区四区在线观看地址 | 欧美一区二区在线免费观看| 国内自拍亚洲| 你懂的成人av| 制服丝袜亚洲播放| 久久亚洲精品一区二区| 亚洲精品美女久久7777777| 欧美日韩在线免费视频| 香蕉国产精品偷在线观看不卡| 欧美成人免费大片| aa级大片欧美| 国内外成人在线视频| 欧美激情精品久久久久久大尺度| 亚洲一二三级电影| 欧美福利影院| 欧美一级视频精品观看| 最新成人av在线| 国产精品综合色区在线观看| 免费视频一区二区三区在线观看| 一区二区欧美日韩| 欧美www在线| 欧美在线播放一区| 99精品国产一区二区青青牛奶| 国产日韩精品视频一区二区三区| 欧美成人激情视频| 久久不见久久见免费视频1| 日韩午夜三级在线| 欧美福利小视频| 久久综合色影院| 欧美在线网站| 亚洲一区二区三区四区中文| 在线日本成人| 韩国视频理论视频久久| 国产精品每日更新在线播放网址| 欧美高清在线一区| 久久米奇亚洲|