1
\$\begingroup\$

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.

Camera rotation

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.

\$\endgroup\$
1
  • 3
    \$\begingroup\$ 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. \$\endgroup\$
    – Pikalek
    Commented Feb 24, 2018 at 4:31

1 Answer 1

0
\$\begingroup\$

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

\$\endgroup\$
1
  • \$\begingroup\$ This is actually what i do ! For my camera it is translation * rotation, and then in the shader projection * view * model. \$\endgroup\$
    – KSR
    Commented Jun 5, 2017 at 19:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .