[osg-users] 2D orthographic view with panning and zooming

420 views
Skip to first unread message

Radu Marin Butoi

unread,
Jun 17, 2014, 4:43:28 PM6/17/14
to osg-...@lists.openscenegraph.org
Hello everyone,

I am writing an application to display and select elements from 2D
triangular meshes and 3D tetrahedral meshes. Displaying the 3D mesh
works fine (thanks Robert for the previous help!). With the 2D I'd like
to have the display show the XY (or XZ, or YZ, depending on the input;
the bounding of the geometry can be used to determine this) plane
directly and enable panning and zooming with the mouse. I have a single
osgViewer and I have tried using the various
getCamera()->set{View,Projection}* functions, but as I understand the
camera manipulator will overwrite the view matrix. So, what is the
simplest way to display an orthographic 2D scene with mouse panning and
zooming in a similar way that a perspective 3D scene is displayed by
default?

Thank you,
Radu
_______________________________________________
osg-users mailing list
osg-...@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Robert Osfield

unread,
Jun 18, 2014, 2:58:02 AM6/18/14
to OpenSceneGraph Users
Hi Radu,

osgViewer::CompositeViewer is the appropriate tool to use when you
want multiple VIew on to one or more scenes. Have a look at the
osgcompositeviewer and osghud examples.

Robert.

David Sellin

unread,
Jun 18, 2014, 3:02:58 AM6/18/14
to osg-...@lists.openscenegraph.org
Hi,

If think if you set viewer->setCameraManipulator( 0 ) the view matrix won't be overwritten by any camera manipulator. I haven't tried it recently but I think that's how it works.

Otherwise maybe this could work:


Code:
while( !viewer->done() )
{

viewer->advance();
viewer->eventTraversal();
viewer->updateTraversal();

// Modify view matrix here

viewer->renderingTraversals();
}



Thank you!

Cheers,
David

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=59796#59796

Marco Kliko

unread,
Jun 18, 2014, 4:28:09 AM6/18/14
to osg-...@lists.openscenegraph.org
Hi,

I think the best way is to go with:

Code:
Viewer.getCamera().setViewMatrixAsLookAt();



Not sure if you can change these values on the fly while rendering, but maybe you can stop the rendering an after changing the values start the rendering again...

You can do this with:

Code:
viewer.stopThreading ()
viewer.startThreading()



I'm not sure if it works, but it is worth the try... ;)

Thank you!

Cheers,
Marco

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=59800#59800

Trajce Nikolov NICK

unread,
Jun 18, 2014, 5:05:05 AM6/18/14
to OpenSceneGraph Users
Hi Radu,

I have done 2D display in the past for mapping purpose and what I did, I kept the default (TrackBall) manipulator and only changed the projection matrix (viewer->getCamera()->setProjectionMatrixAsOrtho2D()). Then I was able to pan, zoom my 2D view

Nick
--
trajce nikolov nick

Radu Marin Butoi

unread,
Jun 19, 2014, 10:26:08 AM6/19/14
to OpenSceneGraph Users
Hi,

Thanks everyone for the help. Taking a look at all your responses, I
realized my problem was a lot simpler than I was making it; since my
geometry only exists in a single plane all I needed to do was to set
the home position through the TrackballManipulator with the bounding
box of the geometry. It is fine to leave the projection matrix as
perspective since there is no depth to the scene. However, I have a
follow up now: how can I disable left click rotation and animation in
the manipulator? I've tried subclassing the TrackballManipulator class
and implementing some virtual functions with empty or just "return
true" bodies (startAnimationByMousePointerIntersection,
applyAnimationStep) but motion still continues after I release the
mouse button.

Thanks again,
Radu
> <mailto:osg-...@lists.openscenegraph.org>
Reply all
Reply to author
Forward
0 new messages