【问题标题】:Display 3D model's coordinates (position)显示 3D 模型的坐标(位置)
【发布时间】:2015-10-28 20:11:36
【问题描述】:

我在 C# wpf 中有一个 3D 模型,它使用时间跨度旋转 360 度,每次旋转 5 度。但我希望能够查看它的坐标,就像在我的窗口窗体上查看 point3DX、point3DY、point3DZ 一样。

任何想法我该怎么做?

这是我设置模型初始位置和旋转的函数

 private void SetViewPosition()
    {
        Vector3D vAxis = new Vector3D(0, 0, 1);
        ///<summary>
        ///R = AxisAngleRotation()
        ///vAxis = Vector length
        ///-15 = Angle
        ///</summary>
        AxisAngleRotation3D myRotation = new AxisAngleRotation3D(vAxis, -15);
        RotateTransform3D myRotationTransform = new RotateTransform3D(myRotation);
        gCamWC = myRotationTransform.Value;
        gCamWC.M14 = -50;
        gCamWC.M24 = 10;
        gCamWC.M34 = 0;

        Point3D camPosition = new Point3D(gCamWC.M14, gCamWC.M24, gCamWC.M34);
        Vector3D startLookAt = new Vector3D(gCamWC.M11, gCamWC.M21, gCamWC.M31);//VLook = 1st Column//DT=[1,0,0]//Vertical
        Vector3D startLookUp = new Vector3D(gCamWC.M13, gCamWC.M23, gCamWC.M33);//VUp = 2nd Column//DT = [0,0,1]//Vertical


        DrawingControl.Viewport.SetView(camPosition, startLookAt, startLookUp, 0);//=DR -> How the camera should move

    }

    //STEP 4
   private void RotatingModelAround(object sender, EventArgs e)
    {
        Vector3D vAxis = new Vector3D(gCamWC.M31, gCamWC.M32, gCamWC.M33);  //Rotate about world z-axis.
        AxisAngleRotation3D myRotation = new AxisAngleRotation3D(vAxis, 5);
        RotateTransform3D myRotationTransform = new RotateTransform3D(myRotation);

        Matrix3D doTranslation = new Matrix3D();
        doTranslation.M24 = 3;  // Offset along camera y-axis.  Presumed to be parallel to world plane.


        gCamWC.Append(myRotationTransform.Value);
        gCamWC.Append(doTranslation);

        Point3D camPosition = new Point3D(gCamWC.M14, gCamWC.M24, gCamWC.M34);
        Vector3D camLookAt = new Vector3D(gCamWC.M11, gCamWC.M21, gCamWC.M31);
        Vector3D camLookUp = new Vector3D(gCamWC.M13, gCamWC.M23, gCamWC.M33);

        DrawingControl.Viewport.SetView(camPosition, camLookAt, camLookUp, 0);
    }

这就是他们的名字

   public XplorerMainWindow()
    {
        InitializeComponent();
        Closed += XplorerMainWindow_Closed;
        //STEP 1
        Loaded += XplorerMainWindow_Loaded;

        Closing += XplorerMainWindow_Closing;
        DrawingControl.UserModeledDimensionChangedEvent += DrawingControl_MeasureChangedEvent;
        InitFromSettings();

        RefreshRecentFiles();

        UserFilters = new FilterValues();//COBie Class filters, set to initial defaults
        CoBieTemplate = UkTemplate;


        if (Settings.Default.PluginStartupLoad)
            RefreshPlugins();




        //STEP 4
       // Add Dispatcer Time so the Rotation will be repeated
        System.Windows.Threading.DispatcherTimer dispatcherTimer = new System.Windows.Threading.DispatcherTimer();
        dispatcherTimer.Tick += RotatingModelAround;
        //dispatcherTimer.Tick += QRotateModel;
        dispatcherTimer.Interval = new TimeSpan(0, 0, 0, 0,300);//(d,h,m,s,mil.s.)
        dispatcherTimer.Start();


    }

例如根据我的项目,我想要这部分代码:

