[osg-users] View coordinates of a 3D point

Wojciech Lewandowski w.p.lewandowski at gmail.com
Sun Mar 18 03:27:35 PDT 2018


Hi,

Knowing the 3D coordinates of a point, is there an easy way in OSG to
> compute its 2D projected equivalent (i.e. in pixel coordinates)?


Yes. In general your pixel coord is computed as:

pixel_coords = WindowMatrix * ProjectionMatrix * ViewMatrix * ModelMatrix *
point;

Your solution may vary whether you compute it in Update/Cull stage.
Visitiors may have some utility functions making it simpler. But here I
present more general solution:

osg::Vec3 point; // Your 3D point somewhere in the graph as a coord of some
vertex under some point_parent_node  Node
osg::Matrix ModelMatrix = point_parent_node->getWorldMatrices()[0]; //
Assuming your point have single parental path
osg::Matrix ViewMatrix = camera->getViewMatrix();
osg::Matrix ProjectionMatrix = camera->getProjectionMatrix();
osg::Matrix WindowMatrix = camera->getViewport()->computeWindowMatrix();

osg::Vec3 pixel_coords = WindowMatrix * ProjectionMatrix * ViewMatrix *
ModelMatrix * point;
// x i y are window screen coords z is depth coord

Cheers,
Wojtek


2018-03-16 13:37 GMT+01:00 Antoine Rennuit <antoinerennuit at hotmail.com>:

> Dear OSG forum,
>
> Knowing the 3D coordinates of a point, is there an easy way in OSG to
> compute its 2D projected equivalent (i.e. in pixel coordinates)?
>
> Thanks,
>
> Antoine.
>
> ------------------
> Read this topic online here:
> http://forum.openscenegraph.org/viewtopic.php?p=73112#73112
>
>
>
>
>
> _______________________________________________
> osg-users mailing list
> osg-users at lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20180318/9734145e/attachment.html>


More information about the osg-users mailing list