Rotation sprite slots not evenly spaced

Bugs that are actually features.
Post Reply
justarandomgeek
Filter Inserter
Filter Inserter
Posts: 300
Joined: Fri Mar 18, 2016 4:34 pm
Contact:

Rotation sprite slots not evenly spaced

Post by justarandomgeek »

In Nixie Tubes I (and GopherATL before me) used a car entity that rotates to display the characters. While extending this to alphabetic characters I found that with a large number of sprite slots the rotations are not spaced evenly around a circle, and some had to be offset ahead/behind their expected position.

See stateOrientMap in this file for the example offset rotations.

posila
Factorio Staff
Factorio Staff
Posts: 5202
Joined: Thu Jun 11, 2015 1:35 pm
Contact:

Re: Rotation sprite slots not evenly spaced

Post by posila »

Hi, it is not a bug.
Factorio uses orthogonal projection with camera tilted by 45°, which causes cicles become ellipses.

You can use something like following to solve your issue:

Code: Select all

local function projected_orientation(turn)
  local x = math.sin(turn * math.pi * 2)
  local y = -math.cos(turn * math.pi * 2)

  y = y * math.cos(math.pi / 4)

  return math.atan2(x, -y) / (math.pi * 2)
end

local stateOrientMap = {
  { 
  ["0"]=projected_orientation(bigstep*0),
  ["1"]=projected_orientation(bigstep*1),
  ["2"]=projected_orientation(bigstep*2),
  ["3"]=projected_orientation(bigstep*3),
...
EDIT: Fixed sign in math.atan2.

justarandomgeek
Filter Inserter
Filter Inserter
Posts: 300
Joined: Fri Mar 18, 2016 4:34 pm
Contact:

Re: Rotation sprite slots not evenly spaced

Post by justarandomgeek »

That makes perfect sense - I'd suspected it was some kind of distortion of the circle based on the 'error' pattern. In my case it's just a lookup table, so fudging the numbers "close enough" is good enough for me, but if I ever need to calculate rotations on the fly (or make another table...) I'll definitely do it that way!

Post Reply

Return to “Not a bug”