[vtkusers] vtkAssembly : restore postion and rotation stored in quaterion ?
David Gobbi
david.gobbi at gmail.com
Fri Jan 13 00:01:36 EST 2012
Hi Umanga,
The RotateWXYZ() method expects an angle in degrees, rather than
radians. Also try calling SetPosition() after RotateWXYZ() instead
of before (I'm not 100% sure if that will work, but you should try it
both ways).
- David
On Thu, Jan 12, 2012 at 7:45 PM, Ashika Umanga Umagiliya
<aumanga at biggjapan.com> wrote:
> Greetings all,
>
> In my application ,I want to store status of my actor (vtkAssembly
> consisting several vtkActors).
> I need to store the rotation as a quaternion.
>
> Here is the code snippet how I store the status :
>
> void captureAssemblyStatus()
> {
>
> CaptureInfo capinfo; //struct to keep the status
> double m[3][3];
> double quat[4];
> double pos[3];
>
> //get the rotation matrix in a 3x3 matrix
> vtkMatrix4x4 *mat=assembly->GetMatrix(); //assembly is a vtkAssembly
> for (int i=0; i<=2; i++)
> for (int j=0; j<=2; j++)
> m[j][i] = mat->GetElement(j,i);
>
> //store the rotation in a quaterion
> vtkMath::Matrix3x3ToQuaternion(m, quat);
> assembly->GetPosition(pos);
>
> capinfo.qw=quat[0]; //quaternion w
> capinfo.qx=quat[1];; //quaternion x
> capinfo.qy=quat[2];; //quaternion y
> capinfo.qz=quat[3];; //quaternion z
> capinfo.x=pos[0]; //postion x
> capinfo.y=pos[1]; //postion y
> capinfo.z=pos[2]; //postion z
>
> }
>
>
> And here's how I am trying to restore the status :
>
> void restoreStatus(CaptureInfo &cap)
> {
> double qw=cap.qw;
> double qx=cap.qx;
> double qy=cap.qy;
> double qz=cap.qz;
>
> //Restore the postion
> assembly->SetPosition(cap.x,cap.y,cap.z);
>
> //Restore the rotation
> double scale=sqrt(qx*qx + qy*qy + qz*qz);
> double angle=2*acos(qw);
> double ax=qx/scale;
> double ay=qy/scale;
> double az=qz/scale;
>
> assembly->RotateWXYZ(angle,ax,ay,az);
>
> this->qtWidget->update();
>
> }
>
>
> But this does work correct.
> Even when I commentout the rotation part,the position restore doesnt work well.
>
> What am I doing wrong here ?
>
> Thanks in advance
More information about the vtkusers
mailing list