Bug with RotateSprite (90, 180, 270 degree rotation)

All bugs related to new C backend
User avatar
diceman
User
User
Posts: 25
Joined: Tue Apr 10, 2018 9:42 pm

Bug with RotateSprite (90, 180, 270 degree rotation)

Post by diceman »

Hello everyone,
I noticed, that when running the DirectX9-Subsystem and using RotateSprite on a perfectly square Sprite with only multiples of 90°, after the rotation the Sprite does NOT align perfectly to the grid anymore. It's new location is off by, like, 1 pixel. There seems to be some kind of rounding error, maybe? This is not a problem when removing the "DirectX9"-Subsystem. As I understand, the default system is now OpenGL?
Thanks!

P.S.: currently throwing together a short snippet, demonstrating the behavior ... stay tuned.
Now these points of data make a beautiful line,
And we're out of Beta, we're releasing on time.
User avatar
diceman
User
User
Posts: 25
Joined: Tue Apr 10, 2018 9:42 pm

Re: Bug with RotateSprite (90, 180, 270 degree rotation)

Post by diceman »

Okay, here it is:
Try running the following code in default Mode and with the DirectX9-Subsystem enabled.
With the former, the rotated Sprite will align perfectly even after rotation, the latter causes a weird offset.
Thanks!

Code: Select all

EnableExplicit

Define screen
Define event	
Define x, y
#xRes = 800
#yRes = 600
#tileSize = 64
Define squareSPR

If Not InitSprite()
	End
EndIf
screen = OpenWindow(#PB_Any, 0, 0, #xRes, #yRes, "RotateSprite()", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
If Not OpenWindowedScreen(WindowID(screen), 0, 0, #xRes, #yRes)
	End
EndIf

squareSPR = CreateSprite(#PB_Any, #tileSize, #tileSize)
If StartDrawing(SpriteOutput(squareSPR))
	Box(0, 0, #tileSize, #tileSize, RGB(255,0,0))
	StopDrawing()
EndIf

Repeat
	ClearScreen(RGB(0,0,0))
	For x = 0 To 3
		For y = 0 To 3
			RotateSprite(squareSPR, Random(3)*90, #PB_Absolute)
			DisplaySprite(squareSPR, x*#tileSize, y*#tileSize)
		Next
	Next
	FlipBuffers()		
	
	Repeat
		event = WindowEvent()
		If event = #PB_Event_CloseWindow
			Break 2
		EndIf
	Until event = #Null		
ForEver
End
Last edited by diceman on Fri Jul 29, 2022 9:29 pm, edited 1 time in total.
Now these points of data make a beautiful line,
And we're out of Beta, we're releasing on time.
User avatar
Mijikai
Addict
Addict
Posts: 1094
Joined: Sun Sep 11, 2016 2:17 pm

Re: Bug with RotateSprite (90, 180, 270 degree rotation)

Post by Mijikai »

No idea what is happening but i get a tiled displaced Sprite with DirectX... something is wrong.
Image
Btw. i get the same ugly result with the ASM backend.
User avatar
diceman
User
User
Posts: 25
Joined: Tue Apr 10, 2018 9:42 pm

Re: Bug with RotateSprite (90, 180, 270 degree rotation)

Post by diceman »

Exactly this.
Found out, you can actually hardcode the necessary corrections to get a clean result in DirectX9.
This is just a workaround, it still feels like a bug and should be fixed.
Thanks! :)

Code: Select all

			rot = Random(3)*90
			xCorr = 0
			yCorr = 0
			Select rot
				Case 90
					xCorr = -1
				Case 180
					xCorr = -1
					yCorr = -1
				Case 270
					yCorr = -1
			EndSelect
			RotateSprite(squareSPR, rot, #PB_Absolute)
			DisplaySprite(squareSPR, (x*#tileSize)+xCorr, (y*#tileSize)+yCorr)
Now these points of data make a beautiful line,
And we're out of Beta, we're releasing on time.
User avatar
STARGÅTE
Addict
Addict
Posts: 1761
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: Bug with RotateSprite (90, 180, 270 degree rotation)

Post by STARGÅTE »

I would recommend to use "my" HyperTransformSprite() for a correct and smooth rotation.
https://www.purebasic.fr/english/viewto ... 95#p493295

RotateSprite() has several limitations, it's not useful anyway (my opinion).
But of cause, it seems like a bug, in correcting the 0.5 px offset in DirectX
PB 5.73 ― Win 10, 20H2 ― Ryzen 9 3900X ― Radeon RX 5600 XT ITX ― Vivaldi 5.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
Post Reply