Author Topic: Janky Sprite Rotation  (Read 49 times)

Astrosynthesist

  • Newbie
  • *
  • Posts: 40
    • View Profile
Janky Sprite Rotation
« on: December 27, 2017, 08:36:40 PM »
Hello again. I will include a small code snippet to illustrate my issue. Not sure if this is a bug or just an inevitability of the way the floating point unit works...
Code: [Select]
call setFrameRate(30)
lockArray = {{MoveTo,2,10},{DrawTo,0,5},{DrawTo,-2,10},{DrawTo,2,10},{MoveTo,2,-10},{DrawTo,0,-5},{DrawTo,-2,-10},{DrawTo,2,-10},_
    {MoveTo,10,2},{DrawTo,5,0},{DrawTo,10,-2},{DrawTo,10,2},{MoveTo,-10,2},{DrawTo,-5,0},{DrawTo,-10,-2},{DrawTo,-10,2}}
call scaleSprite(255)
call returnToOriginSprite()
lock = linesSprite(lockArray)
while True
call waitForFrame(0,0,0)
call spriteRotate(lock, 1)
endwhile

But yeah, on my Vectrex that sprite just dances all over the place while rotating, probably the same on others too. Please let me know if this can be avoided!

Vectrex32

  • Administrator
  • Full Member
  • *****
  • Posts: 114
    • View Profile
Re: Janky Sprite Rotation
« Reply #1 on: December 27, 2017, 08:41:25 PM »
The rotation is done in floating point, but there are always small errors. Then, since you've set the scale to 255, those errors get magnified.

Try making the coordinates larger and the scale smaller.

- Bob

Astrosynthesist

  • Newbie
  • *
  • Posts: 40
    • View Profile
Re: Janky Sprite Rotation
« Reply #2 on: December 27, 2017, 09:57:38 PM »
Silly me. This is great though, thank you!

Vectrex32

  • Administrator
  • Full Member
  • *****
  • Posts: 114
    • View Profile
Re: Janky Sprite Rotation
« Reply #3 on: December 30, 2017, 01:18:21 PM »
I actually described this wrong.

Coordinate rotation is done with floating point numbers, and while there's always some error in the calculation, it's very small and that's not what's causing the "janky" rotation. After the coordinate is rotated, it has to be rounded to an integer to send to the Vectrex. That's where the jankiness comes in.

When the coordinates are larger, the inaccuracy introduced by rounding is a smaller percentage of the total value.

- Bob

Astrosynthesist

  • Newbie
  • *
  • Posts: 40
    • View Profile
Re: Janky Sprite Rotation
« Reply #4 on: December 30, 2017, 02:13:34 PM »
Ah, that makes sense. Thankfully your description of how to fix the problem is still true. :)