Zoom View

BlitzMax Forums/BlitzMax Programming/Zoom View

Is it possible?
I found this from here : http://www.blitzmax.com/Community/posts.php?topic=42799&hl=zoom
rem 
bbdoc: Set the zoom factor of the viewport
about: SetViewZoom allows you to zoom all drawn elements at once, instead
of scaling each individual element. Use the @zoom parameter to define the
level of zoom, a value of 0 is the default zoom, >0 zooms in, <0 zooms out.
endrem
Function SetViewZoom(zoom:Float)
	
	Global o_zoom:Float
	
	glMatrixMode GL_PROJECTION
	glScalef 1.0+(zoom-o_zoom),1.0+(zoom-o_zoom),1.0+(zoom-o_zoom)
	o_zoom = zoom
	
	glMatrixMode GL_MODELVIEW
	glLoadIdentity
	
End Function

It's good use of OpenGL.
But when I zoom in and out the origin changes...
Also I cannot find a proper way to get coordinates using the MouseX() and MouseY().

Is there another way to do this?
Or I am just loosing my time?
Is there a probability to be impemented in Max2D?

?

Well...
I found a way that it works with GLMax2D.
It's pure OpenGL.
I named the function setCenterAndZoom
Function setCenterAndZoom(x:Float , y:Float , Zoom:Float)
	Local LeftGL:Float = x - ((GraphicsWidth() / Zoom) / 2)
	Local RightGL:Float = x + ((GraphicsWidth() / Zoom) / 2)
	Local ButtomGL:Float = y + ((GraphicsHeight() / Zoom) / 2)
	Local TopGL:Float = y - ((GraphicsHeight() / Zoom) / 2)	
	glMatrixMode 	(GL_PROJECTION)
	glLoadIdentity	()
	gluOrtho2D		(LeftGL, RightGL, ButtomGL,TopGL)
End Function


and here it's an example... with Max2D Drawing
SuperStrict

SetGraphicsDriver GLMax2DDriver()

Graphics 640 , 480

Local Zoom:Float = 1.0
Local CenterX:Float = 0.0
Local CenterY:Float = 0.0
While Not KeyDown(KEY_ESCAPE)
	Cls
	setCenterAndZoom( CenterX , CenterY , Zoom )
	
	SetColor 0 , 255 , 0
	DrawOval 30 , 30 , 40 , 40
	SetColor 255 , 0 , 0
	DrawLine 0 , 0 , 30 , 30
	
	If KeyDown(KEY_LEFT) Then CenterX:-1
	If KeyDown(KEY_RIGHT) Then CenterX:+1	
	If KeyDown(KEY_UP) Then CenterY:-1	
	If KeyDown(KEY_DOWN) Then CenterY:+1		
	If KeyDown(KEY_NUMADD) Then Zoom:+ 0.1
	If Zoom > 0.1
		If KeyDown(KEY_NUMSUBTRACT) Then Zoom:- 0.1	
	End If
			
	Flip
Wend

Function setCenterAndZoom(x:Float , y:Float , Zoom:Float)
	Local LeftGL:Float = x - ((GraphicsWidth() / Zoom) / 2)
	Local RightGL:Float = x + ((GraphicsWidth() / Zoom) / 2)
	Local ButtomGL:Float = y + ((GraphicsHeight() / Zoom) / 2)
	Local TopGL:Float = y - ((GraphicsHeight() / Zoom) / 2)	
	glMatrixMode 	(GL_PROJECTION)
	glLoadIdentity	()
	gluOrtho2D		(LeftGL, RightGL, ButtomGL,TopGL)
End Function

please test...

I almost forgot.
Here is the function to get the global coordinates from the Mouse position on the screan.
Function getGlobalXY( x:Double Var , y:Double Var , CenterX:Double , CenterY:Double , Zoom:Double)
	x = (x / zoom) + CenterX - ((GraphicsWidth() / Zoom) / 2)
	y = (y / zoom) + CenterY - ((GraphicsHeight() / Zoom) / 2)
End Function

Also I have to tell you that DrawPixmap gives strange result.
All the other drawing commands works ok. ( and pure OpenGL drawing of curse)