Mars
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:
however, when the camera rotate to the position along x axis, it got stuck.
would anyone help me?
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;
camera.LookAt(posTarget);
however, when the camera rotate to the position along x axis, it got stuck.
would anyone help me?