It is currently Mon Sep 23, 2019 2:22 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Rotated sprites are clipped when partially out-of-screen
PostPosted: Thu Aug 15, 2019 10:39 am 
Offline
Enthusiast
Enthusiast

Joined: Wed Sep 18, 2013 11:54 am
Posts: 363
Location: France
Code:
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 359 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)


This circle is made of multiple lines for performance reasons, and also because I want to be able to draw radar ranges that are (way) bigger than the screen. But there is a serious problem: at the top and the bottom, the lines are clipped. For me, it's a major bug, as my technique is the best one I've tried when it comes to reduce performance impact. From what I read from the documentation, this behavior is not supposed to happen, because the DisplaySprite() section says: This function is clipped, so it's perfectly legal to display the sprite outside of the screen.

Original thread: viewtopic.php?f=13&t=73398


Top
 Profile  
Reply with quote  
 Post subject: Re: Rotated sprites are clipped when partially out-of-screen
PostPosted: Sat Aug 24, 2019 7:17 pm 
Offline
New User
New User

Joined: Sun Aug 18, 2019 8:07 pm
Posts: 5
Joubarbe wrote:
Code:
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 359 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)


This circle is made of multiple lines for performance reasons, and also because I want to be able to draw radar ranges that are (way) bigger than the screen. But there is a serious usps tracking problem: at the top and the bottom, the lines are clipped. For me, it's a major bug, as my technique is the best one I've tried when it comes to reduce performance impact. From what I read from the documentation, this behavior is not supposed to happen, because the DisplaySprite() section says: This function is clipped, so it's perfectly legal to display the sprite outside of the screen.

Original thread: viewtopic.php?f=13&t=73398

Facing same issue here too. Help is appreciated.

Thanks in advance.
Regards,
Shane


Top
 Profile  
Reply with quote  
 Post subject: Re: Rotated sprites are clipped when partially out-of-screen
PostPosted: Sun Aug 25, 2019 8:28 am 
Offline
Addict
Addict

Joined: Thu Aug 30, 2007 11:54 pm
Posts: 1052
Location: right here
Here is a simpler code. The sprite disappears if the center of rotation is moved beyond the top or bottom edge of the screen.
Code:
InitSprite()
InitMouse()
win = OpenWindow(#PB_Any, 50,100, 800, 600, "..")
OpenWindowedScreen(WindowID(win), 0, 0, 800, 600)

spr = CreateSprite(#PB_Any, 400, 100)
StartDrawing(SpriteOutput(spr))
Box(0, 0, OutputWidth(), OutputHeight(), $00ff00)
StopDrawing()

x.f = 400
y.f = 300

Repeat
  ExamineMouse()
  While WindowEvent()
    If Event() =  #PB_Event_CloseWindow
      quit = #True
    EndIf
  Wend
  ClearScreen($0)
  RotateSprite(spr, 1, #PB_Relative)
  x + MouseDeltaX()
  y + MouseDeltaY()
  DisplaySprite(spr, x, y)
  FlipBuffers()
Until quit


Top
 Profile  
Reply with quote  
 Post subject: Re: Rotated sprites are clipped when partially out-of-screen
PostPosted: Sun Aug 25, 2019 8:58 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sun Sep 11, 2016 2:17 pm
Posts: 520
Looks like a bug to me, there is no reason why it should clip the sprite.
A dirty fix would be to extend the screen height by half its size (dont do it).


Top
 Profile  
Reply with quote  
 Post subject: Re: Rotated sprites are clipped when partially out-of-screen
PostPosted: Sun Aug 25, 2019 10:59 am 
Offline
Addict
Addict

Joined: Thu Aug 30, 2007 11:54 pm
Posts: 1052
Location: right here
I guess theoretically you could use TransformSprite instead, but that actually has its own problems with clipping and with OpenGL.
STARGÅTE posted many transformation codes like this one:
https://www.purebasic.fr/english/viewtopic.php?p=484448#p484448
But here in Linux (which uses opengl) I don't get it to work as I would expect.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye