Example #1
0
        public static Rotator ToRotator(Vector3 local, Vector3 target)
        {
            Vector3 rotation = local - target;

            Rotator newViewAngle = new Rotator();

            float hyp = (float)Math.Sqrt(rotation.X * rotation.X + rotation.Y * rotation.Y);

            newViewAngle.Pitch = (float)(-Math.Atan(rotation.Z / hyp) * (180f / Math.PI));
            newViewAngle.Yaw   = (float)(Math.Atan(rotation.Y / rotation.X) * (180f / Math.PI));
            newViewAngle.Roll  = (float)0f;

            if (rotation.X >= 0f)
            {
                newViewAngle.Yaw += 180.0f;
            }

            return(newViewAngle.Clamp());
        }