I assume you mean converting a point to an index in an 'isometric' projection and vice versa.
Interestingly, with a lot of isometric games the tilt angle is 30 degrees not 45.
Take a look at the bottom of this page:
http://2dengine.com/doc_1_3_10/gs_isometric.html
It shows you how to convert the point for 30-degree tilt.
Also note that there are different types of isometric layouts.
Generally, if you want to be able to do the math for ANY tilt angle, you want to research "affine transformations".
There is a nice implementation in the "path" library by Cosmin Apreutesei:
https://code.google.com/p/lua-files/wiki/affine2d
Basically you translate, scale and rotate the original point to match your projection (note that order of transformations is important).
So if you're doing something simple you can probably get away without using matrices:
Code: Select all
-- translation by offset ox, oy
function translate(x, y, ox, oy)
return x + ox, y + oy
end
-- scaling by sx, sy
function scale(x, y, sx, sy)
return x*sx, y*sy
end
-- rotation by a in radians
local cos, sin = math.cos, math.sin
function rotate(x, y, a)
local c = cos(a)
local s = sin(a)
return c*x - s*y, s*x + c*y
end
With, matrices the math is a little more complicated because these three operations are combined together.