Can someone give me an explanation about how to use the Quaternion class in libGDX to move my camera around a sphere or just set it up, manipulate it, and apply it general? I am trying to acheive orbiting my camera around a sphere without gimbal lock, and I'm not having any luck getting the camera to do anything by using quaternions...

  • \$\begingroup\$ I created the Quaternion and initilized it to x=0, y=1, z=0, w=PI/2... but no matter what I change those values to and try to apply it to the camera, I'm not seeing any changes. I assume I'm supposed to set the view matrix to the matrix that is formed by the quaternion but it's not working and I'm not seeing how that will change my position around the sphere. I also don't know how to update the quaternion values dynamically to move it. \$\endgroup\$
    – DRiFTy
    Commented Dec 14, 2012 at 17:44
  • \$\begingroup\$ I can post some code in a few hours when I get out of work, if you would like to see that too. \$\endgroup\$
    – DRiFTy
    Commented Dec 14, 2012 at 17:45

1 Answer 1


I ended up getting this to work. To apply a Quaternion to your camera just do this:

public void update(boolean updateFrustum)
    float aspect = camera.viewportWidth / camera.viewportHeight;
    camera.projection.setToProjection(Math.abs(camera.near), Math.abs(camera.far), camera.fieldOfView, aspect);
    camera.view.setToLookAt(camera.position, tmp.set(camera.position).add(camera.direction), camera.up);

    // This is all you need to do!
    // the rotate() method takes in a Quaternion
    // It needs to be after the call to setToLookAt()

    Matrix4.mul(camera.combined.val, camera.view.val);

    if (updateFrustum)

This is exactly the same as the update() method in the PerspectiveCamera class except for the part about adding the rotation quaternion.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .