Andy Clarke Andy Clarke - 1 year ago 89
C# Question

WPF 3D - Apply a transformation, change the underlying object values

I've got a method that transforms a number of cylinders. If I run the method a second time it transforms the cylinders from their original position rather than their new position.

Is there anyway of 'applying' the transformation so that it changes the underlying values of the cylinders so that I can re-transform from the new values?

Can anyone assist?



void TransformCylinders(double angle)

var rotateTransform3D = new RotateTransform3D { CenterX = 0, CenterY = 0, CenterZ = 0 };
var axisAngleRotation3D = new AxisAngleRotation3D { Axis = new Vector3D(1, 1, 1), Angle = angle };
rotateTransform3D.Rotation = axisAngleRotation3D;
var myTransform3DGroup = new Transform3DGroup();
_cylinders.ForEach(x => x.Transform = myTransform3DGroup);


Answer Source

You are remaking the Transform3DGroup every time the method is called:

var myTransform3DGroup = new Transform3DGroup();

Transforms are essentially a stack of matrices that get multiplied together. You are clearing that stack every time you make a new group. You need to add consecutive transforms to the existing group rather than remake it.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download