Dungeon map scaling issue ?

Started by MetalZelda, December 10, 2016, 02:47:21 PM

Previous topic - Next topic
Hi.

So, while making dungeon minimap for the pause menu, I ran into a problem.
The map background is a placeholder from BoM

If I set the scale of the dungeon floor to the size of the map (for testing if scaling is right), the placement of bitmaps and the position of things can be wrong.

Here, I placed Link at coordinate 0, 0 (8, 13) and the map location on this world is set to 0, 0



You might see that here, the scaling is correct, I purposely show the configuration file so you might be able to reproduce it all by yourself

But, if I set the width / height of the minimap scaling to the size of the room, this happen



Link's position is still 8, 13 and map coordinate in the world is still 0, 0.

I use the MoS and BoM menu, both are similar. So you might be able to reproduce this bug.

My guess is, the faulty part is on map_submenu:to_dungeon_minimap_coordinates(x, y)


This seems annoying stuff, which is hard to debug without more info.  :-\
Could you print and show us the values of the following variables of the function "map_submenu:to_dungeon_minimap_coordinates(x, y)" for that position of the hero in the second image? That may help.

minimap_width, minimap_height,
minimap_x, minimap_y,
self.dungeon.floor_width, self.dungeon.floor_height
x, y (the input values of the function)
"If you make people think they're thinking, they'll love you. But if you really make them think, they'll hate you."

December 11, 2016, 05:01:24 PM #2 Last Edit: December 11, 2016, 05:03:12 PM by MetalZelda
Quote from: Diarandor on December 11, 2016, 12:28:25 PM
This seems annoying stuff, which is hard to debug without more info.  :-\
Could you print and show us the values of the following variables of the function "map_submenu:to_dungeon_minimap_coordinates(x, y)" for that position of the hero in the second image? That may help.

minimap_width, minimap_height,
minimap_x, minimap_y,
self.dungeon.floor_width, self.dungeon.floor_height
x, y (the input values of the function)

This is the same function for both MoS, BoM and my project, nothing has been changed, same for graphic placement
floor width and floor height are in the pictures

https://github.com/solarus-games/zsdx/blob/48ca2a183761599331a98d3db72d6ce403b25db9/data/menus/pause_map.lua#L342
https://github.com/wrightmat/zbom/blob/45e4329a247622fc36e13bdc93c5775067ed2166/data/scripts/menus/pause_map.lua#L329
https://github.com/MetalES/Project-Zelda/blob/94717c09015ef4eba5d4b829dd86cb04708df3e5/data/scripts/menus/pause_submenus/map.lua#L339

December 11, 2016, 07:39:54 PM #3 Last Edit: December 11, 2016, 07:42:31 PM by Diarandor
I haven't read all the code of the scripts and I don't have enough time these days to do so, but I will try to help anyway. I have read the code of the function "map_submenu:to_dungeon_minimap_coordinates(x, y)" and it seems to be ok. Besides, if your code is the same that the one in these games, it should work perfectly as it does in the other games. Hence this is unlikely to be a bug then, but a different issue: maybe a problem of you giving wrong coordinates or sizes to that script, or maybe a problem of the image itself (maybe it is not centered correctly).

