简体   繁体   English

WPF 3D相机位置

[英]WPF 3D camera position

I need to reset my 3D camera position in a WPF 3D viewport. 我需要在WPF 3D视口中重置3D相机位置。 I'm using the trackball decorator from 3Dtools. 我正在使用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 : 我创建一个透视相机,并使用以下代码将其添加到3D视口中:

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. 但是我希望有一个功能可以将相机重设回其原始位置,但是我找不到找到一种方法来直接设置它的位置。

首先,您应该删除相机上使用的动画,可以通过方法camera.ApplyAnimationClock(ProjectCamera.PositionProperty,null)进行操作,然后将原始值分配给相机

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM