Rotating objects does not align?

Thoughts, Help, Feature Requests, Bug Reports, Developing code for...

Moderators: dorpond, trevor, Azhrei

Forum rules
PLEASE don't post images of your entire desktop, attach entire campaign files when only a single file is needed, or generally act in some other anti-social behavior. :)
User avatar
Oryan77
Dragon
Posts: 452
Joined: Sun Feb 20, 2011 3:14 pm

Rotating objects does not align?

Post by Oryan77 »

I have been trying to get double doors to align properly with a rotation rather than with a flip. I can of course flip an object and it will stay aligned with a duplicate of the non flipped object. But why does rotating an object cause it to be a fraction of a pixel misaligned with the other non flipped object?

I've verified this by editing the graphic in Photoshop, making sure that the top half is exactly the same as the bottom half and each half is centered correctly.

Here is a screenshot where the top doors are not aligned because one was rotated. The bottom doors were flipped rather than rotated and are aligned properly. If you were to zoom in on the MT map, the top doors are less than a pixel off. The further out you zoom, the more they look misaligned.
doors.jpg
doors.jpg (134.83 KiB) Viewed 1533 times

User avatar
JamzTheMan
Great Wyrm
Posts: 1872
Joined: Mon May 10, 2010 12:59 pm
Location: Chicagoland
Contact:

Re: Rotating objects does not align?

Post by JamzTheMan »

Is the graphic an odd or even number of pixels high? I would imagine the door should be an odd number of pixels to have an exact middle to rotate on otherwise that may be the source of the issue?
-Jamz
____________________
Custom MapTool 1.4.x.x Fork: maptool.nerps.net
Custom TokenTool 2.0 Fork: tokentool.nerps.net
More information here: MapTool Nerps! Fork

User avatar
Oryan77
Dragon
Posts: 452
Joined: Sun Feb 20, 2011 3:14 pm

Re: Rotating objects does not align?

Post by Oryan77 »

The pixels being even or odd shouldn't matter since flipping after the rotation should put the image in the exact same position (only because the top and bottom halves of the image are exact duplicates).

Basically, the point between the 2 middle horizontal pixels is your center point. Which is where MT should be rotating. But even rotating from a "center" point one pixel higher or lower should still give proper results if you then flip the image after rotating it.

I made a new door with a black line to make an odd pixel count like you suggested (not that it will have any effect in this instance). The result is still the same as expected. But here are 3 screenshots zoomed at different distances.

Up close, you can see the pixels and see that the doors are misaligned a fraction of a pixel. There is no way to nudge them up or down to align correctly because the rotation does not seem to rotate around a pixel count.

The farther you zoom out, the more they look misaligned.

BTW, the only reason I'm bringing this up rather than flipping them instead of rotating then flipping them is because I'm using them with Wolph42's BoT double animated doors macro with attached VBL. It requires the 2nd door to rotate for the VBL to be placed correctly. But now it looks like my MT doors are glitched. :p
doors1.jpg
doors1.jpg (252.98 KiB) Viewed 1510 times
doors2.jpg
doors2.jpg (192.03 KiB) Viewed 1510 times
doors3.jpg
doors3.jpg (102.99 KiB) Viewed 1510 times


User avatar
aliasmask
RPTools Team
Posts: 9024
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: Rotating objects does not align?

Post by aliasmask »

Is this a problem in b89, or the custom build? I recall a very strange error (totally unrelated) where a person could move his token in to certain squares with snap to grid. I loaded his campaign and sure enough, it would just skip right over certain squares. Then I looked at the x,y coords.. about 1mill+ I figured the math was breaking down when at extreme x,y coordinates.

User avatar
wolph42
Winter Wolph
Posts: 9999
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: Rotating objects does not align?

Post by wolph42 »

aliasmask wrote:Is this a problem in b89, or the custom build? I recall a very strange error (totally unrelated) where a person could move his token in to certain squares with snap to grid. I loaded his campaign and sure enough, it would just skip right over certain squares. Then I looked at the x,y coords.. about 1mill+ I figured the math was breaking down when at extreme x,y coordinates.
I know that the math breaks for getTokenX/Y for extreme (e.g. 650) coordinates as in that case it returns a higher (651) value. But i don't know if thats related to this issue.

User avatar
wolph42
Winter Wolph
Posts: 9999
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: Rotating objects does not align?

Post by wolph42 »

I take my earlier confirmation back. I did a more thorough test this time and create one token of 50x50 px with alternating red and white. Then I placed it in a 50px grid maptool map and copied a 180 rotated token next to it:
result
Px alignment.png
Px alignment.png (21.91 KiB) Viewed 1494 times
as you can see, they align perfectly.

and just to be thorough, here a 'door' of 2 px thck in a 50px token. (I tested this on size medium and size large, but that result in the same picture.)
Spoiler
px alignment door.jpg
px alignment door.jpg (51.91 KiB) Viewed 1494 times
zoomed out:
Spoiler
px align zoomed out.jpg
px align zoomed out.jpg (92.3 KiB) Viewed 1494 times
I also checked these at extreme coords (20,000+ RMC+) but no difference.

and finally I flipped them both horizontally, but again: same picture. So the only conclusion that can be derived from this is that the 'door' or Oryan is not in dead centre.

I think (but not tested) that the issue lies with e.g. a door image of 101x101 px which is then forced on a 50px grid. I can imagine that some pixel shift will take place and since its a half px its impossible to align on a 50px grid. edit: tested and nope, then too the line aligns perfectly.

