Apply Quaternion to Camera in libGDX
Posted
by
Alex_Hyzer_Kenoyer
on Stack Overflow
See other posts from Stack Overflow
or by Alex_Hyzer_Kenoyer
Published on 2012-12-15T20:41:12Z
Indexed on
2012/12/17
11:03 UTC
Read the original article
Hit count: 278
I am trying to rotate my camera using a Quaternion
in libGDX. I have a Quaternion
created and being manipulated but I have no idea how to apply it to the camera, everything I've tried hasn't moved the camera at all.
Here is how I set up the rotation Quaternion
:
public void rotateX(float amount) {
tempQuat.set(tempVector.set(1.0f, 0.0f, 0.0f), amount * MathHelper.PIOVER180);
rotation = rotation.mul(tempQuat);
}
public void rotateY(float amount) {
tempQuat.set(tempVector.set(0.0f, 1.0f, 0.0f), amount * MathHelper.PIOVER180);
rotation = tempQuat.mul(rotation);
}
Here is how I am trying to update the camera (Same update method as the original libGDX version but I added the part about the rotation matrix to the top):
public void update(boolean updateFrustum) {
float[] matrix = new float[16];
rotation.toMatrix(matrix);
Matrix4 m = new Matrix4();
m.set(matrix);
camera.view.mul(m);
//camera.direction.mul(m).nor();
//camera.up.mul(m).nor();
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, tempVector.set(camera.position).add(camera.direction), camera.up);
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);
}
}
© Stack Overflow or respective owner