SciChart® the market leader in Fast WPF Charts, WPF 3D Charts, iOS Chart, Android Chart and JavaScript Chart Components
SciChart WPF ships with hundreds of WPF Chart Examples which you can browse, play with, view the source-code and even export each WPF Chart Example to a stand-alone Visual Studio solution. All of this is possible with the new and improved SciChart WPF Examples Suite, which ships as part of the SciChart WPF SDK.
Demonstrates the properties of the Camera3D class which allows data-binding to camera position, target, orientation, field of view etc…
The Camera3D is attached to the SciChart3DSurface.Camera property and may be changed from perspective to orthogonal and zoomed to fit the 3D Chart. The Camera3D can also be animated from position to position, and multiple cameras can be enabled on a scene.
Tip!
Click CAM1 and CAM2 on the left to switch between cameras. You can also change camera properties to see how the viewport of the 3D Chart changes.
The C#/WPF source code for the WPF 3D Chart Modify Camera3D Properties Example example is included below (Scroll down!).
Did you know you can also view the source code from one of the following sources as well?
<UserControl x:Class="SciChart.Examples.Examples.Charts3D.ZoomAndPanA3DChart.ModifyCameraProperties"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:s3D="http://schemas.abtsoftware.co.uk/scichart3D"
xmlns:ext="http://schemas.abtsoftware.co.uk/scichart/exampleExternals"
xmlns:s="http://schemas.abtsoftware.co.uk/scichart"
mc:Ignorable="d"
d:DesignHeight="600"
d:DesignWidth="800"
Loaded="ModifyCameraProperties_OnLoaded">
<UserControl.Resources>
<s3D:Vector3StringConverter StringFormat="n1" x:Key="Vector3StringConverter"/>
<!-- These can also be declared in code behind and set on the SciChart3DSurface.Camera property -->
<s3D:Camera3D x:Key="OrthogonalCamera" CameraId="Ortho Camera" OrthoWidth="600" OrthoHeight="400" ZoomToFitOnAttach="True" ProjectionMode="Orthogonal" Target="0,0,0" Position="-1000,0,-1000"/>
<!-- These can also be declared in code behind and set on the SciChart3DSurface.Camera property -->
<s3D:Camera3D x:Key="PerspectiveCamera" CameraId="Perspective Camera" ProjectionMode="Perspective" ZoomToFitOnAttach="True" OrbitalYaw="45" OrbitalPitch="30"/>
</UserControl.Resources>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<!-- The SciChart3DInteractionToolbar adds rotate, orbit, zoom, pan, zoom extents functionality -->
<!-- to the chart and is included for example purposes. -->
<!-- If you wish to know how to zoom and pan a 3D chart then do a search for Zoom Pan in the Examples suite! -->
<ext:SciChart3DInteractionToolbar TargetSurface="{Binding Source={x:Reference Name=sciChart}}">
<ext:FlyoutSeparator Background="#444"/>
<ext:FlyoutMenuToggleButton x:Name="perspAttached" Style="{StaticResource FlyoutMenuToggleButtonStyle}" FontSize="9" Content="CAM1" Padding="0" IsChecked="True" s:ToggleButtonExtensions.GroupName="ModifyCameraGroup" Checked="OnAttachPerspectiveChecked">
<ext:FlyoutMenuToggleButton.PopupContent>
<StackPanel Orientation="Vertical" MinWidth="240">
<TextBlock Text="Camera 1 (Perspective)" FontSize="11"/>
<ext:FlyoutSeparator/>
<TextBlock Text="Position" FontSize="11"/>
<s3D:VectorEditor FontSize="11" Vector="{Binding Source={StaticResource PerspectiveCamera}, Path=Position, Mode=TwoWay}"/>
<TextBlock Text="Target" FontSize="11"/>
<s3D:VectorEditor FontSize="11" Vector="{Binding Source={StaticResource PerspectiveCamera}, Path=Target, Mode=TwoWay}"/>
<TextBlock Text="Pitch" FontSize="11"/>
<Slider Minimum="-90" Maximum="90" Value="{Binding Source={StaticResource PerspectiveCamera}, Path=OrbitalPitch, Mode=TwoWay}"/>
<TextBlock Text="Yaw" FontSize="11"/>
<Slider Minimum="0" Maximum="360" Value="{Binding Source={StaticResource PerspectiveCamera}, Path=OrbitalYaw, Mode=TwoWay}"/>
<TextBlock Text="Radius" FontSize="11"/>
<Slider Minimum="10" Maximum="3000" Value="{Binding Source={StaticResource PerspectiveCamera}, Path=Radius, Mode=TwoWay}"/>
<TextBlock Text="Field Of View" FontSize="11"/>
<Slider Minimum="10" Maximum="90" Value="{Binding Source={StaticResource PerspectiveCamera}, Path=FieldOfView, Mode=TwoWay}"/>
</StackPanel>
</ext:FlyoutMenuToggleButton.PopupContent>
</ext:FlyoutMenuToggleButton>
<ext:FlyoutMenuToggleButton x:Name="orthoAttached" Style="{StaticResource FlyoutMenuToggleButtonStyle}" FontSize="9" Content="CAM2" Padding="0" s:ToggleButtonExtensions.GroupName="ModifyCameraGroup" Checked="OnAttachOrthogonalChecked">
<ext:FlyoutMenuToggleButton.PopupContent>
<StackPanel Orientation="Vertical" MinWidth="240">
<TextBlock Text="Camera 2 (Orthogonal)" FontSize="11"/>
<ext:FlyoutSeparator/>
<TextBlock Text="Position" FontSize="11"/>
<s3D:VectorEditor FontSize="11" Vector="{Binding Source={StaticResource OrthogonalCamera}, Path=Position, Mode=TwoWay}"/>
<TextBlock Text="Target" FontSize="11"/>
<s3D:VectorEditor FontSize="11" Vector="{Binding Source={StaticResource OrthogonalCamera}, Path=Target, Mode=TwoWay}"/>
<TextBlock Text="Pitch" FontSize="11"/>
<Slider Minimum="-90" Maximum="90" Value="{Binding Source={StaticResource OrthogonalCamera}, Path=OrbitalPitch, Mode=TwoWay}"/>
<TextBlock Text="Yaw" FontSize="11"/>
<Slider Minimum="0" Maximum="360" Value="{Binding Source={StaticResource OrthogonalCamera}, Path=OrbitalYaw, Mode=TwoWay}"/>
<TextBlock Text="OrthoWidth" FontSize="11"/>
<Slider Minimum="1" Maximum="1000" Value="{Binding Source={StaticResource OrthogonalCamera}, Path=OrthoWidth, Mode=TwoWay}"/>
<TextBlock Text="OrthoHeight" FontSize="11"/>
<Slider Minimum="1" Maximum="1000" Value="{Binding Source={StaticResource OrthogonalCamera}, Path=OrthoHeight, Mode=TwoWay}"/>
</StackPanel>
</ext:FlyoutMenuToggleButton.PopupContent>
</ext:FlyoutMenuToggleButton>
<ToggleButton Style="{StaticResource DefaultToggleButtonStyle}" Content="LHS" IsChecked="True" FontSize="9" ToolTip="Use the Left Handed Coordinate system (Default)" Checked="OnUseLhsCoordinates" s:ToggleButtonExtensions.GroupName="CoordinateSystemGroup"/>
<ToggleButton Style="{StaticResource DefaultToggleButtonStyle}" Content="RHS" FontSize="9" ToolTip="Use the Right Handed Coordinate system" Checked="OnUseRhsCoordinates" s:ToggleButtonExtensions.GroupName="CoordinateSystemGroup"/>
</ext:SciChart3DInteractionToolbar>
<s3D:SciChart3DSurface x:Name="sciChart" Grid.Column="1" Camera="{StaticResource PerspectiveCamera}">
<s3D:SciChart3DSurface.XAxis>
<s3D:NumericAxis3D/>
</s3D:SciChart3DSurface.XAxis>
<s3D:SciChart3DSurface.YAxis>
<s3D:NumericAxis3D/>
</s3D:SciChart3DSurface.YAxis>
<s3D:SciChart3DSurface.ZAxis>
<s3D:NumericAxis3D/>
</s3D:SciChart3DSurface.ZAxis>
</s3D:SciChart3DSurface>
<Border Background="#555" Grid.Column="1" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="10"
BorderThickness="1" BorderBrush="White" CornerRadius="2" Opacity="0.4"
MinWidth="300">
<Grid TextElement.Foreground="#FFF" >
<Grid.Resources>
<Style TargetType="TextBlock">
<Setter Property="Margin" Value="3,5"/>
</Style>
</Grid.Resources>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock Text="Bound Camera" FontWeight="Bold"/>
<Border Background="#FFF" Height="1" Grid.Row="1" Margin="3,5" Grid.ColumnSpan="2"/>
<TextBlock Text="Position:" Grid.Row="2" FontWeight="Bold"/>
<TextBlock Text="Target:" Grid.Row="3" FontWeight="Bold"/>
<TextBlock Text="Pitch:" Grid.Row="4" FontWeight="Bold"/>
<TextBlock Text="Yaw:" Grid.Row="5" FontWeight="Bold"/>
<TextBlock Text="Radius:" Grid.Row="6" FontWeight="Bold"/>
<TextBlock Text="Projection Mode:" Grid.Row="7" FontWeight="Bold"/>
<TextBlock Text="Field Of View:" Grid.Row="8" FontWeight="Bold"/>
<TextBlock Text="Orthographic:" Grid.Row="9" FontWeight="Bold"/>
<TextBlock Grid.Row="0" Grid.Column="1">
<Run Text="'"/><Run Text="{Binding Source={x:Reference Name=sciChart}, Path=Camera.CameraId, FallbackValue='NA'}"/><Run Text="'"/>
</TextBlock>
<TextBlock Text="{Binding Source={x:Reference Name=sciChart}, Path=Camera.Position, FallbackValue='NA', Converter={StaticResource Vector3StringConverter}}" Grid.Row="2" Grid.Column="1"/>
<TextBlock Text="{Binding Source={x:Reference Name=sciChart}, Path=Camera.Target, FallbackValue='NA', Converter={StaticResource Vector3StringConverter}}" Grid.Row="3" Grid.Column="1"/>
<TextBlock Text="{Binding Source={x:Reference Name=sciChart}, Path=Camera.OrbitalPitch, FallbackValue='NA'}" Grid.Row="4" Grid.Column="1"/>
<TextBlock Text="{Binding Source={x:Reference Name=sciChart}, Path=Camera.OrbitalYaw, FallbackValue='NA'}" Grid.Row="5" Grid.Column="1"/>
<TextBlock Text="{Binding Source={x:Reference Name=sciChart}, Path=Camera.Radius, FallbackValue='NA'}" Grid.Row="6" Grid.Column="1"/>
<TextBlock Text="{Binding Source={x:Reference Name=sciChart}, Path=Camera.ProjectionMode, FallbackValue='NA'}" Grid.Row="7" Grid.Column="1"/>
<TextBlock Text="{Binding Source={x:Reference Name=sciChart}, Path=Camera.FieldOfView, FallbackValue='NA'}" Grid.Row="8" Grid.Column="1"/>
<TextBlock Grid.Row="9" Grid.Column="1">
<Run Text="Width="/>
<Run Text="{Binding Source={x:Reference Name=sciChart}, Path=Camera.OrthoWidth, FallbackValue='NA'}"/>
<Run Text=", Height="/>
<Run Text="{Binding Source={x:Reference Name=sciChart}, Path=Camera.OrthoHeight, FallbackValue='NA'}"/>
</TextBlock>
</Grid>
</Border>
</Grid>
</UserControl>
// *************************************************************************************
// SCICHART® Copyright SciChart Ltd. 2011-2022. All rights reserved.
//
// Web: http://www.scichart.com
// Support: support@scichart.com
// Sales: sales@scichart.com
//
// ModifyCameraProperties.xaml.cs is part of the SCICHART® Examples. Permission is hereby granted
// to modify, create derivative works, distribute and publish any part of this source
// code whether for commercial, private or personal use.
//
// The SCICHART® examples are distributed in the hope that they will be useful, but
// without any warranty. It is provided "AS IS" without warranty of any kind, either
// expressed or implied.
// *************************************************************************************
using System;
using System.Windows;
using System.Windows.Controls;
using SciChart.Charting3D;
namespace SciChart.Examples.Examples.Charts3D.ZoomAndPanA3DChart
{
public partial class ModifyCameraProperties : UserControl
{
public ModifyCameraProperties()
{
InitializeComponent();
}
private void OnAttachOrthogonalChecked(object sender, EventArgs e)
{
if (!IsLoaded) return;
perspAttached.IsChecked = false;
// You can also set these on the scichartsurface entirely in code, creating a new instance of
// Camera3D rather than declaring in XAML
var newCamera = TryFindResource("OrthogonalCamera") as Camera3D;
sciChart.Camera = newCamera;
}
private void OnAttachPerspectiveChecked(object sender, EventArgs e)
{
if (!IsLoaded) return;
orthoAttached.IsChecked = false;
// You can also set these on the scichartsurface entirely in code, creating a new instance of
// Camera3D rather than declaring in XAML
var newCamera = TryFindResource("PerspectiveCamera") as Camera3D;
sciChart.Camera = newCamera;
}
private void ModifyCameraProperties_OnLoaded(object sender, RoutedEventArgs e)
{
OnAttachPerspectiveChecked(null, EventArgs.Empty);
}
private void OnUseLhsCoordinates(object sender, RoutedEventArgs e)
{
if (sciChart != null) sciChart.CoordinateSystem = CoordinateSystem3D.LeftHanded;
}
private void OnUseRhsCoordinates(object sender, RoutedEventArgs e)
{
if (sciChart != null) sciChart.CoordinateSystem = CoordinateSystem3D.RightHanded;
}
}
}