------------------------------------------------------------------------------
| 45 | |
| 46 | //------------------------------------------------------------------------------ |
| 47 | void vtkFollower::ComputeMatrix() |
| 48 | { |
| 49 | // check whether or not need to rebuild the matrix |
| 50 | if (this->GetMTime() > this->MatrixMTime || |
| 51 | (this->Camera && this->Camera->GetMTime() > this->MatrixMTime)) |
| 52 | { |
| 53 | this->GetOrientation(); |
| 54 | this->Transform->Push(); |
| 55 | this->Transform->Identity(); |
| 56 | this->Transform->PostMultiply(); |
| 57 | |
| 58 | this->Transform->Translate(-this->Origin[0], -this->Origin[1], -this->Origin[2]); |
| 59 | // scale |
| 60 | this->Transform->Scale(this->Scale[0], this->Scale[1], this->Scale[2]); |
| 61 | |
| 62 | // rotate |
| 63 | this->Transform->RotateY(this->Orientation[1]); |
| 64 | this->Transform->RotateX(this->Orientation[0]); |
| 65 | this->Transform->RotateZ(this->Orientation[2]); |
| 66 | |
| 67 | if (this->Camera) |
| 68 | { |
| 69 | double *pos, *vup, distance; |
| 70 | double Rx[3], Ry[3], Rz[3]; |
| 71 | |
| 72 | vtkMatrix4x4* matrix = this->InternalMatrix; |
| 73 | matrix->Identity(); |
| 74 | |
| 75 | // do the rotation |
| 76 | // first rotate y |
| 77 | pos = this->Camera->GetPosition(); |
| 78 | vup = this->Camera->GetViewUp(); |
| 79 | |
| 80 | if (this->Camera->GetParallelProjection()) |
| 81 | { |
| 82 | this->Camera->GetDirectionOfProjection(Rz); |
| 83 | Rz[0] = -Rz[0]; |
| 84 | Rz[1] = -Rz[1]; |
| 85 | Rz[2] = -Rz[2]; |
| 86 | } |
| 87 | else |
| 88 | { |
| 89 | distance = sqrt((pos[0] - this->Position[0]) * (pos[0] - this->Position[0]) + |
| 90 | (pos[1] - this->Position[1]) * (pos[1] - this->Position[1]) + |
| 91 | (pos[2] - this->Position[2]) * (pos[2] - this->Position[2])); |
| 92 | for (int i = 0; i < 3; i++) |
| 93 | { |
| 94 | Rz[i] = (pos[i] - this->Position[i]) / distance; |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | // We cannot directly use the vup angle since it can be aligned with Rz: |
| 99 | // vtkMath::Cross(vup,Rz,Rx); |
| 100 | // vtkMath::Normalize(Rx); |
| 101 | // vtkMath::Cross(Rz,Rx,Ry); |
| 102 | |
| 103 | // instead use the view right angle: |
| 104 | double dop[3], vur[3]; |
no test coverage detected