# [osg-users] Computing Image Co-ordinates

Robert Osfield robert.osfield at gmail.com
Thu Sep 6 09:52:45 PDT 2007

```Hi Harash,

Like Zach I've found it difficult working out what you are trying to do.

W.r.t compute world coordinates in window coordinates (I presume this
is what you mean by image coordinates) is to do:

Vec3d windowCoord =
objectCoord * (modellMatrix * viewMatrix * projectionMatrix
* windowMatrix);

You won't need to do the division by w yourself as when using Vec3's
on matrix maths the OSG will automatically do the required division.

The only bit missing in your own example below is the modelMatrix
which you'll need to compute for the nodes in question, each node has
a getWorldMatrices() method then you can use to from local object
coords into world coordinates (this is the modelMatrix in OpenGL
speak).  Please note that this method can return a number of matrices
as would be the case when a node has multiple parents.

Robert.

On 9/6/07, Harash Sharma <harashsharma at yahoo.com> wrote:
> Hi
>    Thanks to all. I now know the problem was probably too simplistic for
> anyone to waste their precious time. I was able to figure out the way to
> compute the image co-ordinates from world object co-ordinates. I am writing
> here the method in case some newbie like me needs it.
>    If the World Co-ordinate of the object Point is P, Then we can obtain the
> Image co-ordinate C as :
>
> 1. C1 = P * MatView * MatProj * MatWind
> 2. C = C1 / C1.w()
>
> where
>
> MatView:- View Matrix obtained through osg::Camera::getViewMatrix()
> MatProj:-  Projection Matrix obtained through
> osg::Camera::getProjectionMatrix()
> MatWind:- Window Matrix obtained through
> osg::Viewport::computeWindowMatrix()
>
>   Here the viewport is set to the size of the image to which the scene is
> rendered through RTT.
>
> Regards
>
> Harash
>
>
>
>
> Harash Sharma <harashsharma at yahoo.com> wrote:
>
> Hi All,
>
>     I want some help regarding computation of projected model co-ordinates.
> The problem is like this. I have a cuboidal model (car). I have been able to
> compute its bounding box -- so I know the world co-ordinates of the car
> bound corners. The scene is being rendered to a texture with an image size
> of MxN Pixels. I would like to calculate the image co-ordinates
> corresponding to the 8 bounding box corner co-ordinates. Is there any
> function available in OSG which I can use to achieve this. If not, it would
> be very kind of you to indicate some  pointers on how to do it. I thought it
> would be as simple as multiplying the model vectors by the
> osg::View::getCamera()->getViewMatrix() *
> osg::View::getCamera()->getProjectionMatrix(), but I think
> I am missing something.
>
>
> Regards
>
> Harash
>  ________________________________
>  Sick sense of humor? Visit Yahoo! TV's Comedy with an Edge to see what's
> on, when. _______________________________________________
> osg-users mailing list
> osg-users at lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
>
>
>  ________________________________
> Boardwalk for \$500? In 2007? Ha!
> Play Monopoly Here and Now (it's updated for today's economy) at Yahoo!
> Games.
>
>
> _______________________________________________
> osg-users mailing list
> osg-users at lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
>

```