计算等轴测网格上的矩形内包含的像元 [英] Calculating the cells contained inside a rectangle on an Isometric Grid

查看:112
本文介绍了计算等轴测网格上的矩形内包含的像元的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑给我们一个等距的网格(考虑暗黑破坏神(Diablo)之类的东西).我们对网格有一些度量,例如网格高度,网格宽度和图块高度/宽度.考虑此图像:

网格的中心像元是0,0,扩展了iso-north(+ y),iso-south(-y),iso-east(+ x)​​,iso-west(-x).

假设我们在网格上的任意位置绘制一个矩形.我们没有矩形的等距位置,但是有网格的法线绘制坐标,其中左上角为0,0,南为y +,右为x +.

如果我们要讨论的是矩形的顶部,左侧,高度和宽度-我们如何计算与矩形底部边缘交叉的iso-cell数组.

您选择的任何语言来证明这一点就足够了.

解决方案

在一些有关等距编程的文章和书籍中(使用Direct X7进行等距编程,是的,但是它提供了有关问题和技术的概述),他们使用了鼠标映射./p>

还有一种技术可以将矩形覆盖的地图区域渲染为图像,每个图块都具有唯一的颜色(而这仅仅是渲染的颜色).然后,他们检查图像中有哪些颜色,然后提取图块列表.

由于您使用的是经典的等距图块宽度一半高度,因此也可能存在数学上的解决方案.不幸的是,建议的算法在很大程度上取决于您的地图布局.

基于Java的TileSystem的代码可以在此处找到

Consider that we are given an isometric grid (consider something like Diablo) of tiles. We have some measures for the grid, like grid height, grid width and tile height/width. Consider this image:

The center cell of the grid is 0,0 extending iso-north (+y), iso-south(-y), iso-east(+x), iso-west(-x).

Let's say we to draw a rectangle at an arbitrary location on the grid. We do NOT have the isometric positions for the rectangle, but rather have the normal draw coordinates for the grid where the top left hand corner is 0,0 and south is y+, right is x+.

If we had the top, left, height, width of the rectangle in question - how could we calculate an array of iso-cells that crossed by the bottom edge of the rectangle.

Any language you choose to demonstrate this will suffice.

解决方案

In some papers and books about isometric programming (Isometric programming with Direct X7, yes its old but gives an overview about the problems and techniques) they use mousemaps.

Also there is the technique to render the area of the map covered by the rectangle into an image, each tile gets a unique color (and it is just the color rendered). Afterwards they check which colors are in the image and so extract the list of tiles.

Since you are using a classic isometric tile width half height there could be a mathematical solution too. Unfortunatly an suggested algorithm would depend heavily on your map layout.

The code for a Java based TileSystem can be found here

这篇关于计算等轴测网格上的矩形内包含的像元的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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