【发布时间】:2019-03-25 14:52:27
【问题描述】:
我需要一些帮助来在 Visual Studio 的 WPF 项目中旋转 3D 模型。我已经通过使用 helix 工具包导入了模型。但我找不到任何关于如何在线旋转 3D 模型的示例。我找到了一些 C# 和 xaml 示例,但它们似乎主要是旋转相机而不是模型。
【问题讨论】:
标签: c# wpf helix-3d-toolkit
我需要一些帮助来在 Visual Studio 的 WPF 项目中旋转 3D 模型。我已经通过使用 helix 工具包导入了模型。但我找不到任何关于如何在线旋转 3D 模型的示例。我找到了一些 C# 和 xaml 示例,但它们似乎主要是旋转相机而不是模型。
【问题讨论】:
标签: c# wpf helix-3d-toolkit
我发现使用矩阵进行转换特别有用。
在我的例子中,我注意到的是,通常如果您应用 RotateTransform3D 等变换,然后使用模型的“.transform”属性应用另一个变换,它会覆盖最后一个变换。在大多数情况下,您希望将新的转换应用于上一个转换。
这就是我进行轮换的方式:
Vector3D axis = new Vector3D (1,0,0) //In case you want to rotate it about the x-axis
Matrix3D transformationMatrix = model.Content.Transform.Value; //Gets the matrix indicating the current transformation value
transformationMatrix.Rotate(new Quaternion(axis, angle)) //Makes a rotation transformation over this matrix
model.Content.Transform = new MatrixTransform3D(transformationMatrix); //Applies the transformation to your model
别忘了,如果你想让模型在它自己的中心旋转,而不是'.Rotate',使用'.RotateAt' 像这样:
transformationMatrix.RotateAt(new Quaternion(axis, angle), modelCenter); //modelCenter is the Point3D variable indicating the center
【讨论】:
为您的 GeometryModel3D.Transform 创建一个 RotateTransform3D
【讨论】: