Janky Sprite Rotation

Started by Astrosynthesist, December 27, 2017, 08:36:40 PM

Previous topic - Next topic

Astrosynthesist

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...
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

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

Silly me. This is great though, thank you!

Vectrex32

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

Ah, that makes sense. Thankfully your description of how to fix the problem is still true. :)