Rotate my camera


06-05-2007 15:42:11

I am writing some code to get the effect of rotating the camera around a object, but I didnt found any build-in methods to use, so I tried it like this:
Vector3 posTarget = target.Position;
Vector3 posCamera = camera.Position;
Vector3 dir = posCamera - posTarget;
dir.y = 0;
Radian ang = Mogre.Math.ACos(dir.NormalisedCopy.DotProduct(Vector3.UNIT_X));
ang += new Radian(delta) / 180;
posCamera.x = dir.Length * Mogre.Math.Cos(ang) + posTarget.x;
posCamera.z = dir.Length * Mogre.Math.Sin(ang) + posTarget.z;
camera.Position = posCamera;

however, when the camera rotate to the position along x axis, it got stuck.
would anyone help me?


22-05-2007 14:14:00

Set the camera as a child of the object you want the camera to rotate around. Translate the camera a certain distance from the object and set the cameras LookAt to the object position.