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

牽著老婆滿街逛

嚴以律己,寬以待人. 三思而后行.
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>
            一区二区三区欧美视频| 午夜亚洲精品| 亚洲欧美综合精品久久成人| 一区二区三区国产盗摄| 亚洲香蕉伊综合在人在线视看| 亚洲精品资源| 9色精品在线| 亚洲欧美中日韩| 欧美在线播放视频| 美女任你摸久久| 亚洲黄色免费电影| 欧美成人久久| 亚洲精品乱码久久久久久蜜桃麻豆| 99精品国产在热久久下载| 一区二区三区国产在线观看| 亚洲专区免费| 麻豆精品视频在线| 国产精品日本| 亚洲欧洲在线看| 亚洲免费视频网站| 你懂的成人av| 亚洲综合久久久久| 欧美mv日韩mv亚洲| 国产伦精品免费视频| 亚洲电影下载| 亚洲欧美日韩精品久久亚洲区 | 久久久青草婷婷精品综合日韩| 免费视频一区| 亚洲午夜精品福利| 免费在线视频一区| 国产精品久久看| 亚洲国产91色在线| 欧美一区网站| 亚洲精品网址在线观看| 亚洲精选一区| 一区二区三区视频在线看| 欧美一级理论片| 亚洲国产精品尤物yw在线观看| 99精品久久| 麻豆国产精品777777在线| 国产精品久久久久影院色老大 | 国产精品久久久99| 在线日韩精品视频| 欧美一区二区在线视频| 91久久精品国产91性色| 久久精品91久久香蕉加勒比| 欧美日韩一区二区三区高清| 亚洲国产你懂的| 久久亚洲春色中文字幕| 亚洲欧美国产视频| 国产精品国产三级国产a| 亚洲另类自拍| 欧美激情无毛| 免费看av成人| 亚洲国产精品久久久久婷婷老年| 久久久亚洲一区| 欧美在线视频a| 国产手机视频一区二区| 欧美诱惑福利视频| 午夜精品视频在线| 国产一区二区三区直播精品电影| 欧美一区二区视频在线观看2020| 亚洲视频一区| 国产精品欧美一区喷水| 亚洲女同在线| 亚洲私人黄色宅男| 欧美日韩亚洲系列| 亚洲欧美在线aaa| 亚洲在线一区二区三区| 国产精品一卡二| 久久精品一区二区三区中文字幕| 香蕉av777xxx色综合一区| 国产一区二区毛片| 美女国产一区| 欧美成人久久| 国产精品99久久久久久久久| 一道本一区二区| 国产精品尤物| 免费在线观看一区二区| 欧美插天视频在线播放| 一区二区三区 在线观看视| aa日韩免费精品视频一| 国产精品拍天天在线| 老鸭窝亚洲一区二区三区| 欧美成人dvd在线视频| 亚洲一区日韩| 欧美在线观看一二区| 亚洲国产一区二区三区a毛片| 欧美国产亚洲视频| 欧美日在线观看| 久久都是精品| 欧美黄色大片网站| 午夜在线不卡| 男人插女人欧美| 午夜精品久久久久久久| 女女同性女同一区二区三区91| 免费成人av在线看| 亚洲一区三区电影在线观看| 性欧美暴力猛交69hd| 亚洲国产精彩中文乱码av在线播放 | 国产精品夜夜夜| 久久免费视频网站| 欧美日本在线视频| 久久欧美中文字幕| 欧美三级第一页| 麻豆freexxxx性91精品| 欧美性大战久久久久| 欧美成人一区二区在线 | 欧美日韩在线播放一区| 久久精品亚洲精品| 欧美日韩高清区| 免费在线成人av| 国产午夜精品福利| 亚洲天堂网站在线观看视频| 亚洲高清视频在线| 性欧美长视频| 亚洲欧美日韩视频二区| 欧美精品乱人伦久久久久久| 鲁大师成人一区二区三区| 国产精品乱看| 亚洲精一区二区三区| 在线成人免费观看| 欧美在线国产精品| 欧美一级在线视频| 欧美日韩专区在线| 亚洲日产国产精品| 亚洲精品国产精品国产自| 欧美在线首页| 久久久精品一区| 国产日韩欧美一区二区三区在线观看| 日韩一区二区免费高清| 99精品国产一区二区青青牛奶| 麻豆成人av| 亚洲国产高清高潮精品美女| 亚洲国产91精品在线观看| 久久野战av| 欧美99在线视频观看| 今天的高清视频免费播放成人| 香蕉成人久久| 久久久国产一区二区三区| 国产精自产拍久久久久久| 亚洲男人第一网站| 欧美资源在线| 狠狠色狠狠色综合日日小说| 欧美专区中文字幕| 久久久在线视频| 在线播放中文字幕一区| 麻豆av福利av久久av| 亚洲二区视频在线| 亚洲精品视频在线看| 欧美激情久久久久| 日韩视频在线观看国产| 午夜精品久久| 精品1区2区| 欧美激情精品久久久久久久变态| 亚洲美女一区| 欧美一区综合| 亚洲国产高清自拍| 欧美性感一类影片在线播放| 午夜精品久久久久久久99黑人| 可以看av的网站久久看| 欧美成人一品| 亚洲私人影吧| 久久亚洲国产精品日日av夜夜| 亚洲第一中文字幕在线观看| 欧美欧美在线| 亚洲欧美日韩中文视频| 女仆av观看一区| 亚洲视频高清| 极品尤物久久久av免费看| 欧美精品1区| 亚洲欧美视频一区| 欧美国产三区| 性欧美办公室18xxxxhd| 亚洲黄一区二区| 国产精品国产三级国产专播精品人| 欧美一进一出视频| 亚洲九九九在线观看| 久久久国产精品一区| 日韩亚洲欧美在线观看| 国产一区二区无遮挡| 欧美女主播在线| 久久久欧美一区二区| 中文网丁香综合网| 亚洲国产精品日韩| 久久久久高清| 亚洲欧美日韩国产综合| 亚洲精选成人| 韩国成人精品a∨在线观看| 欧美日韩一区在线观看视频| 久久久久久婷| 性伦欧美刺激片在线观看| 亚洲毛片在线观看| 欧美激情四色| 久久综合伊人77777| 欧美一级免费视频| 亚洲一区二区三区四区中文| 亚洲三级免费电影| 影音先锋欧美精品| 国产一区二区三区电影在线观看|