[vtkusers] vtkAssembly : restore postion and rotation stored in quaterion ?
David Gobbi
david.gobbi at gmail.com
Fri Jan 13 07:51:39 EST 2012
Instead of GetMatrix()->Identity(), try setting all of the pose
variables to zero:
assembly->SetOrientation(0,0,0);
assembly->SetPosition(0,0,0);
assembly->SetOrigin(0,0,0);
The assembly computes its matrix from these variable, so if you clear
the matrix without clearing the variables, then the assembly might
re-create the matrix.
- David
On Fri, Jan 13, 2012 at 12:44 AM, Ashika Umanga Umagiliya
<aumanga at biggjapan.com> wrote:
> Thanks david for the tips,
> I tried to use the degree as you told ,but still it doesnt work correct.
> This is how restore the state :
>
>
> assembly->GetMatrix()->Identity();
>
> double qw=cap.qw;
> double qx=cap.qx;
> double qy=cap.qy;
> double qz=cap.qz;
>
>
>
>
> double scale=sqrt(qw*qw+ 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( vtkMath::DegreesFromRadians(angle),ax,ay,az);
> assembly->SetPosition(cap.x,cap.y,cap.z);
>
>
>
> Any tips ?
>
> On 13 January 2012 14:01, David Gobbi <david.gobbi at gmail.com> wrote:
>> 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