I need some help rotating a 3D model in a WPF project on visual studios. I have imported the model in through the use of the helix toolkit. But I can not find any example of how to rotate the 3D model online. I've found some C# and xaml examples but they mainly seem to rotate the camera not the model.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
WPF 3D Rotation
Create a RotateTransform3D for your GeometryModel3D.Transform
回答2:
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. 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:
transformationMatrix.RotateAt(new Quaternion(axis, angle), modelCenter); //modelCenter is the Point3D variable indicating the center