| 26 | vtkOpenGLPropItem::~vtkOpenGLPropItem() = default; |
| 27 | |
| 28 | void vtkOpenGLPropItem::UpdateTransforms() |
| 29 | { |
| 30 | vtkContextDevice2D* dev = this->Painter->GetDevice(); |
| 31 | vtkOpenGLContextDevice2D* glDev = vtkOpenGLContextDevice2D::SafeDownCast(dev); |
| 32 | if (!glDev) |
| 33 | { |
| 34 | vtkErrorMacro(<< "Context device is not vtkOpenGLContextDevice2D."); |
| 35 | return; |
| 36 | } |
| 37 | |
| 38 | // Get the active camera: |
| 39 | vtkRenderer* ren = this->Scene->GetRenderer(); |
| 40 | vtkCamera* activeCamera = ren->GetActiveCamera(); |
| 41 | |
| 42 | // Cache the current state: |
| 43 | this->CameraCache->DeepCopy(activeCamera); |
| 44 | |
| 45 | // Reset the info that computes the view: |
| 46 | vtkNew<vtkTransform> identity; |
| 47 | identity->Identity(); |
| 48 | activeCamera->SetUserViewTransform(identity); |
| 49 | activeCamera->SetFocalPoint(0.0, 0.0, 0.0); |
| 50 | activeCamera->SetPosition(0.0, 0.0, 1.0); |
| 51 | activeCamera->SetViewUp(0.0, 1.0, 0.0); |
| 52 | |
| 53 | // Update the camera model matrix with the current context2D modelview matrix: |
| 54 | double mv[16]; |
| 55 | double* glMv = glDev->GetModelMatrix()->Element[0]; |
| 56 | std::copy(glMv, glMv + 16, mv); |
| 57 | activeCamera->SetModelTransformMatrix(mv); |
| 58 | |
| 59 | /* The perspective updates aren't nearly as straight-forward, and take a bit |
| 60 | * of code-spelunking and algebra. By inspecting the following methods, we |
| 61 | * see how the perspective matrix gets built at render-time: |
| 62 | * |
| 63 | * 1) vtkOpenGLCamera::Render() calls |
| 64 | * vtkCamera::GetProjectionTransformMatrix() with zRange = [-1, 1] and |
| 65 | * aspect = aspectModification * usize / vsize (see below). |
| 66 | * 2) vtkCamera::GetProjectionTransformMatrix() calls |
| 67 | * vtkCamera::ComputeProjectionTransform with the same arguments. |
| 68 | * 3) vtkCamera::ComputeProjectionTransform calls |
| 69 | * vtkPerspectiveTransform::Ortho with: |
| 70 | * xminGL = (vtkCamera::WindowCenter[0] - 1) * vtkCamera::ParallelScale * aspect |
| 71 | * xmaxGL = (vtkCamera::WindowCenter[0] + 1) * vtkCamera::ParallelScale * aspect |
| 72 | * yminGL = (vtkCamera::WindowCenter[1] - 1) * vtkCamera::ParallelScale |
| 73 | * ymaxGL = (vtkCamera::WindowCenter[1] + 1) * vtkCamera::ParallelScale |
| 74 | * zminGL = vtkCamera::ClippingRange[0] |
| 75 | * zmaxGL = vtkCamera::ClippingRange[1] |
| 76 | * |
| 77 | * In vtkOpenGLContext2D::Begin, glOrtho is called with: |
| 78 | * xminCTX = 0.5 |
| 79 | * xmaxCTX = glViewport[0] - 0.5 |
| 80 | * yminCTX = 0.5 |
| 81 | * ymaxCTX = glViewport[1] - 0.5 |
| 82 | * zminCTX = -2000 |
| 83 | * zmaxCTX = 2000 |
| 84 | * |
| 85 | * To set the camera parameters to reproduce the Context2D projective matrix, |
nothing calls this directly
no test coverage detected