camera system object centric

Started by
2 comments, last by kauna 12 years, 8 months ago
hello.
I have this function in webgl for a camera system:

function handleMouseMove(event) {

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

var deltaX = newX - lastMouseX
var newRotationMatrix = mat4.create();
mat4.identity(newRotationMatrix);
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.
thanks.
Advertisement
You could use the object's world transformation to find out the axis you'll wish to rotate around.

You should find a function called LookAt to generate a view matrix from desired location to the center of your object. Now, only thing you'll need to do is to rotate the camera location around the axis you get from the world matrix.

Possibly, there might even be a function for that.

Cheers!

You could use the object's world transformation to find out the axis you'll wish to rotate around.

You should find a function called LookAt to generate a view matrix from desired location to the center of your object. Now, only thing you'll need to do is to rotate the camera location around the axis you get from the world matrix.

Possibly, there might even be a function for that.

Cheers!


thanks, but how i can find the object axis?

[quote name='kauna' timestamp='1312205794' post='4843112']
You could use the object's world transformation to find out the axis you'll wish to rotate around.

You should find a function called LookAt to generate a view matrix from desired location to the center of your object. Now, only thing you'll need to do is to rotate the camera location around the axis you get from the world matrix.

Possibly, there might even be a function for that.

Cheers!


thanks, but how i can find the object axis?
[/quote]

Well, you should look in to the world transform matrix of the object, which practically contains 3 vectors describing the XYZ-axises of rotation.

Does it matter that you camera rotates around the object's axis or do you just want your camera to rotate around the object regardless of the object axis?

Cheers!


This topic is closed to new replies.

Advertisement