User avatar
Oryan77
Dragon
Posts: 452
Joined: Sun Feb 20, 2011 3:14 pm

Re: Rotating objects does not align?

Post by Oryan77 »

My maps and doors are set at 100px grid size. Would that make a difference? Also, as I said, the closer you zoom in, the better aligned it looks. So you can zoom in close enough where it looks correct. The farther you zoom out, the worse it looks.

The left doors in your last example still look misaligned. The bounding boxes do not look lined up, which is the same effect I get when rotating objects (can't align a rotated bounding box by nudging because it is always off by less than a pixel).

My door graphics are 400x100. As I said earlier, for testing, I used Photoshop to copy the bottom half of the door, delete the top half, pasted and flipped the other half and positioned it so that both sides are exactly the same. It is centered along the horizontal middle. When I place it in MT, I set the size to gargantuan (100px grid map) so that the door appears to be large (fits in 2 squares).

Could it be a graphics card issue where it just appears to be misaligned in MT?

Here is a door if anyone wants to test it:
Door1.png
Door1.png (28.02 KiB) Viewed 1485 times

User avatar
wolph42
Winter Wolph
Posts: 9999
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: Rotating objects does not align?

Post by wolph42 »

I'll check out your door later.the bounding box looks disaligned because of the red colors I used. But believe me I checked all kinds of zoom levels.

edit: AH Now I get it. I can confirm your issue. This issue happens when you 'unsnap' the tokens and then move them. In that case its impossible to align them. This is also the case for the tests I did earlier.
The workaround is to snap them, set them up and unsnap them. That way they stay aligned correctly.

I don't know if the devs can fix this issue as the disalignment is very tiny: her you can see the effect:
Spoiler
px align test 3.jpg
px align test 3.jpg (28.94 KiB) Viewed 1477 times
. As you can see the token on the right is rotated 180 degrees and is a tiny bit disaligned to the grid. The effect switches with each zoom level.
and if anyone else wishes to test, here's the token:
Spoiler
test.png
test.png (2.78 KiB) Viewed 1477 times

User avatar
Oryan77
Dragon
Posts: 452
Joined: Sun Feb 20, 2011 3:14 pm

Re: Rotating objects does not align?

Post by Oryan77 »

wolph42 wrote:I can confirm your issue. This issue happens when you 'unsnap' the tokens and then move them. In that case its impossible to align them. This is also the case for the tests I did earlier.
The workaround is to snap them, set them up and unsnap them. That way they stay aligned correctly.
I'm trying that trick but the door still ends up misaligned.

I turn snapping on, drop a door from my library, copy/paste a 2nd door, rotate it, flip it vertical, and it is misaligned.

Anyway, it doesn't seem like we are getting much feedback about this issue. :p
As a graphics guy, this is a very irritating visual to see on a map.

User avatar
wolph42
Winter Wolph
Posts: 9999
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: Rotating objects does not align?

Post by wolph42 »

indeed ! which is funny, cause try my trick with this door:
door (2).png
door (2).png (9.6 KiB) Viewed 1456 times
edit: i compared your door and this one on the same map next to eachother and noticed that the black line you drew was 1pixel ABOVE the grid, so obviously it disaligns!! Try this on a 50px grid, its also noticeable on a 100px grid but barely. Anyway its more then one issue. There's an issue with unsnapped tokens that cannot be aligned properly to the grid when rotated and apparently there is an issue with your door, cause with my door attached here I can only replicate your issue unsnapped.

User avatar
Oryan77
Dragon
Posts: 452
Joined: Sun Feb 20, 2011 3:14 pm

Re: Rotating objects does not align?

Post by Oryan77 »

wolph42 wrote:edit: i compared your door and this one on the same map next to eachother and noticed that the black line you drew was 1pixel ABOVE the grid, so obviously it disaligns!!
No, the black line is 2 pixels tall. So one pixel black line is above the center line and the other one pixel black line is below the center line. It was created in Photoshop on a 100px grid.


User avatar
Azhrei
Site Admin
Posts: 12086
Joined: Mon Jun 12, 2006 1:20 pm
Location: Tampa, FL

Re: Rotating objects does not align?

Post by Azhrei »

This is very interesting. I'm not a graphics guy (in terms of writing fancy-pants graphics handling code) but I can't think of any reason why a rotated image might not line up.

Each token has a couple of (x,y) coordinates in it for when it's snapped to the grid and when it's not. Those coordinates are interpreted differently when the token is on the Token layer vs. when it's on the Object layer. I'd need to think about this a bit and perhaps work out some of the matrix transforms myself to see what happens to the coordinates when rotating them, but it's certainly a fascinating problem!

I would think that an image with an odd number of pixels (w,h) would rotate more accurately with the pixel in the center sitting still. So when there's an even number of pixels maybe there's some kind of round off error getting in the way? The transforms should be done in double precision arithmetic which I would expect to be plenty accurate enough but maybe that's where the issue lies?

No promises that I'll get this fixed though; I remember digging into that code previously and keeping track of the transforms (in my head) while reading the code got tricky.

User avatar
DreadKatak
Kobold
Posts: 12
Joined: Wed Aug 02, 2017 2:58 am
Location: Santa Clara, CA

Re: Rotating objects does not align?

Post by DreadKatak »

I can confirm the same issue as the original poster. Been driving me nuts trying to fix it, but I don't think the issue is with the images.

I also ran into this when trying to get double doors to line up properly.

Post Reply

Return to “MapTool”