Misalignment caused by rotation

Discussions about the technical aspects of graphics development, including NewGRF tools and utilities.

Moderator: Graphics Moderators

User avatar
Erato
Chief Executive
Chief Executive
Posts: 740
Joined: 25 May 2015 09:09
Location: The Netherlands

Misalignment caused by rotation

Post by Erato »

So, I've got this problem, that every train with a length that isn't 8 tends to misalign when rotated, or when just going the other direction:
Image
The smaller the train, the worse the misalignment. (ignore the gap between the the carriages of the second train) This misalignment is present for every train you rotate.

Note: I suppose that the misalignment on every second track in horizontal position is just me being lazy, but I would like to point out that the alignment I used there is the width of the sprite /2, but this causes the trains in both directions to be disaligned equally but opposite.

Why is this happening, and how do I get rid of it?

Source
No pics no clicks. Seriously.
ImageImageImageImageImageImage
User avatar
Leanden
Tycoon
Tycoon
Posts: 2613
Joined: 19 Mar 2009 19:25
Location: Kent

Re: Misalignment caused by rotation

Post by Leanden »

This is purely down to offsets, also the trains that you've ticked are also not properly aligned.
Image
frosch
OpenTTD Developer
OpenTTD Developer
Posts: 988
Joined: 20 Dec 2006 13:31
Location: Aschaffenburg

Re: Misalignment caused by rotation

Post by frosch »

You are using 4 sprites-per-set/vehicle, correct?

It looks like everyone in the past 10 years only used the 8 sprites-per-set variant, so the 4-sprites-per-set variant was never adjusted to account for shortened vehicles.
⢇⡸⢸⠢⡇⡇⢎⡁⢎⡱⢸⡱⢸⣭⠀⢸⢜⢸⢸⣀⢸⣀⢸⣭⢸⡱⠀⢰⠭⡆⣫⠰⣉⢸⢸⠀⢰⠭⡆⡯⡆⢹⠁⠀⢐⠰⡁
User avatar
Erato
Chief Executive
Chief Executive
Posts: 740
Joined: 25 May 2015 09:09
Location: The Netherlands

Re: Misalignment caused by rotation

Post by Erato »

Leanden wrote:This is purely down to offsets, also the trains that you've ticked are also not properly aligned.
1) I can only provide 1 offset per direction. As for the second train, I set the vehicle size higher to simulate the damned loose coupling that occurred. This is the only not-perfectly aligned train: Image
frosch wrote:You are using 4 sprites-per-set/vehicle, correct?

It looks like everyone in the past 10 years only used the 8 sprites-per-set variant, so the 4-sprites-per-set variant was never adjusted to account for shortened vehicles.
No. Here, have some spritesets:

Image
Image
Image
Image

If the problem was with the 4-sprites per set stuff, then almost all wagons in almost every set should have this problem. On top of that; the engines of 3 out of 4 of these trains should also experience the problem, which they don't.
No pics no clicks. Seriously.
ImageImageImageImageImageImage
User avatar
Leanden
Tycoon
Tycoon
Posts: 2613
Joined: 19 Mar 2009 19:25
Location: Kent

Re: Misalignment caused by rotation

Post by Leanden »

Ah i use 8 sprite format as well, you can still use the 8 sprite setup defining the same sprites twice with different offsets.
Image
User avatar
Erato
Chief Executive
Chief Executive
Posts: 740
Joined: 25 May 2015 09:09
Location: The Netherlands

Re: Misalignment caused by rotation

Post by Erato »

Leanden wrote:Ah i use 8 sprite format as well, you can still use the 8 sprite setup defining the same sprites twice with different offsets.
Excuse me, what do you mean by 8-sprite-whatyamacallit? Like this:
Image rather than this: Image

If so, it makes no difference, as this:
Image
is hit just as hard by this problem as the 4-sprite cars, even though it has the 8-sprite thing.
No pics no clicks. Seriously.
ImageImageImageImageImageImage
Eddi
Tycoon
Tycoon
Posts: 8267
Joined: 17 Jan 2007 00:14

Re: Misalignment caused by rotation

Post by Eddi »

