简体   繁体   English

等距物体检测

[英]Isometric object detection

I'm currently using this for collsion detection: 我目前正在使用它进行碰撞检测:

    var overlaps = (function () {
    function getPositions( elem ) {
        var pos, width, height;
        pos = $( elem ).position();
        width = $( elem ).width();
        height = $( elem ).height();
        return [ [ pos.left, pos.left + width ], [ pos.top, pos.top + height ] ];
    }

    function comparePositions( p1, p2 ) {
        var r1, r2;
        r1 = p1[0] < p2[0] ? p1 : p2;
        r2 = p1[0] < p2[0] ? p2 : p1;
        return r1[1] > r2[0] || r1[0] === r2[0];
    }

    return function ( a, b ) {
        var pos1 = getPositions( a ),
            pos2 = getPositions( b );
        return comparePositions( pos1[0], pos2[0] ) && comparePositions( pos1[1], pos2[1] );
    };

})();

But the problem is i work with isometric images for buildings, so there is a large empty area where you cannot place currently. 但是问题是我使用建筑物的等轴测图像,因此有一个很大的空白区域,您当前无法放置该区域。 For example: 例如:
在此处输入图片说明

So i cannot place them more closer to eachother. 因此,我无法将它们放置得更近。
How can i fix this, 我怎样才能解决这个问题,

My Image is loaded like this: 我的图像加载如下:

<div id='obj' name="build_6" class="build_88" style='top:584px;left:1094px;'><img src ="img/buildings/6.png" /></div>


Thank you, 谢谢,
Jeffrey 杰弗里

You probably need to use "real" overlap detection - as in, using a bounding box or a bounding circle/ellipsis, instead of comparing the element sizes. 您可能需要使用“真实”重叠检测-例如,使用边界框或边界圆/省略号,而不是比较元素大小。

A bounding circle is probably the easiest to implement in terms of algorithm complexity. 就算法复杂度而言,边界圆可能是最容易实现的。 For example, http://mathworld.wolfram.com/Circle-CircleIntersection.html 例如, http://mathworld.wolfram.com/Circle-CircleIntersection.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM