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

牽著老婆滿街逛

嚴以律己,寬以待人. 三思而后行.
GMail/GTalk: yanglinbo#google.com;
MSN/Email: tx7do#yahoo.com.cn;
QQ: 3 0 3 3 9 6 9 2 0 .

Collision detection with Recursive Dimensional Clustering

http://lab.polygonal.de/articles/recursive-dimensional-clustering/

Collision detection with Recursive Dimensional Clustering

Brute force comparison

Collision detection can be done in many ways. The most straightforward and simplest way is to just test every object against all other objects. Because every object has to test only for others after it in the list of objects, and testing an object with itself is useless, we arrive at the well known brute force comparison algorithm:

for (i = 0; i <  n; i++)
{
    a
= obj[i];

   
for (j = i + 1; j <  n; j++)
   
{
        b
= obj[j];
        collide
(a, b)
   
}
}

This double nested loop has a time complexity (n is the number of objects to check) of:
brute force time complexity
It can be immediately seen that this suffers from a big problem: exponential growth. An excellent article by Dave Roberts describes this problem in more detail and also covers several alternative approaches to collision detection.

Space partitioning

The algorithm represented here uses space partitioning, which means it subdivides the screen into smaller regions. Each region then obviously contains a fewer number of objects. The collision checks for all the entities in the region (space garbage, alien spaceships, orks, whatever) are then performed by the brute force comparison - which is very efficient for a small number of objects.

Two other common spatial partitioning schemes are Binary Space Partitioning (BSP) and Quadtree/Octree Partitioning. All have in common that they recursively subdivide the space into smaller pieces. RDC however, does not construct a tree based structure and must be recomputed every frame. BSP and Quad trees on the other side are best used when precomputed since they are expensive to modify.

So first, we limit the number of collision checks by using spatial partitioning and second, we wrap each object in a bounding shape (e.g. bounding sphere) to quickly eliminate objects that aren’t colliding.

RDC has an average time complexity of:
RDC time complexity
While the number of tests using brute-force alone explodes, RDC method increases approximately linearly.

The algorithm

RDC was described by Steve Rabin, in the book Game Programming Gems II: “Recursive Dimensional Clustering: A Fast Algorithm for Collision Detection”. Without going into the depth as much, I’ll try to recap the basic principles, followed by an working implementation which you can download and try for yourself.

The steps involved in the RDC algorithm are as follows:

Step1: Iterate trough all objects and store the intervals for a given axis in a list data structure. e.g. for the x-axis we store the minimum (open) and maximum (close) x position of the object boundary. An easy way to do this is using displayObjectInstance.getBounds(). The same is done for the y-axis (and of course for the z-axis, if you are in 3D space). Each boundary has to also remember what entity it belongs to and if its a ‘open’ or ‘close’ type:

class Boundary
{
   
public var type:String;
   
public var position:Number;
   
public var object:Object;
}

Step2: Sort the collected list of boundary objects in ascending order from lowest to highest position:

var boundaries:Array = getIntervals(objects, axis)
boundaries
.sortOn("position", Array.NUMERIC);

Step3: Iterate trough the sorted boundary list and store objects with overlapping intervals into groups:

var group:Array = [];
var groupCollection:Array;
var count:int = 0;

for (var i:int = 0; i <  boundaries.length; i++)
{
   
var object:Boundary = boundaries[i];

   
if (object.type == "open")
   
{
        count
++;
       
group.push(object);
   
}
   
else
   
{
        count
--;
       
if (count == 0)
       
{
            groupCollection
.push(group);
           
group = [];
       
}
   
}
}

If you are dealing just with one dimension (which would be a strange game…) you would be done.
For this to work in higher dimensions, you have to also subdivide the group along the other axis (y in 2d, y and z in 3d), and then re-analyze those groups along every other axis as well. For the 2d case, this means:

1. subdivide along the x-axis
2. subdivide the result along the y-axis.
3. re-subdivide the result along the x-axis.

Those steps are repeated until the recursion depth is reached. This is best shown with some pictures:

x-axis no intersection
All objects are happily separated, no groups are found.

x-axis intersection
The open/close boundaries of object a and b overlap -
thus both are put into a group.

y-axis no intersection
Even though the intervals of object a and b overlap along the
x-axis, they are still separated along the y-axis.

y-axis reanalyze x-axis
Subdividing along the x-axis results in one group [A, B, C].
Second pass along y-axis splits the group into [B], [A, C].
Subdividing along the x-axis again splits [A,C], so finally we
get the correct result: [A], [B], [C].

Interactive demo

