[osg-users] Object position on screen coordinates

724 views
Skip to first unread message

Eduard Trulls

unread,
Mar 26, 2008, 7:05:15 AM3/26/08
to osg-...@lists.openscenegraph.org
Hi all, first message here. I want to translate the position of a number
of objects on screen coordinates, so that I can create a hud-like bubble
over each of them at z=0 giving feedback on the objects' name, status,
etc. From what I see I could use intersectors, as a sort of inverse
picking, but I'm not sure how to go about it. That is, what should I
intersect with? Or is there a simpler way, or an example I might look
at? I've been using osg for a few weeks, so any pointers would be welcome.

Again, I'm a first-timer, so please excuse any breaks of etiquette.

Regards,
E.
_______________________________________________
osg-users mailing list
osg-...@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Robert Osfield

unread,
Mar 26, 2008, 7:25:02 AM3/26/08
to OpenSceneGraph Users
Hi Eduard,

To translate objects from object coordinates to screen coordinates you
must multiple it by a series of matrices in turn, these
multiplications can all be wrapped up into a single matrices. The
order of transformation is:

world_coordinate = object_coordinate * world_matrix;
eye_coordinate = world_coordinate * view_matrix;
clipspace_coordinate = eye_coordinate * projection_matrix;
window_coordindates = clipspace_coordinate * viewport_matrix;

These can be put together thus:

window_coordinate = object_coordinate * (world_matrix * view_matrix
* projection_matrix * viewport_matrix);

The world_matrix can be obtained from the node->getWorldMatrices()
which provides a list of matrices, as and Node can have multiple
parent paths and be in have multiple world transforms placing it in
space. The rest of the matrices come from the Camera that you wish to
get the window coords from, here it'll be camera->getViewMatrix() *
camera->getProjectionMatrix() *
camera->getViewport()->computeWindowMatrix();

Robert.

J.P. Delport

unread,
Mar 26, 2008, 7:29:51 AM3/26/08
to OpenSceneGraph Users
Hi,

Eduard Trulls wrote:
> Hi all, first message here. I want to translate the position of a number
> of objects on screen coordinates, so that I can create a hud-like bubble
> over each of them at z=0 giving feedback on the objects' name, status,
> etc. From what I see I could use intersectors, as a sort of inverse
> picking, but I'm not sure how to go about it. That is, what should I
> intersect with? Or is there a simpler way, or an example I might look
> at? I've been using osg for a few weeks, so any pointers would be welcome.

I think you might want to have a look at AutoTransform and screen
aligned text. Look at the osgtext example for text and search for
AutoTransform in the examples.

We use screen aligned text for displaying object labels. It creates the
illusion that "HUD" text is moving with the object, while the text is
actually attached to the 3D coordinates of the object. Therefore no
intersections need to be done.

The same effect can be created with autotransform, but now you can have
e.g. icons attached to the objects. The icons would stay the same size
even if the objects move in depth and would be aligned to the screen.

>
> Again, I'm a first-timer, so please excuse any breaks of etiquette.

Please do not be afraid to ask questions.

>
> Regards,
> E.

cheers
jp


--
This message is subject to the CSIR's copyright terms and conditions, e-mail legal notice, and implemented Open Document Format (ODF) standard.
The full disclaimer details can be found at http://www.csir.co.za/disclaimer.html.

This message has been scanned for viruses and dangerous content by MailScanner,
and is believed to be clean. MailScanner thanks Transtec Computers for their support.

Eduard Trulls

unread,
Mar 26, 2008, 10:45:23 AM3/26/08
to OpenSceneGraph Users
Thanks for your suggestions JP, Robert,

> I think you might want to have a look at AutoTransform and screen
> aligned text. Look at the osgtext example for text and search for
> AutoTransform in the examples.
>
> We use screen aligned text for displaying object labels. It creates the
> illusion that "HUD" text is moving with the object, while the text is
> actually attached to the 3D coordinates of the object. Therefore no
> intersections need to be done.
>

I gave screen-aligned text a go, but as the camera moves around the
label is cut off by other objects. I can't have it on top of everything
else, so I can't think of a way around this besides moving the label to
a region where no collisions may occur (which is a possibility, since
I'm displaying objects in a city-like environment and the sky is free;
that's kind of ugly, though). I'll look at autotransform later, even
though I think the behaviour is similar to screen-aligned text in this
regard.

I think I'll try translating the coordinates to the screen as per
Robert's suggestion, and using intersectors from real to translated
coordinates to determine whether the object is occluded or not and
render the label accordingly (which sounds overkill, but I can't think
of anything else for the time being). Again, if there's a better way to
handle this I'm all ears.

Regards,
E.

Eric ZAREMBA

unread,
Mar 26, 2008, 10:56:44 AM3/26/08
to OpenSceneGraph Users
Hi,

To display a node on top of the other, I think you can set off the depth buffer test and put it into a render bin up all the others (> 10, since it is the transparent bin, if I remember) to draw them at the end. It's all done via StateSet, you should find them easily.


Eric Z.

-----Message d'origine-----
De : osg-user...@lists.openscenegraph.org [mailto:osg-user...@lists.openscenegraph.org] De la part de Eduard Trulls
Envoyé : mercredi 26 mars 2008 15:45
À : OpenSceneGraph Users
Objet : Re: [osg-users] Object position on screen coordinates

Reply all
Reply to author
Forward
0 new messages