Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invert Y axis option #249

Open
Beast96GT opened this issue Jul 29, 2012 · 34 comments
Open

Invert Y axis option #249

Beast96GT opened this issue Jul 29, 2012 · 34 comments

Comments

@Beast96GT
Copy link

@Beast96GT Beast96GT commented Jul 29, 2012

Currently the tiling y-axis starts with the height at 0 at the top and incrementing as it goes down the map. I think it would a be a nice feature, but relatively simple task, to add some kind of checkbox option to invert the Y axis so that (0,0) starts at the bottom and then (0, 1) is the tile above.

Thanks!

@encukou

This comment has been minimized.

Copy link
Contributor

@encukou encukou commented Aug 14, 2012

I think this should be done in the software that uses the map, i.e. if you're making an OpenGL game, have your OpenGL loader adjust the coordinates accordingly. I don't see a need for the GUI and all other loaders to support a feature like that.

@bjorn

This comment has been minimized.

Copy link
Owner

@bjorn bjorn commented Aug 14, 2012

I guess it may still be confusing to see different coordinates in Tiled than in the game. So, when such a feature would be implemented in Tiled, it would have to be purely a presentation thing and not something that affects any internal data structures or the map format.

@encukou

This comment has been minimized.

Copy link
Contributor

@encukou encukou commented Aug 14, 2012

In that case, also consider offsets. Maps in my game are chunks of a large world, so (0, 0) in a map might translate to (256, 512) in the game.

@Beast96GT

This comment has been minimized.

Copy link
Author

@Beast96GT Beast96GT commented Aug 17, 2012

You're right. I currently modify the coordinates for my game.. however, I
would argue the benefit of such a feature would make things more clear
during placement, and at almost no cost. I vote implement. :)

=Chris

On Tue, Aug 14, 2012 at 11:38 AM, Petr Viktorin notifications@github.comwrote:

In that case, also consider offsets. Maps in my game are chunks of a large
world, so (0, 0) in a map might translate to (256, 512) in the game.


Reply to this email directly or view it on GitHubhttps://github.com//issues/249#issuecomment-7731675.

@davos555

This comment has been minimized.

Copy link

@davos555 davos555 commented May 20, 2013

I think this is a good idea, rather than having to adjust the code in game it would make more sense just to have an option here. Then you wouldn't need to make boilerplate code just to invert the access in game for every object.

@graehu

This comment has been minimized.

Copy link

@graehu graehu commented Oct 30, 2014

Just wondering if this is a dead feature request or if it's been moved somewhere else.
And just to be clear, is this feature about changing the status bar display?

statusbar

So for instance in the above picture you'd have an option to display 0, 0 instead of 0, 15.

@bjorn

This comment has been minimized.

Copy link
Owner

@bjorn bjorn commented Oct 30, 2014

Just wondering if this is a dead feature request or if it's been moved somewhere else.
And just to be clear, is this feature about changing the status bar display?

This issue represents the most up-to-date state. After a short discussion there was a general agreement that it would be nice for Tiled to support this (indeed affecting the status bar display only), but so far no work has been done on it. It's not dead because it's still open for implementation.

@graehu

This comment has been minimized.

Copy link

@graehu graehu commented Oct 30, 2014

I'm thinking about forking and adding this feature but I'm not sure if it should just be a checkbox to invert or something more complicated as suggested above.

I think that the best solution would be a pop-up on the status bar that lets you set an offset (x, y).
So for instance if you have a 16x16 and you want the bottom left to be (0, 0) you'd set an offset of (0, -16).

If that sounds unreasonable let me know, or if you had a different idea. 😄

@encukou

This comment has been minimized.

Copy link
Contributor

@encukou encukou commented Oct 30, 2014

Offsets are a more advanced feature, the main thing here is Y flipping (in Tiled the Y coordinate grows down, in OpenGL it traditionally grows up). You can do that with a checkbox, plus some attribute saved in the map file.
If you do that, adding e.g. X flipping and X/Y offsets should be straightforward.

