BRL.Max2D - SetViewRotation + SetViewOffset
BlitzMax Forums/BlitzMax Module Tweaks/BRL.Max2D - SetViewRotation + SetViewOffset
| ||
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. |
| ||
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 |
| ||
Worth adding to the official imho |
| ||
agreed |
| ||
Does anybody know if these will be added to the official modules? |
| ||
Hmmm. This was worked pre 1.03 but now complains about glmatrixmode. Have I done something wrong? <edit> Sorry Import Pub.Glew |
| ||
This doesn't work with DX? |
| ||
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. |
| ||
Yep! would be nice if it was official and 'dx-ified' |
| ||
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? |
| ||
Don't forget to set the Graphicsdriver to OpenGL before using this functions.SetGraphicsDriver GLMax2DDriver() |
| ||
i think i forgot too :) what happens they dont work? these functions had no effect for me , i created a context up front.. |
| ||
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. |
| ||
You have to set the offset to the middle of you screen. Then you can rotate, scale, etc. |
| ||
scale as in zoom? setorigin graphicswidth/2 height/2 ?? |
| ||
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. ?? |
| ||
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. |