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) { int savedLimits, 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(); BOOL abortOnHit = flags&SUBHIT_ABORTONHIT?TRUE:FALSE; BOOL selOnly = flags&SUBHIT_SELONLY?TRUE:FALSE; BOOL unselOnly = 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); return res; }
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.