C# Method to Set WPF PerspectiveCamera Target
Here's a method for Windows Presentation Foundation developers wanting to parse some text into a target location for a Camera, such as a PerspectiveCamera:
public static void SetCameraTarget(string Target, Camera Camera) { double[] TargetPoint = Array.ConvertAll(Target.Split(char.Parse(" ")), new Converter(DoubleStringConverter)); PerspectiveCamera MyCamera = (PerspectiveCamera)Camera; Vector3D v1 = new Vector3D(MyCamera.Position.X, MyCamera.Position.Y, MyCamera.Position.Z); Vector3D v2 = new Vector3D(TargetPoint[0], TargetPoint[1], TargetPoint[2]); Vector3D NewVector = v2 - v1; MyCamera.LookDirection = NewVector; System.Diagnostics.Debug.WriteLine(NewVector); }
Just pass a space-delimited string value into it with 3 double values such as: "2 5 3" and a reference to the camera object you want to update.