@graehu

This comment has been minimized.

Copy link

@graehu graehu commented Oct 30, 2014

It seems to me that if you just add an offset you wouldn't need to flip it. X flipped would simply be setting an offset of your maps width. Unless displaying negative numbers is unacceptable, I think it would be a viable solution.

Though I guess that it might not be immediately obvious to set the offset to your maps width or height in order to get the inverted values.

@Beast96GT

This comment has been minimized.

Copy link
Author

@Beast96GT Beast96GT commented Oct 30, 2014

I originally requested this feature because I use openGL coordinates to
correlate to map tiles (as Petr said). However, it makes the entire
process more tedious for visualizing placement and debugging in general
when you have to flip the Y coordinates. Which checkbox are you talking
about? I'd still really like to see this feature implemented if it's not.

Chris Long

On Thu, Oct 30, 2014 at 9:03 AM, Petr Viktorin notifications@github.com
wrote:

Offsets are a more advanced feature, the main thing here is Y flipping (in
Tiled the Y coordinate grows down, in OpenGL it traditionally grows up).
You can do that with a checkbox, plus some attribute saved in the map file.
If you do that, adding e.g. X flipping and X/Y offsets should be
straightforward.


Reply to this email directly or view it on GitHub
#249 (comment).

@graehu

This comment has been minimized.

Copy link

@graehu graehu commented Oct 30, 2014

Which checkbox are you talking about?

@Beast96GT I'm talking about adding a check box (perhaps on the statusbar) that inverts y when ticked. Which was the original suggestion as far as I can tell, but other suggestions have been made since which I wanted to consider before I did any work.

@Beast96GT

This comment has been minimized.

Copy link
Author

@Beast96GT Beast96GT commented Oct 30, 2014

If you can do that, it would be awesome. I would think it would be
trivial to implement, but I haven't looked at the source...

On Thu, Oct 30, 2014 at 10:00 AM, Graham Hughes notifications@github.com
wrote:

Which checkbox are you talking about?

@Beast96GT https://github.com/Beast96GT I'm talking about adding a
check box (perhaps on the statusbar) that inverts y when ticked. Which was
the original suggestion as far as I can tell, but other suggestions have
been made since which I wanted to consider before I did any work.


Reply to this email directly or view it on GitHub
#249 (comment).

@bjorn

This comment has been minimized.

Copy link
Owner

@bjorn bjorn commented Oct 30, 2014

Unfortunately adding a checkbox on the actual status bar is not something I can accept in general, because it would add visual noise for the majority of people who have no need for this feature. I think it would be fine as a checkbox in the Preferences dialog, though.

@Beast96GT

This comment has been minimized.

Copy link
Author

@Beast96GT Beast96GT commented Oct 30, 2014

Sure. It should be in the general preferences as once it's set, you're
probably not going to change it again. Let me know if you go through with
it!

On Thu, Oct 30, 2014 at 4:44 PM, Thorbjørn Lindeijer <
notifications@github.com> wrote:

Unfortunately adding a checkbox on the actual status bar is not something
I can accept in general, because it would add visual noise for the majority
of people who have no need for this feature. I think it would be fine as a
checkbox in the Preferences dialog, though.


Reply to this email directly or view it on GitHub
#249 (comment).

@jrmgx

This comment has been minimized.

Copy link

@jrmgx jrmgx commented Dec 1, 2015

I'm much in favor of this feature request! :)

@bjorn

This comment has been minimized.

Copy link
Owner

@bjorn bjorn commented Sep 26, 2016

Also requested on the forum.

@ghost

This comment has been minimized.

Copy link

@ghost ghost commented Nov 28, 2016

This feature would be very helpful.

@bjorn

This comment has been minimized.

Copy link
Owner

@bjorn bjorn commented Nov 28, 2016

I think this is a good idea, rather than having to adjust the code in game it would make more sense just to have an option here. Then you wouldn't need to make boilerplate code just to invert the access in game for every object.

