View Full Version : Rotation About An Axis

10-02-2016, 10:32 AM
I want to Rotate my object around it's axis , i.e i want to create a fan like rotation

But i am not able to get the desired effect

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;

Main Game Loop:


Rotating Along Z axis also make by object cange it's y and x position thus making it revoving with rotation.
But, it's not rotating along it's own axis. What am I missing here?
Please Help

Full Code - dropbox.com/sh/1glu6x4ajd6y4mw/AABvIPdCcUw4HwI9aZkiM5z4a/src?dl=0
sample image - i.stack.imgur.com/knBlT.gif

10-06-2016, 04:24 AM
Try moving it to the origin and then rotating it and then moving it back.

You can easily wind up with an orbit instead of a rotation. That's one way of dealing with it, and probably not my first choice these days, but it works and it's in line with what you are currently doing.

These days I would probably reverse the order of multiplication in the matrix operations, but you're not doing the matrix math yourself and so that's obfuscated to where you can't get to it.