English 中文(简体)
在2D非对称电网中进行浮点探测?
原标题:Click detection in a 2D isometric grid?

多年来,我一直在进行网络开发,我慢慢慢慢地亲自参与游戏发展,而对于我目前的项目,我已经走过这个非对称地图,在那里,我需要使用算法来探测哪些领域正在被点击。 所有这一切都是用 way字进行的。

The map
It looks like this and I ve added some numbers to show you the structure of the fields (tiles) and their IDs. All the fields have a center point (array of x,y) which the four corners are based on when drawn.
As you can see it s not a diamond shape, but a zig-zag map and there s no angle (top-down view) which is why I can t find an answer myself considering that all articles and calculations are usually based on a diamond shape with an angle.

The numbers
It s a dynamic map and all sizes and numbers can be changed to generate a new map.
I know it isn t a lot of data, but the map is generated based on the map and field sizes.
- Map Size: x:800 y:400
- Field Size: 80x80 (between corners)
- Center position of all the fields (x,y)

The goal
To come up with an algorithm which tells the client (game) which field the mouse is located in at any given event (click, movement etc).

Disclaimer
I do want to mention that I ve already come up with a working solution myself, however I m 100% certain it could be written in a better way (my solution involves a lot of nested if-statements and loops), and that s why I m asking here.

https://i.stack.imgur.com/h8zRjpg”rel=“nofollow”> 在此,是我解决办法的一个实例,我基本上在最接近的4个已知职位中找到一个角逐点,然后根据最接近的2个领域之间的最小平方得出我的结果。 这是否有意义?

如果我错了。

最佳回答

在此,我要谈谈,

function posInGrid(x, y, length) {
xFromColCenter = x % length - length / 2;
yFromRowCenter = y % length - length / 2;
col = (x - xFromColCenter) / length;
row = (y - yFromRowCenter) / length;
if (yFromRowCenter < xFromColCenter) {
    if (yFromRowCenter < (-xFromColCenter))--row;
    else++col;
} else if (yFromRowCenter > xFromColCenter) {
    if (yFromRowCenter < (-xFromColCenter))--col;
    else++row;
}
return "Col:"+col+", Row:"+row+", xFC:"+xFromColCenter+", yFC:"+yFromRowCenter;
}

X和Y是图像中的 co,长度是电网的间隔。

现在,它只恢复体力,只是为了测试,结果应当是row和col,而我选择的是座标:你一只tile(1,0)tile2(3,0,10(0,1),tile11(2,1)。 你可以把我的坐标转换成一行或两行的贵重位置。

http://jsfiddle.net/NHV3y/“rel=“nofollow” http://jsfiddle.net/NHV3y/。

乘客。

EDIT: 改变了返回表,但有一些变数被我用于脱胎。

问题回答

过去(在开放式GL中,这个概念也在这里)使用的是探测一号探测仪的完美方法,是用不同颜色识别不同物体的场景。

这种做法要求记忆翻一番,使情况翻一番,但用简单的彩色眼光探测任意复杂的景象。

由于你想要在一个电网中发现一个囚室,也许会有更有效的解决办法,但我要提到这种解决办法是简单和灵活的。





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签