Skip to main content
GameDev.net gamedev.net
🔒 Locked

2D Camera Center

Started by Critical_Impact Jul 26, 2010 at 11:17 AM 0 replies 1.1k views
Original Post
Critical_Impact
Critical_Impact
So I have a Camera that I've setup using GLOrtho that has working zoom and panning but the problem I have is that it only zooms into the bottom left.
What I really want is to be able to zoom to either the center or some sort of arbitary point.

In my render loop I use

GL.Scale(ZoomLevel, ZoomLevel, 0.0);GL.Translate(-(int)CameraController.ActiveCamera.Position.X, -(int)CameraController.ActiveCamera.Position.Y, 0);


To scale and translate. I've tried translating before the Scale then after so that it scales from the center which causes the origin to be in the center. This is a problem because I apply bounds to the camera.

Basically how would I go about being able to zoom but also keep the view in bounds.

I can post more code if you need it.
Zakwayda
Zakwayda
I'd recommend zooming by adjusting the parameters of the orthographic projection rather than by applying scaling. If you place the origin of your projection at the center of the screen, it should be straightforward to center the 'zoom' effect.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.