This should give you a better idea what RDC does. The value in the input field defines how many objects a group must have to stop recursion. By lowering the number, you actually increase the recursion depth (slower computation). So you tell the algorithm: “try to make smaller groups by subdividing further!”. If you set this value to 1, only one object is allowed per group. If you set the value too high (faster computation) you get bigger groups. This can also be seen as a blending factor between brute force comparison and RDC. Usually you have to find a value in between, so that perhaps each group contains 5-10 object to make this algorithm efficient.

The ’s’ key toggles snap on/off. This is to show a potential problem that arises when the boundaries of two object share the same position. The sorting algorithm then arbitrary puts both object in a group (e.g. if the open boundary of object is stored before the close boundary of object b in the list), although they aren’t colliding, but just touching.
You can resolve the issue in the sorting function, but as we want the algorithm to be as fast as possible, this is not a good idea. Instead, it’s best to use a tiny threshold value, which is accumulated to the interval. If the threshold value is positive, the boundaries are ‘puffed’ in, and object touching each other are not counted as colliding. If the value is negative, touching objects are grouped together and checked for collision later.

‘+/-’ keys simple increase/decrease the number of objects, and ‘d’ key toggles drawing of the boundaries, which gets very messy on large number of objects. Green rectangles denote the final computed groups, whereas gray groups are temporary groups formed by the recursive nature of the algorithm and are further subdivided.

Drag the circles around, begin with a small number of object (3-4) and watch what the algo does.

Full screen demo: interactive, animated (Flash Player 9)

pro’s

- recursive dimensional clustering is most efficient if the objects are distributed evenly across the screen and not in collision.

- it is great for static objects since you can precompute the groups and use them as bounding boxes for dynamic objects.

con’s

- the worst case is when all objects are in contact with each other and the recursion depth is very high - the algorithm cannot isolate groups and is just wasting valuable processing time.

- because of the recursive nature the algorithm is easy to grasp, but tricky to implement.

the AVM2 is very fast, so unless you use expensive collision tests or have a large number of objects, a simple brute force comparison with a bounding sphere distance check is still faster than RDC.

Download, implementation and usage

Download the source code here. Please note that it is coded for clarity, not speed.
Usage is very simple. You create an instance of the RDC class and pass a reference to a collision function to the constructor. The function is called with both objects as arguments if a collision is detected. A more elegant solution would use event handlers.

function collide(a:*, b:*)
{
     
// do something meaningful
}

var rdc:RDC = new RDC(collide);

gameLoop
()
{
   
// start with x-axis (0), followed by y-axis (1)
    rdc
.recursiveClustering([object0, object1, ...], 0, 1);
}

Have fun!
Mike

