1
\$\begingroup\$

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;

But, it's not rotating along it's own axis. What am I missing here?

\$\endgroup\$
  • \$\begingroup\$ "But, it's not rotating along it's own axis." What is it doing instead? \$\endgroup\$ – Vaillancourt Oct 1 '16 at 13:36
  • \$\begingroup\$ @AlexandreVaillancourt It's move like flipping coin .. i.e in one rotation Head is front and other rotation Tails is front... i want simple rotation no side change... \$\endgroup\$ – Marvel Oct 1 '16 at 14:00
  • \$\begingroup\$ @AlexandreVaillancourt 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 '16 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 '16 at 1:58
2
\$\begingroup\$

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.

\$\endgroup\$
  • \$\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 '16 at 14:29
  • \$\begingroup\$ Have you checked this? en.wikipedia.org/wiki/Rotation_matrix#In_three_dimensions \$\endgroup\$ – Tyyppi_77 Oct 1 '16 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 '16 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\$ – Tyyppi_77 Oct 4 '16 at 11:02
  • \$\begingroup\$ I applied the tranformation as suggest you but still no luck \$\endgroup\$ – Marvel Oct 4 '16 at 11:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.