A
A
Alexander2016-01-27 17:19:54
Game development
Alexander, 2016-01-27 17:19:54

How to convert local coordinates to isometric?

there is an isometric grid:
9ba782930c4846a096bf2f2636a0dbc8.png
it is built in this way:

property int mapcols: 8 // ширина карты
    property int maprows: mapcols * 4 // высота карты
    property int cellsize: 96 // размер клетки, если бы она не была в изометрии :)
    property int cellsizew: cellsize // ширина тайла
    property int cellsizeh: cellsize / 2 // высота тайла

    function createTextures() {
        var cellcount = mapcols * maprows

        for(var id = 0; id < cellcount; id++) {
            // по индексу тайла (слева-направо, сверху-вниз) получаем 
            // номер колонки и номер строки
            var col = id % mapcols
            var row = Math.floor(id / mapcols)

            // находим координаты 
            // левого верхнего угла описывающего тайл прямоугольника
            var iseven = row / 2 == Math.floor(row / 2) // четная/нечетная строка
            var cx = iseven ? col * cellsizew : col * cellsizew + cellsizew/2
            var cy = iseven ? row * cellsizeh : row * cellsizeh - cellsizeh/2

            cy -= Math.floor(row/2) * cellsizeh

            var component = Qt.createComponent("Cell.qml")
            var cell = component.createObject(map, { "x": cx, "y": cy });
        }
    }

how to find the coordinates of the white point on the isometric grid (i.e., in fact, you need to find the numbers 2x4), knowing the local coordinates of this point in the window?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
G
GreatRash, 2016-01-27
@wxmaper

Sobssno

D
DrSpritz, 2016-01-27
@DrSpritz

Of course, I'm not a pro in 2D graphics, but it seems to me that you have some kind of strange approach =)
But if this is not taken into account, then I can offer you the same strange solution, provided that the position of your camera is static, otherwise you can't leave from
matrices (object, view, etc.) no distortion, everything is linear. I think you should calculate the ratio of pixels to local coordinates. You are counting from the upper left corner, and you can clearly see that 1px vertically in local coordinates is 2 times more than horizontally. Derive this ratio and pour the coordinates in one direction and the other.
I'm sorry, the method is clearly perverted :D

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question