How to scale and rotate the "camera" ?

BlitzMax Forums/BlitzMax Programming/How to scale and rotate the "camera" ?

In Blitzmax one of the main missing features in the 2D library is to scale and rotate the entire screen reliably in all the drawing drivers, such as ogl dx7 and dx9 etc.

I would like a module which allows me to affect the screen or "camera" scale, position and rotation without messing with my existing game...

Please tell me it can be done simply and reliably, or if it has already been done!

Here are some examples in a previous topic:

http://www.blitzmax.com/Community/posts.php?topic=78579

hope it helps.

Thanks but there were absolutely no driver independant solutions there. I am hoping at minimum for a usable DX+OGL technique which would not call for an entire rewrite of my games graphics, but work regardless of driver used...

I only want to rotate, shake and zoom the camera if possible... one would assume it was built in.

no ideas?

Can we have a scale and rotate viewport command? would make max games look a lot more dynamic.

You'll have to recode part of your game. If you derived every graphic object from a base class (this is highly recommended on every game), it should be as easy as adding this feature to the base class.

This is still using the wrong tool for the job.

What I am looking for is the guts of the projection matrix, or some better ideas. Transforming every single object by hand is needlessly computatively expensive for such a simple task, no?

There is some GL stuff here to get you started ..

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

Rem
	bbdoc: Flip the screen horizontally
EndRem
Function FlipScreenX()
	glMatrixMode GL_PROJECTION
	glScalef -1.0 , 1.0 , 1.0
	glTranslatef -GraphicsWidth(),0,0
	glMatrixMode GL_MODELVIEW
	glLoadIdentity
End Function

Rem
	bbdoc: Flip the screen vertically
EndRem
Function FlipScreenY()
	glMatrixMode GL_PROJECTION
	glScalef 1.0 , -1.0 , 1.0
	glTranslatef 0,-GraphicsHeight(),0
	glMatrixMode GL_MODELVIEW
	glLoadIdentity
End Function


Thats fantastic thanks jim, but my problem is that DX must be used on windows.

Anyone got a DX driver version?

http://www.blitzbasic.com/Community/posts.php?topic=72268

??

Thanks for that but apparently it "warps" and stretches. I have decided to abandon the idea of rotating the screen until its a feature. I still don't understand why the developer didn't make it a command.

You could take screenshots and move that.

Thanks but there were absolutely no driver independant solutions there. I am hoping at minimum for a usable DX+OGL technique which would not call for an entire rewrite of my games graphics, but work regardless of driver used...


I didn't use any drivers in my version in that post

Try the following example with code included

http://server.dedicatedservices.org/upload/zip/retro.zip

I first wrote a game and after that I wanted to rotate and shake and zoom everything also when needed. What I did was create a load of new functions. After that I replaced all draw commands which are affected by zoom, rotate or movement by my own functions. And after that I just tell how much it must be zoomed in or rotated or moved.

You are free to use my example, but you might want to change stuff to make it easier to add to your game. At least try it to get the idea.

I tried out your retro zip and I'm very impressed. It wasn't what I was looking for as it requires calculating absolutely everything thats being drawn on screen so its processor intensive....

however I liked it so much and there seems to be no alternative so I may verywell give it a try

Thank you for your patience and contribution Mark G . :)

I agree with Lowcs. This needs to be a built in language independant feature. Why isn't it? Having to rotate all objects one at a time is not good.

When using MiniB3D or Blitz3D you work with a camera view and you could move or rotate that, so using MiniB3d with flat 3D objects which look 2D will take the load away from the CPU and let the GPU do all the work.

I'm a bit new to MiniB3D, so I have no examples on how to do that yet...

But for BlitzMax calculating every tiles position is the fastest way I can come up with.

Changing the projection matrix is the fastest way to rotate all on screen, I'm not sure why max2d never bothered.