0

I am coding a game using LWJGL OpenGL, I rotate my objects about their model origins using a transformation matrix:

public static Matrix4f createTransformationMatrix(Vector3f translation, float rx, float ry, float rz, Vector3f scale) {

    Matrix4f matrix = new Matrix4f();
    matrix.setIdentity();
    Matrix4f.translate(translation, 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.rotate((float) Math.toRadians(rx), new Vector3f(1, 0, 0), matrix, matrix);
    Matrix4f.scale(scale, matrix, matrix);

    return matrix;
}

However, I wish to rotate an object around the origin of another object, instead of its own origin. Please help? Thanks

  • see [Understanding 4x4 homogenous transform matrices](https://stackoverflow.com/a/28084380/2521214) for how to extract position from matrix and the rest is in the linked duplicate or in here [How to rotate a vector in opengl?](https://stackoverflow.com/a/50170363/2521214) – Spektre Jul 14 '18 at 08:27
  • you need to translate that object into the origin you want, rotate, and then translate it back – elect Jul 16 '18 at 07:34

0 Answers0