【问题标题】:World point to Isometric point - Need help understanding世界点到等距点 - 需要帮助理解
【发布时间】:2015-08-23 06:10:09
【问题描述】:

现在我知道这个问题已经在这个网站和许多其他网站上被问过和回答了数百次,但我找不到解释为什么计算有效,以及如何根据我的需要实际更改它。

这是我目前的功能:

//Converts X, Y from the 2D World to a Point in the Isometric Grid
public static Vector2 WorldToIsometric(float x, float y, int scale)
{
    Vector2 point = new Vector2(x, y);
    Vector2 iso_point = new Vector2(point.x, point.y);
    float half_scale = scale / 2;

    iso_point.x = point.x - (point.y * 2) + half_scale;
    iso_point.y = point.x + (point.y * 2) - half_scale;

    iso_point.x /= scale;
    iso_point.y /= scale;

    iso_point.x = Mathf.Floor (iso_point.x);
    iso_point.y = Mathf.Floor (iso_point.y);

    return iso_point;
}

键:

        x  =  mouse x in world
        y  =  mouse y in world
    scale  =  width of isometric tile
    point  =  mouse point in world
iso_point  =  mouse point on isometric grid

我希望输出的样子:

输出的实际样子:

我只是无法理解更改代码的概念,我可能在这方面花了很长时间并且喝了太多咖啡,但无论我如何更改它似乎都不像我想的那样奏效会的。

请随意链接一个详细的教程,了解它在数学上是如何工作的,但我找不到任何能真正帮助我理解如何修改代码的东西。

提前干杯

【问题讨论】:

    标签: c# unity3d isometric


    【解决方案1】:

    如果你必须把整个公式放在一起,

    iso_point.x = point.x/scale - (point.y + 1) / (scale / 2);
    

    在您的情况下,当您将鼠标向右移动时,point.x/scale 会增加 X。如果您将鼠标向上移动,您可以看到 iso_point.x 会减少 point.y / (scale/2)。

    scale/2 来自瓦片的高度 = 宽度/2

    由于您希望 iso_point.x 随着 point.x 和 point.y 的增加而增加,所以您需要类似

    iso_point.x = point.x + (point.y * 2) - half_scale;
    

    以同样的方式,iso_point.y 必须随着 point.x 的减少和 point.y 的增加而增加:

    iso_point.y = -point.x + (point.y * 2) - half_scale;
    

    【讨论】:

    • 我要测试一下,已经很晚了,我已经研究了这么久,但是这个简单的解释完全有道理......到目前为止一直在阅读复杂的数学解释跨度>
    • 完美,我终于明白这一切是如何运作的
    猜你喜欢
    • 1970-01-01
    • 2013-07-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多