[vtk-developers] TestCollisionDetection ?
qhsoft0012
qhsoft0012 at 163.com
Mon Apr 17 21:45:47 EDT 2006
hi;
I changed TestCollisionDetection example,Add this code
"for(int i=0;i<4;i++){<BR> renWin->Render();<BR> actor2->AddPosition(0.5,0,0);</DIV>
<DIV> //sphere0->SetCenter(-0.7+i*0.5,0,0);<BR> collide->Update();<BR> sum=collide->GetNumberOfContacts();<BR> }<BR>." why sum is always 0,Actually two actors have been collided?
This is all the code.
vtkSphereSource *sphere0=vtkSphereSource::New();
sphere0->SetPhiResolution(30);
sphere0->SetThetaResolution(30);
sphere0->SetCenter(-0.7,0,0);
sphere0->Update();
vtkSphereSource *sphere1=vtkSphereSource::New();
sphere1->SetPhiResolution(30);
sphere1->SetThetaResolution(30);
sphere0->SetCenter(1.7,0,0);
sphere1->Update();
vtkMatrix4x4 *matrix0=vtkMatrix4x4::New();
vtkMatrix4x4 *matrix1=vtkMatrix4x4::New();
vtkCollisionDetectionFilter *collide=vtkCollisionDetectionFilter::New();
collide->SetInput(0,sphere0->GetOutput());
collide->SetMatrix(0,matrix0);
collide->SetInput(1,sphere1->GetOutput());
collide->SetMatrix(1,matrix1);
collide->SetBoxTolerance(0.0);
collide->SetCellTolerance(0.0);
collide->SetNumberOfCellsPerBucket(2);
collide->GetCollisionModeMaxValue();
collide->GeneratePolydataOutputOn();
vtkTextActor *txt=vtkTextActor::New();
txt->GetTextProperty()->SetFontFamilyToCourier();
vtkSphereSource *point=vtkSphereSource::New();
point->SetRadius(0.01);
vtkPolyData *pointdata=vtkPolyData::New();
pointdata->SetPoints(collide->GetContactPoints());
vtkGlyph3D *points=vtkGlyph3D::New();
points->SetInput(pointdata);
points->SetSource(point->GetOutput());
vtkPolyDataMapper *mapper1=vtkPolyDataMapper::New();
mapper1->SetInput(collide->GetOutput(0));
vtkActor *actor1=vtkActor::New();
actor1->SetMapper(mapper1);
actor1->GetProperty()->BackfaceCullingOn();
actor1->SetUserMatrix(matrix0);
vtkPolyDataMapper *mapper2=vtkPolyDataMapper::New();
mapper2->SetInput(collide->GetOutput(1));
vtkActor *actor2=vtkActor::New();
actor2->SetMapper(mapper2);
actor2->GetProperty()->BackfaceCullingOn();
actor2->SetUserMatrix(matrix1);
vtkPolyDataMapper *mapper3=vtkPolyDataMapper::New();
mapper3->SetInput(points->GetOutput());
vtkActor *actor3=vtkActor::New();
actor3->SetMapper(mapper3);
actor3->GetProperty()->SetColor(0,0,0);
vtkRenderer *ren=vtkRenderer::New();
ren->AddActor(actor1);
ren->AddActor(actor2);
ChangeOrigin *changeorigin=ChangeOrigin::New();
changeorigin->actor1=actor1;
changeorigin->actor2=actor2;
changeorigin->collide=collide;
//ren->AddObserver(vtkCommand::EndEvent,changeorigin);
cbCollision *cbcollision=cbCollision::New();
cbcollision->collide=collide;
cbcollision->txt=txt;
cbcollision->points=points;
//collide->AddObserver(vtkCommand::AnyEvent,cbcollision);
ren->AddActor(txt);
ren->SetBackground(0.5,0.5,0.5);
vtkRenderWindow *renWin=vtkRenderWindow::New();
renWin->AddRenderer(ren);
int sum,j;
for(int i=0;i<4;i++){
renWin->Render();
actor2->AddPosition(0.5,0,0);
//sphere0->SetCenter(-0.7+i*0.5,0,0);
collide->Update();
sum=collide->GetNumberOfContacts();
}
vtkInteractorStyleJoystickActor *istyle=vtkInteractorStyleJoystickActor::New();
vtkRenderWindowInteractor *iren=vtkRenderWindowInteractor::New();
iren->SetRenderWindow(renWin);
iren->SetInteractorStyle(istyle);
iren->Initialize();
iren->Start();
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtk-developers/attachments/20060418/e6760d31/attachment.html>
More information about the vtk-developers
mailing list