one can be neater (and magnitudes faster) in python (since maya knows the operations directly with api calls*) same problems apply.
import maya.OpenMaya as om
def pointWorldToCam(cameraName, point, res):
sel = om.MSelectionList()
dag = om.MDagPath()
sel.add(cameraName)
sel.getDagPath(0,dag)
cam = om.MFnCamera(dag)
floatMat = cam.projectionMatrix()
projMat = om.MMatrix(floatMat.matrix)
floatMat = cam.postProjectionMatrix()
postProjMat = om.MMatrix(floatMat.matrix)
transMat = dag.inclusiveMatrix()
#long form ensures compatibility with MPoint and any iterable
point = om.MPoint(point[0],point[1],point[2])
fullMat = transMat.inverse() * projMat * postProjMat
nuPoint = point * fullMat
return [(nuPoint[0]/nuPoint[3]/2+0.5)*res[0],
(1-(nuPoint[1]/nuPoint[3]/2+0.5))*res[1]]
#test
print pointWorldToCam('persp', (0,0,0), (640,480))
Mayas cordinates are measured form center positive being up. For example adobbe shows points in editors form top left hence the /2+0.5 and inverse for other axis. However many programs including adobe (eg illustrator, pdf, eps etc.) do internally use lower left corners as starting point. Modify to suit your need.
BTW while searched for my old codes i stumbled across:
http://koichitamura.blogspot.fi/2008/07/world-point-to-point-on-image-maya.html
that does much the same except for a bit of unnecceserily extra code for floatmatrix to mmatrix transform. i guess its the same base source as your code above. But yeah common ogl code style. Whileas i have a Lisplike dialect of coding.
PS: if you need many points then cache the fullMatrix
- It looks a bit long because c is like that you need to declare thinkgs as types up front and the om is a c++ wrapper. So it makes it unneccery longwinded. Only the last 3 lines actually do anything other than fetching data. If you use somepthing like pymel it gets shorter to write