Isometric & Screen Space

I’m working on a game that required me to convert screen -> isometric space, and it took me some time to come up with these equations, and theagentd suggested I post my findings: https://gist.github.com/4009942

in case it gets deleted

Screen -> Isometric space equations
iX = (((ScreenX) / tileWidth) - ((ScreenY) / tileHeight));
iY = (((ScreenX) / tileWidth) + ((ScreenY) / tileHeight));

Isometric -> Screen space equations
ScreenX = (iX + iY) * tileWidth / 2;
ScreenY = (iY - iX) * tileHeight / 2;

Assuming the isometric coordinating system goes as this: http://i.imgur.com/aUM4g.png

cool. I hope it works. ;D

In case anyone’s wondering, those equations can for example be used to find which tile the player is clicking on, something I’ve seen people struggle with before.

Good, it’s simple :slight_smile:

I’m not. ;D

Wait a minute, I’m pretty sure

((2*ScreenY) / tileHeight)) / 2

is exactly the same as

ScreenY / tileHeight

Sorry, I’ll fix it in a bit, I didn’t take the time to simplify it because I was dying to see it work.

EDIT: theagentd, take a look at the parentheses again XD Its a bit confusing, but look here

((2*ScreenY) / tileHeight)) / 2

The parens don’t matter – the 2’s should cancel out regardless.

Yes, if you put this into a fraction you get this:
`
2 * screenY

tileHeight

    2

You can leave out all the brackets here, because you only do * and / calculations. So you can also form this into this:
screenY
2 * -----------
tileHeight

    2

and then you can cancel out those 2's:
screenY

tileHeight
`

Also, what I want to add:
We sould create a Wiki for isometric resources.
We’ve got soooo good resources: Jonjava ::slight_smile:

Oh ok, let me check one second.

Alright, I fixed it. It made more sense when I entered it on wolfram to simplify. xD