get screen position

「get screen position」の編集履歴(バックアップ)一覧はこちら

get screen position」(2011/02/09 (水) 12:44:19) の最新版変更点

追加された行は緑色になります。

削除された行は赤色になります。

Use M3dView. #highlight(python){{ def screenPositionAPI(panel, pos): mp = OpenMaya.MPoint(pos[0], pos[1], pos[2]) m3v = OpenMayaUI.M3dView.active3dView() OpenMayaUI.M3dView.getM3dViewFromModelPanel(panel, m3v) xp = OpenMaya.MScriptUtil().asShortPtr() yp = OpenMaya.MScriptUtil().asShortPtr() ret = m3v.worldToView(mp, xp, yp) x = OpenMaya.MScriptUtil().getShort(xp) y = OpenMaya.MScriptUtil().getShort(yp) xPtr = OpenMaya.MScriptUtil().asUintPtr() yPtr = OpenMaya.MScriptUtil().asUintPtr() widthPtr = OpenMaya.MScriptUtil().asUintPtr() heightPtr = OpenMaya.MScriptUtil().asUintPtr() m3v.viewport(xPtr, yPtr, widthPtr, heightPtr) viewWidth = OpenMaya.MScriptUtil().getUint( widthPtr ) viewHeight = OpenMaya.MScriptUtil().getUint( heightPtr ) return (float(x)/float(viewWidth), float(y)/float(viewHeight)) }} Or calculate by yourself(using inverse Matrix) #highlight(python){{ def screenPositionAPI2(cam, pos): mp = OpenMaya.MPoint(pos[0], pos[1], pos[2]) camDagPath = mDagPathFromName(cam) mtx = camDagPath.inclusiveMatrixInverse() newPos = mp * mtx resX = - newPos.x / newPos.z * cmds.camera(cam, q=True, fl=True) resY = - newPos.y / newPos.z * cmds.camera(cam, q=True, fl=True) resX /= cmds.camera(cam, q=True, hfa=True)/ 25.4 resY /= cmds.camera(cam, q=True, vfa=True)/ 25.4 return (resX, resY) }} This one is better. #highlight(python){{ import math def screenPositionAPI3(cam, pos): mp = OpenMaya.MPoint(pos[0], pos[1], pos[2]) camDagPath = mDagPathFromName(cam) mtx = camDagPath.inclusiveMatrixInverse() newPos = mp * mtx hfv = cmds.camera(cam, q=True, hfv=True) resX = ((newPos.x/(-newPos.z))/math.tan(math.radians(hfv/2)))/2.0; vfv = cmds.camera(cam, q=True, vfv=True) resY = ((newPos.y/(-newPos.z))/math.tan(math.radians(vfv/2)))/2.0; return (resX, resY) }}

表示オプション

横に並べて表示:
変化行の前後のみ表示:
ツールボックス

下から選んでください:

新しいページを作成する
ヘルプ / FAQ もご覧ください。