BRL.Max2D - SetViewRotation + SetViewOffset

BlitzMax Forums/BlitzMax Module Tweaks/BRL.Max2D - SetViewRotation + SetViewOffset

fredborg(Posted 2005) [#1]
Hi,

I find these two functions very helpful, when rotating or scrolling the entire viewport at once, instead of rotating each element. Feel free to add them to the official module.
rem
bbdoc: Set the rotation of the viewport
about: SetViewRotation allows you to rotate the entire viewport, so that all
drawing is rotated according to the @angle parameter.
endrem
Function SetViewRotation(angle:Float)
	
	Global o_angle:Float
	
	glMatrixMode GL_PROJECTION
	glRotatef angle-o_angle,0,0,1
	o_angle=angle
	
	glMatrixMode GL_MODELVIEW
	glLoadIdentity
	
End Function

rem
bbdoc: Set the offset of the viewport
about: SetViewOffset allows you to offset the entire viewport, so that all
drawing is offset according to the @offsetx and @offsety parameters.
endrem
Function SetViewOffset(offsetx:Float,offsety:Float)
	
	Global o_offsetx:Float
	Global o_offsety:Float
	
	glMatrixMode GL_PROJECTION
	glTranslatef offsetx-o_offsetx,offsety-o_offsety,0
	o_offsetx = offsetx
	o_offsety = offsety
	
	glMatrixMode GL_MODELVIEW
	glLoadIdentity
	
End Function

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
[Edit] Added SetViewZoom as well.


EOF(Posted 2005) [#2]
I was going to ask about zoom ... Nice.
It also means with glScale we can stretch and shrink the display. By supplying negative values to glScale you can flip the screen but you need to offset the display by a negative amount according to its dimensions:
' flip screen horizontally
glMatrixMode GL_PROJECTION
glScalef -1.0 , 1.0 , 1.0
glTranslatef -GraphicsWidth(),0,0
glMatrixMode GL_MODELVIEW
glLoadIdentity

' flip screen vertically
glMatrixMode GL_PROJECTION
glScalef 1.0 , -1.0 , 1.0
glTranslatef 0,-GraphicsHeight(),0
glMatrixMode GL_MODELVIEW
glLoadIdentity



flying willy(Posted 2005) [#3]
Worth adding to the official imho


Jeroen(Posted 2005) [#4]
agreed


tonyg(Posted 2005) [#5]
Does anybody know if these will be added to the official modules?


tonyg(Posted 2005) [#6]
Hmmm. This was worked pre 1.03 but now complains about glmatrixmode.
Have I done something wrong?
<edit> Sorry Import Pub.Glew


Robert Cummings(Posted 2005) [#7]
This doesn't work with DX?


tonyg(Posted 2005) [#8]
That'll be all those ogl commands then.
<edit> don't forget this was 6 months ago when we didn't know there'd be a DX driver.


Robert Cummings(Posted 2005) [#9]
Yep! would be nice if it was official and 'dx-ified'


DocFritz(Posted 2005) [#10]
Sorry for dumb question, but... how do I use these functions?
If i copy them into my code and call one of them nothing happens. How do I "install" them or what do I have to do to get them working?


klepto2(Posted 2005) [#11]
Don't forget to set the Graphicsdriver to OpenGL before using this functions.


SetGraphicsDriver GLMax2DDriver()




Cruis.In(Posted 2005) [#12]
i think i forgot too :)

what happens they dont work? these functions had no effect for me , i created a context up front..


Cruis.In(Posted 2005) [#13]
ok got it, how would I get a ship I have at the centre of the screen, to stay at the centre? currently when i zoom out with the mouse wheel with your function and my zoom factor, it makes the graphic zoom out till eventually its a small window viewport in the upper left corner. but i still love it, because now the ships are still as close to one another before zooming.


DocFritz(Posted 2005) [#14]
You have to set the offset to the middle of you screen. Then you can rotate, scale, etc.


Cruis.In(Posted 2005) [#15]
scale as in zoom? setorigin graphicswidth/2 height/2

??


Cruis.In(Posted 2005) [#16]
scale as in zoom? setorigin graphicswidth/2 height/2

I put in this and it still does the same thing, just that the image starts at the bottom right hand corner on execution instead of the centre.
??


Cruis.In(Posted 2005) [#17]
do I have to use the offset viewport function listed here in conjunction with the zooming of the viewport? and not the standard offsets? cause they aint working.