Hey just wondering if anyone could help me with the maths for Oblique/"Military" Projection?
Like perspective view.
Things such as screen x,y to grid coordinates and the other way around. Whats the best formula for both in anyone's experience?
As much as you can teach me is awesome, thanks
Maths questions if anyone can help a brother out
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: Maths questions if anyone can help a brother out
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:
With, matrices the math is a little more complicated because these three operations are combined together.
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
Re: Maths questions if anyone can help a brother out
Recently I've found interesting paper on SSR method (scale-shear-rotate) to do isometric projection. It is important that shearing is involved in the process:
http://design.tutsplus.com/tutorials/ho ... ector-1058
http://design.tutsplus.com/tutorials/ho ... ector-1058
Re: Maths questions if anyone can help a brother out
Thank you both but I'm actually looking at the 45 Degree version; Like Ultima Online.
Have either of you had experience or know how or where I could learn to do that?
Have either of you had experience or know how or where I could learn to do that?
Re: Maths questions if anyone can help a brother out
For 45-degrees, you can just rotate the point math.pi/2, no scaling/skewing involved.
As I said, there are different types of isometric layouts (diamond, staggered, etc).
Generally speaking you could probably get away with something like:
Assuming diamond ordering and the 'mapOrigin' is the top left corner of the diamond in screen coords.
As I said, there are different types of isometric layouts (diamond, staggered, etc).
Generally speaking you could probably get away with something like:
Code: Select all
screenX, screenY = ... -- get mouse coords
-- screen coords to map coords
mapX, mapY = translate(screenX, screenY, -mapOriginX, -mapOriginY)
mapX, mapY = rotate(mapX, mapY, math.pi/2)
-- map coords to tile index
tileX, tileY = floor(mapX/tileWidth) + 1, floor(mapY/tileHeight) + 1
Re: Maths questions if anyone can help a brother out
This is a good video too, you'll learn a lot about some of the techniques used. Kind of lengthy, but worth it.
https://www.youtube.com/watch?v=go1qrWFw_bs
https://www.youtube.com/watch?v=go1qrWFw_bs
GitHub | MLib - Math and shape intersections library | Walt - Animation library | Brady - Camera library with parallax scrolling | Vim-love-docs - Help files and syntax coloring for Vim
Who is online
Users browsing this forum: Bing [Bot] and 5 guests