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();
 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;

But, it's not rotating along its own axis, it is flipping like a coin instead. What am I missing here?

  • \$\begingroup\$ The above one is for Y rotation , while moving along Z axis it's rotating fine but it's Y position changes \$\endgroup\$
    – Marvel
    Oct 1, 2016 at 14:07
  • \$\begingroup\$ If you want it to rotate around its own axis, then how about doing a rotation around its own axis, instead of 3 rotations around the X/Y/Z axes? \$\endgroup\$
    – user253751
    Oct 3, 2016 at 1:58

1 Answer 1


You apply your transformations in the wrong order. The usual way is scale first, then rotate, and lastly translate. Currently you are translating first, then rotating, and finally scaling.

See this question for more information.

  • \$\begingroup\$ When I am using Z rotation it's rotating and revolving both i.e Y position is also changing so what element in my matrix should i change \$\endgroup\$
    – Marvel
    Oct 1, 2016 at 14:29
  • \$\begingroup\$ Have you checked this? en.wikipedia.org/wiki/Rotation_matrix#In_three_dimensions \$\endgroup\$
    – user35344
    Oct 1, 2016 at 14:38
  • \$\begingroup\$ Here is my full code can't figure out it yet dropbox.com/sh/1glu6x4ajd6y4mw/AABvIPdCcUw4HwI9aZkiM5z4a/… any idea ? \$\endgroup\$
    – Marvel
    Oct 4, 2016 at 4:55
  • \$\begingroup\$ Did you even read my answer? You haven't done anything to your code. Anyways there's no way I'll have time nor interest to dig through all of your code. \$\endgroup\$
    – user35344
    Oct 4, 2016 at 11:02
  • \$\begingroup\$ I applied the tranformation as suggest you but still no luck \$\endgroup\$
    – Marvel
    Oct 4, 2016 at 11:29

You must log in to answer this question.

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