public override void doPress(MEvent eventArg) { base.doPress(eventArg); // If we are not in selecting mode (i.e. an object has been selected) // then set up for the translation. if (!_isSelecting()) { eventArg.getPosition(ref startPos_x, ref startPos_y); view = M3dView.active3dView; MDagPath camera = view.Camera; MFnCamera fnCamera = new MFnCamera(camera); MVector upDir = fnCamera.upDirection(MSpace.Space.kWorld); MVector rightDir = fnCamera.rightDirection(MSpace.Space.kWorld); // Determine the camera used in the current view if (fnCamera.isOrtho) { if (upDir.isEquivalent(MVector.zNegAxis, 1e-3)) { currWin = 0; // TOP } else if (rightDir.isEquivalent(MVector.xAxis, 1e-3)) { currWin = 1; // FRONT } else { currWin = 2; // SIDE } } else { currWin = 3; // PERSP MGlobal.displayWarning("moveTool only works in top, front and side views"); } // Create an instance of the move tool command. cmd = _newToolCommand() as moveCmd; cmd.setVector(0.0, 0.0, 0.0); } }
public override void doPress(MEvent eventArg) { base.doPress (eventArg) ; // If we are not in selecting mode (i.e. an object has been selected) // then set up for the translation. if ( !_isSelecting () ) { eventArg.getPosition (ref startPos_x, ref startPos_y) ; view = M3dView.active3dView; MDagPath camera = view.Camera ; MFnCamera fnCamera =new MFnCamera (camera) ; MVector upDir =fnCamera.upDirection (MSpace.Space.kWorld) ; MVector rightDir =fnCamera.rightDirection (MSpace.Space.kWorld) ; // Determine the camera used in the current view if ( fnCamera.isOrtho ) { if ( upDir.isEquivalent (MVector.zNegAxis, 1e-3) ) currWin =0 ; // TOP else if ( rightDir.isEquivalent (MVector.xAxis, 1e-3) ) currWin =1 ; // FRONT else currWin =2 ; // SIDE } else { currWin =3 ; // PERSP MGlobal.displayWarning ("moveTool only works in top, front and side views") ; } // Create an instance of the move tool command. cmd = _newToolCommand () as moveCmd; cmd.setVector (0.0, 0.0, 0.0) ; } }
public override void doDrag(MEvent eventArg) { base.doDrag(eventArg); // If we are not in selecting mode (i.e. an object has been selected) // then do the translation. if (!_isSelecting()) { eventArg.getPosition(ref endPos_x, ref endPos_y); MPoint endW = new MPoint(); MPoint startW = new MPoint(); MVector vec = new MVector(); view.viewToWorld(startPos_x, startPos_y, startW, vec); view.viewToWorld(endPos_x, endPos_y, endW, vec); downButton = eventArg.mouseButton; // We reset the the move vector each time a drag event occurs // and then recalculate it based on the start position. cmd.undoIt(); switch (currWin) { case 0: // TOP switch (downButton) { case MEvent.MouseButtonType.kMiddleMouse: cmd.setVector(endW.x - startW.x, 0.0, 0.0); break; case MEvent.MouseButtonType.kLeftMouse: default: cmd.setVector(endW.x - startW.x, 0.0, endW.z - startW.z); break; } break; case 1: // FRONT switch (downButton) { case MEvent.MouseButtonType.kMiddleMouse: cmd.setVector(endW.x - startW.x, 0.0, 0.0); break; case MEvent.MouseButtonType.kLeftMouse: default: cmd.setVector(endW.x - startW.x, endW.y - startW.y, 0.0); break; } break; case 2: //SIDE switch (downButton) { case MEvent.MouseButtonType.kMiddleMouse: cmd.setVector(0.0, 0.0, endW.z - startW.z); break; case MEvent.MouseButtonType.kLeftMouse: default: cmd.setVector(0.0, endW.y - startW.y, endW.z - startW.z); break; } break; default: case 3: // PERSP break; } cmd.redoIt(); view.refresh(true, false); } }