Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

cb007sax

Mouse to tile problem

This topic is 5816 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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;

Share this post


Link to post
Share on other sites
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~

Share this post


Link to post
Share on other sites
agreed, there needs to be a nice comprehensive article on this subject, with many different examples and different tile shapes and sizes

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Isometric Game Programming with DirectX 7, has like a huge section on this.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!