Home Game Development opengl – Rotate camera around its center in 2D

opengl – Rotate camera around its center in 2D

0
opengl – Rotate camera around its center in 2D

[ad_1]

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

I have implemented 4×4 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.

[ad_2]

Previous article Jets vs. Raiders live stream: watch the NFL for free
Next article Rebel Moon looks like Seven Samurai in space with laser swords
Hello there! My name is YoleeTeam, and I am thrilled to welcome you to AmazonianGames.com. As the premier destination for all things related to Amazon Games' universe, we are dedicated to providing you with the most exciting and immersive gaming experiences out there. From captivating visuals to exhilarating gameplay, our website is packed with comprehensive insights, updates, and reviews to keep you ahead of the game. Whether you're a seasoned gamer or new to the scene, I am here to guide you through this virtual frontier. If you have any questions or suggestions, feel free to reach out to me at john@yoleesolutions.com. Embark on your Amazon gaming journey today with AmazonianGames.com and let the adventure begin!