Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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...

share|improve this question
    
What have you tried so far? –  MrKWatkins Dec 14 '12 at 16:43
    
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. –  DiscGolfer Dec 14 '12 at 17:44
    
I can post some code in a few hours when I get out of work, if you would like to see that too. –  DiscGolfer Dec 14 '12 at 17:45
add comment

1 Answer

up vote 0 down vote accepted

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()
    camera.view.rotate(rotation);

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

    if (updateFrustum)
    {
        camera.invProjectionView.set(camera.combined);
        Matrix4.inv(camera.invProjectionView.val);
        camera.frustum.update(camera.invProjectionView);
    }
}

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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