Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length

 
Advanced search

877065 Posts in 32845 Topics- by 24286 Members - Latest Member: himowa

May 18, 2013, 12:38:14 PM
TIGSource ForumsDeveloperTechnical (Moderators: Glaiel-Gamer, ThemsAllTook)How to check if a point is inside an isometric tile.
Pages: [1]
Print
Author Topic: How to check if a point is inside an isometric tile.  (Read 454 times)
EmptyNull
Level 0
*


View Profile
« on: June 13, 2012, 04:00:54 AM »

Oh noes! It's math time again  My Word!

I'd like some help to replace the inefficient hacks I'm using to see if a point is inside an isometric tile.

I'm currently looping trough every tile to check if the point is inside it's bounding box.
If it is I do a check between the tile's mask and a pixel at the place's point to check if the point is actually inside the tile.

This is the code I use to calculate the place where my tiles must be displayed on the screen.
x = ((tile.width/2)*rowx+((tile.width/2)*rowy))
y = ((tile.height*4)+((tile.height/2)*rowy)-((tile.height/2)*rowx)) + (300-tile.eight*1.5)



I've also looked around a bit to see how other people fixed their math isometric problem but most of their solutions were above me.

One option I heard of was using matrices to rotate the tiles so that they form squares and can be used fully in a isinRect check.
Though I have no idea how to do that.

So anyone have any advice?
« Last Edit: June 13, 2012, 04:43:02 AM by EmptyNull » Logged
Christian Knudsen
Level 10
*****



View Profile WWW Email
« Reply #1 on: June 13, 2012, 04:25:38 AM »

This might be helpful:

http://laserbrainstudios.com/2010/08/the-basics-of-isometric-programming/

Smiley
Logged

Laserbrain Studios
Currently working on Hostile Takeover (TIGSource DevLog)
EmptyNull
Level 0
*


View Profile
« Reply #2 on: June 13, 2012, 04:53:29 AM »


Sadly this does not help me with my issue.
Since photobucket refused to replace my image for some reason it wasn't updated and I posted the old example picture here.
And as you can see on that picture my 0.0 origin is at the west side.
And the one in your example sadly uses a top origin.
Logged
Polly
Level 2
**


View Profile
« Reply #3 on: June 13, 2012, 05:33:36 AM »

It's super easy. First divide the point coordinates by the tile size, and then simply add / subtract the coordinates for both axes.

Code:
float x = position_x / tile_width;
float y = position_y / tile_height;

int tile_x = x + y - origin_y;
int tile_y = x - y - origin_y;

Should give you this Smiley

Logged
EmptyNull
Level 0
*


View Profile
« Reply #4 on: June 13, 2012, 05:41:18 AM »

That is remarkable. Such elegant math.
Simply brilliant! Hats off to you good sir!  Gentleman
Logged
Christian Knudsen
Level 10
*****



View Profile WWW Email
« Reply #5 on: June 13, 2012, 07:04:32 AM »

Which is pretty much the exact algorithm in the blog post I linked to...

Wink
Logged

Laserbrain Studios
Currently working on Hostile Takeover (TIGSource DevLog)
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic