• Advertisement

Archived

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

Mouse to tile problem

This topic is 5550 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
Taken from my engine, I hope it helps:


void get_world_x_y()
{
float x,y,x1,y1,a,t;

x=(float)(mouse_x*9.0f/window_width)-(9.0f/2.0f);
y=(float)((window_height-mouse_y)*6.0f/window_height)-(6.0f/2.0f);

a=(rz)*3.1415926/180;
t=(rx)*3.1415926/180;

y=y/cos(t);

x1=x*cos(a)+y*sin(a);
y1=y*cos(a)-x*sin(a);


scene_mouse_x=-cx+x1;
scene_mouse_y=-cy+y1;

}


Height Map Editor

Share this post


Link to post
Share on other sites
man this is killing me, i''ve done this for like a week and got nothing, all the stuff you guys have posted have been helpful but i need a good tut. I would like to buy that book but don''t feel like spending money... doesn''t anyone know alot on the subject and want to talk on aim ?

Share this post


Link to post
Share on other sites
I''ve submitted an article a while back on using 2d Isometric tiles with a height maped mouse map, and I''m still waiting on a reply about when / if it will be shown.

If you are still needing help drop me an e-mail and I will try and help you out.

The amount of tutorials out there are numerous, and I''ve looked at most of them. I still think that TANSTAAFL''s book describes it best and in the simplest form.



When I find my code in tons of trouble,
Friends and colleages come to me,
Speaking words of wisdom:
"Write in C."

Share this post


Link to post
Share on other sites
quote:
Original post by cb007sax
2d............................
i don''t want to use angle math though


Why? It can eb evry helpful, and it''s not even complicated.



Height Map Editor

Share this post


Link to post
Share on other sites
A nice solution that Civilization 2 uses is a bitmap with various colors for the different parts of an isometric tile. I assume it calculates where the mouse is on the bitmap, finds what color is at that position, and uses that to determine the tile location.

Share this post


Link to post
Share on other sites
yeah, that is what I am going to use in my game. The game sees an iso tile as a bunch of overlapping rectangles. When you click, it calculates which rectangle you clicked on, then calculates the click coordinates relative to the rectangle. It then compares the relative coordinate on that click to an iso tile in memory, where each section is a different color. Based on the color it can detrmine the tile.

Share this post


Link to post
Share on other sites

  • Advertisement