Isometric tile picking and matrix

Anything about development not directly related to libgdx, e.g. OpenGL, Android APIs etc.

Isometric tile picking and matrix

Postby tonyp7 » Sun Nov 25, 2012 6:02 am

Hello,

I have a classic isometric engine with tiles with a height of 1/2 the width.
Image

I'm trying to understand the mechanism for picking.

First, I get the cartersian coordinates using camera.unproject and store it into a Vector2 touchCartesian. This is working fine.

Then I create the following:
Matrix3 m3x = new Matrix3();
m3x.idt();
m3x.rotate(45.0f);
m3x.scale(1.0f, 0.5f);
m3x.inv();

And do:
touchCartesian.mul(m3x);

Finally i get the result as:
x_iso = (int)touchCartesian.x;
y_iso = (int)touchCartesian.y;

The result is interesting, I don't get garbage back, but I'm not getting the right value either. Problem is I'm not a math wizard and this is a bit beyond me.

Can anybody share their experience/knowledge on isometric picking?
tonyp7
 
Posts: 336
Joined: Fri Feb 17, 2012 1:02 pm

Re: Isometric tile picking and matrix

Postby tonyp7 » Mon Nov 26, 2012 7:52 am

I found the answer.

Scale must be m3x.scale(1.0f, 2.0f); Why? I've got no idea.

Image

This was drawn using:
m4x = new Matrix4();
m4x.idt();
m4x.rotate(0, 0, 1.0f, 45.0f);
m4x.scale(1.0f, 2.0f, 1.0f);
m4x.inv();

spriteBatch.setTransformMatrix(m4x);
spriteBatch.begin();
spriteBatch.draw(square, 0f, 0f, 1.0f, 1.0f);
spriteBatch.draw(square, 1.0f, 0f, 1.0f, 1.0f);
spriteBatch.draw(square, 1.0f, 1.0f, 1.0f, 1.0f);
spriteBatch.draw(square, 0f, 1.0f, 1.0f, 1.0f);
spriteBatch.end();
tonyp7
 
Posts: 336
Joined: Fri Feb 17, 2012 1:02 pm

Re: Isometric tile picking and matrix

Postby tonyp7 » Sat Dec 01, 2012 3:01 pm

OK I have fully understood how it works now... It was more complicated than I thought. There is a trick with a sqrt(2)... Anyway, I wrote a tutorial; I'm sure it'll interest a few people here:

http://www.alcove-games.com/isometric_tile_picking.php
tonyp7
 
Posts: 336
Joined: Fri Feb 17, 2012 1:02 pm

Re: Isometric tile picking and matrix

Postby gorilabrutal » Tue Dec 18, 2012 3:23 am

great job!!!!
your tutorials are the best…
thanks!!
gorilabrutal
 
Posts: 1
Joined: Tue Dec 18, 2012 3:15 am

Re: Isometric tile picking and matrix

Postby tonyp7 » Wed Dec 19, 2012 1:28 am

Well thanks, I'm happy to share some knowledge :)
tonyp7
 
Posts: 336
Joined: Fri Feb 17, 2012 1:02 pm

Re: Isometric tile picking and matrix

Postby TheCrack » Sun Jul 16, 2017 8:18 pm

Tony,

I really liked your tutorial, it was extremely informative and got me a few steps forward. I downloaded your demo and stepped through the code and it all works flawlessly.

The problem I'm running into, is i'm rendering my isometric map using the libgdx IsometricTiledMapRenderer. When I use this, the transform matrix does not appear to work correctly.

I assume I'm missing something obvious. Have you run into this before? Or have any examples that would assist?

Thanks.
TheCrack
 
Posts: 1
Joined: Sun Jul 16, 2017 6:57 pm


Return to General Development

Who is online

Users browsing this forum: No registered users and 5 guests