alexeyvanzhula
How to know depth (not distance) from camera to any point in world space?
I had view direction of camera. How to project point to cameraPlane by this vector and calculate length of result vector? 
Reply 0 0
pshipkov
depth = distance :)
Reply 0 0
alexeyvanzhula



Reply 0 0
noizfactory
Simple pythagora's theorem, no?

(distance)^2 = (point.y - camera.y)^2 - (depth)^2

Hence :

depth =  sqrt((point.y - camera.y)^2 - (distance)^2)

Or am I missing something here...? I'm assuming you know the distance here.
Reply 0 0
pshipkov
Oh, i see.
Funny thing is i always do the simple thing - i.e. - distance :)
Reply 0 0
alexeyvanzhula
Just try this scene and move cube. As you see only Y-axis not work for what we need
http://dl.dropbox.com/u/75376916/testCam.ma

I need line at camera plane or [ intersection-point from cameraDirection vector and  camera plane through cube center] for pythagora's theorem
Reply 0 0
noizfactory
You could use trigonometry to solve this. Given the angle between the red line (depth) and the green line (distance), say xAngle, and the length of the blue line which would be (locator.y - cameraPlaneCenter.y), say yLength, you can try this formula :

tan xAngle = yLength/depth

So you can solve for depth.

Reply 0 0
alexeyvanzhula
OK. thx, but i founded it with similar way :) :

Quote:
itemsPos = mc.xform(self.items, q=1, ws=1, t=1)
camPos = mc.xform( currentCamera(), q=1, ws=1, t=1 )
camDir = mfnCamera.viewDirection( api.MSpace.kWorld ).normal()
camToObjVector = api.MVector( camPos[0]-itemsPos[0], camPos[1]-itemsPos[1], camPos[2]-itemsPos[2] )

angle = camToObjVector.angle( camDir )
depth = abs( camToObjVector.length() * math.cos(angle) )
Reply 0 0
Reply