# Rotating a camera around an Object

Hi all,

I’m working on a PhysX project with GLUT and I’m attempting to have a camera rotate around an object, steered by the mouse.

My first step was to port over the C# code found here:
http://wiki.unity3d.com/index.php/MouseOrbitImproved

This is for Unity but allowed exactly what I required (except the raycasts, I’ve omitted those)

This works to some degree - the camera rotates around the object, however it fails to look at the object.

``````void Camera::UpdateCamera(float mouseX, float mouseY) {
x += mouseX * xMoveSpeed * distance * 0.02f;
y -= mouseY * yMoveSpeed * 0.02f;

y = ClampAngle(y, yMinLimit, yMaxLimit);

PxQuat rot = PxQuat::Euler(PxVec3(y, x, 0));

distance = PxClamp(distance, distanceMin, distanceMax);

PxVec3 negDist = PxVec3(0.0f, 0.0f, -distance);
PxVec3 pos = rot.rotate(negDist) + target->getGlobalPose().p;

eye = pos;
dir = PxVec3(y, x, 0);
}

float Camera::ClampAngle(float angle, float min, float max) {
if (angle < -360.0f)
angle += 360.0f;
if (angle > 360.0f)
angle -= 360.0f;

return PxClamp(angle, min, max);
}
``````

(PxQuat::Euler is just a custom function I added to create a Quat from a Vec3)

Does anyone have an idea what is going wrong here? The camera always faces directly downwards.