c# - 如何在 3d 模型上移动轴
问题描述
用了几天的 3d 模型,我不知道如何移动轴,这样我就可以开始旋转了。例如....我想将 X 倾斜 30 度,然后我将排好队进行每个轴的旋转。如果我将 X 旋转到 30 度,它会抛出 Y 和 Z 旋转。如何在后面的代码中执行此操作的任何示例?我找到的最接近的示例是在 Manipulator 演示中,但它没有显示有关操纵器如何工作的代码。
private Transform3DGroup GetTransforms(Model3D model)
{
var transforms = new Transform3DGroup();
// Rotation around X
transforms.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(1, 0, 0), 0)));
// Rotation around Y
transforms.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 1, 0), 0)));
// Rotation around Z
transforms.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 0, 1), 0)));
// Translate transform (if required)
transforms.Children.Add(new TranslateTransform3D());
model.Transform = transforms;
return transforms;
}
private void SetRotation(double amountX, double amountY, double amountZ, Model3D model, Point3D center)
{
// Suppose we have a function that gives us all the transforms
// applied to this object
var transforms = GetTransforms(model);
var translation = transforms.Children[3];
// Suppose GetCenter() obtains the center point of an object
// in Point3D format
var translatedCenter = translation.Transform(center);
if (!(transforms.Children[0] is RotateTransform3D rotX)) throw new ArgumentNullException(nameof(rotX));
if (!(transforms.Children[1] is RotateTransform3D rotY)) throw new ArgumentNullException(nameof(rotY));
if (!(transforms.Children[2] is RotateTransform3D rotZ)) throw new ArgumentNullException(nameof(rotZ));
// Set the center point of transformation to the translated center of the object
rotX.CenterX = rotY.CenterX = rotZ.CenterX = translatedCenter.X;
rotX.CenterY = rotY.CenterY = rotZ.CenterY = translatedCenter.Y;
rotX.CenterZ = rotY.CenterZ = rotZ.CenterZ = translatedCenter.Z;
// Apply the angle amounts
((AxisAngleRotation3D) rotX.Rotation).Angle = amountX;
((AxisAngleRotation3D) rotY.Rotation).Angle = amountY;
((AxisAngleRotation3D) rotZ.Rotation).Angle = amountZ;
}
解决方案
推荐阅读
- android - 为什么这些随机标记出现在每个 recyclerview 和 viewpager 项目中?
- orientdb - orientdb oetl 错误/我想要 pokec 数据
- python-3.x - 具有 FIFO 的 Python 选择器运行到无限循环
- vue.js - 如何清理所有缓存数据?
- fpdi - setasign\Fpdi\FpdfTplTrait::setPageFormat(array $size, string $orientation) Laravel 5.4 和 php 7 的声明
- powershell - 如果 Else Loop 在 Powershell 清单脚本中不起作用
- python - 海上联合图上的 set_title
- c++ - 查找生成给定数字所需的最小位数
- wpf - 从 ListBoxItem 引发时,WPF 弹出窗口不会自动关闭
- excel - 导入数据覆盖下拉列表数据