frosch wrote:It looks like everyone in the past 10 years only used the 8 sprites-per-set variant, so the 4-sprites-per-set variant was never adjusted to account for shortened vehicles.
i think that's backwards. everyone used the 8-sprite variant, because the 4-sprite variant was never adjusted for shortened vehicles. (which would only have been possible after the bounding box change, which is "only" like 5(?) years ago)

(this also overlaps with vehicle flipping working so poorly with shortened vehicles)
User avatar
Erato
Chief Executive
Chief Executive
Posts: 740
Joined: 25 May 2015 09:09
Location: The Netherlands

Re: Misalignment caused by rotation

Post by Erato »

Could I ask whether this:
Image
Is 8-sprite or 4?
Because none of you guys are making any sense to me.
No pics no clicks. Seriously.
ImageImageImageImageImageImage
User avatar
Leanden
Tycoon
Tycoon
Posts: 2613
Joined: 19 Mar 2009 19:25
Location: Kent

Re: Misalignment caused by rotation

Post by Leanden »

That is 8 sprite. Which would mean if you have set it up correctly you would 8 different offsets for each sprite.

Are you using templates for your spritesheets?
Image
User avatar
Erato
Chief Executive
Chief Executive
Posts: 740
Joined: 25 May 2015 09:09
Location: The Netherlands

Re: Misalignment caused by rotation

Post by Erato »

Leanden wrote:That is 8 sprite. Which would mean if you have set it up correctly you would 8 different offsets for each sprite.

Are you using templates for your spritesheets?
Yes. And if I understand correctly, this:
Image
Is also 8-sprite. And it's hit really damned hard by this bug.
No pics no clicks. Seriously.
ImageImageImageImageImageImage
User avatar
Leanden
Tycoon
Tycoon
Posts: 2613
Joined: 19 Mar 2009 19:25
Location: Kent

Re: Misalignment caused by rotation

Post by Leanden »

Erato wrote:
Leanden wrote:That is 8 sprite. Which would mean if you have set it up correctly you would 8 different offsets for each sprite.

Are you using templates for your spritesheets?
Yes. And if I understand correctly, this:
Image
Is also 8-sprite. And it's hit really damned hard by this bug.
I believe thats part of a 16 sprite setup which was first devised by oberhuemer as part of CETS.
Image
User avatar
Erato
Chief Executive
Chief Executive
Posts: 740
Joined: 25 May 2015 09:09
Location: The Netherlands

Re: Misalignment caused by rotation

Post by Erato »

Leanden wrote:
Erato wrote:
Leanden wrote:That is 8 sprite. Which would mean if you have set it up correctly you would 8 different offsets for each sprite.

Are you using templates for your spritesheets?
Yes. And if I understand correctly, this:
Image
Is also 8-sprite. And it's hit really damned hard by this bug.
I believe thats part of a 16 sprite setup which was first devised by oberhuemer as part of CETS.
I'm confused. It's the same setup as the other one.
No pics no clicks. Seriously.
ImageImageImageImageImageImage
User avatar
Leanden
Tycoon
Tycoon
Posts: 2613
Joined: 19 Mar 2009 19:25
Location: Kent

Re: Misalignment caused by rotation

Post by Leanden »

My absolute apologies, im on my phone and its a really small scale. You were right that is an 8 sprite set.
Image
User avatar
Erato
Chief Executive
Chief Executive
Posts: 740
Joined: 25 May 2015 09:09
Location: The Netherlands

Re: Misalignment caused by rotation

Post by Erato »

Leanden wrote:My absolute apologies, im on my phone and its a really small scale. You were right that is an 8 sprite set.
No problem.

So, now I finally get what you guys are talking about, let's go back to my main question; why do both 8-sprite trains and 4-sprite trains misalign when their size is less than 8? And how do I solve it?
No pics no clicks. Seriously.
ImageImageImageImageImageImage
User avatar
Leanden
Tycoon
Tycoon
Posts: 2613
Joined: 19 Mar 2009 19:25
Location: Kent

Re: Misalignment caused by rotation

Post by Leanden »

Erato wrote:
Leanden wrote:My absolute apologies, im on my phone and its a really small scale. You were right that is an 8 sprite set.
No problem.

So, now I finally get what you guys are talking about, let's go back to my main question; why do both 8-sprite trains and 4-sprite trains misalign when their size is less than 8? And how do I solve it?
Two points:

