------------------------------------------------------------------------------
| 24 | |
| 25 | //------------------------------------------------------------------------------ |
| 26 | void vtkVRFollower::ComputeMatrix() |
| 27 | { |
| 28 | // check whether or not need to rebuild the matrix |
| 29 | // only rebuild on left eye otherwise we get two different |
| 30 | // poses for two eyes |
| 31 | if (this->Camera->GetLeftEye() && |
| 32 | (this->GetMTime() > this->MatrixMTime || |
| 33 | (this->Camera && this->Camera->GetMTime() > this->MatrixMTime))) |
| 34 | { |
| 35 | this->GetOrientation(); |
| 36 | this->Transform->Push(); |
| 37 | this->Transform->Identity(); |
| 38 | this->Transform->PostMultiply(); |
| 39 | |
| 40 | this->Transform->Translate(-this->Origin[0], -this->Origin[1], -this->Origin[2]); |
| 41 | // scale |
| 42 | this->Transform->Scale(this->Scale[0], this->Scale[1], this->Scale[2]); |
| 43 | |
| 44 | // rotate |
| 45 | this->Transform->RotateY(this->Orientation[1]); |
| 46 | this->Transform->RotateX(this->Orientation[0]); |
| 47 | this->Transform->RotateZ(this->Orientation[2]); |
| 48 | |
| 49 | if (this->Camera) |
| 50 | { |
| 51 | double *pos, *vup, distance; |
| 52 | double Rx[3], Ry[3], Rz[3]; |
| 53 | |
| 54 | vtkMatrix4x4* matrix = this->InternalMatrix; |
| 55 | matrix->Identity(); |
| 56 | |
| 57 | // do the rotation |
| 58 | // first rotate y |
| 59 | pos = this->Camera->GetPosition(); |
| 60 | vup = this->LastViewUp; |
| 61 | |
| 62 | if (this->Camera->GetParallelProjection()) |
| 63 | { |
| 64 | this->Camera->GetDirectionOfProjection(Rz); |
| 65 | Rz[0] = -Rz[0]; |
| 66 | Rz[1] = -Rz[1]; |
| 67 | Rz[2] = -Rz[2]; |
| 68 | } |
| 69 | else |
| 70 | { |
| 71 | distance = sqrt((pos[0] - this->Position[0]) * (pos[0] - this->Position[0]) + |
| 72 | (pos[1] - this->Position[1]) * (pos[1] - this->Position[1]) + |
| 73 | (pos[2] - this->Position[2]) * (pos[2] - this->Position[2])); |
| 74 | for (int i = 0; i < 3; i++) |
| 75 | { |
| 76 | Rz[i] = (pos[i] - this->Position[i]) / distance; |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | // We cannot directly use the vup angle since it can be aligned with Rz: |
| 81 | |
| 82 | // instead use the view right angle: |
| 83 | double dop[3], vur[3]; |