Re: [osg-users] 3D HUD Elements

2010-08-11 Thread Gianni Ambrosio
I succesfully implemented the axes hud. You can find more details here:

http://forum.openscenegraph.org/viewtopic.php?t=6001&highlight=hud

Gianni

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





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] 3D HUD Elements

2009-09-23 Thread Jimmy Lin
Hi Andrew,

You will need a separate camera for just rendering the 3D Axis. And implement a 
update callback for the camera.

Something like this:


Code:
class AxisCameraUpdateCallback:public osg::NodeCallback
{
public:
   /** Callback method called by the NodeVisitor when visiting a node.*/
virtual void operator()(osg::Node* node, osg::NodeVisitor* nv)
{ 
if(nv->getVisitorType() == osg::NodeVisitor::UPDATE_VISITOR)
{
osg::Camera* camera = dynamic_cast(node);
if(camera && camera->getView()->getNumSlaves() > 0)
{
osg::View::Slave* slave = &camera->getView()->getSlave(0);
if(slave->_camera.get() == camera)
{
osg::Camera* masterCam = camera->getView()->getCamera();
osg::Vec3 eye, center, up;
masterCam->getViewMatrixAsLookAt(eye, center, up, 30);
osg::Matrixd matrix;
matrix.makeLookAt(eye-center, osg::Vec3(0, 0, 0), up); // 
always look at (0, 0, 0)
camera->setViewMatrix(matrix);
}
}
}

// note, callback is responsible for scenegraph traversal so
// they must call traverse(node,nv) to ensure that the
// scene graph subtree (and associated callbacks) are traversed.
traverse(node,nv);
}
};





Code:
m_Camera->setUpdateCallback(new AxisCameraUpdateCallback); // setup update 
callback, so we can update it's view matrix


Cheers,
Jimmy

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





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] 3D HUD Elements

2009-09-15 Thread Andrew Burnett-Thompson
Hi Jimmy,

I just stumbled across this thread when searching for a similar solution,
and found it very interesting. Would you be prepapred to share some of your
code for a 3D Axis in the HUD? I'd understand if not.

Otherwise - what is the basic principle?

I have a HUD added to my scene as a seperate camera, this uses an ortho2D
projection and an identity view matrix as in the osgHUD example.

On this I'd like to add a 3D Axis. Should I just create the Geode for the
axis (with an update callback to reorient it) and plop it in the lower left?
Or do I require a separate HUD for the 3D element?

Thanks in advance,

Andrew

On Thu, Aug 20, 2009 at 9:04 AM, Robert Osfield wrote:

> Hi Jimmy,
>
> If you are doing the frame loop you know when it's the first frame
> before you just place any viewer setup prior to the frame loop.  The
> _firstFrame code block you see if just a fallback in case the viewer
> hasn't already been setup.
>
> Robert.
>
> On Wed, Aug 19, 2009 at 10:49 PM, Jimmy Lin wrote:
> > Hi,
> >
> > Here is the code of frame()
> >
> >
> > Code:
> > void ViewerBase::frame(double simulationTime)
> > {
> >if (_done) return;
> >
> >if (_firstFrame)
> >{
> >viewerInit();
> >
> >if (!isRealized())
> >{
> >realize();
> >}
> >
> >_firstFrame = false;
> >}
> >advance(simulationTime);
> >
> >eventTraversal();
> >updateTraversal();
> >renderingTraversals();
> > }
> >
> >
> >
> > It calls viewerInit() on the first frame.
> > Don't I need to do that myself if I expand the code?
> > By looking at the viewerInit() code. I think I might be able to expand
> the code and init all the view I created.
> >
> > Thank you!
> >
> > Cheers,
> > Jimmy
> >
> > --
> > Read this topic online here:
> > http://forum.openscenegraph.org/viewtopic.php?p=16447#16447
> >
> >
> >
> >
> >
> > ___
> > osg-users mailing list
> > osg-users@lists.openscenegraph.org
> >
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
> >
> ___
> osg-users mailing list
> osg-users@lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] 3D HUD Elements

2009-08-20 Thread Robert Osfield
Hi Jimmy,

If you are doing the frame loop you know when it's the first frame
before you just place any viewer setup prior to the frame loop.  The
_firstFrame code block you see if just a fallback in case the viewer
hasn't already been setup.

Robert.

On Wed, Aug 19, 2009 at 10:49 PM, Jimmy Lin wrote:
> Hi,
>
> Here is the code of frame()
>
>
> Code:
> void ViewerBase::frame(double simulationTime)
> {
>    if (_done) return;
>
>    if (_firstFrame)
>    {
>        viewerInit();
>
>        if (!isRealized())
>        {
>            realize();
>        }
>
>        _firstFrame = false;
>    }
>    advance(simulationTime);
>
>    eventTraversal();
>    updateTraversal();
>    renderingTraversals();
> }
>
>
>
> It calls viewerInit() on the first frame.
> Don't I need to do that myself if I expand the code?
> By looking at the viewerInit() code. I think I might be able to expand the 
> code and init all the view I created.
>
> Thank you!
>
> Cheers,
> Jimmy
>
> --
> Read this topic online here:
> http://forum.openscenegraph.org/viewtopic.php?p=16447#16447
>
>
>
>
>
> ___
> osg-users mailing list
> osg-users@lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] 3D HUD Elements

2009-08-19 Thread Jimmy Lin
Hi,

Here is the code of frame()


Code:
void ViewerBase::frame(double simulationTime)
{
if (_done) return;

if (_firstFrame)
{
viewerInit();

if (!isRealized())
{
realize();
}

_firstFrame = false;
}
advance(simulationTime);

eventTraversal();
updateTraversal();
renderingTraversals();
}



It calls viewerInit() on the first frame. 
Don't I need to do that myself if I expand the code?
By looking at the viewerInit() code. I think I might be able to expand the code 
and init all the view I created.

Thank you!

Cheers,
Jimmy

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





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] 3D HUD Elements

2009-08-19 Thread Robert Osfield
Hi Jimmy,

On Tue, Aug 18, 2009 at 10:45 PM, Jimmy Lin wrote:
> Looking at the CompositeViewer::updateTraversal(), it seems the update 
> callback is called before update the view matrix, which mean my slave camera 
> is using master camera's previous view matrix. But I think it's allright in 
> my case to have 1 frame out of sync.
>
> Just want to know if I want to put my update between the updateTraversal() 
> and renderingTraversal(). Does that mean I need to break up the frame()? In 
> that case how can I access _firstFrame member and viewerInit() ?

Breaking up frame is trivial, and it's a very common thing to do when
writing a OSG graphics app, viewer.run() and viewer.frame() are just
high level convenience methods that you can use if you don't need fine
control over things.  The expanded frame loop simple looks like:

viewer.realize();
while(!viewer.done())
{
viewer.advance();
viewer.eventTraversal();
viewer.updateTraversal();
// do the updates you require
viewer.renderingTraversals();
}

I'm not sure why you'd need an internal variable like _firstFrame in
your code, the expanded main loop should offer plenty of scope for
putting code where you need it.

Robert.
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] 3D HUD Elements

2009-08-18 Thread Jimmy Lin
Hi Robert,

Looking at the CompositeViewer::updateTraversal(), it seems the update callback 
is called before update the view matrix, which mean my slave camera is using 
master camera's previous view matrix. But I think it's allright in my case to 
have 1 frame out of sync.

Just want to know if I want to put my update between the updateTraversal() and 
renderingTraversal(). Does that mean I need to break up the frame()? In that 
case how can I access _firstFrame member and viewerInit() ?

Thank you!

Cheers,
Jimmy

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





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] 3D HUD Elements

2009-08-18 Thread Robert Osfield
Hi Jimmy,

