Scaling Quad correctly ?

BlitzMax Forums/BlitzMax Programming/Scaling Quad correctly ?

SillyPutty(Posted 2006) [#1]
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



Haramanai(Posted 2006) [#2]
Just change the line :
DrawRect x1,y1,3,3
to :
DrawRect x1,y1,1,1


SillyPutty(Posted 2006) [#3]
no no

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


Haramanai(Posted 2006) [#4]
But you are scalling the quad to the length of the line.


SillyPutty(Posted 2006) [#5]
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.


Haramanai(Posted 2006) [#6]
Ok run this.



SillyPutty(Posted 2006) [#7]
That did it !

Thanks so much.