@davos555 I realize I'm a bit late with this reply, but I just thought I'd point out that I see this option as only a display option in Tiled. It would not affect the actual coordinates stored in a TMX file. So if you want to use the inverted coordinates in your game, you'll still have to invert them while or after loading the map. That is because if the TMX format would support storing inverted coordinates, then every loader out there would suddenly need to add such conversion code.

@kibertoad

This comment has been minimized.

Copy link

@kibertoad kibertoad commented Nov 28, 2016

@bjorn Why can't this conversion be applied transparently during the save process so that loaders do not have to do anything at all?.. Aren't coords actually saved?

@ghost

This comment has been minimized.

Copy link

@ghost ghost commented Nov 28, 2016

@bjorn

This comment has been minimized.

Copy link
Owner

@bjorn bjorn commented Dec 2, 2016

@bjorn Why can't this conversion be applied transparently during the save process so that loaders do not have to do anything at all?.. Aren't coords actually saved?

@kibertoad There are many loaders either integrated into various game development frameworks or provided by 3rd parties, that both read the map file and render the map. When an option to invert the Y axis in the TMX file is introduced, then in order to render the map correctly, they would all need to be aware of this option and invert the Y axis when appropriate while rendering.

I think it is better to keep a particular coordinate system on the file format level so that we are all on the same page. At the same time, I understand that some people are working with their coordinates inverted, and that it could help if Tiled could display them as such.

@ShipshapeDetour In addition to the status bar I think it'll need to affect the Properties view as well, but still you're right that this is less work than changing the interpretation of the data.

@kibertoad

This comment has been minimized.

Copy link

@kibertoad kibertoad commented Dec 2, 2016

@bjorn Yes, if this is implemented as "invertCoords = true" parameter. What I mean by "transparently" is that if "invertCoords = true" is set, then on saving map Tiled will replace "X=1, Y=1" with "X=1, Y=100", and on loading (through Tiled) swap it all back.

@bjorn bjorn changed the title Request: Invert Y axis option Invert Y axis option Dec 2, 2016
@viking

This comment has been minimized.

Copy link

@viking viking commented Jan 30, 2018

Any news on this feature? Would the option also affect x and y coordinates in Python export plugins?

@bjorn

This comment has been minimized.

Copy link
Owner

@bjorn bjorn commented Jan 30, 2018

@viking This is currently not one of my priorities, though I think it would be a good issue for somebody new to Tiled development to look into, so I've now tagged it as such.

To avoid making the map format more complex, it is planned to only affect the display of coordinates in Tiled. So it would not affect Python export plugins.

@divitto

This comment has been minimized.

Copy link

@divitto divitto commented Feb 5, 2018

I'm interested in trying to implement this feature. Just to be clear all that needs to be done is add a check box in the settings to flip the y coordinates of tiles that is being displayed in the status bar right? Nothing else involving actually saving the maps or modifying the properties view as mentioned above? I'm confident i can do that, but this is my first time contributing so any pointers would be greatly apreciated. :)

@bjorn

This comment has been minimized.

Copy link
Owner

@bjorn bjorn commented Feb 6, 2018

Just to be clear all that needs to be done is add a check box in the settings to flip the y coordinates of tiles that is being displayed in the status bar right? Nothing else involving actually saving the maps or modifying the properties view as mentioned above?

Almost. Note that the status bar is not the only place where coordinates are displayed. And it does also affect the Properties view, since the flipping should probably be applied to both tile coordinates and the object coordinates:

  • Object coordinates are also displayed (optionally) in the Objects view. It's a column you can enable by right-clicking on the header. So the flipping needs to be supported also by the MapObjectModel.

  • Object coordinates are editable in the Properties view. In this case, the flipping needs to happen before setting the value of the property and when applying changes the user made using this control (in reverse). This is the PropertyBrowser.

Thanks for working on this, @divitto, and feel free to ask any additional questions!

