2
$\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;

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

$\endgroup$
2
  • $\begingroup$ What is it doing instead? Is it rotating along a different axis? $\endgroup$ Oct 2, 2016 at 11:35
  • $\begingroup$ I wanted to read your question but that animated gif is too distracting. $\endgroup$
    – 3Dave
    Oct 5, 2016 at 23:07

1 Answer 1

1
$\begingroup$

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;
$\endgroup$
2
  • $\begingroup$ Do you know if this solves the problem? $\endgroup$ Oct 3, 2016 at 7:17
  • $\begingroup$ I believe the problem was not rotating along its own axis so doing it this way should solve it. Maybe there are other solutions $\endgroup$
    – mdkdy
    Oct 3, 2016 at 15:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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