Hey guys could some one please help me understanding this post
http://www.gamedev.n...aps-part-i-r747
In the part mouse matters, i understand the first and second steps(find regionx regiony and mousemapx mousemapy) but not the steps 3 and 4 (finding regiondx regiondy). I know the html code is messed up in the fourth step so i put it on a new html page and here is what it gave (its a table):
/Color/-----/RegionDX/-----/RegionDY/
/red/----------/(-1)/---------------/(-1)/
/yellow/--------/0/----------------/(-1)/
/white/---------/0/------------------/0/
/green/------/(-1)/-----------------/1/
/blue/----------/0/------------------/1/
They say i must find the region (color) in the MouseMap where the mouse is but how can i translate this in programming?
Thanks for your help!
Isometric mouse mapping i need help understanding a post
Started by jeremyskateboard, Oct 19 2012 03:47 PM
3 replies to this topic
Sponsor:
#2 Crossbones+ - Reputation: 2422
Posted 19 October 2012 - 05:22 PM
For step 3 and beyond you would read your mouse map image into an array that is height X width X bpp. You would then build a mouse map array doing something like (imagine you have an image class with accessors or a struct):
[source lang="cpp"]std::vector< TouchRegion > touch_map;touch_map.reserve(image.width() * image.height());const uint8_t* pixels = image.data();uint32_t size = image.width() * image.height() * image.bpp();uint32_t stride = image.bpp();for(uint32_t x = 0; x < size; x += stride){ if(pixels[x] == 255 && pixels[x + 1] == 255 && pixels[x + 2] == 255) { touch_map.push_back(TouchRegion::TopLeft); } // TODO: you would fill in the other cases here depending on if you are using hex, diamond, etc.}[/source]
Now you have an array built that you can query extremely easily. You just check the location (i.e. tile 0) and see which Region it is and modify based on that. (i.e. if you hit TouchRegion::TopLeft you modify the coordinates by (-1, -1). I tried to write it out as prose as I could, I hope it helps with your issue.
[source lang="cpp"]std::vector< TouchRegion > touch_map;touch_map.reserve(image.width() * image.height());const uint8_t* pixels = image.data();uint32_t size = image.width() * image.height() * image.bpp();uint32_t stride = image.bpp();for(uint32_t x = 0; x < size; x += stride){ if(pixels[x] == 255 && pixels[x + 1] == 255 && pixels[x + 2] == 255) { touch_map.push_back(TouchRegion::TopLeft); } // TODO: you would fill in the other cases here depending on if you are using hex, diamond, etc.}[/source]
Now you have an array built that you can query extremely easily. You just check the location (i.e. tile 0) and see which Region it is and modify based on that. (i.e. if you hit TouchRegion::TopLeft you modify the coordinates by (-1, -1). I tried to write it out as prose as I could, I hope it helps with your issue.
Edited by Saruman, 19 October 2012 - 05:24 PM.
#3 Members - Reputation: 102
Posted 19 October 2012 - 06:32 PM
I don't really understand what you are saying
why do you check the pixels of the image? And also, we already know the width and height of the image. I don't want to check if the image is really of a certain colour(red, yellow, white, green, blue) they are only fictive zones. If the mouse click occurs inside the rhombus then it should return the coords of this tile but the thing is tilesets are made of rectangles so i want to check if the click has occured inside the rhombus or outside of it because depending on this the coordinates of the tile will be different. In an isometric tileset the rows and columns dont go from right to left and up down but in an angled way and so if the click occurs in one of the 4 corners of the tile the x and y value will either increase or decrease.Thanks for any further help
#4 Crossbones+ - Reputation: 2422
Posted 19 October 2012 - 07:39 PM
Just to make sure we're on the same page the image I was saying to load is the actual mouse map, the one from the article you linked (unfortunately I can't embed a GIF on these forums but the rectangle right under the line "It had a little picture, kind of like this:")
The reason you read the pixels to check the color is to get the proper zone. For example if you clicked in the red zone you would modify the tile position by (-1, -1), etc. You don't have to do it by loading the image and building a map with the colors, it's just easier to modify down the road. If you didn't want to load a mouse map image you could just build the array yourself and include it in the code where you assign each zone a number or enum.
So if you loaded the image above and in step 2 you got the coordinates (0,0) then you would look up the index 0 of the array to see which zone you hit and then modify accordingly.
The reason you read the pixels to check the color is to get the proper zone. For example if you clicked in the red zone you would modify the tile position by (-1, -1), etc. You don't have to do it by loading the image and building a map with the colors, it's just easier to modify down the road. If you didn't want to load a mouse map image you could just build the array yourself and include it in the code where you assign each zone a number or enum.
So if you loaded the image above and in step 2 you got the coordinates (0,0) then you would look up the index 0 of the array to see which zone you hit and then modify accordingly.






