Sign in to follow this  
polarboy

Why doesn't linear algebra approach work for Iso

Recommended Posts

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 this post


Link to post
Share on other sites
Your explanation isn't very clear.
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 this post


Link to post
Share on other sites
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
|
|
V
screen 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 this post


Link to post
Share on other sites
Quote:
Original post by LorenzoGatti
Your explanation isn't very clear.
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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this