<p>Instead of "stacking" or overwriting these transformations on one matrix You may try doing that using matrix multiplication:</p>

<pre><code>Matrix4f translate = translate(translation,  new Matrix4F() /*identity*/);
Matrix4f rotateX = rotate((float) Math.toRadians(rx), new Vector3f(1,0,0), new Matrix4F());
Matrix4f scale = scale(new Vector3f(scale,scale,scale), new Matrix4F());

Matrix4f transformation = translate*rotateX*scale;
</code></pre>

CC BY-SA 3.0
2016-10-03T07:17:19.373Z
Do you know if this solves the problem?
trichoplax is on Codidact now
CC BY-SA 3.0
2016-10-03T15:06:21.257Z
I believe the problem was not rotating along its own axis so doing it this way should solve it. Maybe there are other solutions
mdkdy
CC BY-SA 3.0
2016-10-02T13:18:46.230Z
2016-10-02T13:29:50.337Z
2016-10-02T13:29:50.337Z
mdkdy
<p>I have a circular shape object, which I want to rotate like a fan along it's own axis.</p>

<p>I can change the rotation in any direction i.e. dx, dy, dz using my transformation matrix.</p>

<p>The following it's the code:</p>

<pre><code> Matrix4f matrix = new Matrix4f();
 matrix.setIdentity();
 Matrix4f.translate(translation, matrix, matrix);
 Matrix4f.rotate((float) Math.toRadians(rx), new Vector3f(1,0,0), matrix, matrix);
 Matrix4f.rotate((float) Math.toRadians(ry), new Vector3f(0,1,0), matrix, matrix);
 Matrix4f.rotate((float) Math.toRadians(rz), new Vector3f(0,0,1), matrix, matrix);
 Matrix4f.scale(new Vector3f(scale,scale,scale), matrix, matrix);
</code></pre>

<p>My vertex code:</p>

<pre><code> vec4 worldPosition = transformationMatrix * vec4(position,1.0);
 vec4 positionRelativeToCam = viewMatrix*worldPosition;
 gl_Position = projectionMatrix *positionRelativeToCam;
</code></pre>

<p>Main Game Loop:</p>

<pre><code> Object.increaseRotation(dxf,dyf,dzf);
</code></pre>

<p>But, it's not rotating along it's own axis. What am I missing here? I want something like this. Please Help</p>

<p><a href="https://i.sstatic.net/knBlT.gif" rel="nofollow noreferrer"><img src="https://i.sstatic.net/knBlT.gif" alt="Like This"></a></p>

CC BY-SA 3.0
2016-10-02T11:35:54.200Z
What is it doing instead? Is it rotating along a different axis?
Julien Guertault
CC BY-SA 3.0
2016-10-05T23:07:14.267Z
I wanted to read your question but that animated gif is too distracting.
3Dave
<opengl><shader><transformations><mathematics><matrix>
Rotating an Object Around an Axis
dsd
# Rotating an Object Around an Axis

(Asked by: username_0 on 2016-10-02)

I have a circular shape object, which I want to rotate like a fan along it's own axis.

I can change the rotation in any direction i.e. dx, dy, dz using my transformation matrix.

The following it's the code:

```
 Matrix4f matrix = new Matrix4f();
 matrix.setIdentity();
 Matrix4f.translate(translation, matrix, matrix);
 Matrix4f.rotate((float) Math.toRadians(rx), new Vector3f(1,0,0), matrix, matrix);
 Matrix4f.rotate((float) Math.toRadians(ry), new Vector3f(0,1,0), matrix, matrix);
 Matrix4f.rotate((float) Math.toRadians(rz), new Vector3f(0,0,1), matrix, matrix);
 Matrix4f.scale(new Vector3f(scale,scale,scale), matrix, matrix);

```

My vertex code:

```
 vec4 worldPosition = transformationMatrix * vec4(position,1.0);
 vec4 positionRelativeToCam = viewMatrix*worldPosition;
 gl_Position = projectionMatrix *positionRelativeToCam;

```

Main Game Loop:

```
 Object.increaseRotation(dxf,dyf,dzf);

```

But, it's not rotating along it's own axis. What am I missing here? I want something like this. Please Help

[![Like This](https://i.sstatic.net/knBlT.gif)](https://i.sstatic.net/knBlT.gif)

**Tags:** opengl, shader, transformations, mathematics, matrix

> **Comments:**
> **username_1**: What is it doing instead? Is it rotating along a different axis?  
> **username_2**: I wanted to read your question but that animated gif is too distracting.  

---

## 1 answers

### Answer by username_3 on 2016-10-02. Score: 1

Instead of "stacking" or overwriting these transformations on one matrix You may try doing that using matrix multiplication:

```
Matrix4f translate = translate(translation,  new Matrix4F() /*identity*/);
Matrix4f rotateX = rotate((float) Math.toRadians(rx), new Vector3f(1,0,0), new Matrix4F());
Matrix4f scale = scale(new Vector3f(scale,scale,scale), new Matrix4F());

Matrix4f transformation = translate*rotateX*scale;

```

> **Comments:**
> **username_4**: Do you know if this solves the problem?  
> **username_3**: I believe the problem was not rotating along its own axis so doing it this way should solve it. Maybe there are other solutions  

---

