# Why doesn't linear algebra approach work for Iso

## Recommended Posts

polarboy    145
Well, I'm still working on the top half of my map, to figure out which tile my mouse clicked on. I think this approach would work, but it yields ridiculous numbers. My approach is as following: Since my tiles are 64 * 32, and I set (0,0) at (512,0) screen coord. I create an equation for the left most line: x = -2y + 512; Then I create an equation for my mouse, x = 1/2y + N; and then I figure out the N and find point of intersection -2y + 512 = 1/2y + N; so I find y, and use that y to find the x at Point of intersection. To find the isometric x, I look at how many 64s is the x at P.O.I away from 512 and to find y, I look at how many 64s is the mouse x away from the P.O.I x I think this method makes perfect sense, but it's simply not working right now. Anyone see anything wrong with it?

##### Share on other sites
LorenzoGatti    4442
Quote:
 Then I create an equation for my mouse, x = 1/2y + N;

The mouse cursor is not constrained to a certain line. What is N?
Moreover, what are the tilemap's conventions? Are you perhaps mixing up screen pixel coordinates and tilemap coordinates?

##### Share on other sites
Luctus    584
I don't understand what you mean, but I can assure you that linear algebra works perfectly fine for isometric projections.

Assuming your tiles are 64 pixels wide and 32 pixels high, your world x-axis is pointing down and right on the screen, world y-axis is pointing down and left:
 ---------------------------------> screen x-axis|                /\  |               /  \  |              /    \  |             /      \  |     world |/_      _\| world|    y-axis              x-axis||Vscreen y-axis

You'll get a projection matrix (projecting world coordinates to screen coordinates) as follows:
[32 -32]
[16 16]

Your world (x,y) projected into screen coordinates (x',y') and adjusted 512 pixels will be
x' = 32*x - 32*y + 512
y' = 16*x + 16*y

When you want to find out where in world-coordinates your mouse cursor is, you use the inverse of the projection matrix:
[ 1/64 1/32]
[-1/64 1/32]

To calculate the mouse position in world coordinates (x',y') from it's screen coordinates (x,y):
x' = (x-512)/64 + y/32
y' = -(x-512)/64 + y/32

// Edit: a bit of a miscalculation fixed

[Edited by - Luctus on August 11, 2008 11:30:51 AM]

##### Share on other sites
polarboy    145
Quote:
Original post by LorenzoGatti
Quote:
 Then I create an equation for my mouse, x = 1/2y + N;

The mouse cursor is not constrained to a certain line. What is N?
Moreover, what are the tilemap's conventions? Are you perhaps mixing up screen pixel coordinates and tilemap coordinates?

oh, I'm setting up an equation of the line perpendicular to the x = -2y + 512 line that goes through the point where the mouse is at

It doesn't really concern the tilemap tho, cuz I was just taking the mouse coordinate and use the equation to figure out which tile it should be

I put on a tilemap, but that's only for visual aid

[quote]Original post by Luctus
I don't understand what you mean, but I can assure you that linear algebra works perfectly fine for isometric projections.

Assuming your tiles are 64 pixels wide and 32 pixels high, your world x-axis is pointing down and right on the screen, world y-axis is pointing down and left:
You'll get a projection matrix (projecting world coordinates to screen coordinates) as follows:
[32 -32]
[16 16]

Your world (x,y) projected into screen coordinates (x',y') and adjusted 512 pixels will be
x' = 32*x - 32*y + 512
y' = 16*x + 16*y

When you want to find out where in world-coordinates your mouse cursor is, you use the inverse of the projection matrix:
[ 1/64 1/32]
[-1/64 1/32]

Lol, I need to catch up on linear algebra :(
summer made me forget everything, I was actually doing somethign simpler