Center of vehicle sprites

Forum for technical discussions regarding development. If you have a general suggestion, problem or comment, please use one of the other forums.

Moderator: OpenTTD Developers

Post Reply
User avatar
uzusan
Engineer
Engineer
Posts: 74
Joined: 12 Apr 2005 22:17
Location: Scotland
Contact:

Center of vehicle sprites

Post 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)
Reality is that which, when you stop believing in it, doesn't go away. - PKD
User avatar
WWTBAM
Moderator
Moderator
Posts: 3689
Joined: 02 Apr 2005 07:01
Location: Sydney NSW Antipodea
Contact:

Post by WWTBAM »

read the newgrf specs on the ttdpatch wiki.
Formerly known as r0b0t_b0y2003, robotboy, roboboy and beclawat. The best place to get the most recent nightly builds of TTDPatch is: http://roboboy.users.tt-forums.net/TTDPatch/nightlies/
User avatar
uzusan
Engineer
Engineer
Posts: 74
Joined: 12 Apr 2005 22:17
Location: Scotland
Contact:

Post 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
Reality is that which, when you stop believing in it, doesn't go away. - PKD
DaleStan
TTDPatch Developer
TTDPatch Developer
Posts: 10285
Joined: 18 Feb 2004 03:06
Contact:

Post 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.
To get a good answer, ask a Smart Question. Similarly, if you want a bug fixed, write a Useful Bug Report. No TTDPatch crashlog? Then follow directions.
Projects: NFORenum (download) | PlaneSet (Website) | grfcodec (download) | grfdebug.log parser
User avatar
uzusan
Engineer
Engineer
Posts: 74
Joined: 12 Apr 2005 22:17
Location: Scotland
Contact:

Post 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.
Reality is that which, when you stop believing in it, doesn't go away. - PKD
DaleStan
TTDPatch Developer
TTDPatch Developer
Posts: 10285
Joined: 18 Feb 2004 03:06
Contact:

Post 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.
To get a good answer, ask a Smart Question. Similarly, if you want a bug fixed, write a Useful Bug Report. No TTDPatch crashlog? Then follow directions.
Projects: NFORenum (download) | PlaneSet (Website) | grfcodec (download) | grfdebug.log parser
User avatar
uzusan
Engineer
Engineer
Posts: 74
Joined: 12 Apr 2005 22:17
Location: Scotland
Contact:

Post 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.
Reality is that which, when you stop believing in it, doesn't go away. - PKD
DaleStan
TTDPatch Developer
TTDPatch Developer
Posts: 10285
Joined: 18 Feb 2004 03:06
Contact:

Post 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.
To get a good answer, ask a Smart Question. Similarly, if you want a bug fixed, write a Useful Bug Report. No TTDPatch crashlog? Then follow directions.
Projects: NFORenum (download) | PlaneSet (Website) | grfcodec (download) | grfdebug.log parser
User avatar
uzusan
Engineer
Engineer
Posts: 74
Joined: 12 Apr 2005 22:17
Location: Scotland
Contact:

Post by uzusan »

ill give that a try and see if i can figure out the formula.
Reality is that which, when you stop believing in it, doesn't go away. - PKD
Post Reply

Return to “OpenTTD Development”

Who is online

Users browsing this forum: No registered users and 21 guests