@divitto

This comment has been minimized.

Copy link

@divitto divitto commented Feb 9, 2018

I've been looking over the source code in my spare time the last few days. I think it would help me a lot if you could more clearly define what exactly needs to be done, maybe a high level list of things you would do. I'm having a hard time figuring out where to start so to speak, and i think it stems from not clearly understanding the goal and everything it affects. Thanks for your time i understand you are busy with the real problems. :)

@bjorn

This comment has been minimized.

Copy link
Owner

@bjorn bjorn commented Feb 12, 2018

@divitto So, there are several places that show a tile location to the user. One such location is the hovered coordinate in the status bar. Here's one place where this text is created:

setStatusInfo(QString(QLatin1String("%1, %2 [%3]"))
.arg(mTilePosition.x())
.arg(mTilePosition.y())
.arg(tileIdString));

By finding usages of setStatusInfo you can find additional locations. You will also see that for objects tools, it includes the pixel coordinates as well. These are the locations that would need to be adjusted, such that in terms of the displayed coordinate, the origin is in the bottom-left (Y axis inverted).

In addition, I mentioned the coordinates displayed in the Properties view for a selected object. This happens here:

mIdToProperty[XProperty]->setValue(mapObject->x());
mIdToProperty[YProperty]->setValue(mapObject->y());

Since we should not confuse the user by presenting two coordinate systems, these coordinates will need to be inverted as well. But internally the coordinates will stay like they are, so when the user changes these values, they need to be inverted again before applying them to the object (in applyMapObjectValue).

Finally (if I don't forget anything), the Objects view can optionally display object coordinates. This is done over here:

case Position:
return QLatin1Char('(')
+ QString::number(mapObject->x())
+ QLatin1String(", ")
+ QString::number(mapObject->y())
+ QLatin1Char(')');

Since there are so many places spread over the code where coordinates will need to be inverted, it will make sense to write a small helper class for this, which should check the user preferences (see preferences.h, which is where you'll add this option) and perform the conversion when needed.

@divitto

This comment has been minimized.

Copy link

@divitto divitto commented Feb 16, 2018

Awesome i understand. I will get right on this as soon as possible. :)

@divitto

This comment has been minimized.

Copy link

@divitto divitto commented Feb 24, 2018

@bjorn I Believe i have completed the task. The only problem i am having is that if you place an object in standard mode and then switch to inverted coordinates (or vice-versa) the object you placed will not automaticly update it's coordinates in the PropertyBrowser, you have to move the object to make it update the coordinates in the PropertyBrowser. How do i get the PropertyBrowser to update it's display when the user clicks my checkBox in the preferences? I hope that is clear enough, I am still pretty new to the signals and slots system. It seems like i would want to create a signal whenever the checkBox is clicked that is connected to a slot that updates the PropertyBrowser but i can't seem to get it figured out. Otherwise everything looks great, any ideas?

@bjorn

This comment has been minimized.

Copy link
Owner

@bjorn bjorn commented Feb 28, 2018

@divitto Sounds great! Please open a pull request so I could have a look at the implementation.

Indeed I expect you have added a boolean property to the Preferences class that determines whether the Y axis should be inverted. This property should have a signal emitted when it is changed, like most other preferences, and the PropertyBrowser should connect to this and make sure to update the properties in case it is displaying a MapObject. It is not the first signal from the preferences that the PropertyBrowser connects to: it will look pretty similar to its connection to the Preferences::objectTypesChanged signal (except that the slot should call updateProperties instead of updateCustomProperties).

@divitto

This comment has been minimized.

Copy link

@divitto divitto commented Mar 4, 2018

@bjorn I created the pull request a few days ago but i just noticed the little red X next to my request. Did everything work okay?

@bjorn

This comment has been minimized.

Copy link
Owner

@bjorn bjorn commented Mar 4, 2018

@divitto Let's discuss that on the pull request (#1897). :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
9 participants
You can’t perform that action at this time.