View Full Version : camera system object centric

08-01-2011, 06:41 AM
I have this function in webgl for a camera system:

function handleMouseMove(event) {

if (!mouseDown) {
var newX = event.clientX;
var newY = event.clientY;

var deltaX = newX - lastMouseX
var newRotationMatrix = mat4.create();
mat4.rotate(newRotationMatrix, degToRad(deltaX / 10), [0, 1, 0]);

var deltaY = newY - lastMouseY;
mat4.rotate(newRotationMatrix, degToRad(deltaY / 10), [1, 0, 0]);

mat4.multiply(newRotationMatrix, RotationMatrix, RotationMatrix);

lastMouseX = newX
lastMouseY = newY;

the problem is that this camera system is not object centered.
I wish, when rotate , rotates the object around its axis and for the traslation go ahead and back.
I already done for traslation and mouse weel, but i don't know how do for the rotation of the camera around object.
How i can find the object axis? i have a bounding sphere, and his center.