sorry for much truble but i looked and found two ways can not understand how 
they work 

the first way is to use call back :

so i added to the code :


class UpdateCallback : public osg::NodeCallback
{
        virtual void operator()(osg::Node* node, osg::NodeVisitor* nv)
        { 
            std::cout<<"update callback - pre traverse"<<node<<std::endl;
            traverse(node,nv);
            std::cout<<"update callback - post traverse"<<node<<std::endl;
        }
};

and to the main loop :

mt->setUpdateCallback(new UpdateCallback());

but it made no changes. 
 
the second way :

i added to the code :


// Given a Camera, create a wireframe representation of its
// view frustum. Create a default representation if camera==NULL.
osg::Node*
makeFrustumFromCamera( osg::Camera* camera )
{
        osg::Node* loadedMode35 ;
        loadedMode35 = osgDB::readNodeFile("red.3DS");

    // Projection and ModelView matrices
    osg::Matrixd proj;
    osg::Matrixd mv;
    if (camera)
    {
        proj = camera->getProjectionMatrix();
        mv = camera->getViewMatrix();
    }
    else
    {
        // Create some kind of reasonable default Projection matrix.
        proj.makePerspective( 30., 1., 1., 10. );
        // leave mv as identity
    }

    // Get near and far from the Projection matrix.
    const double near = proj(3,2) / (proj(2,2)-1.0);
    const double far = proj(3,2) / (1.0+proj(2,2));

    // Get the sides of the near plane.
    const double nLeft = near * (proj(2,0)-1.0) / proj(0,0);
    const double nRight = near * (1.0+proj(2,0)) / proj(0,0);
    const double nTop = near * (1.0+proj(2,1)) / proj(1,1);
    const double nBottom = near * (proj(2,1)-1.0) / proj(1,1);

    // Get the sides of the far plane.
    const double fLeft = far * (proj(2,0)-1.0) / proj(0,0);
    const double fRight = far * (1.0+proj(2,0)) / proj(0,0);
    const double fTop = far * (1.0+proj(2,1)) / proj(1,1);
    const double fBottom = far * (proj(2,1)-1.0) / proj(1,1);


    // Create parent MatrixTransform to transform the view volume by
    // the inverse ModelView matrix.
    osg::MatrixTransform* mt = new osg::MatrixTransform;
    mt->setMatrix( osg::Matrixd::inverse( mv ) );
    mt->addChild( loadedMode35 );

    return mt;
}
 

and i was suppose to change the loop to :

while (!viewer.done())
    {
        // Update the wireframe frustum
        root->removeChild( 0, 1 );
        root->insertChild( 0, makeFrustumFromCamera(
                viewer.getView( 0 )->getCamera() ) );

        viewer.frame();
    }


but i was not sure what is this suppose to do ??
also i did not find "viewer.getView" function or equivelant to it 


is there some way to help me fix or understand one of the two previous ways or 
is there a way to directly update the node positon from the camira position in 
the loop like using :

osg::NodeCallback* nc = new osg::AnimationPathCallback( 
),osg::Vec3(0.0f,0.0f,1.0f),osg::inDegrees());
    transform->setUpdateCallback(nc);

or transform(x,y,z)
   rotate (h,p,r);

and get it directly from the current camera position matrix ?


please help
--- On Wed, 12/17/08, Vincent Bourdier <[email protected]> wrote:

