Author Topic: Dungeon map scaling issue ?  (Read 1134 times)

MetalZelda

  • Hero Member
  • *****
  • Posts: 508
    • View Profile
Dungeon map scaling issue ?
« on: December 10, 2016, 02:47:21 pm »
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)


Diarandor

  • Hero Member
  • *****
  • Posts: 781
  • Cats are cool! (ΦωΦ)
    • View Profile
Re: Dungeon map scaling issue ?
« Reply #1 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)

MetalZelda

  • Hero Member
  • *****
  • Posts: 508
    • View Profile
Re: Dungeon map scaling issue ?
« Reply #2 on: December 11, 2016, 05:01:24 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
« Last Edit: December 11, 2016, 05:03:12 pm by MetalZelda »

Diarandor

  • Hero Member
  • *****
  • Posts: 781
  • Cats are cool! (ΦωΦ)
    • View Profile
Re: Dungeon map scaling issue ?
« Reply #3 on: December 11, 2016, 07:39:54 pm »
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
« Last Edit: December 11, 2016, 07:42:31 pm by Diarandor »

Zefk

  • Sr. Member
  • ****
  • Posts: 492
  • Just helping Solarus
    • View Profile
    • Zelzec Business
Re: Dungeon map scaling issue ?
« Reply #4 on: December 11, 2016, 09:03:16 pm »
Maybe the image size? Does not Solarus zoom during game play?
http://forum.solarus-games.org/index.php/topic,756.msg4073.html#msg4073

Diarandor

  • Hero Member
  • *****
  • Posts: 781
  • Cats are cool! (ΦωΦ)
    • View Profile
Re: Dungeon map scaling issue ?
« Reply #5 on: December 12, 2016, 12:07:21 am »
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...)

Diarandor

  • Hero Member
  • *****
  • Posts: 781
  • Cats are cool! (ΦωΦ)
    • View Profile
Re: Dungeon map scaling issue ?
« Reply #6 on: December 12, 2016, 12:38:35 am »
If what I found is the problem, another solution would be to modify the function and keep the image unchanged.

MetalZelda

  • Hero Member
  • *****
  • Posts: 508
    • View Profile
Re: Dungeon map scaling issue ?
« Reply #7 on: December 14, 2016, 01:48:19 pm »
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.

Diarandor

  • Hero Member
  • *****
  • Posts: 781
  • Cats are cool! (ΦωΦ)
    • View Profile
Re: Dungeon map scaling issue ?
« Reply #8 on: December 14, 2016, 07:27:13 pm »
I think the problem comes, either from the image, or from here:
Code: Lua
  1. if (self.dungeon.floor_width * 119) / (self.dungeon.floor_height * 123) > 1 then
  2.     -- The floor height does not use the entire vertical space.
  3.     minimap_height = self.dungeon.floor_height * 123 / self.dungeon.floor_width
  4.     minimap_y = (119 - minimap_height) / 2
  5.   else
  6.     -- The floor width does not use the entire horizontal space.
  7.     minimap_width = self.dungeon.floor_width * 119 / self.dungeon.floor_height
  8.     minimap_x = (123 - minimap_width) / 2
  9.   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
Code: [Select]
self.dungeon.floor_width / self.dungeon.floor_height > 123 / 119that 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.
« Last Edit: December 14, 2016, 07:28:48 pm by Diarandor »

Diarandor

  • Hero Member
  • *****
  • Posts: 781
  • Cats are cool! (ΦωΦ)
    • View Profile
Re: Dungeon map scaling issue ?
« Reply #9 on: December 14, 2016, 07:48:52 pm »
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.

Christopho

  • Administrator
  • Hero Member
  • *****
  • Posts: 1043
    • View Profile
Re: Dungeon map scaling issue ?
« Reply #10 on: December 14, 2016, 08:06:34 pm »
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.

Diarandor

  • Hero Member
  • *****
  • Posts: 781
  • Cats are cool! (ΦωΦ)
    • View Profile
Re: Dungeon map scaling issue ?
« Reply #11 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.
« Last Edit: December 14, 2016, 08:34:40 pm by Diarandor »

MetalZelda

  • Hero Member
  • *****
  • Posts: 508
    • View Profile
Re: Dungeon map scaling issue ?
« Reply #12 on: December 14, 2016, 09:22:21 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