A) have you adjusted the length property for the shorter sprites (divide the number of pixels of the horizontal sprite into 32 and then multiply by 8 rounding up any decimals)

B) Have you adjusted the absolute size of the sprite in your spritesheet definition?
Image
User avatar
Erato
Chief Executive
Chief Executive
Posts: 740
Joined: 25 May 2015 09:09
Location: The Netherlands

Re: Misalignment caused by rotation

Post by Erato »

Leanden wrote:
Erato wrote:
Leanden wrote:My absolute apologies, im on my phone and its a really small scale. You were right that is an 8 sprite set.
No problem.

So, now I finally get what you guys are talking about, let's go back to my main question; why do both 8-sprite trains and 4-sprite trains misalign when their size is less than 8? And how do I solve it?
Two points:

A) have you adjusted the length property for the shorter sprites (divide the number of pixels of the horizontal sprite into 32 and then multiply by 8 rounding up any decimals)

B) Have you adjusted the absolute size of the sprite in your spritesheet definition?
A) Yes
B) I don't really understand what you mean by that. Do you mean that I should put the sprites in the boxes that I use for the sprites with a length of 8?
No pics no clicks. Seriously.
ImageImageImageImageImageImage
Transportman
Tycoon
Tycoon
Posts: 2781
Joined: 22 Feb 2011 18:34

Re: Misalignment caused by rotation

Post by Transportman »

Erato wrote:B) I don't really understand what you mean by that. Do you mean that I should put the sprites in the boxes that I use for the sprites with a length of 8?
Depends on the template you use. The Dutch Trainset uses separate templates for the different lengths, while the 2cc TrainsInNML set uses one template for all vehicles with length 1-8. Both approaches have their pros and cons. So to answer your question, there is no answer, as it can be both YES (if you take the 2cc TrainsInNML route) and NO (if you take the Dutch Trainset route), you have to decide how to do it.
Coder of the Dutch Trackset | Development support for the Dutch Trainset | Coder of the 2cc TrainsInNML
User avatar
Leanden
Tycoon
Tycoon
Posts: 2613
Joined: 19 Mar 2009 19:25
Location: Kent

Re: Misalignment caused by rotation

Post by Leanden »

For example i have different templates depending on the length of the train in the horizontal view.

I then setup templates within the code with offsets based upon which sprite template im using.
[+] Spoiler

Code: Select all

template template_train20px(x,y){
    //left_x, upper_y, width, height, offset_x, offset_y
    [ x,        y,       8,     17,      -1,       -9]
    [ x+10,     y,       15,    15,     -6,        -8]
    [ x+27,     y,       20,    12,     -3,        -7]
    [ x+49,     y,       15,    15,     0,        -6]
    [ x+66,     y,       8,     17,      -1,       -6]
    [ x+76,     y,       15,    15,     -13,        -5]
    [ x+93,    y,       20,    12,     -13,        -7]
    [ x+115,    y,       15,    15,      -8,        -9]
}

template template_train21px(x,y){
    //left_x, upper_y, width, height, offset_x, offset_y
    [ x,        y,       8,     18,      -1,       -9]
    [ x+10,     y,       17,    15,     -6,        -8]
    [ x+29,     y,       21,    12,     -3,        -7]
    [ x+52,     y,       17,    15,     0,        -6]
    [ x+71,     y,       8,     18,      -1,       -9]
    [ x+81,     y,       17,    15,     -13,        -5]
    [ x+100,    y,       21,    12,     -13,        -7]
    [ x+123,    y,       17,    15,      -8,        -8]
}
I then reference these templates in the spritesets:
[+] Spoiler

Code: Select all

spriteset(spriteset_BR158b_ATW, "gfx/BR158b.png") {
	template_train32px(0, 13)
}
Attachments
20px.png
20px.png (258 Bytes) Viewed 2729 times
21px.png
21px.png (267 Bytes) Viewed 2729 times
28px.png
28px.png (560 Bytes) Viewed 2729 times
Image
User avatar
Erato
Chief Executive
Chief Executive
Posts: 740
Joined: 25 May 2015 09:09
Location: The Netherlands

Re: Misalignment caused by rotation

Post by Erato »

