Question

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.

Was it helpful?

Solution 2

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

OTHER TIPS

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top