How to set the center of vtkActor autobiography when I moved the translate the actor？
Do you mean to set the center of vtkActor automatically when you move (translate) the actor with the mouse?
yes! Do you have any suggestions?
Please, take a look at this example: https://kitware.github.io/vtk-examples/site/Cxx/Visualization/MoveActor .
I have read this code,and run it.But it is not what i want. I want to rotate the actor around a specify 3D point.
And I have tried the SetOrigin() of vtkActor which say:"
- Set/Get the origin of the Prop3D. This is the point about which all
- rotations take place.
the code like this:
virtual void SetOrigin(double x, double y, double z)
vtkDebugMacro(<< this->GetClassName() << " (" << this <<
“): setting Origin to (” << x << “,” << y << “,” <<
z << “)”);
if ((this->Origin != x)||
(this->Origin != y)||
(this->Origin != z))
this->Origin = x;
this->Origin = y;
this->Origin = z;
this->IsIdentity = 0;
But it is not the result! Someone say it must be:
Move prop to the origin;
Rotate around the y-axis;
Rotate around the x-axis;
Rotate around Z axis;
Move back to the original position from the origin;
Sorry！ I forgot to say it is a stl file.
Sorry for the late response. What you’ve been told is somewhat correct since setting its origin is not enough, but it less complicated than that.
The sequence of operations is:
- Translate object to origin;
- Apply rotation;
- Reverse the translation;
Any complex linear transform can be expressed a multiplication of matrices. The sequence of operations is expressed in reverse order:
Y = T-1RT
Y: the final rotation around a point matrix that you want.
T and T-1: the translation matrix and its inverse.
R: the rotation around the origin matrix.
Then, to rotate your object around a point, simply do X* = YX, where X is the vector of input coordinates (a matrix with a single column with the x, y, z values) and X* is the transformed coordinates.
Now to some code. VTK does all that math for you. After setting its center, you can rotate an actor about one of the main axes with
actor->RotateX(45); for example to rotate about the local X axis by 45º.
If you want to rotate an actor in world coordinates, you can do
actor->RotateWXYZ(45, 1, 0, 0) to rotate the actor by 45º about the global X axis.
I hope this helps,
thank you very much!,it is ok