Development environment: VTK-8.1.1

To observe all details during rotating the cone, I put a axes actor and another same size cone on the same initial position. So it looks that there is only one cone but that’s not the truth.
The two cones are located in the center [0, 0, 0] in world coordinate system as the above image, I moved the ring and axes with the opposite direction of axis X until the center of ring reach the bottom of cones.
I want to rotate a cone with the rotating center which is the center of the ring and rotate the other one with the rotating center which is its center. It sounds a little messy and confusing, the rotating scene is displayed in the following image.

Now let’s discuss how to achieve it, the rotating angle can be calculated by two rotating vectors, the details can be found in my previous article vtk rotate cone with ring, so skip it and go ahead.
To rotate the cone with the rotating center which is its center is easy for us, I named the cone `m_OldConeActor`, we just need:
`m_OldConeActor->RotateZ( degreeDelta );`
To rotate the other one with the rotating center which is the center of the ring, I name the cone `m_ConeActor`, we have to move it to the center of the ring, then rotate it as `m_OldConeActor`, finally move it back. These are all tasks we need to finish in one mouse move event.

``````    PointStruct rotateCenter( m_ZRingActor->GetCenter() );
vtkPtr( oldTransform, vtkTransform );
oldTransform->SetMatrix( m_ConeActor->GetMatrix() );
vtkPtr( trans, vtkTransform );
trans->Translate( rotateCenter.point );
trans->RotateWXYZ( degreeDelta, 0, 0, 1 );
rotateCenter = -rotateCenter;
trans->Translate( rotateCenter.point );
trans->Concatenate( oldTransform );
m_ConeActor->SetUserTransform( trans );``````

Categories: CPlusPlusVTK

Article Rating
Subscribe
Notify of