C# 显示三维模型';s坐标(位置)
我有一个C#wpf的3D模型,它可以旋转360度,每次使用timespan旋转5度。但是我希望能够查看它的坐标,就像在我的窗体上查看point3DX,point3DY,point3DZ一样 你知道我该怎么做吗 以下是我设置初始位置和模型旋转的函数C# 显示三维模型';s坐标(位置),c#,wpf,coordinates,3d-model,C#,Wpf,Coordinates,3d Model,我有一个C#wpf的3D模型,它可以旋转360度,每次使用timespan旋转5度。但是我希望能够查看它的坐标,就像在我的窗体上查看point3DX,point3DY,point3DZ一样 你知道我该怎么做吗 以下是我设置初始位置和模型旋转的函数 private void SetViewPosition() { Vector3D vAxis = new Vector3D(0, 0, 1); ///<summary> ///R
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);
}
例如,根据我的项目,我希望代码的这一部分:
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模型的坐标
我有一个C#wpf的3D模型,旋转360度,旋转5度
每次都使用timespan。但我希望能够查看它的
在我的窗口上查看点3DX、点3DY、点3DZ等坐标
形式
然而,在一篇评论中,你澄清了这实际上是你感兴趣的相机位置
。。。我想要的是。。。查看设备的坐标或位置
摄影机每次移动时,我都希望坐标显示在屏幕上
我的窗体
假设评论是您真正的问题(如何获取并显示相机的3d位置),下面是我的解决方案:
gCamWC是一个新的组织。我知道这一点是因为:
gCamWC = myRotationTransform.Value;
…由于myRotationTransform是RotateTransform3d,所以它的值是Matrix3D()
我不熟悉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后添加以下代码:
密码?如果您向我们展示旋转和渲染所使用的内容,我们可以更轻松地根据您的需要定制解决方案。你也试过什么?我的代码很大,但我只会添加我添加位置和旋转的函数。我没有尝试过任何东西,因为我找不到任何示例Swall,而不知道如何渲染模型。很难说如何获得值。你能说你是否在使用一个特定的库、工具包、类或其他东西吗?还有相关链接:@MaxvonHippel我确实旋转了模型,但我想要的是在我的函数中添加一个断点,并在每次摄像机移动时查看摄像机的坐标或位置,我希望坐标显示在我的窗口窗体上。如果我下面的回答不起作用,你能评论一下发生了什么(或没有发生什么)当你尝试它的时候?它工作得很好。非常感谢,对于模型位置和相机位置的混淆感到抱歉,只是有时候我忘记了我在相机上工作,而不是在模型上工作,因为这使它看起来像是你在移动模型而不是相机:)
posLabel.Text = "{0}\t{1}\t{2}", gCamWC.offsetX, gCamWC.offsetY, gCamWC.offsetZ;
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 + ")";