Page 1 of 1

Fixed line width, at any angle...

Posted: Tue Aug 17, 2004 11:08 pm
by snap2000
I've been racking my mind to try to find a way to be able to have a line point toward the mouse cursor, without exceeding a specific length. I am currently doing a sort of development thing to try and find a way, but I'm not having much luck. An ideal method would be to have the line go all the way to the mouse, and simply clip it inside of a circle, but that seems highly unlikely...

I'm going to go take another look at the snippits... if I can remember where the site is...

Posted: Wed Aug 18, 2004 12:41 am
by GreenGiant
Not sure if I've understood the question or not, but something like this?

Code: Select all

Procedure.f Dist(x1,y1,x2,y2)
  ProcedureReturn Sqr(Pow(x2-x1,2)+Pow(y2-y1,2))
EndProcedure 

Procedure DrawLine()
  centrex=WindowWidth()/2
  centrey=WindowHeight()/2
  mousex=WindowMouseX()
  mousey=WindowMouseY()
  StartDrawing(ScreenOutput())
    DrawingMode(0)
    Box(0,0,WindowWidth(),WindowHeight(),$FFFFFF)
    DrawingMode(4)
    Circle(centrex,centrey,100,$FF0000)
    dist.f=Dist(centrex,centrey,mousex,mousey)
    If dist>100
      factor.f=100/dist
      diffx=(mousex-centrex)*factor
      diffy=(mousey-centrey)*factor
      Line(centrex,centrey,diffx,diffy,$000000)
    Else
      Line(centrex,centrey,mousex-centrex,mousey-centrey,$000000)
    EndIf
  StopDrawing()
  FlipBuffers()
EndProcedure 

OpenWindow(0,0,0,400,400,#PB_Window_SystemMenu | #PB_Window_ScreenCentered,"test")
InitSprite()
OpenWindowedScreen(WindowID(0),0,0,400,400,0,0,0)
Drawline()

Repeat
ev=WaitWindowEvent()
  If ev=512
    DrawLine()
  EndIf
Until ev=#PB_Event_CloseWindow

Posted: Wed Aug 18, 2004 4:12 am
by snap2000
Yes! That's just what I need! I'll be examining that to see what you did. :)

Thank you. :D