如何变换等距平铺地图鼠标的位置? [英] How to transform mouse location in isometric tiling map?

查看:106
本文介绍了如何变换等距平铺地图鼠标的位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我操控着我自己写的第一部分(算法)来计算每个块的位置,是否应该同时绘制这张地图放在(参见下文)。不过,我需要能够对鼠标的位置转换到相应的单元格,我已经差不多拉我的头发了,因为我不能想出一个办法如何从鼠标位置的单元格。我担心的是,它涉及到一些pretty的高数学或东西我只是简单的东西我是不能够注意到。
例如,如果鼠标位置是 112; 35 我怎么计算/它转换得到的细胞是 2; 3 在那个位置? 也许有一些非常好的数学思维的程序员在这里谁也帮我在这或某人谁知道如何做到这一点还是可以提供一些信息?

  VAR线:点=新的点();
cord.x =(X  -  1)* 28 +(Y  -  1)* 28;
cord.y =(Y  -  1)* 14 +(X  -  1)*( -  14);
 

说到的地图中,每个小区(透明瓦片的 56x28 的像素)被放置在previous小区的中心(或针对小区1零位置1),上述是在code我用转换单元到的位置。我尝试很多事情和计算位置 - 细胞但他们每个人的失败。

编辑: 阅读大量的资料后的似乎的,使用过的屏幕色彩映射(其中颜色映射到砖)是最快,最有效的解决方案?

解决方案

 (1)x` = 28倍-28 + 28Y -28 = 28X + 28Y -56
(2)y` = -14x + 14 14y的-14 = -14x + 14y的
 

变化表:

  [X] [28 28 -56] = [x`]
[Y] [-14 14 0] [y`]
[1] [0 0 1] [1]

[28 28 -56] ^ -1
[-14 14 0]
[0 0 1]
 

计算与绘图仪(我喜欢的 WIMS

  [1/56 -1/28 1]
[1/56 1/28 1]
[0 0 1]

X = 1/56 * x`  -  1 / 28y` +1
Y = 1/56 * x` + 1 / 28y` +1
 

So I've managed myself to write the first part (algorithm) to calculate each tile's position where should it be placed while drawing this map (see bellow). However I need to be able to convert mouse location to the appropriate cell and I've been almost pulling my hair off because I can't figure out a way how to get the cell from mouse location. My concern is that it involves some pretty high math or something i'm just something easy i'm not capable to notice.
For example if the mouse position is 112;35 how do i calculate/transform it to to get that the cell is 2;3 at that position? Maybe there is some really good math-thinking programmer here who would help me on this or someone who knows how to do it or can give some information?

var cord:Point = new Point();
cord.x = (x - 1) * 28 + (y - 1) * 28;
cord.y = (y - 1) * 14 + (x - 1) * (- 14);

Speaking of the map, each cell (transparent tile 56x28 pixels) is placed in the center of the previous cell (or at zero position for the cell 1;1), above is the code I use for converting cell-to-position. I tried lot of things and calculations for position-to-cell but each of them failed.

Edit: After reading lot of information it seems that using off screen color map (where colors are mapped to tiles) is the fastest and most efficient solution?

解决方案

(1) x` = 28x -28 + 28y -28  = 28x + 28y -56
(2) y` = -14x +14 +14y -14 = -14x + 14y

Transformation table:

[x] [28  28 -56 ] = [x`]
[y] [-14 14  0  ]   [y`]
[1] [0    0  1  ]   [1 ]

[28  28 -56 ] ^ -1 
[-14 14  0  ]
[0    0  1  ] 

Calculate that with a plotter ( I like wims )

[1/56 -1/28  1 ]
[1/56  1/28  1 ]
[0      0    1 ]

x = 1/56*x` - 1/28y` + 1
y = 1/56*x` + 1/28y` + 1

这篇关于如何变换等距平铺地图鼠标的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