[osg-users] Problem with setProjectionMatrixAsFrustum()
Hi Everyone, im having some trouble setting up a frustum view. i used the following code: Code: viewer.getCamera()-setProjectionMatrixAsFrustum(-640, 640, -480, 480, 1900, 20); and i queried the frustum with: Code: viewer.getCamera()-getProjectionMatrixAsFrustum(a, b, c, d, e, f); But im getting 1448.3 for all these values! Also, i placed an object at 0, 0, -1000 in world space, which is lesser that the near clip plane. But the object was still visible. im not able to understand why this is happening. Could anyone please explain what mistake im doing? Thanks, Mukund -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=36277#36277 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Problem with setProjectionMatrixAsFrustum()
Well, i saw a similar post in the forum. http://forum.openscenegraph.org/viewtopic.php?t=1780 So, my first query is clear. Well as for my second one. How is it the object is being projected if it is even placed before the near-clip plane? ie before 1900? i could not get this part. Thanks, Mukund -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=36294#36294 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Problem with setProjectionMatrixAsFrustum()
Hi Mukund, So, my first query is clear. Well as for my second one. How is it the object is being projected if it is even placed before the near-clip plane? ie before 1900? i could not get this part. Do you have a camera manipulator attached to your viewer? Even if you don't create one yourself, some usage models of osgViewer will create a TrackballManipulator for you. Whether the object is in view does not just depend on the projection matrix, it also depends on the view matrix. If you set up your projection matrix like you said, but your view matrix is identity except for a translation by (0, -2000, -1000), then you will still see your node. And by default, on first frame, the default camera manipulator will do just that - change the view matrix so that the whole scene is visible... So if you want total control over camera placement and projection, remove the camera manipulator. And if you want to see why your node is visible, check the view matrix of your camera after a few frames in the debugger... Hope this helps, J-S -- __ Jean-Sebastien Guayjean-sebastien.g...@cm-labs.com http://www.cm-labs.com/ http://whitestar02.webhop.org/ ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Problem with setProjectionMatrixAsFrustum()
this is a test ! thank you 2011/2/2 Jean-Sébastien Guay jean-sebastien.g...@cm-labs.com Hi Mukund, So, my first query is clear. Well as for my second one. How is it the object is being projected if it is even placed before the near-clip plane? ie before 1900? i could not get this part. Do you have a camera manipulator attached to your viewer? Even if you don't create one yourself, some usage models of osgViewer will create a TrackballManipulator for you. Whether the object is in view does not just depend on the projection matrix, it also depends on the view matrix. If you set up your projection matrix like you said, but your view matrix is identity except for a translation by (0, -2000, -1000), then you will still see your node. And by default, on first frame, the default camera manipulator will do just that - change the view matrix so that the whole scene is visible... So if you want total control over camera placement and projection, remove the camera manipulator. And if you want to see why your node is visible, check the view matrix of your camera after a few frames in the debugger... Hope this helps, J-S -- __ Jean-Sebastien Guayjean-sebastien.g...@cm-labs.com http://www.cm-labs.com/ http://whitestar02.webhop.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] Problem with setProjectionMatrixAsFrustum()
Hi J-S, Thanks for the reply. Well, im not using a camera manipulator. This is what im doing: Code: int main() { // code here viewer.getCamera()-setProjectionMatrixAsFrustum(-640, 640, -480, 480, 1900, 20); osg::Matrix t; t.makeTranslate(osg::Vec3(0, 0, -1000)); //translate by 1000 while (!viewer.done()) { viewer.getCamera()-setViewMatrix( t ); // Draw the next frame. viewer.frame(); } return 0; } Now, i tried this: Inside the while loop, i gave Code: viewer.getCamera()-setViewMatrix(osg::Matrix::identity()); Now, isn't this equivalent to Code: glMatrixMode(GL_MODELVIEW); glLoadIdentity(); And i drew a line from (-640, 0, -1800) to (640, 0, -1800). But it is visible! Could you please comment? Thanks, Mukund -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=36298#36298 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Problem with setProjectionMatrixAsFrustum()
Hello Mukund, There are two factors here: your setting the frustum, and OSG's compute near-far mode. First, since you are calling setProjectionMatrixAsFrustum yourself, you are resetting the coordinate system to be Y-up, with the Z axis going out of the screen. So when you make a line that goes from -640,0,-1800 to 640,0,-1800 and you set up your camera with the identity matrix, you are looking along the -Z axis, so your far plane actually starts at -1900 in world space: (0,0,0) + (0,0,1900) dot (0,0,-1) If you change your camera to look along the +Z axis, or you change your line to be at Z=1800 instead of -1800 you won't see it anymore, so that confirms that this first part is what's happening (I've just tried it in a small test app). The second part is that by default, OSG recomputes the camera's near and far planes so that the scene is in view and do not use up too much depth buffer precision. There are ways to tune this, look at the osg::CullSettings class which osg::Camera inherits. But in your case, if you just want to not see your line (because it's closer to the camera than the near plane, and you want that near plane to stay set the way you've set it), do this before your frame loop: viewer.getCamera()-setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR); Then, as expected, you won't see your line. See the osgthirdpersonview example for a demo of OSG's compute near far functionality in action. Also it's a cool way to view your frustum and be able to debug this kind of thing. I kind of think if you'd have tried a few things and tried your app in a debugger, you would have been able to find this out on your own. The mailing list or forum archives are very useful (the compute near far thing comes up really often). Also printing the result of camera-getProjectionMatrixAsFrustum() in your frame loop would have shown that the near and far values had been changed, and you would have probably gone looking for what had changed them (data breakpoints in a debugger can help there). Hope this helps, J-S -- __ Jean-Sebastien Guayjean-sebastien.g...@cm-labs.com http://www.cm-labs.com/ http://whitestar02.webhop.org/ ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Problem with setProjectionMatrixAsFrustum()
Hi J-S, But in your case, if you just want to not see your line (because it's closer to the camera than the near plane, and you want that near plane to stay set the way you've set it), do this before your frame loop: viewer.getCamera()-setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR); Just what i was looking for. Thanks! I kind of think if you'd have tried a few things and tried your app in a debugger, you would have been able to find this out on your own. Well, i tried using the Visual Studio debugger to inspect the matrix values after retrieving them into an osg::Matrix variable. But that didn't help much. Could you kindly give some references on these basic issues involved? The only material i have now is the web and the OSG QuickStartGuide. PS: Is there a glDrawPixels() equivalent in OSG? Thank you! Cheers, Mukund -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=36300#36300 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Problem with setProjectionMatrixAsFrustum()
Hi Mukund, Well, i tried using the Visual Studio debugger to inspect the matrix values after retrieving them into an osg::Matrix variable. But that didn't help much. No, I said do a getProjectionMatrixAsFrustum() and inspect the result. For example: double left, right, top, bottom, zNear, zFar; viewer.getCamera()-getProjectionMatrixAsFrustum(left, right, bottom, top, zNear, zFar); osg::notify(osg::ALWAYS) Frustum is left , right , bottom , top , zNear , zFar std::endl; That would have told you that the near and far values had changed from what you had set them to. Getting the matrix is not much help, because the calculations involved in making a projection matrix from those recognizable values make the matrix values themselves hard to interpret... See this site for example: http://www.songho.ca/opengl/gl_projectionmatrix.html And again, you could have found this with a simple google search. Could you kindly give some references on these basic issues involved? The only material i have now is the web and the OSG QuickStartGuide. Oh come on... Check the OSG website, you'll have a wealth of links to read. In the documentation section there are tutorials, in the community section there are links to the mailing list archives, and you can search the forum too... Show a little initiative, we won't be there to give you all the answers all the time! PS: Is there a glDrawPixels() equivalent in OSG? Do some searching, you'll find out it's extremely slow. If you still want to use it, search for drawable drawImplementation or drawCallback (hint: OSG website, Documentation, Reference documentation, Classes, look for osg::Drawable), in which you can use plain OpenGL code. Hope this helps, J-S -- __ Jean-Sebastien Guayjean-sebastien.g...@cm-labs.com http://www.cm-labs.com/ http://whitestar02.webhop.org/ ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Problem with setProjectionMatrixAsFrustum()
Hi J-S, Thanks a lot for the reply. You have been of great help. Show a little initiative, we won't be there to give you all the answers all the time! Sure. i think i have been a little lazy! i will do a thorough search in future, before asking any questions. Thanks a lot for the support. Its been really helpful Mukund -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=36312#36312 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org