void PointHelpObject::Snap(TimeValue t, INode* inode, SnapInfo *snap, IPoint2 *p, ViewExp *vpt) { if ( ! vpt || ! vpt->IsAlive() ) { // why are we here DbgAssert(!_T("Invalid viewport!")); return; } if(suspendSnap) return; Matrix3 tm = inode->GetObjectTM(t); GraphicsWindow *gw = vpt->getGW(); gw->setTransform(tm); Matrix3 invPlane = Inverse(snap->plane); // Make sure the vertex priority is active and at least as important as the best snap so far if(snap->vertPriority > 0 && snap->vertPriority <= snap->priority) { Point2 fp = Point2((float)p->x, (float)p->y); Point2 screen2; IPoint3 pt3; Point3 thePoint(0,0,0); // If constrained to the plane, make sure this point is in it! if(snap->snapType == SNAP_2D || snap->flags & SNAP_IN_PLANE) { Point3 test = thePoint * tm * invPlane; if(fabs(test.z) > 0.0001) // Is it in the plane (within reason)? return; } gw->wTransPoint(&thePoint,&pt3); screen2.x = (float)pt3.x; screen2.y = (float)pt3.y; // Are we within the snap radius? int len = (int)Length(screen2 - fp); if(len <= snap->strength) { // Is this priority better than the best so far? if(snap->vertPriority < snap->priority) { snap->priority = snap->vertPriority; snap->bestWorld = thePoint * tm; snap->bestScreen = screen2; snap->bestDist = len; } else if(len < snap->bestDist) { snap->priority = snap->vertPriority; snap->bestWorld = thePoint * tm; snap->bestScreen = screen2; snap->bestDist = len; } } } }
/* ---------------------------------------------------------------------- */ Bool xpathforall(PATHFORALL *thepath) { OBJECT *theo ; LINELIST *currline , *theline , *templine ; PATHLIST *currpath ; SYSTEMVALUE x , y ; currpath = thePathOf(*thepath) ; currline = theSubPath(*currpath) ; for (;;) { if ( ! currline ) { if ( ! currpath->next) { path_free_list( currpath, mm_pool_temp ) ; free_forallpath( thepath ) ; npop( 5 , & executionstack ) ; return TRUE ; } else { thePathOf(*thepath) = currpath->next ; currpath->next = NULL ; path_free_list( currpath, mm_pool_temp ) ; currpath = thePathOf(*thepath) ; currline = theSubPath(*currpath) ; } } switch ( theLineType(*currline) ) { case MYMOVETO : currline = currline->next ; continue ; case MYCLOSE : thePathOf(*thepath) = currpath->next ; currpath->next = NULL ; path_free_list( currpath, mm_pool_temp ) ; currpath = thePathOf(*thepath) ; if ( ! currpath ) { free_forallpath( thepath ) ; npop( 5 , & executionstack ) ; return TRUE ; } currline = theSubPath(*currpath) ; continue ; } break ; } theo = NULL ; switch ( theLineType(*currline) ) { case CURVETO : theo = stackindex( 3 , & executionstack ) ; MATRIX_TRANSFORM_XY( theX(thePoint(*currline)), theY(thePoint(*currline)), x, y, &thePathCTM(*thepath)) ; if ( ! stack_push_real( x, &operandstack )) return FALSE ; if ( ! stack_push_real( y, &operandstack )) return FALSE ; currline = currline->next ; MATRIX_TRANSFORM_XY( theX(thePoint(*currline)), theY(thePoint(*currline)), x, y, &thePathCTM(*thepath)) ; if ( ! stack_push_real( x, &operandstack )) return FALSE ; if ( ! stack_push_real( y, &operandstack )) return FALSE ; currline = currline->next ; case MOVETO : if ( ! theo ) theo = stackindex( 1 , & executionstack ) ; case LINETO : if ( ! theo ) theo = stackindex( 2 , & executionstack ) ; MATRIX_TRANSFORM_XY( theX(thePoint(*currline)), theY(thePoint(*currline)), x, y, &thePathCTM(*thepath)) ; if ( ! stack_push_real( x, &operandstack )) return FALSE ; if ( ! stack_push_real( y, &operandstack )) return FALSE ; case CLOSEPATH : if ( ! theo ) theo = stackindex( 4 , & executionstack ) ; currline = currline->next ; break ; } /* Free any structs going ... */ theline = theSubPath(*currpath) ; while ( theline != currline ) { templine = theline ; theline = theline->next ; free_line( templine, mm_pool_temp ) ; } theSubPath(*currpath) = theline ; return setup_pending_exec( theo, FALSE ) ; }