RotateCoordinates X and Y origin parameters are unresponsive

Just starting out? Need help? Post your questions and find answers here.
Henry00
User
User
Posts: 88
Joined: Thu Jul 12, 2012 7:00 pm
Location: Germany
Contact:

RotateCoordinates X and Y origin parameters are unresponsive

Post 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.
#NULL
Addict
Addict
Posts: 1440
Joined: Thu Aug 30, 2007 11:54 pm
Location: right here

Re: RotateCoordinates X and Y origin parameters are unrespon

Post 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
SiggeSvahn
User
User
Posts: 40
Joined: Wed Oct 06, 2010 9:37 pm

Re: RotateCoordinates X and Y origin parameters are unrespon

Post 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
Newbie
Fred
Administrator
Administrator
Posts: 16619
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: RotateCoordinates X and Y origin parameters are unrespon

Post by Fred »

Your event loop was wrong in the first topic code. You need to handle all the events at once.
User avatar
kenmo
Addict
Addict
Posts: 1967
Joined: Tue Dec 23, 2003 3:54 am

Re: RotateCoordinates X and Y origin parameters are unrespon

Post 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
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4636
Joined: Sun Apr 12, 2009 6:27 am

Re: RotateCoordinates X and Y origin parameters are unrespon

Post 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
Egypt my love
Post Reply