有人知道根据相机光圈、焦距、过扫描和分辨率计算图像平面的数学方法吗?
我基本上只是试图制作一个基于代表图像平面的当前视口的平面。
谢谢你的帮助。
您几乎肯定会遇到一个恼人的事实,即 Maya 以英寸为单位存储相机后部光圈,但以毫米为单位存储焦距。因此:
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
这应该是您执行此操作所需的所有数学运算。 花了很多研究才找到它!