How to change LookDirection, UpDirection in CompositionTarget.Rendering?

27 views Asked by At

This project performs frame-based animation using WPF’s CompositionTarget.Rendering. During rendering when it wants to change the PerspectiveCamera’s position or vectors it will do something equivalent to this:

CompositionTarget.Rendering += Loop;

private void Loop(object sender, EventArgs e)  
{

       // Change properties on the Camera
       Camera.Position = new(1D, 2D, 3D);   // Point3D
       Camera.LookDirection = new(0D, 0D, 0D); // Vector3D
       Camera.UpDirection = new(0D, 1D, 0D);   // Vector3D
}

Each of these is a Dependency Property on the Camera. The Position immediately takes on the new value. But neither LookDirection nor UpDirection will get the new value. When similar statements are run outside of CompositionTarget.Rendering both LookDirection and UpDirection will get the new value. Any thoughts about how to set LookDirection and UpDirection from inside CompositionTarget.Rendering?

Position changing from CompositionTarget.Rendering works great, the camera's location changes. But LookDirection and UpDirection are not taking the new values. I've reviewed the .Net reference source and nothing is jumping out. In-fact the code paths for setting all three properties is nearly identical.

1

There are 1 answers

0
WoodManEXP On

This has been solved by setting the property in this fashion:

Rather than

Camera.UpDirection = someVector;

code it as

Camera.SetCurrentValue(ProjectionCamera.UpDirectionProperty, someVector);