Page 1 of 1
RotateCoordinates X and Y origin parameters are unresponsive
Posted: Mon Sep 30, 2019 11:51 pm
by Henry00
Hello PB Team,
I am using PureBasic 5.71 LTS. It appears that RotateCoordinates' X and Y parameters are completely unresponsive. Here is a modified example from the manual (I input WindowMouseX and WindowMouseY to show that changing the origin does nothing):
Code: Select all
If OpenWindow(0, 0, 0, 400, 200, "VectorDrawing", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
CanvasGadget(0, 0, 0, 400, 200)
LoadImage(0, #PB_Compiler_Home + "examples/Sources/Data/PureBasicLogo.bmp")
Repeat
Event = WindowEvent()
If StartVectorDrawing(CanvasVectorOutput(0))
AddPathBox(0, 0, 400, 200)
VectorSourceColor(RGBA(255, 255, 255, 255))
FillPath()
MovePathCursor(50 + WindowMouseX(0), 50)
DrawVectorImage(ImageID(0), 127)
MovePathCursor(75, 75)
DrawVectorImage(ImageID(0), 127, ImageWidth(0) / 2, ImageHeight(0))
MovePathCursor(120, 0)
RotateCoordinates(WindowMouseX(0), WindowMouseY(0), 35) ; <-- here
DrawVectorImage(ImageID(0), 127)
StopVectorDrawing()
EndIf
Delay(10)
Until Event = #PB_Event_CloseWindow
EndIf
What I would like to achieve is simply rotating an image around its center. It's been impossible so far as they always rotate around the upper left corner 0,0.
Re: RotateCoordinates X and Y origin parameters are unrespon
Posted: Tue Oct 01, 2019 7:26 am
by #NULL
I don't know right now if there is something wrong, but the following works:
Code: Select all
If OpenWindow(0, 0, 0, 400, 200, "VectorDrawing", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
CanvasGadget(0, 0, 0, 400, 200)
LoadImage(0, #PB_Compiler_Home + "examples/sources/Data/PureBasicLogo.bmp")
Repeat
Repeat
Event = WindowEvent()
;Delay(10)
If Event = #PB_Event_CloseWindow
quit = 1
EndIf
Until Not Event
If StartVectorDrawing(CanvasVectorOutput(0))
AddPathBox(0, 0, 400, 200)
VectorSourceColor(RGBA(255, 255, 255, 255))
FillPath()
;
; MovePathCursor(50 + WindowMouseX(0), 50)
; DrawVectorImage(ImageID(0), 127)
;
; MovePathCursor(75, 75)
; DrawVectorImage(ImageID(0), 127, ImageWidth(0) / 2, ImageHeight(0))
a.f +0.01
MovePathCursor(400/2-ImageWidth(0)/2, 200/2-ImageHeight(0)/2)
DrawVectorImage(ImageID(0), 127)
MovePathCursor(400/2, 200/2)
RotateCoordinates(0,0, a)
MovePathCursor(-ImageWidth(0)/2, -ImageHeight(0)/2, #PB_Relative)
DrawVectorImage(ImageID(0), 127)
StopVectorDrawing()
EndIf
Until quit
EndIf
Re: RotateCoordinates X and Y origin parameters are unrespon
Posted: Thu Dec 05, 2019 11:11 pm
by SiggeSvahn
Thanks Henry and Null! I got so happy finding your code that I made a variation. The rotation in PB VectorLib is really high speed. Just click and drag in the window to activate.
Code: Select all
EnableExplicit
#cvgCanvas=0
#img=0
Define Ev,x,y
OpenWindow(0, 0, 0, 400, 200, "VectorDrawing", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
CanvasGadget(#cvgCanvas, 0, 0, 400, 200)
LoadImage(#img, #PB_Compiler_Home + "examples/Sources/Data/PureBasicLogo.bmp")
Procedure Draw(x,y)
If x<0:x=0:EndIf
If StartDrawing(CanvasOutput(0))
Box(0, 0, 400, 200, $FF9966);Erasing the old image.
StopDrawing()
EndIf
If StartVectorDrawing(CanvasVectorOutput(#cvgCanvas))
MovePathCursor(75, 75)
DrawVectorImage(ImageID(#img), 127, ImageWidth(#img) * (x/100), ImageHeight(#img))
MovePathCursor(x+ImageWidth(#img)/2,y+ImageHeight(#img) /2);A dirty fix due to the problem in the next row.
RotateCoordinates(0, 0, y*4);WHY DOESN'T Xd NOR Yd CHANGE THE AXIS? Seems to be a bug in PB.
MovePathCursor(-ImageWidth(0)/2, -ImageHeight(0)/2, #PB_Relative);RESETTING CURSOR TO THE CORNERS OF THE "SPRITE"!
DrawVectorImage(ImageID(#img), 127)
StopVectorDrawing()
EndIf
EndProcedure
Repeat
Ev = WaitWindowEvent()
If Ev = #PB_Event_Gadget
Select EventGadget()
Case #cvgCanvas
If EventType() = #PB_EventType_LeftButtonDown Or (EventType() = #PB_EventType_MouseMove And GetGadgetAttribute(#cvgCanvas, #PB_Canvas_Buttons) & #PB_Canvas_LeftButton)
x = GetGadgetAttribute(0, #PB_Canvas_MouseX)
y = GetGadgetAttribute(0, #PB_Canvas_MouseY)
Draw(x,y);Procedure call.
EndIf
EndSelect
EndIf
Until Ev = #PB_Event_CloseWindow
Re: RotateCoordinates X and Y origin parameters are unrespon
Posted: Mon Dec 09, 2019 10:52 am
by Fred
Your event loop was wrong in the first topic code. You need to handle all the events at once.
Re: RotateCoordinates X and Y origin parameters are unrespon
Posted: Mon Dec 09, 2019 7:54 pm
by kenmo
Here's a cleaned up event loop, and I changed the program slightly (the moving image was distracting from the actual rotation issue)
I agree, it looks like a bug, it always seems to rotate around (0,0) ?
Code: Select all
If OpenWindow(0, 0, 0, 400, 200, "VectorDrawing - one should rotate around cursor", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
CanvasGadget(0, 0, 0, 400, 200)
LoadImage(0, #PB_Compiler_Home + "examples/Sources/Data/PureBasicLogo.bmp")
Repeat
Event = WindowEvent()
While (Event)
If Event = #PB_Event_CloseWindow
Done = #True
EndIf
Event = WindowEvent()
Wend
If StartVectorDrawing(CanvasVectorOutput(0))
AddPathBox(0, 0, 400, 200)
VectorSourceColor(RGBA(255, 255, 255, 255))
FillPath()
ResetCoordinates()
MovePathCursor(120, 0)
RotateCoordinates(0, 0, 35) ; <-- here
DrawVectorImage(ImageID(0), 127)
ResetCoordinates()
MovePathCursor(120 + 10, 0) ; slight x offset to show both images
RotateCoordinates(WindowMouseX(0), WindowMouseY(0), 35) ; <-- here
DrawVectorImage(ImageID(0), 127)
StopVectorDrawing()
EndIf
Delay(10)
Until Done
EndIf
Re: RotateCoordinates X and Y origin parameters are unrespon
Posted: Tue Dec 10, 2019 10:10 am
by RASHAD
The rotation will be for all the output area
So rotate the coordinate first then draw every thing as usual (as if there is no any change)
Code: Select all
If OpenWindow(0, 0, 0, 400, 400, "VectorDrawing", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
CanvasGadget(0, 0, 0, 400, 400)
LoadImage(0, #PB_Compiler_Home + "examples/sources/Data/PureBasicLogo.bmp")
x = 400/2-ImageWidth(0)/2
y = 400/2-ImageHeight(0)/2
Repeat
Repeat
Event = WindowEvent()
;Delay(10)
If Event = #PB_Event_CloseWindow
quit = 1
EndIf
Until Not Event
If StartVectorDrawing(CanvasVectorOutput(0))
AddPathBox(0, 0, 400, 400)
VectorSourceColor(RGBA(255, 255, 255, 255))
FillPath()
a.f +0.01
ResetCoordinates()
MovePathCursor(x,y)
DrawVectorImage(ImageID(0), 127)
RotateCoordinates(400/2, 400/2, a )
MovePathCursor(x,y)
DrawVectorImage(ImageID(0), 127)
StopVectorDrawing()
EndIf
Until quit
EndIf