MCPcopy Create free account
hub / github.com/Kitware/VTK / getTorsoTransform

Function getTorsoTransform

Rendering/VRModels/vtkOpenGLAvatar.cxx:52–97  ·  view source on GitHub ↗

calculate a rotation purely around Vup, using an approximate Vr (right) that isn't orthogonal. Reverse Vr, front if torso isn't facing the same way as the head.

Source from the content-addressed store, hash-verified

50// that isn't orthogonal.
51// Reverse Vr, front if torso isn't facing the same way as the head.
52void getTorsoTransform(
53 vtkTransform* trans, double Vup[3], double inVr[3], double HeadOrientation[3])
54{
55 double Vr[3] = { inVr[0], inVr[1], inVr[2] };
56 // temporarily use trans for head orientation
57 setOrientation(trans, HeadOrientation);
58 if (Vr[0] == 0 && Vr[1] == 0 && Vr[2] == 0)
59 {
60 // no information from hands, use head orientation and Vup.
61 Vr[2] = 1;
62 trans->TransformPoint(Vr, Vr);
63 }
64
65 // make Vr orthogonal to Vup
66 double Vtemp[3] = { Vup[0], Vup[1], Vup[2] };
67 vtkMath::MultiplyScalar(Vtemp, vtkMath::Dot(Vup, Vr));
68 vtkMath::Subtract(Vr, Vtemp, Vr);
69 vtkMath::Normalize(Vr);
70 // get third basis vector
71 double Vfr[3];
72 vtkMath::Cross(Vup, Vr, Vfr);
73 // temporarily use trans to test Vfr versus head orientation
74 double Vhead[3] = { 1, 0, 0 };
75 trans->TransformPoint(Vhead, Vhead);
76 if (vtkMath::Dot(Vfr, Vhead) < 0)
77 {
78 // torso is facing behind the head. Swap.
79 Vr[0] = -Vr[0];
80 Vr[1] = -Vr[1];
81 Vr[2] = -Vr[2];
82 Vfr[0] = -Vfr[0];
83 Vfr[1] = -Vfr[1];
84 Vfr[2] = -Vfr[2];
85 }
86 // make new rotation matrix. Basis vectors form the rotation piece.
87 trans->Identity();
88 vtkNew<vtkMatrix4x4> mat;
89 trans->GetMatrix(mat);
90 for (int i = 0; i < 3; ++i)
91 {
92 mat->SetElement(i, 0, Vfr[i]);
93 mat->SetElement(i, 1, Vup[i]);
94 mat->SetElement(i, 2, Vr[i]);
95 }
96 trans->SetMatrix(mat);
97}
98
99// create a triangle between the shoulder and hand, in the plane
100// parallel to the up vector, so elbow is always "down".

Callers 1

CalcBodyMethod · 0.85

Calls 11

setOrientationFunction · 0.85
MultiplyScalarFunction · 0.50
DotFunction · 0.50
SubtractFunction · 0.50
NormalizeFunction · 0.50
CrossFunction · 0.50
TransformPointMethod · 0.45
IdentityMethod · 0.45
GetMatrixMethod · 0.45
SetElementMethod · 0.45
SetMatrixMethod · 0.45

Tested by

no test coverage detected