简体   繁体   English

如何使用HelixToolkit旋转3D模型?

[英]How do you rotate a 3D model using HelixToolkit?

I need some help rotating a 3D model in a WPF project on visual studios. 在视觉工作室的WPF项目中,我需要一些旋转3D模型的帮助。 I have imported the model in through the use of the helix toolkit. 我已经通过使用helix工具包导入了模型。 But I can not find any example of how to rotate the 3D model online. 但是我找不到任何有关如何在线旋转3D模型的示例。 I've found some C# and xaml examples but they mainly seem to rotate the camera not the model. 我发现了一些C#和xaml示例,但它们似乎主要是在旋转相机而不是旋转模型。

WPF 3D Rotation WPF 3D旋转

Create a RotateTransform3D for your GeometryModel3D.Transform 为您的GeometryModel3D.Transform创建RotateTransform3D。

I have found it particularly useful to use matrices in order to make tranformations. 我发现使用矩阵进行转换特别有用。

In my case, what I noticed was that usually if you apply a transformation such as a RotateTransform3D, and then apply another transformation using your model's '.transform' property, it overrides the last transform. 就我而言,我注意到的是,通常情况下,如果您应用诸如RotateTransform3D之类的转换,然后使用模型的'.transform'属性应用另一个转换,它将覆盖最后的转换。 In most cases, you want the new transformation to be applied over the last one. 在大多数情况下,您希望将新的转换应用于最后一个转换。

This is how I make my rotations: 这就是我的轮换方式:

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

Don't forget, if you want the model to rotate on it's own center, instead of '.Rotate', use '.RotateAt' like such: 别忘了,如果您希望模型在其自身的中心旋转,而不是使用“ .Rotate”,请使用“ .RotateAt”,例如:

transformationMatrix.RotateAt(new Quaternion(axis, angle), modelCenter); //modelCenter is the Point3D variable indicating the center

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM