View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# camera system object centric

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

3 replies to this topic

### #1giugio  Members

Posted 01 August 2011 - 06:40 AM

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.

### #2kauna  Members

Posted 01 August 2011 - 07:36 AM

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!

### #3giugio  Members

Posted 01 August 2011 - 08:17 AM

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?

### #4kauna  Members

Posted 02 August 2011 - 01:13 AM

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?

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!

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.