<p>I'm trying to create a camera using matrix transforms, the gist as follows:</p>
<pre><code>Transform =
                Matrix.CreateRotationZ(Rotation) *
                 Matrix.CreateTranslation(new Vector3(-Position.X, -Position.Y, 0)) *
                Matrix.CreateScale(Zoom) *
                Matrix.CreateTranslation(new Vector3(Bounds.Width * 0.5f, Bounds.Height * 0.5f, 0));
</code></pre>
<p>It works but with one issue. The rotation origin remains at the starting (-Position.X, -Position.Y) while the zoom works fine (at the center screen) which is obvious from the code. I'd like the rotation to occur at the center screen as well.</p>

CC BY-SA 4.0
2020-11-17T01:15:04.407Z
In order to rotate around any arbitrary point, you first move the object to the origin, rotate it, then back to the point where you wanna move it around.
gallickgunner
CC BY-SA 4.0
2020-11-17T08:38:03.467Z
I tried with: translate to middle screen -> rotate -> inverse translate to middle screen -> translate to position but the rotation does not stay in the center when the camera moves
Pooper
CC BY-SA 4.0
2020-11-17T12:18:54.143Z
What exactly is `Position` ? And what exactly do you mean by middle screen? Rotation is always around origin i.e `(0,0,0)`. So you need to first translate to origin then rotate then translate to any arbitrary position you want. Need more clear code and possibly some pictures to understand what problem you are facing.
gallickgunner
<opengl><transformations><matrix>
Matrix transforming with translation/rotation/scale at center of screen
Pooper
# Matrix transforming with translation/rotation/scale at center of screen

(Asked by: username_0 on 2020-11-16)

I'm trying to create a camera using matrix transforms, the gist as follows:

```
Transform =
                Matrix.CreateRotationZ(Rotation) *
                 Matrix.CreateTranslation(new Vector3(-Position.X, -Position.Y, 0)) *
                Matrix.CreateScale(Zoom) *
                Matrix.CreateTranslation(new Vector3(Bounds.Width * 0.5f, Bounds.Height * 0.5f, 0));

```

It works but with one issue. The rotation origin remains at the starting (-Position.X, -Position.Y) while the zoom works fine (at the center screen) which is obvious from the code. I'd like the rotation to occur at the center screen as well.

**Tags:** opengl, transformations, matrix

> **Comments:**
> **username_1**: In order to rotate around any arbitrary point, you first move the object to the origin, rotate it, then back to the point where you wanna move it around.  
> **username_0**: I tried with: translate to middle screen -> rotate -> inverse translate to middle screen -> translate to position but the rotation does not stay in the center when the camera moves  
> **username_1**: What exactly is `Position` ? And what exactly do you mean by middle screen? Rotation is always around origin i.e `(0,0,0)`. So you need to first translate to origin then rotate then translate to any arbitrary position you want. Need more clear code and possibly some pictures to understand what problem you are facing.  

---

## 0 answers

