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;

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

Image

\$\endgroup\$
4
  • 1
    \$\begingroup\$ Possible duplicate of Rotating a circle on its axis \$\endgroup\$
    – user35344
    Commented Oct 2, 2016 at 8:09
  • \$\begingroup\$ You can edit your questions instead of creating a new one just to add a gif :) \$\endgroup\$
    – eclmist
    Commented Oct 2, 2016 at 12:18
  • \$\begingroup\$ I can't tell if there is anything wrong. But why don't you try putting all of the matrix calculations in one line, that's the only thing I can think of. \$\endgroup\$
    – J22o
    Commented Oct 3, 2016 at 19:30
  • \$\begingroup\$ @JasonPh here full code dropbox.com/sh/1glu6x4ajd6y4mw/AABvIPdCcUw4HwI9aZkiM5z4a/… any idea.. \$\endgroup\$
    – Marvel
    Commented Oct 4, 2016 at 4:54

0

You must log in to answer this question.

Browse other questions tagged .