SciChart WPF 3D Charts > SciChart3D Basics > The SciChart3DSurface Camera
The SciChart3DSurface Camera

The property SciChart3DSurface.Camera defines an ICameraController instance. Derived types are CameraController (a plain CLR object, which implements INotifyPropertyChanged) and Camera3D (a FrameworkElement with DependencyProperties).

By default, the SciChart3DSurface.Camera is set to a new CameraController instance. This defines the Position, Target (in world coordinates) of the camera, and whether the camera is in Perspective or Orthogonal projection modes.

Above: the representation of a Camera in 3D Space. The camera is attached to the SciChart3DSurface.Camera property and is defined by a Position, Target, plus other properties which define the properties of the viewport.

Camera Position, Target

The camera is defined by a PositionTarget which are XYZ vectors in World Coordinates.

Other properties which define the viewport as seen by the camera include:

 

The WPF Chart Example Modify Camera3D Properties shows how to manipulate the camera, and how to switch between perspective and orthogonal modes.

 

 

NOTE: SciChart3D supports unlimited, multiple cameras with different properties but only one can be attached to the ScIChart3DSurface.Camera property at any one time.

 

Controlling the Camera in code-behind

In code-behind 3D applications, there are two options for controlling the camera: using the default CameraController instance or creating a custom Camera3D instance.

By default, the CameraController instance is automatically created with the SciChart3DSurface and provides a range of properties for controlling the camera. You can obtain this instance using the SciChart3DSurface.Camera or Viewport3D.CameraController properties.

Controlling the Camera using the ICameraController instance
Copy Code
var sciChart3DSurface = new SciChart3DSurface();
var cameraController = sciChart3DSurface.Camera;
cameraController.Position = new Vector3(450, 300, -450);
cameraController.Target = new Vector3(-15, 50, 15);
// ...

Alternatively, you can create a custom Camera3D instance, assign it to the SciChart3DSurface.Camera property, and control the camera through that instance. This gives you full control over the camera and is particularly beneficial for advanced use cases or when implementing custom camera interactions.

Controlling the Camera using a custom Camera3D instance
Copy Code
var sciChart3DSurface = new SciChart3DSurface();
var camera3D = new Camera3D();
sciChart3DSurface.Camera = camera3D;
camera3D.Position = new Vector3(450, 300, -450);
camera3D.Target = new Vector3(-15, 50, 15);
// ...

Controlling the Camera in view-model (MVVM)

In MVVM-based 3D applications, the camera can be controlled directly from the ViewModel by defining a custom Camera3D instance in XAML and configuring appropriate data bindings. You need to bind the Camera3D’s dependency properties – such as Position, Target, etc. – to corresponding properties in the view-model. The ViewModel must implement the INotifyPropertyChanged interface to ensure that updates propagate correctly to the Camera3D instance.

Creating a custom Camera3D instance in XAML
Copy Code
<!—- DataContext must be set to an instance of YourChart3DViewModel -->
<s3D:SciChart3DSurface>
    <s3D:SciChart3DSurface.Camera>
        <s3D:Camera3D Position="{Binding Position}"
                      Target="{Binding Target}"/>
    </s3D:SciChart3DSurface.Camera>
</s3D:SciChart3DSurface>
Controlling the Camera using view-model properties
Copy Code
public class YourChart3DViewModel : INotifyPropertyChanged
{
    private Vector3 _position;
    private Vector3 _target;
    public Vector3 Position
    {
        get => _position;
        set
        {
            _position = value;
            RaisePropertyChanged(nameof(Position));
        }
    }
    public Vector3 Target
    {
        get => _target;
        set
        {
            _target = value;
            RaisePropertyChanged(nameof(Target));
        }
    }
    public YourChart3DViewModel()
    {
        Position = new Vector3(350, 200, -350);
        Target = new Vector3(-10, 40, 10);
    }
    // ...
    public event PropertyChangedEventHandler PropertyChanged;
    private void RaisePropertyChanged(string propertyName)
    {
        var handler = PropertyChanged;
        handler?.Invoke(this, new PropertyChangedEventArgs(propertyName));          
    }
}
Controlling the Camera using view-model properties
Copy Code
var viewModel = new YourChart3DViewModel();
viewModel.Position = new Vector3(450, 300, -450);
viewModel.Target = new Vector3(-15, 50, 15);
// ...

See Also