Vectrex32

General Category => Feature Requests and Bug Reports => Topic started by: Astrosynthesist on December 27, 2017, 08:36:40 PM

Title: Janky Sprite Rotation
Post by: Astrosynthesist 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...
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!
Title: Re: Janky Sprite Rotation
Post by: Vectrex32 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
Title: Re: Janky Sprite Rotation
Post by: Astrosynthesist on December 27, 2017, 09:57:38 PM
Silly me. This is great though, thank you!
Title: Re: Janky Sprite Rotation
Post by: Vectrex32 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
Title: Re: Janky Sprite Rotation
Post by: Astrosynthesist on December 30, 2017, 02:13:34 PM
Ah, that makes sense. Thankfully your description of how to fix the problem is still true. :)