Transform multiple obj
#1
Guys... I'm getting crazy!!

I have some object and, selecting one of them, i need to apply a rotation

I create an AxisAngleRotation3D variable and  a RotateTransform3D variable, created a Transform3DGroup and apply transformation to the first object. (all variables are public)

Everithing works, but if i select another obj when i apply to it the transformation also the first object rotates!
I thought to use a matrix variable with a value for each of the obj:
Code:
Public rotationy As New List(Of AxisAngleRotation3D)
   Public rotationx As New List(Of AxisAngleRotation3D)

   Public rotationz As New List(Of AxisAngleRotation3D)
   Public Transformx As New List(Of RotateTransform3D)
   Public Transformy As New List(Of RotateTransform3D)
   Public Transformz As New List(Of RotateTransform3D)

   Public rotationgroup As New List(Of Transform3DGroup)

But when i change values on, for example rotationx at the same time the value of rotationy and rotationz changes and i don't know why!
Here is my code
Code:
 If args.RotationAxis = ModelRotatorVisual3D.XRotationAxis Then

           rotationx(denteclick).Axis = New Media3D.Vector3D(1, 0, 0)
           rotategumx.Axis = New Media3D.Vector3D(1, 0, 0)
           rotategumx.Angle = -(-args.RotationAngle + rotationprecx)
           trasformgumx.Rotation = rotategumx
           rotationprecx = args.RotationAngle
           rotationx(denteclick).Angle = args.RotationAngle + _startRotateX
           Label8.Text = rotationx(denteclick).Angle
           Transformx(denteclick).CenterX = mybx
           Transformx(denteclick).CenterY = myby
           Transformx(denteclick).CenterZ = mybz
           trasformgumx.CenterX = mybx
           trasformgumx.CenterY = myby
           trasformgumx.CenterZ = mybz
           Transformx(denteclick).Rotation = rotationx(denteclick)

           Label4.Text = args.RotationAngle + _startRotateX
           Label7.Text = args.RotationAngle
           If rotationgroup(denteclick).Children.Contains(Transformx(denteclick)) = False Then rotationgroup(denteclick).Children.Add(Transformx(denteclick))

       End If
       If args.RotationAxis = ModelRotatorVisual3D.YRotationAxis Then

           rotationy(denteclick).Axis = New Media3D.Vector3D(0, 1, 0)
           rotategumy.Axis = New Media3D.Vector3D(0, 1, 0)
           rotategumy.Angle = -(-args.RotationAngle + rotationprecy)
           trasformgumy.Rotation = rotategumy
           rotationprecy = args.RotationAngle
           rotationy(denteclick).Angle = args.RotationAngle + _startRotateY
           Label9.Text = rotationx(denteclick).Angle
           Transformy(denteclick).CenterX = mybx
           Transformy(denteclick).CenterY = myby
           Transformy(denteclick).CenterZ = mybz
           trasformgumy.CenterX = mybx
           trasformgumy.CenterY = myby
           trasformgumy.CenterZ = mybz
           Transformy(denteclick).Rotation = rotationy(denteclick)

           Label4.Text = args.RotationAngle + _startRotateX
           Label7.Text = args.RotationAngle
           '    dentehit.visualhit.transform = transformy(denteclick)
           If rotationgroup(denteclick).Children.Contains(Transformy(denteclick)) = False Then rotationgroup(denteclick).Children.Add(Transformy(denteclick))
           '   If rotationgroupgum.Children.Contains(transformy(denteclick)) = False Then rotationgroupgum.Children.Add(trasformgumy)
       End If
       If args.RotationAxis = ModelRotatorVisual3D.ZRotationAxis Then

           rotationz(denteclick).Axis = New Media3D.Vector3D(0, 0, 1)
           rotategumz.Axis = New Media3D.Vector3D(0, 0, 1)
           rotategumz.Angle = -(-args.RotationAngle + rotationprecz)
           trasformgumz.Rotation = rotategumz
           rotationprecz = args.RotationAngle
           rotationz(denteclick).Angle = args.RotationAngle + _startRotateZ
           Label10.Text = rotationx(denteclick).Angle
           Transformz(denteclick).CenterX = mybx
           Transformz(denteclick).CenterY = myby
           Transformz(denteclick).CenterZ = mybz
           trasformgumz.CenterX = mybx
           trasformgumz.CenterY = myby
           trasformgumz.CenterZ = mybz
           Transformz(denteclick).Rotation = rotationz(denteclick)

           Label4.Text = args.RotationAngle + _startRotateX
           Label7.Text = args.RotationAngle
           If rotationgroup(denteclick).Children.Contains(Transformz(denteclick)) = False Then rotationgroup(denteclick).Children.Add(Transformz(denteclick))
           '  If rotationgroupgum.Children.Contains(transformz(denteclick)) = False Then rotationgroupgum.Children.Add(trasformgumz)
       End If

How i can solve?
#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
#3
(03-29-2020, 12:29 PM)close Wrote: 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

This is ok but i have 2 obj. I apply transformation to first obj. When i select the second obj and apply the transformation the first object moves with the first.... I don't want to do that i need the objects move separately.
#4
The upper method takes the current transormation and applies the new one to the obj.transformation w/o any global variables. If you apply an global variable as transformation the reference will be stored inside the obj.transformation and this results in an behavior like you describe. Are you using VB?
#5
(03-30-2020, 12:15 PM)close Wrote: The upper method takes the current transormation and applies the new one to the obj.transformation w/o any global variables. If you apply an global variable as transformation the reference will be stored inside the obj.transformation and this results in an behavior like you describe. Are you using VB?

yes VB.
I try to follow the example but nothing... when i apply transformation on the second obj also the first is moved...  i'm getting crazy!
Here is my code:
Code:
sub createcontrol(numdente1)


  Dim  mymodelrotator As New ModelRotatorVisual3D
  mymodelrotator.Position = pointcenter
  mymodelrotator.Transform = mygroupx
  mymodelrotator.InnerRadius = 10
  mymodelrotator.OuterRadius = 10.3
  mymodelrotator.CircleWidth = 0.3
  AddHandler mymodelrotator.ModelRotateStarted, AddressOf started
  AddHandler mymodelrotator.ModelRotated, AddressOf rotated
  AddHandler mymodelrotator.ModelRotateEnded, AddressOf endrotate
  _EventManager3D.RegisterEventSource3D(visualEvent)
End sub

Sub started(sender As Object, args As ModelRotatedEventArgs)
       _startRotate.Angle = args.RotationAngle
       Dim rotatetransform As New RotateTransform3D(_startRotate)
       addtransform(dentehit.visualhit, rotatetransform)
End Sub
Sub rotated(sender As Object, args As ModelRotatedEventArgs)



   
       _startRotate.Angle = args.RotationAngle

End sub


 Sub addtransform(myvisual As Visual3D, mytransform As Transform3D)
       If myvisual.Transform Is Nothing Then
           myvisual.Transform = mytransform
       End If


       Dim transformgroup As New Transform3DGroup


       transformgroup.Children.Add(myvisual.Transform)
       myvisual.Transform = transformgroup


       transformgroup.Children.Add(mytransform)


   End Sub
#6
Solved!!
There was another public variable!!
  


Forum Jump:


Users browsing this thread:
1 Guest(s)