Sign in to follow this  
giugio

camera system object centric

Recommended Posts

giugio    246
hello.
I have this function in webgl for a camera system:
[code]
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;
}
[/code]
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.

Share this post


Link to post
Share on other sites
kauna    2922
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!

Share this post


Link to post
Share on other sites
giugio    246
[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!
[/quote]

thanks, but how i can find the object axis?

Share this post


Link to post
Share on other sites
kauna    2922
[quote name='giugio' timestamp='1312208252' post='4843122']
[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!
[/quote]

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!


Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this