I'm working towards implementing resizing shapes in my project, but I am unsure how to determine where the corners of the box are when its rotated. For example, when the box is rotated to 40 degrees, what was the bottom-right corner is now at the bottom. Is there a formula or something I can use to determine where the corners are?
Code: Select all
EnableExplicit
Structure Box
x.i : y.i
w.i : h.i
angle.i
EndStructure
Global handleSize = 6
Global *b.Box = AllocateStructure(Box)
With *b
\x = 270 : \y = 178
\w = 100 : \h = 125
\angle = 0
EndWith
Procedure DrawCanvas()
Protected txt$
txt$ = ~"Left/right to rotate\n\n0 to reset\n\nEscape to end\n\n\nAngle: " + Str(*b\angle) + Chr(176)
If StartVectorDrawing(CanvasVectorOutput(0))
VectorSourceColor(RGBA(0, 0, 0, 255))
FillVectorOutput()
VectorSourceColor(RGBA(255, 255, 255, 255))
MovePathCursor(20, 20)
DrawVectorParagraph(txt$, 200, 200)
RotateCoordinates(*b\x + *b\w / 2, *b\y + *b\h / 2, *b\angle)
AddPathBox(*b\x, *b\y, *b\w, *b\h)
VectorSourceColor(RGBA(0, 0, 255, 255))
StrokePath(1)
StopVectorDrawing()
EndIf
EndProcedure
Procedure OnCanvasEvents()
Select EventType()
Case #PB_EventType_KeyDown
Select GetGadgetAttribute(0, #PB_Canvas_Key)
Case #PB_Shortcut_Left
*b\angle - 3
If *b\angle < 0
*b\angle = 359
EndIf
If *b\angle > 359
*b\angle = 0
EndIf
Case #PB_Shortcut_Right
*b\angle + 3
If *b\angle < 0
*b\angle = 359
EndIf
If *b\angle > 359
*b\angle = 0
EndIf
Case #PB_Shortcut_0 : *b\angle = 0
Case #PB_Shortcut_Escape : End
EndSelect
DrawCanvas()
EndSelect
EndProcedure
If OpenWindow(0, 0, 0, 640, 480, "", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
CanvasGadget(0, 0, 0, 640, 480, #PB_Canvas_Keyboard)
BindGadgetEvent(0, @OnCanvasEvents(), #PB_All)
DrawCanvas()
SetActiveGadget(0)
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf