Re: [osg-users] current View Point
Have a look on the Third person view example... You get your code from it, and this example works well, so you should use it a base code, and modify it to have what you are looking for. You will be able to reply yourself I think. 2008/12/17 olfat ibrahim > 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"<traverse(node,nv); >std::cout<<"update callback - post traverse"<} > }; > > 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 wrote: > > > From: Vincent Bourdier > > Subject: Re: [osg-users] current View Point > > To: olfat_ibra...@yahoo.com, "OpenSceneGraph Users" < > osg-users@lists.openscenegraph.org> > > 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 > > > > > 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; //
Re: [osg-users] current View Point
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"<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 wrote: > From: Vincent Bourdier > Subject: Re: [osg-users] current View Point > To: olfat_ibra...@yahoo.com, "OpenSceneGraph Users" > > 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 > > > 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 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 cameraR = new > osg::Camera; > > > > viewer1.setCameraManipulator( > keyswitchManipulatorR.get() ); > > > > > > > > //load data for each viewer > > viewer.setSceneData( root); > > viewer1.setSceneData( Mainroot); > > > > > > //run the vie
Re: [osg-users] current View Point
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 > 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 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 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 wrote: > > > From: Vincent Bourdier > > Subject: Re: [osg-users] current View Point > > To: olfat_ibra...@yahoo.com, "OpenSceneGraph Users" < > osg-users@lists.openscenegraph.org> > > 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 > > > > > 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 > > > 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] current View Point
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 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 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 wrote: > From: Vincent Bourdier > Subject: Re: [osg-users] current View Point > To: olfat_ibra...@yahoo.com, "OpenSceneGraph Users" > > 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 > > > 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 > > 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] current View Point
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 > 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 > 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] current View Point
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 osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] current View Point
Hi, Please, answer to all the list. Be careful with list management. If it is not well used, you won't be helped. You must be member of the list to get the replies. Have a look on osgCompositeViewer example, and osgthirdpersonview example to see how to manage different views and see where the camera is from in the scene from an other view. Vincent. 2008/12/16 olfat ibrahim > > 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 > > forgive my poshing but iam a new osg programer just switched from OpenGL > performer so the things mixed up with me a little can you at least recommend > a certai toutorial or a certain example > > tahnks > > --- On Tue, 12/16/08, Vincent Bourdier wrote: > > > From: Vincent Bourdier > > Subject: Re: [osg-users] current View Point > > To: olfat_ibra...@yahoo.com, "OpenSceneGraph Users" < > osg-users@lists.openscenegraph.org> > > Date: Tuesday, December 16, 2008, 4:50 AM > > Hi, > > > > Please do not make a new thread each time... just reply the > > first one. > > > > Next, you can make some search on the mailing list > > archives... a lot of > > things are now resolved in it. > > > > Last, you can get the camera position with the camera > > manipulator : > > getMatrix or getInverseMatrix method. With this matrix, you > > can get the > > center, up and front vectors. > > > > Regards, > > Vincent. > > > > 2008/12/16 olfat ibrahim > > > > > i need the function to get the current view point ?? > > > can any one help me? > > > > > > > > > > > > ___ > > > 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] current View Point
I would suggest working through these tutorials http://www.openscenegraph.org/projects/osg/wiki/Support/Tutorials Also try looking at the 130 odd examples in the examples direcotry And reading http://www.osgbooks.com/books/osg_qs.html Capture the magic of Christmas this year see http://www.capturethemagic.com __ Gordon Tomlinson gor...@gordontomlinson.com IM: gordon3db...@3dscenegraph.com www.vis-sim.com www.gordontomlinson.com __ -Original Message- From: osg-users-boun...@lists.openscenegraph.org [mailto:osg-users-boun...@lists.openscenegraph.org] On Behalf Of olfat ibrahim Sent: Tuesday, December 16, 2008 9:42 AM To: OSG Subject: [osg-users] current View Point i need the function to get the current view point ?? can any one help me? ___ 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] current View Point
Hi, Please do not make a new thread each time... just reply the first one. Next, you can make some search on the mailing list archives... a lot of things are now resolved in it. Last, you can get the camera position with the camera manipulator : getMatrix or getInverseMatrix method. With this matrix, you can get the center, up and front vectors. Regards, Vincent. 2008/12/16 olfat ibrahim > i need the function to get the current view point ?? > can any one help me? > > > > ___ > 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] current View Point
i need the function to get the current view point ?? can any one help me? ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org