Mouse to tile problem

Started by
16 comments, last by cb007sax 21 years, 4 months ago
I am having real problems with getting map coordinates in an isometric map from the mouse coordinates. Can i speak with anyone who is comfortable with the subject online? I have ready a ton of tutorials and it''s just not sticking clear in my mind. Any help will be appreciated.
Advertisement
I don''t really have the time for a dedicated talk, but the click problem dominates this forum - in my opinion, there is no really good resource out there for those unable to derive a solution on their own. I''ve gone through the procedure from A-Z with someone in a thread once, but since the search is gone, I can''t find it anymore.
I''m now thinking that I should write a very detailed article about it, specifically explaining why the presented algorithms work. The article would cover rhombe and rectangular tiles, both on flat maps and maps with varying altitudes.
Would anyone be in favour of this?

- JQ
Full Speed Games. Are back.
~phil
quote:Original post by JonnyQuest
I don''t really have the time for a dedicated talk, but the click problem dominates this forum - in my opinion, there is no really good resource out there for those unable to derive a solution on their own. I''ve gone through the procedure from A-Z with someone in a thread once, but since the search is gone, I can''t find it anymore.
I''m now thinking that I should write a very detailed article about it, specifically explaining why the presented algorithms work. The article would cover rhombe and rectangular tiles, both on flat maps and maps with varying altitudes.
Would anyone be in favour of this?

- JQ
Full Speed Games. Are back.


Oh god yes.

It''s really a shame that this is one of those things that is amazingly elusive.

And a problem too is that oftentimes an article will not put it into practice with sample code.
[Piebert Entertainment] [Ask The All-Knowing Oracle A Question]------------------------------------------------------------GDSFUBY GameDev Society For UnBanning YodaTheCodaIf you want to see yoda unbanned then put this in your sig ------------------------------------------------------------DAIAGA Dave Astle is a God Association. To join, put this in your sig!Founder and High Priest of DAIAGA[edited by - YodaTheCoda on December 10, 2003 1:57:54 PM]
It''s last week of uni before the holidays next week, so I''ll try and cough something up, possibly already at the weekend. I can early-host it on my site and then send it to gamedev. (the latter takes a few weeks)
I''ll let you know when something''s done in a new Iso Land thread.

- JQ
Full Speed Games. Are back.
~phil
Here''s a couple of procedures for an isometric engine I was writing (in Delphi):
procedure TForm1.MapToScreen(MapX, MapY, MapZ: Double; out ScreenX, ScreenY: Integer);begin  ScreenX := Trunc(32 *(MapY + MapX))- OffsetX;  ScreenY := Trunc(16 *(MapY - MapX - MapZ))- OffsetY;end;procedure TForm1.ScreenToMap(ScreenX, ScreenY: Integer; out MapX, MapY: Double);var  t1, t2: Integer;begin  t1 := ScreenX + OffsetX;  t2 := 2 *(ScreenY + OffsetY);  MapX := (t1 - t2)/ 64;  MapY := (t1 + t2)/ 64;end; 
[ PGD - The Home of Pascal Game Development! ] [ Help GameDev.net fight cancer ]
Some bla I came up with for my sidescroller (2d "square" tiles):



// If we''re writing to the level, the mouse pointer controls where on the screen we''re
// writing the new element. We''ll "int" the actual focus when it comes time to adding it to the map.
// First, get the position of the cursor
GetCursorPos( &ptCursor );
// and translate it to window coordinates
ScreenToClient( hWnd, &ptCursor );
// Next, calculate the map position relative to mouse. I broke down the calculation with the
// x-axis for your benefit, to make it more obvious.
// Optimization of code and execution speed isn''t too important in WRITE mode-
// ...we''re just editing the map, after all...
float PositionAlongX = ptCursor.x / ScreenWidth; // 0 = left border of screen, 1 = right border
float TilesFromLeft = PositionAlongX * SpanX; // how many tiles from the left side
Focus.posx = TilesFromLeft + (float)mapx; // The X position onscreen, in tiles
// Here it is as one statement (the y-axis version):
Focus.posy = ((ptCursor.y / ScreenHeight) * SpanY) + (float)mapy;
// If we''re in bounds of the map, let''s track what the value "under" our pointer is:
if(MapInfo && (int)((int)Focus.posy*MapWidth+(int)Focus.posx) < MapWidth*MapHeight)
FocusOver = (int)MapInfo[(int)((int)Focus.posy*MapWidth+(int)Focus.posx)];


---email--- Tok ----surf----
~The Feature Creep of the Family~
--------------------------~The Feature Creep of the Family~
agreed, there needs to be a nice comprehensive article on this subject, with many different examples and different tile shapes and sizes
Just so you guys know - I''m actually working on the article. I might release it in two parts if it gets too big, but you can no doubt expect to see something around Xmas. I was a bit over-eager with my estimates of free time, I kind of got held up in end-of-term stress.

- JQ
Full Speed Games. Are back.
~phil
anyone have links for now?
Isometric Game Programming with DirectX 7, has like a huge section on this.

This topic is closed to new replies.

Advertisement