문제

Anyone know the math for calculating an image plane based off camera aperture, focal length, overscan, and resolution?

I basically just trying to make a plane that's based off the current viewport that represents an image plane.

Thanks for any help.

도움이 되었습니까?

해결책 2

This should be all the math you'll need to do this. Took lots of research to find it!

다른 팁

You'll almost certainly run into an issue with the irritating fact that Maya stores the camera back apertures in inches but the focal length in millimeters. Hence:

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
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top