Gizmo Hit Testing using PolyLines
 
 
 

The following sample code demonstrates controller gizmo hit testing. This method hit tests a series of 'footstep' shaped PolyLines that serves as the controller's gizmo.

int FootStepControl::HitTest(
               TimeValue t,
              INode* inode,
              int type,
              int crossing,
              int flags,
              IPoint2 *p,
              ViewExp *vpt)
{
   intsavedLimits, res = 0;
   GraphicsWindow *gw = vpt->getGW();
   Matrix3 ntm = inode->GetNodeTM(t);
   HitRegion hr;
   MakeHitRegion(hr,type,crossing,4,p);
  
   gw->setHitRegion(&hr);
   gw->setRndLimits(((savedLimits =
   gw->getRndLimits()) | GW_PICK) & ~GW_ILLUM);
   gw->clearHitCode();
  
   BOOLabortOnHit = flags&SUBHIT_ABORTONHIT?TRUE:FALSE;
   BOOLselOnly = flags&SUBHIT_SELONLY?TRUE:FALSE;
   BOOLunselOnly = flags&SUBHIT_UNSELONLY?TRUE:FALSE;
   for (int i=0; i<NUM_FOOTSTEPS; i++)
   {
     if (selOnly && !sel[i]) continue;
     if (unselOnly && sel[i]) continue;
     gw->setTransform(fs[i]*ntm);
     gw->polyline(FOOT_POINTS,footPts,NULL,NULL,TRUE,NULL);
     if (gw->checkHitCode())
     {
      res = TRUE;
      vpt->CtrlLogHit(inode,gw->getHitDistance(),i,0);
      if (abortOnHit)
       {
         break;
       }
      gw->clearHitCode();
     }
   }
   gw->setRndLimits(savedLimits);
   returnres;
}

If you are hit testing polygons they must be drawn as 3 sided entities for 3ds Max to properly hit test them. Polygons drawn with more than 3 sides will not hit test properly.