mrbencowell
mrbencowell

Reputation: 155

WPF 3D camera position

I need to reset my 3D camera position in a WPF 3D viewport. I'm using the trackball decorator from 3Dtools. Hacking around I've found I can clear the camera's transformations using :

Transform3DGroup group = camera.Transform as Transform3DGroup;
group.Children.Clear();

However this breaks the trackball as I'm guessing the camera no longer has a transform matrix. Is there a way I can get the camera back to where I created it, ie: can I manually reposition the camera and have the trackball still work ?

Edit :

I create a perspective camera and add it to a 3D Viewport using the following code :

perspectiveCamera.Position = new Point3D(sceneSize.X * 4 , 
                                         sceneSize.Y , 
                                         sceneSize.Z * (-4));

CameraLookAt = new Point3D(0, (sceneSize.Y / 2), 0);

perspectiveCamera.LookDirection = new Vector3D (
                                  CameraLookAt.X - perspectiveCamera.Position.X, 
                                  CameraLookAt.Y - perspectiveCamera.Position.Y, 
                                  CameraLookAt.Z - perspectiveCamera.Position.Z);
perspectiveCamera.FieldOfView = 24;

Viewport_3D.Camera = perspectiveCamera;

The viewport has a Trackball decorator, which allows the user to rotate the camera around the scene. However I want a function to reset the camera back to it's original position, but I can't find a way to directly set it's position once created.

Upvotes: 0

Views: 4793

Answers (1)

yangtam
yangtam

Reputation: 73

First you should remove the animations use on the camera, you can do it through the method camera.ApplyAnimationClock(ProjectCamera.PositionProperty, null) then assigned the original value to the camera

Upvotes: 0

Related Questions