picking object problem

picking object problem

Anonymous
Not applicable
589 Views
0 Replies
Message 1 of 1

picking object problem

Anonymous
Not applicable

I'm a newcomer of max sdk programming. I want pick and drag object in my own way in max, so I create a utility plugin project, set my own command mode with GetCOREInterface()->SetCommandMode(). I use left click to pick object (MOUSE_POINT 0) and MOUSE_MOVE to drag object.

 

The problem is sometimes I cannot pick and drag object in my command mode. For example, I create a sphere and a teapot using the 3dsMax standard way, then I set my own command mode. If I pick the sphere and drag it, it works. But if I quickly move the cursor to pick and drag the teapot, the teapot will not moving. I must left click and drag the teapot several times to make the teapot moving. But if after drag the sphere, I first suspend cursor on the teapot for about 1 sec, or first I right click on the teapot, then left click the teapot and drag it , all things will be correct.

 

 

Can someone tell me how to fix this problem? I post the picture and source code below.

 

Another problem is throughout the entire process, the bounding box is always on the teapot. Did anybody know how to display bounding box on the picked object?

 

// class MyMouseProc : public MouseCallBack

void MyMouseProc :: PanMoving(HWND hWnd, IPoint2 m)
{
 ViewExp& vpt = GetCOREInterface()->GetViewExp(hWnd);
 if ( !vpt.IsAlive() )
 {
   DbgAssert(!_T("Invalid viewport!"));
  return;
 }

 TimeValue t = GetCOREInterface()->GetTime(); 

 if ( pHitNode != NULL )  // pHitNode is a private member of MyMouseProc
 {
  Point3 p1, p2;
  p1 = vpt.MapScreenToView(om, GetPerspMouseSpeed());
  p2 = vpt.MapScreenToView(m, GetPerspMouseSpeed());

    Matrix3 viewTM, coordSysTM;

   vpt.GetAffineTM(viewTM);
  coordSysTM = Inverse(viewTM);

  Point3 viewPos = coordSysTM.GetRow(3); // view position

  Matrix3 axis;
  axis.SetFromToUp(viewPos, Point3(0, 0, 0), Point3(0, 0, 1));
   Point3 delta = p2-p1;
   pHitNode->Move(t, axis, delta);

  
  om = m;  // om is a private member of MyMouseProc.  

}

}

 

int MyMouseProc :: proc(HWND hWnd, int msg, int point, int flags, IPoint2 m)
{
 switch (msg)
 {
 case MOUSE_POINT:
  if ( point==0 ) {
   SetCursor(GetCOREInterface()->GetSysCursor(SYSCUR_SELECT));
   ViewExp& vpt = GetCOREInterface()->GetViewExp(hWnd);
   pHitNode = vpt.GetClosestHit();
   om = m;
   GetCOREInterface()->RedrawViews(GetCOREInterface()->GetTime(), REDRAW_BEGIN);
     }

else if ( point==1 ) {
   SetCursor(GetCOREInterface()->GetSysCursor(SYSCUR_SELECT));
   ViewExp& vpt = GetCOREInterface()->GetViewExp(hWnd);
   vpt.ClearHitList();
   pHitNode = NULL; 

   GetCOREInterface()->RedrawViews(GetCOREInterface()->GetTime(), REDRAW_END);
    }  
  break;

 

 case MOUSE_MOVE:
     SetCursor(GetPanCursor());
   PanMoving(hWnd, m);
   GetCOREInterface()->RedrawViews(GetCOREInterface()->GetTime(), REDRAW_INTERACTIVE); 
  break;

 

 case MOUSE_ABORT:
   GetCOREInterface()->RedrawViews(GetCOREInterface()->GetTime(), REDRAW_END);
   break;

 

 case MOUSE_PROPCLICK:
    break;

 

 case MOUSE_FREEMOVE:
    break;
 }

 return TRUE;
}

 

 

sphere and teapot and bounding box

0 Likes
590 Views
0 Replies
Replies (0)