【发布时间】:2010-07-23 10:50:29
【问题描述】:
我目前正在尝试围绕 WPF 进行研究,并且正处于使用 Matrix3D 结构在坐标空间之间进行转换的阶段。
在意识到 WPF 在 Point3D 和 Vector3D 之间存在差异(那两个小时我永远不会回来......)之后,我可以设置一个平移矩阵。我现在正在尝试引入一个旋转矩阵,但它似乎给出了不准确的结果。这是我的世界坐标转换代码...
private Point3D toWorldCoords(int x, int y)
{
Point3D inM = new Point3D(x, y, 0);
//setup matrix for screen to world
Screen2World = Matrix3D.Identity;
Screen2World.Translate(new Vector3D(-200, -200, 0));
Screen2World.Rotate(new Quaternion(new Vector3D(0, 0, 1), 90));
//do the multiplication
Point3D outM = Point3D.Multiply(inM, Screen2World);
//return the transformed point
return new Point3D(outM.X, outM.Y, m_ZVal);
}
翻译似乎工作正常,但旋转 90 度似乎返回浮点不准确。矩阵的 Offset 行似乎偏离了一个微小的因子(无论哪种方式都是 0.000001),这会在渲染上产生锯齿。我在这里遗漏了什么,还是我只需要手动将矩阵向上取整?
干杯
【问题讨论】:
标签: c# wpf matrix rotation transformation