Leanden wrote:For example i have different templates depending on the length of the train in the horizontal view.

I then setup templates within the code with offsets based upon which sprite template im using.
[+] Spoiler

Code: Select all

template template_train20px(x,y){
    //left_x, upper_y, width, height, offset_x, offset_y
    [ x,        y,       8,     17,      -1,       -9]
    [ x+10,     y,       15,    15,     -6,        -8]
    [ x+27,     y,       20,    12,     -3,        -7]
    [ x+49,     y,       15,    15,     0,        -6]
    [ x+66,     y,       8,     17,      -1,       -6]
    [ x+76,     y,       15,    15,     -13,        -5]
    [ x+93,    y,       20,    12,     -13,        -7]
    [ x+115,    y,       15,    15,      -8,        -9]
}

template template_train21px(x,y){
    //left_x, upper_y, width, height, offset_x, offset_y
    [ x,        y,       8,     18,      -1,       -9]
    [ x+10,     y,       17,    15,     -6,        -8]
    [ x+29,     y,       21,    12,     -3,        -7]
    [ x+52,     y,       17,    15,     0,        -6]
    [ x+71,     y,       8,     18,      -1,       -9]
    [ x+81,     y,       17,    15,     -13,        -5]
    [ x+100,    y,       21,    12,     -13,        -7]
    [ x+123,    y,       17,    15,      -8,        -8]
}
I then reference these templates in the spritesets:
[+] Spoiler

Code: Select all

spriteset(spriteset_BR158b_ATW, "gfx/BR158b.png") {
	template_train32px(0, 13)
}
You mean like this? I've got one for every length that I use; 8, 7, 5 and 2. And when it's not 8, I get the damned bug.
Image
[+] Spoiler

Code: Select all

template TEMP_TRAIN_DOUBLE_5(h,d) {
	[0, 0, 8, 16+h+d, -3, -11-h]
	[9, 0, 16, 14+h+d, -14, -4-h]
	[26, 0, 20, 12+h+d, -10, -6-h]
	[47, 0, 16, 14+h+d, -2, -4-h]
	[64, 0, 8, 16+h+d, -3, -11-h]
	[73, 0, 16, 14+h+d, -14, -4-h]
	[90, 0, 20, 12+h+d, -10, -6-h]
	[111, 0, 16, 14+h+d, -2, -4-h]
}
template TEMP_CAR_5_NEW(y,h,d) {
	[0, y, 8, 16+h+d, -3, -11-h]
	[9, y, 16, 14+h+d, -14, -4-h]
	[26, y, 20, 12+h+d, -10, -6-h]
	[47, y, 16, 14+h+d, -2, -4-h]
}
No pics no clicks. Seriously.
ImageImageImageImageImageImage
User avatar
Leanden
Tycoon
Tycoon
Posts: 2613
Joined: 19 Mar 2009 19:25
Location: Kent

Re: Misalignment caused by rotation

Post by Leanden »

Erato wrote:

Code: Select all

template TEMP_CAR_5_NEW(y,h,d) {
	[0, y, 8, 16+h+d, -3, -11-h]
	[9, y, 16, 14+h+d, -14, -4-h]
	[26, y, 20, 12+h+d, -10, -6-h]
	[47, y, 16, 14+h+d, -2, -4-h]
This is your issue right here, you are defining the same offsets in both directions. Try something like this:

Code: Select all

template TEMP_CAR_5_NEW(y,h,d) {
	[0, y, 8, 16+h+d, -3, -11-h]
	[9, y, 16, 14+h+d, -14, -4-h]
	[26, y, 20, 12+h+d, -10, -6-h]
	[47, y, 16, 14+h+d, -2, -4-h]
	[0, y, 8, 16+h+d, -3, -11-h]
	[9, y, 16, 14+h+d, -14, -4-h]
	[26, y, 20, 12+h+d, -10, -6-h]
	[47, y, 16, 14+h+d, -2, -4-h]
And adjust the offsets in the second set for when its going in reverse.

Also why are you using the h + d modifiers?? If you are consistently using the same templates you should be able to just put absolute values in here.
Image
Post Reply

Return to “NewGRF Technical Discussions”

Who is online

Users browsing this forum: No registered users and 15 guests