posted on 2007-12-28 16:57 楊粼波 閱讀(421) 評論(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>
            午夜激情一区| 欧美www在线| 久久狠狠久久综合桃花| 亚洲欧洲精品一区二区| 亚洲亚洲精品三区日韩精品在线视频| 国内欧美视频一区二区| 国产精品美女久久福利网站| 欧美日韩aaaaa| 国产三级欧美三级日产三级99| 久热精品视频在线观看| 亚洲无线一线二线三线区别av| 亚洲国产精品久久| 欧美激情a∨在线视频播放| 欧美成人精品在线视频| 亚洲一区二区三区高清| 亚洲视频精品| 亚洲欧美国产一区二区三区| 亚洲专区在线| 国产一区二区精品| **网站欧美大片在线观看| 在线观看亚洲专区| 亚洲午夜性刺激影院| 久久久久久久久久久久久久一区| 欧美韩日一区二区三区| 亚洲午夜激情免费视频| 免费中文日韩| 国产亚洲精久久久久久| 亚洲视屏在线播放| 老司机一区二区| 99视频精品免费观看| 久久久久久黄| 国产精品女主播一区二区三区| 在线欧美福利| 欧美综合二区| 99精品视频一区二区三区| 久久先锋影音av| 国产美女搞久久| 亚洲视屏一区| 91久久久久久久久| 久久综合九色九九| 国精产品99永久一区一区| 亚洲视频碰碰| 亚洲精品视频在线播放| 欧美岛国激情| 91久久国产自产拍夜夜嗨| 久久精品国产久精国产一老狼 | 欧美一区在线看| 亚洲人成7777| 欧美高清一区| 亚洲毛片在线观看.| 欧美成人午夜剧场免费观看| 久久精品视频在线| 韩日精品视频一区| 久久夜色精品亚洲噜噜国产mv | 欧美金8天国| 在线观看日韩欧美| 蜜臀久久99精品久久久画质超高清| 欧美一区二区三区四区在线观看地址| 国产精品日本一区二区| 欧美夜福利tv在线| 欧美在线综合视频| 一区在线免费| 欧美高清视频一二三区| 女女同性精品视频| 久久婷婷av| 久久蜜桃精品| 亚洲电影激情视频网站| 免费在线观看日韩欧美| 美女久久网站| 99视频有精品| 亚洲一区二区三区涩| 国产精品免费看| 久久精品综合网| 开心色5月久久精品| 亚洲美洲欧洲综合国产一区| 日韩午夜黄色| 国产日韩1区| 欧美福利一区| 欧美日韩三级| 久久精品视频导航| 欧美成人午夜激情| 午夜一级在线看亚洲| 久久国产乱子精品免费女 | 午夜精品久久久久久 | 欧美伦理91| 亚洲欧美日韩成人高清在线一区| 亚洲欧洲av一区二区三区久久| 国内伊人久久久久久网站视频| 免费在线观看一区二区| 欧美日韩高清在线| 久久精品国产2020观看福利| 麻豆成人在线观看| 亚洲欧美日韩国产综合| 久久久www免费人成黑人精品| 1024成人网色www| 一区二区三区导航| 亚洲高清久久久| 夜夜嗨一区二区| 一区在线影院| 日韩午夜激情av| 亚洲国产导航| 西西人体一区二区| aa日韩免费精品视频一| 欧美一区二区三区四区高清 | 香蕉视频成人在线观看| 亚洲黄色免费电影| 亚洲欧美日本国产有色| 亚洲经典自拍| 久久精品青青大伊人av| 亚洲一区二区三区四区五区午夜 | 最新精品在线| 国产一区二区久久精品| 日韩视频一区二区| 亚洲人成网站精品片在线观看| 欧美一区永久视频免费观看| 亚洲午夜极品| 欧美日本亚洲视频| 欧美激情视频一区二区三区免费| 国产精品永久免费视频| 99国产一区| 一区二区电影免费观看| 欧美刺激性大交免费视频| 亚洲国产精品久久| 欧美色综合天天久久综合精品| 欧美成人首页| 在线欧美日韩国产| 久久精品国产一区二区三| 香蕉成人啪国产精品视频综合网| 欧美精品少妇一区二区三区| 欧美69wwwcom| 一区二区三区在线免费播放| 欧美影院在线| 久久久久久久性| 国产一区91| 久久久久久**毛片大全| 久久婷婷国产综合国色天香| 国产视频一区二区三区在线观看| 亚洲一区久久| 久久www成人_看片免费不卡| 国产一区二区三区av电影| 西瓜成人精品人成网站| 久久久久久亚洲精品杨幂换脸| 国内成+人亚洲+欧美+综合在线| 欧美在线国产| 欧美成人亚洲成人日韩成人| 亚洲人成在线播放网站岛国| 欧美日本在线看| 亚洲一级片在线看| 久久久精品性| 在线精品视频一区二区| 美女精品在线| 9l国产精品久久久久麻豆| 亚洲综合日韩| 国产一区二区久久久| 美女诱惑一区| 99精品久久久| 久久久久国色av免费观看性色| 在线精品视频在线观看高清| 欧美精品1区2区3区| 亚洲一级二级在线| 女主播福利一区| 在线视频欧美一区| 国产无一区二区| 美国十次了思思久久精品导航| 日韩一二三在线视频播| 久久精品成人一区二区三区蜜臀| 亚洲风情在线资源站| 欧美视频一区二区在线观看 | 欧美亚州韩日在线看免费版国语版| 亚洲一线二线三线久久久| 欧美大片91| 欧美一区二区免费观在线| 亚洲国产精品久久人人爱蜜臀| 欧美午夜www高清视频| 久久深夜福利免费观看| 中文一区二区| 欧美好吊妞视频| 欧美一区三区二区在线观看| 亚洲日本免费电影| 国产色产综合色产在线视频| 欧美精品日韩| 久热国产精品| 羞羞视频在线观看欧美| 亚洲免费精彩视频| 麻豆国产精品va在线观看不卡| 亚洲一区免费在线观看| 91久久精品久久国产性色也91| 国产三级精品三级| 国产精品视频免费观看www| 欧美精品在线视频| 另类人畜视频在线| 欧美屁股在线| 日韩视频一区二区三区在线播放| 久久久91精品国产一区二区三区 | 欧美中文字幕久久| 国产精品99久久久久久久女警| 亚洲国产中文字幕在线观看| 裸体丰满少妇做受久久99精品| 欧美亚洲免费在线| 亚洲午夜一二三区视频|