简体   繁体   English

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

[英]Display 3D model's coordinates (position)

I have a 3D model in C# wpf that rotates 360degrees rotating 5degrees each time using timespan. 我在C#wpf中有一个3D模型,每次使用时间跨度旋转360度,每次旋转5度。 But I want to be able to view its coordinates like viewing the point3DX, point3DY, point3DZ on my window form. 但我希望能够像在窗口窗体上查看point3DX,point3DY,point3DZ一样查看其坐标。

Any ideas how can I do that? 有什么想法我该怎么做?

Here are the functions where I set the initial position and the rotation of the model 这是我设置模型的初始位置和旋转角度的功能

 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);
    }

And this is where they are called 这就是所谓的

   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();


    }

For example according to my project, I want this part of my code: 例如,根据我的项目,我需要代码的这一部分:

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);

... to be displayed on my window form like: ...显示在我的窗口表单中,例如:

Camera Position: (-50.00, 10.00, 0.00) Camera LookAt: (1.00, 0.00, 0.00) Camera LookUp: (0.00, 0.00, 1.00) 摄像头位置:(-50.00,10.00,0.00)摄像头外观:(1.00,0.00,0.00)摄像头外观:(0.00,0.00,1.00)

And every time the camera will rotate 5degrees, the changed values will be displayed on the window form 摄像机每旋转5度,更改的值就会显示在窗口窗体上

(See update below in response to you clarifying your question a bit more :) ) (请参见下面的更新,以进一步澄清您的问题:))

Originally you said you wanted to know the coordinates of your 3d model. 最初,您说过您想知道3D模型的坐标。

I have a 3D model in C# wpf that rotates 360degrees rotating 5degrees each time using timespan. 我在C#wpf中有一个3D模型,每次使用时间跨度旋转360度,每次旋转5度。 But I want to be able to view its coordinates like viewing the point3DX, point3DY, point3DZ on my window form. 但我希望能够像在窗口窗体上查看point3DX,point3DY,point3DZ一样查看其坐标。

However in a comment you clarified it was actually the camera location you were interested in. 但是,在注释中,您澄清了它实际上是您感兴趣的摄像机位置。

... what I want is to ... view the coordinates or position of the camera each time it moves, I want the coordinates to be displayed on my window form. ...我想要的是...每次移动时查看摄像机的坐标或位置,我希望坐标显示在窗口窗体上。

Assuming the comment is your real question (How do I get and show the 3d position of my camera), here is my solution: 假设评论是您的真正问题(如何获取并显示相机的3d位置),这是我的解决方案:

gCamWC is a Matrix3D . gCamWCMatrix3D I know this because: 我知道这是因为:

gCamWC = myRotationTransform.Value;

..and since myRotationTransform is a RotateTransform3d, its value is a Matrix3D ( documentation ). ..并且myRotationTransform是RotateTransform3d,因此其值是Matrix3D( 文档 )。

I am unfamiliar with Matrix3D's, but a quick MSDN search suggests you could just create a label (I'll call this posLabel) and in the RotatingModelAround method after you append gCamWC do this: 我不熟悉Matrix3D,但快速的MSDN搜索建议您可以创建一个标签(我将其称为posLabel),并在附加gCamWC之后在RotatingModelAround方法中执行以下操作:

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

If it works, this should make the label say something like this (for an example of a vector of 3.0, 6.7, 8.9): 如果可行,这应该使标签说出这样的内容(例如,矢量为3.0、6.7、8.9):

3.0 6.7 8.9 3.0 6.7 8.9

**(sorry SO formatting doesn't let me do tab spaces but there would be a tab between each of those values)* **(抱歉,SO格式不允许我使用制表符空格,但是每个值之间都会有一个制表符)*

And it should update every time it rotates. 并且它应该在每次旋转时更新。

EDIT: You say you want a label like this: 编辑:您说您想要这样的标签:

Camera Position: (-50.00, 10.00, 0.00) Camera LookAt: (1.00, 0.00, 0.00) Camera LookUp: (0.00, 0.00, 1.00) 摄像头位置:(-50.00,10.00,0.00)摄像头外观:(1.00,0.00,0.00)摄像头外观:(0.00,0.00,1.00)

Try creating a label called posLabel and then add the following code after you finish appending gCamWC in the RotatingModelAround() method: 尝试创建一个名为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 + ")";

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

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