如何更改 3D WPF 对象的中心
我正在努力寻找在 WPF 中更改 3D 对象 (Model3DGroup) 中心点的最佳方法。
我已经从 SketchUp 导出了一个模型,一切都很好,但中心偏离了位置,导致我在旋转对象时遇到麻烦。 现在我需要围绕每个对象自己的中心进行一些旋转,但不知道如何做到这一点......
任何建议将不胜感激。
感谢
使用 Jackson Pope 的建议,我使用下面的代码来获取对象的中心点:
var bounds = this.My3DObject.Bounds;
var x = bounds.X + (bounds.SizeX / 2);
var y = bounds.Y + (bounds.SizeY / 2);
var z = bounds.Z + (bounds.SizeZ / 2);
var centerPoint = new Point3D(x, y, z);
同时我将尝试找到一个更好的解决方案来尝试将所有点移动到所需的偏移量......
I'm struggling with the best way of changing the center point of a 3D object (Model3DGroup) in WPF.
I've exported a model from SketchUp and everything is fine, but the centers got off position, causing me trouble in rotating the objects.
Now I need to make some rotations around each object own center and have no idea on how to do it...
Any suggestions would be appreciated.
Thanks
Using Jackson Pope suggestion, I used the code below to get the center point of an object:
var bounds = this.My3DObject.Bounds;
var x = bounds.X + (bounds.SizeX / 2);
var y = bounds.Y + (bounds.SizeY / 2);
var z = bounds.Z + (bounds.SizeZ / 2);
var centerPoint = new Point3D(x, y, z);
Meanwhile I'll try find a better solution to try and move all the points to the desired offset...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要绕其中心旋转对象,您需要首先平移它,使其中心位于原点。然后旋转它(然后可能将其平移回其原始位置)。
找到物体的最小和最大范围,计算其中心 = min + (max-min)/2。按 (-centreX, -centreY, -centreZ) 平移,旋转,然后按 (centreX, centerY, centerZ) 平移。
To rotate an object around it's centre you need to first translate it so that its centre is at the origin. Then rotate it (and then potentially translate it back to its original position).
Find the minimum and maximum extent of the object, calculate its centre = min + (max-min)/2. Translate by (-centreX, -centreY, -centreZ), rotate and then translate by (centreX, centreY, centreZ).