> From: Vincent Bourdier <[email protected]>
> Subject: Re: [osg-users] current View Point
> To: [email protected], "OpenSceneGraph Users" 
> <[email protected]>
> Date: Wednesday, December 17, 2008, 3:09 AM
> Each frame, you have to update your matrix. For the moment
> you set it, next
> you frame() the viewer, nothing more. Matrix will no update
> itself.
> 
> To update it, do it in the viewer loop (after/before
> frame()), or create a
> new nodeCallback. Have a look on nodeCallback to see how to
> use it.
> 
> Regards,
>    Vincent.
> 
> 2008/12/17 olfat ibrahim <[email protected]>
> 
> > i have two viewers and put the scene in groups one for
> the whole scene and
> > one for the pointer i want to move:
> >
> > osg::Group* root = new osg::Group; // groupp have all
> other objects
> >        osg::Group* Mainroot = new osg::Group; // the
> whole scene
> >        Mainroot->addChild(root);
> >
> > osgViewer::Viewer viewer;
> > osgViewer::Viewer viewer1;
> >
> > //set left camera for left view
> > osg::ref_ptr<osg::Camera> cameraL = new
> osg::Camera;
> > ...
> > // add the matrix transformation
> > osg::MatrixTransform* mt = new osg::MatrixTransform;
> >                 mt->setMatrix(
> cameraL->getViewMatrix() );
> >                 mt->addChild( loadedMode35 );
> >                Mainroot->addChild(mt);
> >
> > viewer.setCameraManipulator(
> keyswitchManipulatorL.get() );
> >
> > //set right camera for the right view
> > osg::ref_ptr<osg::Camera> cameraR = new
> osg::Camera;
> >
> > viewer1.setCameraManipulator(
> keyswitchManipulatorR.get() );
> >
> >
> >
> > //load data for each viewer
> > viewer.setSceneData( root);
> > viewer1.setSceneData( Mainroot);
> >
> >
> > //run the viewer
> > while( !viewer.done() )
> >    {
> >        // fire off the cull and draw traversals of the
> scene.
> >        viewer.frame();
> >        viewer1.frame();
> >
> >    }
> >
> > now the object i used did not move what is the problem
> ??
> >
> > --- On Wed, 12/17/08, Vincent Bourdier
> <[email protected]> wrote:
> >
> > > From: Vincent Bourdier
> <[email protected]>
> > > Subject: Re: [osg-users] current View Point
> > > To: [email protected], "OpenSceneGraph
> Users" <
> > [email protected]>
> > > Date: Wednesday, December 17, 2008, 2:46 AM
> > > Hi,
> > >
> > > Please, make replies to your posts ! do not make
> a new
> > > thread each time ...
> > > If you reply to your post, we will have all the
> mailing
> > > history of this
> > > question, and we can see the evolution of the
> problem.
> > >
> > > Next, just with this code, we cannot see what the
> problem
> > > is.
> > > Tell us what is good in your code, what you want
> to do with
> > > this code...
> > >
> > > For your problem : maybe it works, but you need a
> callback
> > > or a loop to see
> > > the matrix changing in real-time... Not easy to
> understand
> > > this little peace
> > > of code without more explanations.
> > >
> > > Regards,
> > >    Vincent.
> > >
> > > 2008/12/16 olfat ibrahim
> <[email protected]>
> > >
> > > > hi :
> > > >
> > > > iam creating a program that have two windows
> one i
> > > make a drive in it and
> > > > the other is like a map i want to put
> indecator in the
> > > 2nd window that
> > > > indicate my current position in the first
> one
> > > >
> > > > i used the following code but nothing
> happend:
> > > >
> > > >
> > > > // Projection and ModelView matrices
> > > >    osg::Matrixd proj;
> > > >    osg::Matrixd mv;
> > > > ...
> > > > proj = cameraL->getProjectionMatrix();
> > > >
> > > >  mv = cameraL->getViewMatrix();
> > > >                // Create parent
> MatrixTransform to
> > > transform the view
> > > > volume by
> > > >                // the inverse ModelView
> matrix.
> > > >                osg::MatrixTransform* mt =
> new
> > > osg::MatrixTransform;
> > > >                mt->setMatrix(
> > > osg::Matrixd::inverse( mv ) );
> > > >                mt->addChild( loadedMode35
> );
> > > >                Mainroot->addChild(mt);
> > > >
> > > > ...
> > > >
> > > >
> > > > can some one tell me where iam going wrong
> ??
> > > >
> > > >
> > > > tahnks
> > > >
> > > >
> > > >
> > > >
> > > >
> _______________________________________________
> > > > osg-users mailing list
> > > > [email protected]
> > > >
> > >
> >
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
> > > >
> >
> >
> >
> > _______________________________________________
> > osg-users mailing list
> > [email protected]
> >
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
> >


      
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to