Simply drawing a float value

BlitzMax Forums/BlitzMax Beginners Area/Simply drawing a float value

Ryan Burnside(Posted 2006) [#1]
I know this is cvery easy for you more expearanced users. I simply need to know how to draw the values of a number. I know there are some value to string conversions but I'm not sure how to fill the parameters.
I have a float, angle that needs to be drawn at 0,0


TomToad(Posted 2006) [#2]
drawtext Angle,0,0

It's automatically converted to a string :)
You can even append it to other strings.
DrawText "The angle is "+Angle,0,0


Ryan Burnside(Posted 2006) [#3]
Oh, maybe my function is wrong then. It uses the mouse x and y in the calculation.

the following is my function:

Function point_angle#(x#,y#,x2#,y2#)
Local x_length#=x-x2
Local y_length#=y-y2
Local angle#=ATan(y_length/x_length)
Return angle
End Function

Perhaps using the mouse x and y values for the x2 and y2 are causing the error.


TomToad(Posted 2006) [#4]
I don't think that function has anything to do with DrawText, but there is a logic error in your function.
ATan only returns correct info when both x_length and y_length are either positive or negative. You need to use the ATan2 function to correct for this. The way to use it is ATan2(y,x). Notice that the y parameter is first, not the x like you would expect. This is to keep consistency with the ATan(y/x) function. It will also return a value between -180 and 180. 0 points right, -values turn counterclockwise, and +values turn clockwise. If you want 0-360, you can either add 180 to the return value, which makes 0 point left instead of right, or you can do something like If Angle < 0 then Angle :+ 360.
To see it in action, try this program out
Graphics 800,600,32

Local MX:Int, MY:Int, Angle:Float

While Not KeyHit(KEY_ESCAPE)
	MX = MouseX()
	MY = MouseY()
	
	Cls
	DrawLine(400,300,MX,MY)
	
	Angle = ATan2(MY-300,MX-400)

	DrawText "Angle = "+Angle,10,10
	
	Flip
Wend



ImaginaryHuman(Posted 2006) [#5]
Neat, although it seems the angel range is -180 to 180 instead of 0 to 360. You might add `If Angle<0 Then Angle:+360'.


TomToad(Posted 2006) [#6]
You mean like I said in my previous post?
you can do something like If Angle < 0 then Angle :+ 360.

:D


Ryan Burnside(Posted 2006) [#7]
I got it working fine. Are the screen positions for the mouse ints by default? Because I might want to do this with float vars....