Point3D camPosition = new Point3D(gCamWC.M14, gCamWC.M24, gCamWC.M34);
        Vector3D camLookAt = new Vector3D(gCamWC.M11, gCamWC.M21, gCamWC.M31);
        Vector3D camLookUp = new Vector3D(gCamWC.M13, gCamWC.M23, gCamWC.M33);

...要显示在我的窗口窗体上,例如:

相机位置:(-50.00, 10.00, 0.00) 相机注视:(1.00, 0.00, 0.00) 相机查找:(0.00, 0.00, 1.00)

并且相机每旋转5度,改变的值就会显示在窗体上

【问题讨论】:

  • 代码?如果您向我们展示您用于旋转和渲染的内容,我们可以更轻松地根据您的需求定制解决方案。你还试过什么?
  • 我的代码很大,但我只会添加添加位置和旋转的功能。我没有尝试任何东西,因为我找不到任何示例
  • 好吧,不知道你是如何渲染模型的,很难说你是如​​何获得这些值的。你能说你是否使用特定的库、工具包或类或其他东西吗?还有相关链接:stackoverflow.com/questions/3127753/displaying-3d-models-in-wpf
  • @MaxvonHippel 我确实旋转了模型,但我想要的是在我的函数中添加一个断点并在每次移动时查看相机的坐标或位置,我希望坐标显示在我的窗体。
  • 如果我在下面的回答不起作用,您能否评论一下尝试时会发生什么(或没有发生)?

标签: c# wpf coordinates 3d-model


【解决方案1】:

(请参阅下面的更新以回应您进一步澄清您的问题:))

最初你说你想知道你的 3d 模型的坐标。

我在 C# wpf 中有一个 3D 模型,可以旋转 360 度旋转 5 度 每次使用时间跨度。但我希望能够查看它 坐标,例如在我的窗口上查看 point3DX、point3DY、point3DZ 表格。

但是,您在评论中澄清说,这实际上是您感兴趣的相机位置。

...我想要的是...查看坐标或位置 相机每次移动时,我都希望显示坐标 我的窗体。

假设评论是您真正的问题(如何获取并显示相机的 3d 位置),这是我的解决方案:

gCamWCMatrix3D。我知道这是因为:

gCamWC = myRotationTransform.Value;

..由于 myRotationTransform 是一个 RotateTransform3d,它的值是一个 Matrix3D (documentation)。

我不熟悉 Matrix3D,但快速 MSDN 搜索表明您可以创建一个标签(我将称之为 posLabel)并在附加 gCamWC 后的 RotatingModelAround 方法中执行以下操作:

posLabel.Text = "{0}\t{1}\t{2}", gCamWC.offsetX, gCamWC.offsetY, gCamWC.offsetZ;

如果可行,这应该使标签显示如下内容(以 3.0、6.7、8.9 的向量为例):

3.0 6.7 8.9

**(抱歉,格式不允许我使用制表符空格,但每个值之间都会有一个制表符)*

它应该在每次旋转时更新。

编辑: 你说你想要这样的标签:

摄像机位置:(-50.00, 10.00, 0.00) 摄像机注视点:(1.00, 0.00, 0.00) 相机查找:(0.00, 0.00, 1.00)

尝试创建一个名为 posLabel 的标签,然后在 RotatingModelAround() 方法中完成附加 gCamWC 后添加以下代码:

posLabel.Text = "Camera Position: (" + gCamWC.M14 + ", " + gCamWC.M24 + ", " + gCamWC.M34 + ") Camera LookAt: (" + gCamWC.M11 + ", " + gCamWC.M21 + ", " + gCamWC.M31 + ") Camera LookUp: (" + gCamWC.M13 + ", " + gCamWC.M23 + ", " + gCamWC.M33 + ")";

【讨论】:

  • 效果很好。非常感谢,对于模型位置和相机位置的混淆,我很抱歉,只是有时我忘记了我在相机上而不是在模型上工作,因为它看起来像你移动模型而不是移动模型相机:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-04-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-05-20
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多