Page 1 of 1

Center of vehicle sprites

Posted: 06 Sep 2006 21:51
by uzusan
Not sure if this should be in graphics or in here.

Im looking to find out how openttd determines where the center of a vehicle graphic is.

i.e. the values it uses to calculate xrel and yrel in the newgrf files.

in the code, it is these values, im looking to find out where they are set.

Code: Select all

struct Vehicle {
	byte z_height;		// z-height of vehicle sprite
	int8 x_offs;			// x offset for vehicle sprite
	int8 y_offs;			// y offset for vehicle sprite
};
(thats if im looking at the correct values. i suspect that these offset's might be the last two items in the newgrf files, if so where are the values they are used relative to? ie the center x + y of a sprite)

Posted: 07 Sep 2006 06:48
by WWTBAM
read the newgrf specs on the ttdpatch wiki.

Posted: 07 Sep 2006 07:18
by uzusan
thats where i was trying to work out the value from, but its not very clear where the box is. for anything other than vehicles the reference point is clear, but for vehicles it says
For vehicles, the center of the bounding box (shown with a red dot in the yellow boxframe) is the reference point from which the xofs and yofs are counted. This means that in most cases, xofs and yofs need to be negative to get the sprite to fit on the box. Normally, as indicated above, this means xofs is approximately the negative value of half the sprite width, and yofs is approximately the negative value of half the sprite height.
I was looking for the actual code that calculates this rather that "approximately". Also the red dot on the image seems to be 2 pixels to the right and 2 down from the center. I cant find a definitive idea of what this center value is. I was looking for the calculation in the code.

http://wiki.ttdpatch.net/tiki-index.php ... oordinates

Posted: 07 Sep 2006 07:54
by DaleStan
uzusan wrote:I was looking for the actual code that calculates this rather that "approximately".
Such doesn't exist.

Start with something "approximate".
Then fix it with the GRFAuthorHelperWindow.
Then copy those fixes back to your nfo and re-encode.

Posted: 07 Sep 2006 08:00
by uzusan
DaleStan wrote:
uzusan wrote:I was looking for the actual code that calculates this rather that "approximately".
Such doesn't exist.

Start with something "approximate".
Then fix it with the GRFAuthorHelperWindow.
Then copy those fixes back to your nfo and re-encode.
how does the code actually calculate the bounding box? thats the section im looking for.

If it calculates it in a different way then fine, im just looking for the code that deals with the bounding box that openttd uses to draw the sprites so i can use that to work out the required offsets.

Posted: 07 Sep 2006 08:23
by DaleStan
uzusan wrote:how does the code actually calculate the bounding box? thats the section im looking for.
Magic. Unless you are coding houses or industry tiles, the bounding box is just not relevant, and even if you are, it has nothing to do with the xrel and yrel in the NFO. Set the xrel and yrel correctly, and all will be fine.

Posted: 07 Sep 2006 15:30
by uzusan
DaleStan wrote:
uzusan wrote:how does the code actually calculate the bounding box? thats the section im looking for.
Magic. Unless you are coding houses or industry tiles, the bounding box is just not relevant, and even if you are, it has nothing to do with the xrel and yrel in the NFO. Set the xrel and yrel correctly, and all will be fine.
Thats the problem though, how do i set them correctly? is it just half the sprite width?

im trying to create a program similar to grfmaker, mainly for my own use to start with, but if i can do it good enough ill release it.

I cant just write a program that takes a random number and uses that. I need something a bit more specific than that.

Posted: 07 Sep 2006 17:38
by DaleStan
uzusan wrote:
DaleStan wrote:Set the xrel and yrel correctly, and all will be fine.
Thats the problem though, how do i set them correctly? is it just half the sprite width?
Approximately. Use the GRFAuthorHelperWindow to get the exact value, like I've already told you.

Or, if you absolutely CANNOT run TTDPatch (Patchman runs it on both x86 Linux and PPC Mac, so I don't see why any other OS wouldn't work) just do it the old fashioned way: Change the nfo, re-encode, and repeat until it's correct.

Posted: 07 Sep 2006 17:45
by uzusan
ill give that a try and see if i can figure out the formula.