[vtkusers] vtkCollisionDetectionFilter
Larcher Aurélie
aurelie.larcher at imag.fr
Thu Jan 22 10:46:54 EST 2009
Hello !
I try to use vtkCollisionDetectionFilter. I download the package vtkBioeng
with the example TestCollisionDetection.cxx
My future goal is to manipulate an object and detect when it collide an
other.
But I dont succeed to consider the Position(x,y,z) of my object.
For example,
If I dont inform the position of my object, its OK : the collision
detection work.
But if I inform the position of an object far away of the other, it doesnt
work : collisions are detected whereas there is not.
Here, piece of code
*************
vtkSphereSource *sphere = vtkSphereSource::New();
sphere->SetRadius(30);
sphere->SetPhiResolution(100);
sphere->SetThetaResolution(100);
sphere->SetCenter(0, 0, 0);
vtkPolyDataReader *outilsReader = vtkPolyDataReader::New();
outilsReader->SetFileName( "C:/Images/vtk/outils.vtk" );
vtkMatrix4x4 *matrix0 = vtkMatrix4x4::New();
vtkMatrix4x4 *matrix1 = vtkMatrix4x4::New();
vtkCollisionDetectionFilter *collide =
vtkCollisionDetectionFilter::New();
collide->SetInputConnection(0, outilsReader->GetOutputPort());
collide->SetMatrix(0, matrix0);
collide->SetInputConnection(1, sphere->GetOutputPort());
collide->SetMatrix(1, matrix1);
vtkPolyDataMapper *sphereMapper = vtkPolyDataMapper::New();
sphereMapper->SetInputConnection(outilsReader->GetOutputPort(0));
vtkActor *sphereActor = vtkActor::New();
sphereActor->SetMapper(sphereMapper);
(sphereActor->GetProperty())->BackfaceCullingOn();
sphereActor->SetPosition(0,0,0);
sphereActor->SetUserMatrix(matrix0);
sphereActor->GetProperty()->SetColor(1,0,0);
vtkPolyDataMapper *toolMapper= vtkPolyDataMapper::New();
toolMapper->SetInputConnection(sphere->GetOutputPort(1));
vtkActor *toolActor = vtkActor::New();
toolActor->SetMapper(toolMapper);
toolActor->SetUserMatrix(matrix1);
toolActor->SetPosition(100,0,0); // OK if this line is
in comment
toolActor->GetProperty()->SetColor(0,0,1);
vtkTextActor *txt = vtkTextActor::New();
vtkRenderer *ren = vtkRenderer::New();
ren->AddActor(sphereActor);
ren->AddActor(toolActor);
ren->AddActor(txt);
ren->SetBackground(0.5,0.5,0.5);
vtkRenderWindow *renWin = vtkRenderWindow::New();
renWin->AddRenderer(ren);
vtkInteractorStyleJoystickActor *istyle =
vtkInteractorStyleJoystickActor::New();
vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
iren->SetRenderWindow(renWin);
iren->SetInteractorStyle(istyle);
vtkMyCallback *callback = vtkMyCallback::New();
vtkBoxWidget *boxWidget = vtkBoxWidget::New();
boxWidget->SetInteractor(iren);
boxWidget->SetPlaceFactor(1.25);
boxWidget->SetDefaultRenderer(ren);
boxWidget->SetProp3D(sphereActor);
boxWidget->PlaceWidget();
boxWidget->AddObserver(vtkCommand::InteractionEvent, callback);
boxWidget->On();
vtkCollisionCallback *cbCollide = vtkCollisionCallback::New();
cbCollide->SetTextActor(txt);
cbCollide->SetRenderWindow(renWin);
collide->AddObserver(vtkCommand::EndEvent, cbCollide);
(
)
*************
I hope that you can help me.
Thanks,
Aurélie
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20090122/02019026/attachment.htm>
More information about the vtkusers
mailing list