Good to hear you've got it working.  One thing to watch is whether
your callback is getting the current or previous frames view matrix.
The viewer camera view matrix is updated in the update traversal, so
if you want to be 100% sure of getting the correct view matrix then
placing the update between the call to viewer.updateTraversal() and
viewer.renderingTraversals() will do the trick.

Robert.

On Tue, Aug 18, 2009 at 2:30 AM, Jimmy Lin wrote:
> Hi,
>
> I think I got it now.
>
> I combine both hud and callback approach.
>
> I created a slave camera similar to the one in the example, then add a update 
> callback to it.
> In the callback I update the view matrix of the slave camera relate to the 
> master camera's view matrix. so the views are basically the same between the 
> slave and master camera, but for slave camera it was translated so it always 
> look at my 3D axis object's center (which is (0, 0, 0) in my case to make it 
> simple).
>
> It seems work fine now, but I would happy to know if there are other ways to 
> do this.
>
>
> Thank you!
>
> Cheers,
> Jimmy
>
> --
> Read this topic online here:
> http://forum.openscenegraph.org/viewtopic.php?p=16363#16363
>
>
>
>
>
> ___
> osg-users mailing list
> osg-users@lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] 3D HUD Elements

2009-08-17 Thread Jimmy Lin
Hi,

I think I got it now.

I combine both hud and callback approach.

I created a slave camera similar to the one in the example, then add a update 
callback to it.
In the callback I update the view matrix of the slave camera relate to the 
master camera's view matrix. so the views are basically the same between the 
slave and master camera, but for slave camera it was translated so it always 
look at my 3D axis object's center (which is (0, 0, 0) in my case to make it 
simple).

It seems work fine now, but I would happy to know if there are other ways to do 
this.


Thank you!

Cheers,
Jimmy

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





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] 3D HUD Elements

2009-08-17 Thread Jimmy Lin
Hi Robert,

My first attemp was doing something similar to osghud, it does successfully 
display my 3D axis as hud, but it won't rotate when the view changes.

Basically I want something similar to a hud but changes with view/camera.
or
a 3d model always stay in the same position relative to the camera.

Thank you!

Cheers,
Jimmy

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





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] 3D HUD Elements

2009-08-17 Thread Robert Osfield
Hi Jimmy,

I'd recommend doing 3D hud's using a second camera, see the osghud
example.  The second camera needn't be an othrographic one as
illustrate in the example.

Robert.

On Mon, Aug 17, 2009 at 5:21 AM, Jimmy Lin wrote:
> Hi,
>
> Does anyone has solution for this?
>
> I am doing a simliar thing as well.
>
> I tried to update my 3D Axis object with camera's position by using 
> CullCallBack, but I have flickering problem with mutiple view/camera.
> It seems it's too late to update the node position/matrix at the culling 
> stage, but only cullvisitor able to access eye point.
>
> Is there a way to do this?
>
> Thank you!
>
> Cheers,
> Jimmy
>
> --
> Read this topic online here:
> http://forum.openscenegraph.org/viewtopic.php?p=16318#16318
>
>
>
>
>
> ___
> osg-users mailing list
> osg-users@lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] 3D HUD Elements

2009-08-16 Thread Jimmy Lin
Hi,

Does anyone has solution for this?

I am doing a simliar thing as well.

I tried to update my 3D Axis object with camera's position by using 
CullCallBack, but I have flickering problem with mutiple view/camera. 
It seems it's too late to update the node position/matrix at the culling stage, 
but only cullvisitor able to access eye point.

Is there a way to do this?

Thank you!

Cheers,
Jimmy

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





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


[osg-users] 3D HUD Elements

2009-04-10 Thread Martins Innus

Hello,
	I've got a HUD working great with an osg::Camera attached to the 
scenegraph like in the examples with the orthographic projection, 
POST_RENDER, etc. Now I want to add a simple 3D axis element, like they 
have in modeling software that spins around based on your view and am 
having some trouble.  The best I can do is have it show up as a 
squished, flat shaded blob.  I'm sure someone has done this before, do i 
need a separate camera for 3D hud elements?


Thanks

Martins
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org