Page 1 of 1

Rotation sprite slots not evenly spaced

Posted: Fri Jul 29, 2016 3:12 pm
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.

Re: Rotation sprite slots not evenly spaced

Posted: Fri Jul 29, 2016 4:02 pm
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.

Re: Rotation sprite slots not evenly spaced

Posted: Fri Jul 29, 2016 10:59 pm
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!