setscale oddities...

BlitzMax Forums/BlitzMax Beginners Area/setscale oddities...

Graphics 800,600

SetBlend alphablend
SetAlpha 0.3
SetOrigin 400,300

Global z:Float = 1.0
Global dz:Float = 0.2

While Not AppTerminate()

Cls

Global x2:Float = 0.0
Global y2:Float = 0.0
Global y:Float = 0.0

DrawLine -2, 0, 2, 0
DrawLine 0 , - 2 , 0 , 2

SetScale z,z

For Local x:Float = -100.0 To 100.0 Step 1.0
	y =( x ^ 2.0 )/ 5.0
	'SetScale 50.0 , 50.0
	SetColor 255 , 0 , 0
	DrawOval x*z - 2*z , y*z - 2*z ,4 , 4
	
	SetColor 0, 255, 0
	DrawOval x2*z - 1.0*z , y2*z - 1.0*z , 2 , 2
		
	SetColor 255,255,255
	DrawLine x , y , x2 , y2
		
	x2 = x
	y2 = y
Next 

Flip

If z > 40.0 Then
	dz:* - 1
Else If z < 1.0 Then
	dz:* - 1
EndIf

z:+dz

Wend


Try this at scale 1,1 it draws a nice curve from line segments and green circles on the start point and red on the end points.

But once the scale goes up instead of zooming in on the line and circles, the circles and lines drift off.

What am I doing wrong?

DrawOval's parameters are the X and Y coordinates of the top left corner of its 'bounding box', not the centre. So no matter what you set the scale to, that point is always going to be in the same place.

It also has width and height parameters, which *are* affected by SetScale.

Dagnammit! ;0)

But that does not explain why the lines used to draw the curve end up wandering off creating a nice hedgehog effect?

I've updated the Oval drawing routine, to reflect the fact that the top left co-ords are not affected by the scaling values.

But how does this work with line drawing co-ords?