Scaling Quad correctly ?

BlitzMax Forums/BlitzMax Programming/Scaling Quad correctly ?

can anyone help me scale a quad to the same length as the line I am drawing below ? The lines endpoint is at the mouse x,y pos, I have no idea how to do this.

Strict
graphics 800,600

 Function DrawScaledQuad(x1:Int,y1:Int,x2:Int,y2)
   	Local dx = x2-x1
	Local dy = y2-y1
 
	Local angle:Float            
	
	Local llen:Float = Sqr((x1 - x2) ^ 2 + (y1 - y2) ^ 2)
	
    If  Sgn(dy) > 0 Then angle = ATan2(dy,dx)
    If  Sgn(dy) < 0 Then angle = ATan2(dy,dx) '+ Pi
    
 	DrawLine x1,y1,x2,y2
    
 	SetScale llen,1 
	SetRotation angle
	DrawRect x1,y1,3,3 
	SetScale 1,1     
	SetRotation 0
 
 End Function

 While not KeyDown(KEY_ESCAPE)
 	
 	
 	DrawScaledQuad(300,300,MouseX(),MouseY())
 	    
 	    Flip
 	    Cls
 	
 Wend


Just change the line :
DrawRect x1,y1,3,3
to :
DrawRect x1,y1,1,1

no no

I want to scale the quad to the length of the line, not the width.

But you are scalling the quad to the length of the line.

nope, you will notice the quad goes past mouse pos.

comment out the drawing of the quad and you will see what I mean.

I want the quad to be of exact same length as the line.

Ok run this.
Strict
Graphics 800,600

 Function DrawScaledQuad(x1:Int,y1:Int,x2:Int,y2)
   	Local dx = x2-x1
	Local dy = y2-y1
 
	Local angle:Float            
	
	Local llen:Float = Sqr((x1 - x2) ^ 2 + (y1 - y2) ^ 2)
	'llen:/10.0
    If  Sgn(dy) > 0 Then angle = ATan2(dy,dx)
    If  Sgn(dy) < 0 Then angle = ATan2(dy,dx) '+ Pi
 

	SetColor 255 , 0 , 0
 	SetScale llen,1.0
	SetRotation angle
	DrawRect x1,y1,1,3 
	SetScale 1,1     
	SetRotation 0
	
 	SetColor 0 , 255 , 0
 	DrawLine x1,y1,x2,y2
 
 End Function

 While Not KeyDown(KEY_ESCAPE)
 	
 	
 	DrawScaledQuad(300,300,MouseX(),MouseY())
 	    
 	    Flip
 	    Cls
 	
 Wend


That did it !

Thanks so much.