我在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度时,更改的值将显示在窗口
上答案 0 :(得分:2)
(请参阅下面的更新以回应您更多地澄清您的问题:))
最初你说你想知道你的3D模型的坐标。
我在C#wpf中有一个3D模型,旋转360度旋转5度 每次使用时间跨度。但我希望能够查看它 像在我的窗口上查看point3DX,point3DY,point3DZ一样坐标 形式。
然而,在评论中,您澄清说它实际上是您感兴趣的相机位置。
......我想要的是...查看坐标或位置 相机每次移动时,我都希望显示坐标 我的窗口形式。
假设评论是您真正的问题(如何获取并显示我相机的3D位置),这是我的解决方案:
gCamWC 是Matrix3D。我知道这是因为:
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 + ")";