[vtkusers] Re: [vtkusers]Rotations
Marta Kersten
8mak2 at qlink.queensu.ca
Wed Aug 22 10:35:18 EDT 2001
We are having some troubles to do with rotations and were wondering if
anyone else has come across them. We have 3 sliders (X, Y and Z) and they
each rotate an actor around the X, Y or Z axis (about the actors center).
This
was all working fine when we did something like this:
vtkMatrix4x4 *oldMatrix = vtkMatrix4x4::New();
vtkTransform *transform = vtkTransform::New();
float bounds[6];
m_InteractionActor->GetBounds(bounds);
//get position/center/origin from matrix does not work before interaction
//therefore calculate the center of the bounding box implicitly
m_ActorCenter[0] = ((bounds[0] + bounds[1])/2);
m_ActorCenter[1] = ((bounds[2] + bounds[3])/2);
m_ActorCenter[2] = ((bounds[4] + bounds[5])/2);
m_InteractionActor->GetMatrix(oldMatrix);
transform->SetMatrix(oldMatrix);
transform->PostMultiply();
transform->Translate(-(m_ActorCenter[0]), -(m_ActorCenter[1]), -(m_ActorCent
er[2]));
transform->RotateWXYZ(rotateValue, 1, 0, 0);
transform->Translate(m_ActorCenter[0], m_ActorCenter[1],
m_ActorCenter[2]);
m_InteractionActor->GetMatrix(oldMatrix);
m_InteractionActor->SetPosition(transform->GetPosition());
m_InteractionActor->SetOrientation(transform->GetOrientation());
HighlightActor(m_InteractionActor);
oldMatrix->Delete();
transform->Delete();
The problem is that we have now been told that we must recompute the
rotation each time so that the rotation is done in the same order always.
So we did something like this:
vtkMatrix4x4 *oldMatrix = vtkMatrix4x4::New();
vtkTransform *transform = vtkTransform::New();
float actOrient[3];
m_InteractionActor->GetOrientation(actOrient);
float bounds[6];
m_InteractionActor->GetBounds(bounds);
//get position/center/origin from matrix does not work before interaction
//therefore calculate the center of the bounding box implicitly
m_ActorCenter[0] = ((bounds[0] + bounds[1])/2.0);
m_ActorCenter[1] = ((bounds[2] + bounds[3])/2.0);
m_ActorCenter[2] = ((bounds[4] + bounds[5])/2.0);
m_InteractionActor->GetMatrix(oldMatrix);
transform->SetMatrix(oldMatrix);
transform->PostMultiply();
//translate to world origin
transform->Translate(-(m_ActorCenter[0]), -(m_ActorCenter[1]), -(m_ActorCent
er[2]));
//Rotate to original orientation of the actor
transform->RotateZ(-(actOrient[2]));
transform->RotateX(-(actOrient[0]));
transform->RotateY(-(actOrient[1]));
//Rotate to new Rotations- all rotations done in the order Y, X, Z
transform->RotateY(Y);
transform->RotateX(m_ActRotateX);
transform->RotateZ(m_ActRotateZ);
//translate back to last position of actor
transform->Translate(m_ActorCenter[0], m_ActorCenter[1],
m_ActorCenter[2]);
//set the new position and orientation back to the actor
m_InteractionActor->GetMatrix(oldMatrix);
m_InteractionActor->SetPosition(transform->GetPosition());
m_InteractionActor->SetOrientation(transform->GetOrientation());
HighlightActor(m_InteractionActor);
oldMatrix->Delete();
transform->Delete();
This seems to work for Z and maybe Y to but it definitely does not work for
X. Our solution then was to forget about using the vtkTransform and just
compute the matrices ourselves and stuff them back into the actor by using
SetUserMatrix. However, if we do this it seems GetOrientation and
GetPosition do not get updated, which is a very big problem for us. Does
anyone have any suggestions, or has anyone come across any similar problems.
Thank you for any help you can give us,
Marta
More information about the vtkusers
mailing list