PDA

View Full Version : Zooming Control with a 2D Camera


Shunter
2006.06.23, 08:51 PM
I'm using a camera control in my 2D platformer game (using BlitzMax if that matters) to 'handle' my image drawing; ie drawing images at (image.x - camera.x),(image.y - camera.y).

Then I had the idea to use layers, which also works OK; drawing to ((image.x*image.layer) - camera.x),((image.y*image.layer) - camera.y)

Now I'd like to add in zooming, and I seem to have hit a brick wall. I thought it would be something like (((image.x*image.layer) - camera.x)*size),(((image.y*image.layer) - camera.y)*size), but that doesn't seem to work right :cry: . I've tried a few other cominations, but no luck.

Does anyone have any advice?

Thanks in advance

Leisure Suit Lurie
2006.06.23, 11:55 PM
So things on layer 2 are to be twice as big, for example?

unknown
2006.06.24, 12:12 AM
Do an OpenGL and use 3x3 matrices for everything, you can do rotation, translation and scaling with it no problem.

Leisure Suit Lurie
2006.06.24, 12:44 AM
If you don't know OpenGL, use the math from here for now: http://easyweb.easynet.co.uk/~mrmeanie/persp/persp.htm

Shunter
2006.06.24, 01:24 AM
Aye, that's a good tutorial; I'll look into it thanks.

Najdorf
2006.06.24, 07:47 PM
I'd use

apparentX=window.width/2.0+(image.x - camera.x)/distance
apparentY=window.height/2.0+(image.y - camera.y)/distance

where distance is the distance between the camera and the object (which changes depending on the "layer" and if you zoom in-out)

Also you will have to scale the objects inversely to the distance