RollingStock wheels position

Place to report issues and suggest improvements to the API documentation.
User avatar
BrainGamer_
Long Handed Inserter
Long Handed Inserter
Posts: 93
Joined: Sun Nov 14, 2021 9:52 pm
Contact:

RollingStock wheels position

Post by BrainGamer_ »

How are the positions for the wheels of a rolling-stock determined?

My current implementation uses the joint_distance and then rotates that according to the orientation of the entity but I seem to be missing some vertical offset (and the horizontal offset also seems to not fit perfectly).

Code: Select all

let offset: Vector = (Direction::North.get_offset() * (self.joint_distance / 2.0)).rotate(orientation);
+ flipping the offset & orientation for the second wheel

Image

also see the vertical render, not included since it is so long.

I guess the proper shifts will also include additional offsets from the rolling-stocks draw_data but boskid explained how that works on discord a while ago.
However I will probably not need those train head dependent offsets since I only plan to render entities from blueprints and afaik it would be fine without it for that purpose.

User avatar
BrainGamer_
Long Handed Inserter
Long Handed Inserter
Posts: 93
Joined: Sun Nov 14, 2021 9:52 pm
Contact:

Re: RollingStock wheels position

Post by BrainGamer_ »

Alright this has been solved after taking a look at how FBSR does this and with some help from the mod-making channel on discord.

First of all one thing I didn't knew before is that rolling-stocks (or vehicles in general maybe?) don't directly use the orientation to get the corresponding sprite but rather project the orientation circle onto an ellipse due to factorios distortion of 1/sqrt(2). FBSR has a method for this here and after some discussion about it on discord GodOfHyperDeath came up with this. My rust implementation of that is here.

The location of the wheels is determined by the rolling-stock's joint distance and orientation (circular, not the projected one). See calculation here.
In addition to that the wheels get a vertical offset of -(0.25 * abs(cos(orientation * TAU + PI/2)).

With this you can then get the wheel sprites for the projected_orientation and (projected_orientation + 0.5) modulo 1.0 for each wheel respectively.
Also need to flip the location offset for the second wheel (but don't flip the vertical offset of course).

In the end we get something that looks like this:
t2_train.png
t2_train.png (1.97 MiB) Viewed 463 times

Post Reply

Return to “Documentation Improvement Requests”