Rotate and move transform
#1
Hi I need an hand.

I'm using a modelmover and a model rotator to move my meshes.

here is the code for modelrotator and modelmover:
Code:
 
AddHandler mymodelrotator(numdente).ModelRotateStarted, AddressOf started
AddHandler mymodelrotator(numdente).ModelRotated, AddressOf rotated
AddHandler mymodelrotator(numdente).ModelRotateEnded, AddressOf endrotate
'handel for modelrotator
 Sub started(sender As Object, args As ModelRotatedEventArgs)
       rotationvector = args.RotationAxis
       
       _startRotate = New AxisAngleRotation3D(rotationvector, 0)
       Dim rotatetransform As New RotateTransform3D(_startRotate)
'create new transformation on modelhit
       addtransform(dentehit.modelhit, rotatetransform)
    End Sub
Sub rotated(sender As Object, args As ModelRotatedEventArgs)

       _startRotate.Angle = args.RotationAngle


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


       Dim transformgroup As New Transform3DGroup


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


'handler for modelmover

  AddHandler mymodelmover(numdente).ModelMoveStarted, AddressOf startedmove
  AddHandler mymodelmover(numdente).ModelMoved, AddressOf rotatedmove
   AddHandler mymodelmover(numdente).ModelMoveEnded, AddressOf endrotatemove

Sub startedmove(sender As Object, args As EventArgs)

       translate = New Vector3D
       Dim translatetransform As New TranslateTransform3D(translate)
     ' create new transformation on modelhit
       addtransform1(dentehit.modelhit, translatetransform)

   End Sub
Sub rotatedmove(sender As Object, args As Ab3d.Common.ModelMovedEventArgs)
       translate = args.MoveVector3D

   End Sub
Sub addtransform1(myvisual As Model3D, mytransform As TranslateTransform3D)
       If myvisual.Transform Is Nothing Then
           myvisual.Transform = mytransform
       End If


       Dim transformgroup1 As New Transform3DGroup


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

   End Sub


For modelrotator i use rotatetransform3d and everything works perfetctly, but with model mover i use translatetransform3d with the same parameters but nothing change!
Where i'm wrong?
#2
I have quickly checked the code and did not find a reason why the translation would not be shown. However, the way you apply transformations is not correct - if you have multiple transformations, they should be apply with first applying scale, then rotation and finally translation. If you translate the object before rotating it, the object will be moved away from the center of rotation (0,0,0) and this will create a different rotation then it would be if the objects would be first rotated and then translated.

To solve that I would advise you that for each 3D object you create a Transform3DGroup and add a RotateTransform3D and a TranslateTransform3D to the group - then assign a new instance of that Transform3DGroup to each 3D object in your scene. When you have a rotation or movement then just adjust the already applied translation or rotation. This way you will be also able to read the already applied rotation and when starting a rotation you will be able to rotate the ModelRotator to already rotated angles.

Another option is to use StandardTransform3D object from Ab3d.Utilities namespace. It provides TranslateX, TranslateY, TranslateZ, ScaleX, ScaleY, ScaleZ, RotateX, RotateY and RotateZ properrties. Note that because it is not possible to derive from Transform3D, this object cannot be assigned to Transform property. Instead the StandardTransform3D provides a public Transform of type MatrixTransform3D that can be assigned to the object's Transform property. 

The StandardTransform3D can be assigned to the Tag property (when using objects from BaseVisual3D). If you are working on Model3D objects or ModelVisual3D objects that doe not provide Tag property, you will need to define a Disctionary<Model3D,StandardTransform3D> that will link the Model3D and StandardTransform3D.
Andrej Benedik
  


Forum Jump:


Users browsing this thread:
1 Guest(s)