Hi, Shuiying
lets assume your eye coord is osg::Vec4 eyeCoord:
eyeCoord = eyeCoord * osgProjectionMatrix;
if (eyeCoord.w() < 0 )
//vertex behind camera
else
{
eyeCoord /= eyeCoord.w()
}
26.05.2012, 19:58, "wang shuiying" <[email protected]>:
> Hallo,
>
> I simulate a real camera with OSG camera node and for debugging I have
> some problem with the pixel location. I would like to know whether the
> following statement is correct or false:
>
> if coordinate of vertex in eye coordinate is (xe,ye,ze), and we assume
> that xe>0,ye<0,ze<0, namely, the verice should appear next to bottom
> right corner of the image. (Origin of the image is top left, x forwards
> to right, y forwards to bottom)
>
> Then can its corresponding pixel location(px, py) on the image
> calculated like following? (x resolution of image is xRes, y
> Resoluation is yRes, yaw angle of camera is ViewYaw, pitch angle of
> camera is ViewPitch, near plane is 1 )
>
> px=xe/abs(ze)* (xRes/2/tan(ViewYaw/2)) +xRes/2
>
> py=abs(ye)/abs(ze)* (yRes/2/tan(ViewPitch/2)) +yRes/2
>
> I get coordinate of vertex in eye coordinate by a product of vertex
> global coordinate and camera->getViewmatrix(), and then calculate the
> corresponding pixel location following the above formulas. But the
> location is not correct compared to what appears on the image. the error
> is about 50 pixels in the x coordinate.
>
> Can anybody give me some tips on that?
>
> Thank you very much in advance!
>
> Best regards
>
> Shuiying
>
> _______________________________________________
> osg-users mailing list
> [email protected]
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org