/* bennett@cc.gatech.edu */ /* http://www.cc.gatech.edu/gvu/perception/projects/motionMatching/cameraTrack/ */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include // a place to store the info from the camera before the button is pushed class camera_data { public: MVector trans; double rotate[3], scale[3]; double hfa, vfa, fl, squeeze, fstop, fd, sa, coi; }; camera_data Global_Cam; // what to do when the button is pushed void activateButton( Widget /* widget */, XtPointer /* clientData */, XtPointer /* callbackData */) // // Description: // Handle activation of the button. // { char delta [50]; MStatus status; MSelectionList list; MGlobal::getActiveSelectionList( list ); MItSelectionList * iter = new MItSelectionList( list ); // get the information for the current camera for ( ; !iter->isDone(); iter->next() ) { MDagPath DagNode; iter->getDagPath( DagNode ); MFnCamera camShapeFn( DagNode, &status ); if (status != MS::kSuccess) cerr << "Error finding camera shape." << endl; MFnTransform camXFn ( DagNode, &status ); if (status != MS::kSuccess) cerr << "Error finding camera transform." << endl; MVector mv = camXFn.translation(MSpace::kWorld); double scale[3], rotation[3]; camXFn.getScale( scale ); MTransformationMatrix::RotationOrder temp; camXFn.getRotation ( rotation , temp, MSpace::kWorld) ; double vfa = camShapeFn.verticalFilmAperture (); double hfa = camShapeFn.horizontalFilmAperture (); double fl = camShapeFn.focalLength(); double squeeze = camShapeFn.lensSqueezeRatio (); double fstop = camShapeFn.fStop(); double fd = camShapeFn.focusDistance(); double sa = camShapeFn.shutterAngle(); double coi = camShapeFn.centerOfInterest(); // compute delta for translation and shift. sprintf(delta, "%f", (mv[0] - Global_Cam.trans[0])); if (MGlobal::executeCommand ( MString("shiftPath -a \"translateX\" -v ") + MString(delta )) != MS::kSuccess) cerr << "shiftPath is not loaded.\n" ; cerr << "translation x moved from " << Global_Cam.trans[0] << " to " << mv[0] << endl; sprintf(delta, "%f", (mv[1] - Global_Cam.trans[1])); if (MGlobal::executeCommand ( MString("shiftPath -a \"translateY\" -v ") + MString(delta )) != MS::kSuccess) cerr << "shif tPath is not loaded.\n" ; cerr << "translation y moved from " << Global_Cam.trans[1] << " to " << mv[1] << endl; sprintf(delta, "%f", (mv[2] - Global_Cam.trans[2])); if (MGlobal::executeCommand ( MString("shiftPath -a \"translateZ\" -v ") + MString(delta )) != MS::kSuccess) cerr << "shif tPath is not loaded.\n" ; cerr << "translation z moved from " << Global_Cam.trans[2] << " to " << mv[2] << endl; // compute delta for rotate and rotate sprintf(delta, "%f", (rotation[0] - Global_Cam.rotate[0])); if (MGlobal::executeCommand ( MString("shiftPath -a \"rotateX\" -v ") + MString(delta )) != MS::kSuccess) cerr << "shif tPath is not loaded.\n" ; cerr << "rotation x moved from " << Global_Cam.rotate[0] << " to " << rotation[0] << endl; sprintf(delta, "%f", (rotation[1] - Global_Cam.rotate[1])); if (MGlobal::executeCommand ( MString("shiftPath -a \"rotateY\" -v ") + MString(delta )) != MS::kSuccess) cerr << "shif tPath is not loaded.\n" ; cerr << "rotation x moved from " << Global_Cam.rotate[1] << " to " << rotation[1] << endl; sprintf(delta, "%f", (rotation[2] - Global_Cam.rotate[2])); if (MGlobal::executeCommand ( MString("shiftPath -a \"rotateZ\" -v ") + MString(delta )) != MS::kSuccess) cerr << "shif tPath is not loaded.\n" ; cerr << "rotation x moved from " << Global_Cam.rotate[2] << " to " << rotation[2] << endl; // compute delta for scale and scale. sprintf(delta, "%f", (scale[0] - Global_Cam.scale[0])); if (MGlobal::executeCommand ( MString("shiftPath -a \"scaleX\" -v ") + MString(delta )) != MS::kSuccess) cerr << "shif tPath is not loaded.\n" ; cerr << "scale x moved from " << Global_Cam.scale[0] << " to " << scale[0] << endl; sprintf(delta, "%f", (scale[1] - Global_Cam.scale[1])); if (MGlobal::executeCommand ( MString("shiftPath -a \"scaleY\" -v ") + MString(delta )) != MS::kSuccess) cerr << "shif tPath is not loaded.\n" ; cerr << "scale y moved from " << Global_Cam.scale[1] << " to " << scale[1] << endl; sprintf(delta, "%f", (scale[1] - Global_Cam.scale[1])); if (MGlobal::executeCommand ( MString("shiftPath -a \"scaleY\" -v ") + MString(delta )) != MS::kSuccess) cerr << "shif tPath is not loaded.\n" ; cerr << "scale z moved from " << Global_Cam.scale[1] << " to " << scale[1] << endl; // vertical aperture sprintf(delta, "%f", (vfa - Global_Cam.vfa)); if (MGlobal::executeCommand ( MString("shiftPath -a \"verticalFilmAperture\" -v ") + MString(delta )) != MS::kSuccess) cerr << "shift Path is not loaded.\n" ; cerr << "vfa moved from " << Global_Cam.vfa << " to " << vfa << endl; // horizontal aperture sprintf(delta, "%f", (hfa - Global_Cam.hfa)); if (MGlobal::executeCommand ( MString("shiftPath -a \"HorizontalFilmAperture\" -v ") + MString(delta )) != MS::kSuccess) cerr << "shift Path is not loaded.\n" ; cerr << "hfa moved from " << Global_Cam.hfa << " to " << hfa << endl; // focal length sprintf(delta, "%f", (fl - Global_Cam.fl)); if (MGlobal::executeCommand ( MString("shiftPath -a \"focalLength\" -v ") + MString(delta )) != MS::kSuccess) cerr << "shift Path is not loaded.\n" ; cerr << "flength moved from " << Global_Cam.fl << " to " << fl << endl; // squeeze sprintf(delta, "%f", (squeeze - Global_Cam.squeeze)); if (MGlobal::executeCommand ( MString("shiftPath -a \"squeezeRatio\" -v ") + MString(delta )) != MS::kSuccess) cerr << "shift Path is not loaded.\n" ; cerr << "squeeze moved from " << Global_Cam.squeeze << " to " << squeeze << endl; // fstop sprintf(delta, "%f", (fstop - Global_Cam.fstop)); if (MGlobal::executeCommand ( MString("shiftPath -a \"fStop\" -v ") + MString(delta )) != MS::kSuccess) cerr << "shift Path is not loaded.\n" ; cerr << "fstop moved from " << Global_Cam.fstop << " to " << fstop << endl; // focus distance sprintf(delta, "%f", (fd - Global_Cam.fd)); if (MGlobal::executeCommand ( MString("shiftPath -a \"focusDistance\" -v ") + MString(delta )) != MS::kSuccess) cerr << "shift Path is not loaded.\n" ; cerr << "focus distance moved from " << Global_Cam.fd << " to " << fd << endl; // shutterAngle sprintf(delta, "%f", (sa - Global_Cam.sa)); if (MGlobal::executeCommand ( MString("shiftPath -a \"shutterAngle\" -v ") + MString(delta )) != MS::kSuccess) cerr << "shift Path is not loaded.\n" ; cerr << "shutterAngle moved from " << Global_Cam.sa << " to " << sa << endl; // centerOfInterest sprintf(delta, "%f", (coi - Global_Cam.coi)); if (MGlobal::executeCommand ( MString("shiftPath -a \"centerOfInterest\" -v ") + MString(delta )) != MS::kSuccess) cerr << "shift Path is not loaded.\n" ; cerr << "centerOfInterest moved from " << Global_Cam.coi << " to " << coi << endl; } } MStatus guiShift(const MArgList & args) // // Description: // Create a Motif window containing only a button. // { MStatus status; MSelectionList list; MGlobal::getActiveSelectionList( list ); MItSelectionList * iter = new MItSelectionList( list ); // save the location and atrtibutes of the selected camera for ( ; !iter->isDone(); iter->next() ) { MDagPath DagNode; iter->getDagPath( DagNode ); MFnCamera camShapeFn( DagNode, &status ); if (status != MS::kSuccess) cerr << "Error finding camera shape." << endl; MFnTransform camXFn ( DagNode, &status ); if (status != MS::kSuccess) cerr << "Error finding camera transform." << endl; Global_Cam.trans = camXFn.translation(MSpace::kWorld); camXFn.getScale( Global_Cam.scale ); MTransformationMatrix::RotationOrder temp; camXFn.getRotation ( Global_Cam.rotate , temp,MSpace::kWorld); Global_Cam.vfa = camShapeFn.verticalFilmAperture (); Global_Cam.hfa = camShapeFn.horizontalFilmAperture (); Global_Cam.fl = camShapeFn.focalLength(); Global_Cam.squeeze = camShapeFn.lensSqueezeRatio (); Global_Cam.fstop = camShapeFn.fStop(); Global_Cam.fd = camShapeFn.focusDistance(); Global_Cam.sa = camShapeFn.shutterAngle(); Global_Cam.coi = camShapeFn.centerOfInterest(); } // do some X11 stuff to make th window and button show up. // Get the application shell widget. // Widget appShell = MGlobal::applicationShell(); // Create a window shell. // Widget shell = XtCreatePopupShell( "MotifWindow", topLevelShellWidgetClass, appShell, NULL, 0); // Create a layout for the button. // Widget mainWindow = XmCreateMainWindow(shell, "MainWindow", NULL, 0); // Create a button and attach a callback for when the button is // activated. // Widget button = XmCreatePushButton(mainWindow, "Record Change", NULL, 0); XtAddCallback(button, XmNactivateCallback, activateButton, NULL); // Manage your widgets and popup your shell. // (ie. make your window and controls visible). // XtManageChild(button); XtManageChild(mainWindow); XtPopup(shell, XtGrabNone); return MS::kSuccess; } DeclareSingle(guiShift);