Hello, Sergey
Thank you very much for your reply. It helps a lot!
Cheers,
Shuiying
On 05/28/2012 09:03 PM, [email protected] wrote:
Message: 2
Date: Mon, 28 May 2012 14:02:43 +0400
From: Sergey Polischuk<[email protected]>
To: OpenSceneGraph Users<[email protected]>
Subject: Re: [osg-users] Help:Mapping between vertices in eye
coordinate and pixels on rendered image
Message-ID:<[email protected]>
Content-Type: text/plain; charset=koi8-r
Accidentally sent incomplete message:(
lets assume your eye coord is osg::Vec4 eyeCoord:
eyeCoord = eyeCoord * osgProjectionMatrix;//get it from camera
if (eyeCoord.w()< 0 )
//vertex behind camera
else
{
eyeCoord /= eyeCoord.w();
eyeCoord.x() *= 0.5;
eyeCoord.y() *= 0.5;
eyeCoord.x() += 0.5;
eyeCoord.y() += 0.5;
eyeCoord.x() *= width;
eyeCoord.y() *= height;
}
now your eyeCoord.xy contains screen coords in pixels
Cheers,
Sergey
28.05.2012, 14:00, "Sergey Polischuk"<[email protected]>:
> 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
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org