I noticed that your map image here:
https://github.com/wrightmat/zbom/blob/45e4329a247622fc36e13bdc93c5775067ed2166/data/sprites/menus/dungeon_maps/map1.png
is in only 1 file, instead of splitting it into several images, on for each floor, like in zsdx. So maybe the problem is related to this (maybe you are not giving the good coordinates/sizes, or some shifts in the position of the map (or its image) and other elements may be needed, I don't know). Besides, the chest below (in your second image) is too low, outside of the map image, so this probably means that you are giving a size of the map (or minimap) bigger than it is. Since your image has all the floors of the map in the same image, maybe it is taking the size of all the image as the size of each floor of the map, which is bigger than it should; at least that would explain the problem.

If you give us the value of the variables I mentioned before, that would help a lot to deduce what is wrong (or at least to know what is not wrong). Could you please print and give us the values of the following variables in that function?
minimap_width, minimap_height,
minimap_x, minimap_y,
self.dungeon.floor_width, self.dungeon.floor_height
"If you make people think they're thinking, they'll love you. But if you really make them think, they'll hate you."


I think I figured out how to solve part of the problem. I may be wrong, though. (I was probably wrong about the chest position, which may be ok, so forget about that.)

A possible problem is that the function "map_submenu:to_dungeon_minimap_coordinates(x, y)" calculates the minimap position assuming that the map image is centered (that's how that function calculates the minimap coordinate). However each rectangle corresponding to a floor of the minimap image is not centered in the image itself (there is too much space in the down part of each rectangle of size 123 x 119). The solution would be to shift each rectangle of the minimap (move them a bit down to make them centered on each rectangle of size 123 x 119. I don't know if that would solve all the problem or just part of it. (A very stupid question, just to make sure of it: I guess that your minimap image is completely proportional to the "real" floor, isn't it? Otherwise this minimap would not work correctly with any code...)
"If you make people think they're thinking, they'll love you. But if you really make them think, they'll hate you."

If what I found is the problem, another solution would be to modify the function and keep the image unchanged.
"If you make people think they're thinking, they'll love you. But if you really make them think, they'll hate you."

Yeah that might be the calculation in the function that is problematic, I'm trying to figure out. The bitmap can't be the culprit, because it is a 119x123 picture with it's origin set at 0, 0.

December 14, 2016, 07:27:13 PM #8 Last Edit: December 14, 2016, 07:28:48 PM by Diarandor
I think the problem comes, either from the image, or from here:
Code (Lua) Select
if (self.dungeon.floor_width * 119) / (self.dungeon.floor_height * 123) > 1 then
    -- The floor height does not use the entire vertical space.
    minimap_height = self.dungeon.floor_height * 123 / self.dungeon.floor_width
    minimap_y = (119 - minimap_height) / 2
  else
    -- The floor width does not use the entire horizontal space.
    minimap_width = self.dungeon.floor_width * 119 / self.dungeon.floor_height
    minimap_x = (123 - minimap_width) / 2
  end


My guess is that this function assumes that the picture of the map is perfectly centered inside its rectangle because of this:
the first condition is
self.dungeon.floor_width / self.dungeon.floor_height > 123 / 119
that is, the proportion width/height is bigger for the floor than for the minimap rectangle, which is the case in your map;
then the code above shifts the minimap coordinates vertically by giving a positive value to the variable "minimap_y", which centers the coordinates. (I think that this shift is only applied for the things you draw on the minimap, but not to the position of the minimap.) I think this would only work if the drawing of the image is centered in its 123x119 rectangle, which is not the case for your png image; so you should try either to center the image inside its rectangle (in the png file I mean), or change the code.

Maybe Christopho could help to solve this issue since he was who wrote the original code.
"If you make people think they're thinking, they'll love you. But if you really make them think, they'll hate you."

For instance, in zsdx some dungeon minimaps have the image (in the png) shifted on the left and/or up sides:
https://github.com/solarus-games/zsdx/blob/48ca2a183761599331a98d3db72d6ce403b25db9/data/sprites/menus/dungeon_maps/map6_0.png
https://github.com/solarus-games/zsdx/blob/48ca2a183761599331a98d3db72d6ce403b25db9/data/sprites/menus/dungeon_maps/map1_0.png
The shifts seem to be different for the images of each dungeon, so I guess that you have to find the best choice for the shifts by trial and error.
"If you make people think they're thinking, they'll love you. But if you really make them think, they'll hate you."

There is no arbitrary shifting. The minimap PNG of each dungeon is always exactly the map as you can open it in the quest editor, only with an additional horizontal or vertical margin to fit in the 123x119 rectangle.

December 14, 2016, 08:16:36 PM #11 Last Edit: December 14, 2016, 08:34:40 PM by Diarandor
Ok, then I was wrong. I cannot help with this issue.  :(

Edit: but still, these margins seem different for each dungeon, and I don't understand why.
Edit2: ok, I understand that now. Maybe the margins for the maps of MetalZelda are not correct for his maps.
"If you make people think they're thinking, they'll love you. But if you really make them think, they'll hate you."

Quote from: Diarandor on December 14, 2016, 08:16:36 PM
Ok, then I was wrong. I cannot help with this issue.  :(

Edit: but still, these margins seem different for each dungeon, and I don't understand why.
Edit2: ok, I understand that now. Maybe the margins for the maps of MetalZelda are not correct for his maps.

Yes the margin might be wrong, I'm gonna check this