RadCartesianChart3D cannot set initial camera position

1 Answer 19 Views
Chart
Paul
Top achievements
Rank 2
Iron
Iron
Iron
Paul asked on 14 Mar 2024, 11:45 AM


if (mainChart.Camera is ProjectionCamera)
{
    ProjectionCamera projectionCamera = (ProjectionCamera)mainChart.Camera;

    Point3D point3D = projectionCamera.Position;
    point3D.X = 714;
    point3D.Y = -1852;
    point3D.Z = 1255;
    projectionCamera.Position = point3D;

    Vector3D vector3D = projectionCamera.LookDirection;
    vector3D.X = -114;
    vector3D.Y = 1952;
    vector3D.Z = -665;
    projectionCamera.LookDirection = vector3D;

}

I have the above code to try to set the initial camera position via the Loaded event but it does not work.
If I use the code on a keydown event it moves the camera to the position that I want.

What am I missing to make it set the initial camera position?

1 Answer, 1 is accepted

Sort by
0
Accepted
Martin Ivanov
Telerik team
answered on 15 Mar 2024, 08:09 AM

Hello Paul,

This will work if you don't have Chart3DCameraBehavior. Otherwise, you should update the camera a bit after the Loaded event is invoked. You can do that using the Dispatcher.BeginInvoke method.

private void RadCartesianChart3D_Loaded(object sender, RoutedEventArgs e)
{
    Dispatcher.BeginInvoke(new Action(() =>
    {
        ProjectionCamera projectionCamera = (ProjectionCamera)mainChart.Camera;

        Point3D point3D = projectionCamera.Position;
        point3D.X = 714;
        point3D.Y = -1852;
        point3D.Z = 1255;
        projectionCamera.Position = point3D;

        Vector3D vector3D = projectionCamera.LookDirection;
        vector3D.X = -114;
        vector3D.Y = 1952;
        vector3D.Z = -665;
        projectionCamera.LookDirection = vector3D;
    }));
}

However, if you use the Chart3DCameraBehavior, then you can consider using its properties (FirstAngle, SecondAngle, Distance and FieldOfView) instead of the Camera's properties.

Regards,
Martin Ivanov
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Paul
Top achievements
Rank 2
Iron
Iron
Iron
commented on 15 Mar 2024, 11:07 AM

Thank you, using the Chart3DCameraBehavior works best for me.
Tags
Chart
Asked by
Paul
Top achievements
Rank 2
Iron
Iron
Iron
Answers by
Martin Ivanov
Telerik team
Share this question
or