카메라 조리개, 초점 거리, 오버 스캔 및 해상도를 기반으로 이미지 평면을 계산하는 수학을 아는 사람이 있습니까?Maya Python API 이미지 평면 수학
기본적으로 이미지 평면을 나타내는 현재 뷰포트를 기반으로하는 평면을 만들려고합니다.
도움 주셔서 감사합니다.
카메라 조리개, 초점 거리, 오버 스캔 및 해상도를 기반으로 이미지 평면을 계산하는 수학을 아는 사람이 있습니까?Maya Python API 이미지 평면 수학
기본적으로 이미지 평면을 나타내는 현재 뷰포트를 기반으로하는 평면을 만들려고합니다.
도움 주셔서 감사합니다.
This should be all the math you'll need to do this. 찾을 수있는 많은 연구를했습니다.
당신은 거의 확실 마야 인치하지만 밀리미터의 초점 거리에 구멍을 카메라를 다시 저장하는 자극적 사실을 문제로 실행하겠습니다. 따라서 :
import math
import maya.cmds as cmds
import maya.OpenMaya as OpenMaya
# maya uses INCHES for camera backs
# but MILLIMETERS for focal lenghts. Hence the magic number 25.4
def get_vfov (camera):
'''
returns the vertical fov the supplied camera, in degrees.
'''
fl = cmds.getAttr(camera + ".focalLength")
vfa = cmds.getAttr(camera + ".vfa") * 25.4 # in mm
return math.degrees (2 * math.atan(vfa/(2 * fl)))
def get_hfov (camera):
'''
returns the horizontal fov the supplied camera, in degrees.
'''
fl = cmds.getAttr(camera + ".focalLength")
vfa = cmds.getAttr(camera + ".hfa") * 25.4 # in mm
return math.degrees (2 * math.atan(vfa/(2 * fl)))
def get_persp_matrix (FOV, aspect = 1, near = 1, far = 30):
'''
give a FOV amd aspect ratio, generate a perspective matrix
'''
matrix = [0.0] * 16
fov = math.radians(FOV)
yScale = 1.0/math.tan(fov/2)
xScale = yScale/aspect
matrix[0] = xScale
matrix[5] = yScale
matrix[10] = far/(near - far)
matrix[11] = -1.0
matrix[14] = (near * far)/(near - far)
mmatrix = OpenMaya.MMatrix()
OpenMaya.MScriptUtil.createMatrixFromList(matrix, mmatrix)
return mmatrix