# Rotate camera around its center in 2D

I'm currently trying to develop my own little game engine (trying to understand maths in games).

I have implemented 4x4 matrices and 2d vectors (I don't need 3d since I'm aiming at orthographic projection in 2d).

I have a Camera class that has a position and a rotation angle as members.

Every time my camera moves (keyboard input), I update its view matrix.

I do it this way:

• I translate the camera to its position and then create a Z-axis rotation matrix.
• I multiply both and have my view matrix.

Everything looks fine, and by that I mean that translation works, as well as rotation and projection is fine too.

But my problem is that objects in my scene do not rotate around the camera position.

It looks like my objects rotate around a point that is translated by the camera too, not like objects rotate around the actual camera center.

And here is my source code: https://github.com/yann-kaiser/kyengine

I do not know if I shall tweak things in my camera transformation or if it's a model-matrix related thing or anything else; could someone explain this to me?

EDIT: Finally found the solution. I needed to first create a translation matrix to the center of the screen (translate by w/2 and h/2), then apply rotation and only then apply my position translation.

• Please don't add the solution as an edit to your question. If you solved your own problem, write it up as an answer & then mark it as accepted. Feb 24 '18 at 4:31

That usually happens, when you apply the matrices in the wrong order, it should be translation * rotation * scale