Segmented circle out-of-screen problem

Just starting out? Need help? Post your questions and find answers here.
Joubarbe
Enthusiast
Enthusiast
Posts: 555
Joined: Wed Sep 18, 2013 11:54 am
Location: France

Segmented circle out-of-screen problem

Post by Joubarbe »

Hi,

I need to draw big range on screen, so I've decided to split a circle into different lines and assemble them in a proper way to make a circle:

Code: Select all

EnableExplicit

#screen_width = 1920
#screen_height = 1080
#app_title = "TITLE"

Define sprite_mouse.i, sprite_fps.i
Define frame.i, frame_refresh, frame_time.i, event.i
Global delta.d

InitKeyboard() : InitMouse() : InitSprite()

OpenWindow(0, 0, 0, #screen_width, #screen_height, #app_title, #PB_Window_BorderLess | #PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0), 0, 0, #screen_width, #screen_height, #False, 0, 0, #PB_Screen_SmartSynchronization)

sprite_mouse = CreateSprite(#PB_Any, 7, 7)
StartDrawing(SpriteOutput(sprite_mouse))
Box(0, 0, OutputWidth(), OutputHeight(), #Black)
Box(0, 0, OutputWidth() - 2, OutputHeight() - 2, #White)
StopDrawing()

sprite_fps = CreateSprite(#PB_Any, 40, 20)

;{ Circle segments.
Procedure.d GetDistance(x1.d, y1.d, x2.d, y2.d)
  ProcedureReturn Abs(Sqr(Pow(x2 - x1, 2) + Pow(y2 - y1, 2)))
EndProcedure
Define i.i,
       width.d,
       height.d,
       sprite.i,
       x.d, y.d,
       anchor_x.d, anchor_y.d,
       radius.i,
       size_modifier.d = 1.0,
       size_modifier_trend.d = 0.001
NewList sprites.i()
#radius = 500
radius = #radius
anchor_x = #screen_width / 2
anchor_y = #screen_height / 2
#step = 5
width = GetDistance(anchor_x + radius * Cos(Radian(0)),
                    anchor_y + radius * Sin(Radian(0)), 
                    anchor_x + radius * Cos(Radian(#step)),
                    anchor_y + radius * Sin(Radian(#step)))
width + 1
height = 2
For i = 0 To 360 Step #step
  sprite = CreateSprite(#PB_Any, width, height)
  StartDrawing(SpriteOutput(sprite))
  Box(0, 0, width, height)
  StopDrawing()
  AddElement(sprites())
  sprites() = sprite
Next i
;}

MouseLocate(DesktopMouseX(), DesktopMouseY())

Repeat
  Repeat
    event.i = WindowEvent()
    If event = #PB_Event_CloseWindow : Break 2 : EndIf
  Until event = 0
  
  ClearScreen(RGB(0, 0, 0))
  
  ExamineKeyboard() : ExamineMouse()
  MouseLocate(DesktopMouseX(), DesktopMouseY())
  
  ; Draw the lines at the right place.
  size_modifier + size_modifier_trend
  If size_modifier >= 1.5 Or size_modifier <= 0.5
    size_modifier_trend * -1
  EndIf
  i = 0
  radius = #radius * size_modifier
  ForEach sprites()
    ZoomSprite(sprites(), Round(width * size_modifier, #PB_Round_Up), Round(height * size_modifier, #PB_Round_Up))
    x = (anchor_x + radius * Cos(Radian(i))) - width / 2 ; - width / 2 to center the sprite on itself.
    y = anchor_y + radius * Sin(Radian(i))
    RotateSprite(sprites(), i - 90, #PB_Absolute)
    DisplaySprite(sprites(), x, y)
    i + #step
  Next
  
  DisplaySprite(sprite_fps, 0, 0)
  DisplaySprite(sprite_mouse, MouseX(), MouseY())
  
  ; FPS and Delta Time
  frame + 1
  If ElapsedMilliseconds() > frame_refresh
    StartDrawing(SpriteOutput(sprite_fps))
    DrawText(0, 0, "fps:" + frame)
    StopDrawing()
    frame_refresh = ElapsedMilliseconds() + 1000
    frame = 0
  EndIf
  delta = (ElapsedMilliseconds() - frame_time) / 1000
  frame_time = ElapsedMilliseconds()
  
  FlipBuffers()   
Until KeyboardReleased(#PB_Key_Escape)
The problem is that when the circle goes out of the screen, the sprite seems to be cut and not drawn when it's supposed to, giving this weird behavior at the top and bottom. Does anyone have any idea why this is happening and how to avoid it?
#NULL
Addict
Addict
Posts: 1440
Joined: Thu Aug 30, 2007 11:54 pm
Location: right here

Re: Segmented circle out-of-screen problem

Post by #NULL »

IIRC there was a problem with some sprite functions like RotateSprite() that would clip (i.e. not draw) a sprite when it should still be visible at the edges of the screen. But I don't have a testcase or a bugreport at hand right now.
Joubarbe
Enthusiast
Enthusiast
Posts: 555
Joined: Wed Sep 18, 2013 11:54 am
Location: France

Re: Segmented circle out-of-screen problem

Post by Joubarbe »

Hmm, maybe this thread is a bug report then :)

Bug report: viewtopic.php?f=4&t=73405
Post Reply