[vtkusers] ViewToWorld problem ?

Rémy Obein / Muf mufmtp at yahoo.fr
Wed Feb 6 10:51:01 EST 2002


Hi,

I've got a problem to convert mouse coords to world coords. I've searched in
the archives but I've not found any post which can help me.
I use a vtkWin32OpenGLRenderWindow window in an MFC program.
My init function :
    mVtkRenderWindow = vtkWin32OpenGLRenderWindow::New( );
    mVtkRenderer = vtkRenderer::New( );
    mVtkRenderWindow->AddRenderer( mVtkRenderer );

in the OnMouseMove function I call a "displayCoords" function which takes
the x and y coords of the mouse.
Here is the code :

void CWndRenderArea::displayCoords( int X, int Y )
{
float x = X;
float y = Y;
float displayPt[3];
mVtkRenderer->LocalDisplayToDisplay( x, y );
TRACE( "LocalDisplayToDisplay => %d %d => %f %f\n", X, Y, x, y );
mVtkRenderer->SetDisplayPoint( x, y, 0 ); // z = 0 because I'm in the XY vue
mVtkRenderer->DisplayToView( );
mVtkRenderer->GetDisplayPoint(displayPt);
TRACE( "SetDisplayPoint => %f %f %f\n", displayPt[0], displayPt[1],
displayPt[2] );
mVtkRenderer->SetViewPoint( displayPt );
mVtkRenderer->ViewToWorld( );
float worldPt[4];
mVtkRenderer->GetWorldPoint( worldPt );
TRACE( "SetViewPoint => %f %f %f %f\n", worldPt[0], worldPt[1], worldPt[2],
worldPt[3] );
}

This work fine. But when I add an actor to my renderer the worldPt var is
scaled by about 100. I don't know why, I don't change any zoom factor or
something else. If I comment my mVtkRenderer->AddActor( act ); instruction,
all works.

Any idea about what I'm missing ?

Thanks
    Muf

BTW : here is an example of my output

LocalDisplayToDisplay => 371 290 => 371.000000 186.000000
SetDisplayPoint => 371.000000 186.000000 0.000000
SetViewPoint => 0.994092 0.498386 0.990000 1.000000
CWndRenderAreaContainer::updateEntity  <===== here I add the actor into the
renderer
LocalDisplayToDisplay => 371 290 => 371.000000 186.000000
SetDisplayPoint => 371.000000 186.000000 0.000000
SetViewPoint => 96.436813 48.348377 0.029900 1.000000 <=== ~ scaled by 100.
Why ?




More information about the vtkusers mailing list