2

我需要旋转和平移一个对象。我有一个问题,我只能做其中之一。我使用这段代码:

RotateTransform3D myRotate = new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 0, 1), Convert.ToDouble(180)), new Point3D(0, 0, 0));
TranslateTransform3D myTranslate = new TranslateTransform3D(0, 0, 100);
ModelVisual3D device3D2 = new ModelVisual3D();
device3D2.Content = Display3d(MODEL_PATH2);
device3D2.Transform = myRotate;
device3D2.Transform = myTranslate;
viewPort3d.Children.Add(device3D2);

问题是它只进行最后一次转换。我的意思是,如果我应用“myRotate”第二个,它会旋转对象,但不会应用“myTranslate”操作。我需要做这两个转换。

我也在使用 HelixToolkit。

4

3 回答 3

1

您必须Transform直接弄乱这些字段,而不是替换整个Transform, 即transform.position, transform.rotation, transform.localPosition, transform.localEulerAngles, transform.scale,transform.localScale等。

device3D2.Transform.rotation *= new Quaternion.AngleAxis(180f, new Vector3(0f, 0f, 1f));
device3D2.Transform.Translate(0, 0, 100);
于 2015-10-20T15:23:23.927 回答
1

您需要使用 Transform3DGroup 对象。然后向其中添加不同的转换:

Transform3DGroup  myTransformer = new Transform3DGroup;  
RotateTransform3D myRotate = new RotateTransform3D(new AxisAngleRotation3D    (new Vector3D(0, 0, 1), Convert.ToDouble(180)), new Point3D(0, 0, 0));
TranslateTransform3D myTranslate = new TranslateTransform3D(0, 0, 100);
myTransformer.Children.Add(myRotate);
myTransformer.Children.Add(myTranslate);
ModelVisual3D device3D2 = new ModelVisual3D();
device3D2.Content = Display3d(MODEL_PATH2);
device3D2.Transform = myTransformer;
viewPort3d.Children.Add(device3D2);

请注意添加各个转换器的顺序。

于 2015-11-07T17:34:04.230 回答
0

我也在使用 HelixToolkit。

在这里我创建模型并在场景中翻译它:

            ModelVisual3D mdl = new ModelVisual3D();
            mdl.Content = getModel3D();
            if ((thecurrentBox.upperLeft.X != 0)||(thecurrentBox.bottomRight.Y!=0))  {
                Matrix3D mm = mdl.Transform.Value;
                mm.Translate(new Vector3D(-thecurrentBox.upperLeft.X, 0, -thecurrentBox.bottomRight.Y));
// you can do even more transformations here. 
//you can make mm as private field and transform it whenever you like
                mdl.Transform = new MatrixTransform3D(mm);
            }
// add mdl to Children of scene

我得到了转换矩阵的当前值,对其进行操作,然后在 ModelVisual3D 实例上设置转换。这是另一个示例的链接:https ://github.com/wolfoerster/WFTools3D/blob/50cc33f9f9929d4651d0855c386d38e6861382b2/WFTools3D/Basics/Object3D.cs#L142

于 2021-01-14T13:12:29.030 回答