[vtk-developers] whty collide->GetNumberOfContacts() is 0?

qhsoft0012 qhsoft0012 at 163.com
Mon Apr 17 22:44:34 EDT 2006


hi;
  why  actor2->RotateWXYZ(-5,1,0,0) can't change ths collide->GetNumberOfContacts();collide->GetNumberOfContacts() is always 0,actually two actors have been collided;

 
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);
//ren AddObserver EndEvent ChangeOrigin
//ren AddActor actor3
    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(actor3);  
   ren->AddActor(txt);
   ren->SetBackground(0.5,0.5,0.5);
   
 vtkRenderWindow *renWin=vtkRenderWindow::New();
   renWin->AddRenderer(ren);
   int sum,j;
   j=1;
   for(int i=0;i<5;i++){
    renWin->Render();
    actor2->RotateWXYZ(-5,1,0,0);
    collide->Update();
    sum=collide->GetNumberOfContacts();
    j++;
   }
 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/a8002610/attachment.html>


More information about the vtk-developers mailing list