How do I apply an arcball (using quaternions) along with mouse events, to allow the user to look around the screen using the o3d webgl framework?

Posted by Chris on Game Development See other posts from Game Development or by Chris
Published on 2011-01-10T15:23:30Z Indexed on 2011/01/10 16:00 UTC
Read the original article Hit count: 167

Filed under:
|
|
|

How do I apply an arcball (using quaternions) along with mouse events, to allow the user to look around the screen using the o3d webgl framework?

This sample (http://code.google.com/p/o3d/source/browse/trunk/samples_webgl/o3d-webgl-samples/simpleviewer/simpleviewer.html?r=215) uses the arcball for rotating the transform of an "object", but rather than apply this to a transform, I would like to apply the rotation to the camera's target, to create a first person style ability to look around the scene, as if the camera is inside the centre of the arcball instead of rotating from the outside.

The code that is used in this sample is

var rotationQuat = g_aball.drag([e.x, e.y]);
var rot_mat = g_quaternions.quaternionToRotation(rotationQuat);
g_thisRot = g_math.matrix4.mul(g_lastRot, rot_mat);

The code that I am using which doesn't work

var rotationQuat = g_aball.drag([e.x, e.y]);
var rot_mat = g_quaternions.quaternionToRotation(rotationQuat);
g_thisRot = g_math.matrix4.mul(g_lastRot, rot_mat);

var cameraRotationMatrix4 = g_math.matrix4.lookAt(g_eye, g_target, [g_up[0], g_up[1] * -1, g_up[2]]);
var cameraRotation = g_math.matrix4.setUpper3x3(cameraRotationMatrix4,g_thisRot);
g_target = g_math.addVector(cameraRotation, g_target);

where am I going wrong?

Thanks

© Game Development or respective owner

Related posts about 3d

Related posts about JavaScript