Transform multiple obj
#2
Hi kreativasas,

when you applying transformations you have to add the new one to the existing transformations.

This code takes the existig transformations of the Visual3D and add a new one each time. 


Code:
       public static void AddRotationTransformation(Visual3D pVisual3D, Vector3D pVector3DAxis, double pAngle)
       {
           // get the transformation from the axis and angle
           RotateTransform3D rotateTransform3D = new RotateTransform3D(new AxisAngleRotation3D(pVector3DAxis, pAngle));

           // if there is no transformation yet apply the rotation transformation directly and return
           if (pVisual3D.Transform == null)
           {
               pVisual3D.Transform = rotateTransform3D;
               return;
           }

           Transform3DGroup transform3DGroup = (Transform3DGroup)pVisual3D.Transform;
           // check the transform3DGroup of the visual already exists
           //      -> if not create a new one and add it as transform to the visual
           if (transform3DGroup == null)
           {
               transform3DGroup = new Transform3DGroup();
               transform3DGroup.Children.Add(pVisual3D.Transform);
               pVisual3D.Transform = transform3DGroup;
           }

           // add the transformation to the transformGroup
           if (transform3DGroup.Children.Count > 0)
               transform3DGroup.Children.Insert(0, rotateTransform3D);
           else
               transform3DGroup.Children.Add(rotateTransform3D);
       }


You can call the method like this:
Code:
       private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
       {
           TransformTest.AddRotationTransformation(RootModelVisual3D,new Vector3D(1,0,0), 10);
            TransformTest.AddRotationTransformation(RootModelVisual3D_2,new Vector3D(0,1,0), 42);
       }


Maybe this link helps: 
https://docs.microsoft.com/en-us/dotnet/...s-overview

The Ab3d sample is here:
https://github.com/ab4d/Ab3d.PowerToys.W...le.xaml.cs
  


Messages In This Thread
Transform multiple obj - by kreativasas - 03-27-2020, 06:45 PM
RE: Transform multiple obj - by close - 03-29-2020, 12:29 PM
RE: Transform multiple obj - by kreativasas - 03-30-2020, 12:05 PM
RE: Transform multiple obj - by close - 03-30-2020, 12:15 PM
RE: Transform multiple obj - by kreativasas - 03-30-2020, 12:53 PM
RE: Transform multiple obj - by kreativasas - 03-30-2020, 04:45 PM

Forum Jump:


Users browsing this thread:
1 Guest(s)