void vtkRenderer::ViewToWorld()
{
double result[4];
result[0] = this->ViewPoint[0];
result[1] = this->ViewPoint[1];
result[2] = this->ViewPoint[2];
result[3] = 1.0;
this->ViewToWorld(result[0],result[1],result[2]);
this->SetWorldPoint(result);
}
void vtkRenderer::ViewToWorld(double &x, double &y, double &z)
{
double mat[16];
double result[4];
if (this->ActiveCamera == nullptr)
{
vtkErrorMacro("ViewToWorld: no active camera, cannot compute view to world, returning 0,0,0");
x = y = z = 0.0;
return;
}
// get the perspective transformation from the active camera
vtkMatrix4x4 *matrix = this->ActiveCamera->
GetCompositeProjectionTransformMatrix(
this->GetTiledAspectRatio(),0,1);
// use the inverse matrix
vtkMatrix4x4::Invert(*matrix->Element, mat);
// Transform point to world coordinates
result[0] = x;
result[1] = y;
result[2] = z;
result[3] = 1.0;
vtkMatrix4x4::MultiplyPoint(mat,result,result);
// Get the transformed vector & set WorldPoint
// while we are at it try to keep w at one
if (result[3])
{
x = result[0] / result[3];
y = result[1] / result[3];
z = result[2] / result[3];
}
}