显示3D模型的坐标(位置)

本文关键字:位置 坐标 3D 模型 显示 | 更新日期: 2023-09-27 18:06:30

我在c# wpf中有一个3D模型,每次使用时间跨度旋转360度旋转5度。但我希望能看到它的坐标就像在窗口窗体上看到点3dx点3dy点3dz一样。

我该怎么做呢?

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

 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度,改变的值将显示在窗体

显示3D模型的坐标(位置)

(请参阅下文更新,以回应您澄清您的问题:))

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

我有一个3D模型在c# wpf旋转360度旋转5度每次使用时间跨度。但是我想要能够看到它坐标,如查看point3DX, point3DY, point3DZ在我的窗口形式。

然而,在评论中你澄清了这实际上是你感兴趣的相机位置。

…我想要的是……的坐标或位置相机每次移动时,我希望坐标显示在我的窗口窗体。

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

gCamWC是Matrix3D。我知道这是因为:

gCamWC = myRotationTransform.Value;

. .因为myRotationTransform是一个RotateTransform3d,它的值是一个Matrix3D (documentation)。

我不熟悉Matrix3D的,但一个快速的MSDN搜索建议你可以只是创建一个标签(我将称之为posLabel),并在RotatingModelAround方法中添加gCamWC后这样做:

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

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

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

编辑:

你说你想要一个这样的标签:

摄像机位置:(-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 + ")";