Re: [osg-users] How to acquire the screen coordinates of a 3D object?
And here are the contents of matrices: The viewMatrix is 1.00 0.00 0.00 0.00 0.00 1.00 0.00 0.00 0.00 0.00 1.00 0.00 0.00 0.00 0.00 1.00 The projectionMatrix is 2.403846 0.00 0.00 0.00 0.00 3.846154 0.00 0.00 0.00 0.00 -1.000200 -1.00 0.00 0.00 -2.000200 0.00 The projectionMatrix is 840.00 0.00 0.00 0.00 0.00 525.00 0.00 0.00 0.00 0.00 0.50 0.00 0.00 525.00 0.50 1.00 Anything wrong with these matrices? Thank you! Cheers, Fan -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=52533#52533 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] How to acquire the screen coordinates of a 3D object?
Thank you so much! Best regards, Fan On Fri, Feb 8, 2013 at 2:16 AM, Shayne Tueller shayne.tuel...@hill.af.milwrote: It looks like you forgot to concatenate the window matrix from the Viewport object onto the MVPW matrix in what you call the automatic version. You also need to remove the matrix mutiply of the window matrix with the screenPosition4d object. This should not happen after the perspective divide. Look again closely at the orginal code snippet you used for your automatic version to see the error. I think it would be helpful for you to understand the OpenGL transformation pipeline since that is what the OSG is using under the hood. Paul Martz does a great job of explaining this in his book. http://www.opengldistilled.com/ Shayne -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=52475#52475 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org -- Fan ZHANG ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] How to acquire the screen coordinates of a 3D object?
S2LR wrote: If you're new to the OSG, it is really helpful to look at the examples and also search the OSG forums for the problems you're looking for. Many of the questions most new folks ask, have already been addressed and answered in the forum. Hopefully the link below will help you... http://forum.openscenegraph.org/viewtopic.php?t=9172highlight= Shayne Thank you so much for your kindly remind and reply, I will see to it next time. Sorry to disturb you all again, because the result I got was quite strange: Before transformation, the original coordinates of CityGML are X 3450462.314718, Y 5430520.143368, Z 8.289120 After automatically transformation, the coordinates are X -840532249.575058, Y -1322874921.178542 After manually transformation, the coordinates are X -840532249.575058, Y -1322874921.178542, Z 1.120752 Before transformation, the original coordinates of CityGML are X 3450398.833305, Y 5430561.272085, Z 11.772124 After automatically transformation, the coordinates are X -591833875.402660, Y -931484454.045872 After manually transformation, the coordinates are X -591833875.402660, Y -931484454.045872, Z 1.085055 Firstly I load a CityGML dataset and then acquire some of the 3D point information. Automatically and manually are just two names I set, but in fact the same, just to compare the result. Here is the manual one: Code: osg::Matrix local2worldMatrix; osg::MatrixList list = root-getWorldMatrices(); for(osg::MatrixList::iterator it = list.begin(); it != list.end(); ++it) {local2worldMatrix = local2worldMatrix*(*it);}//For loading one model, this step is not necessary actually osg::Matrix finalMatrix;//the final MVPW matrix osg::Matrix viewMatrix = cam-getViewMatrix(); osg::Matrix projectionMatrix = cam-getProjectionMatrix(); osg::Matrix windowMatrix = cam-getViewport()-computeWindowMatrix(); finalMatrix = local2worldMatrix*viewMatrix*projectionMatrix*windowMatrix; And here is the automatic one I got from the link in reply above: Code: osg::Vec2d worldToScreen(const osg::Vec3d worldPosition, const osg::Camera* pCamera) { osg::Vec2d screenPosition; osg::Matrixd MVPW = pCamera-getViewMatrix() * pCamera-getProjectionMatrix(); osg::Vec4d screenPosition4d = osg::Vec4d(worldPosition, 1.0) * MVPW; screenPosition4d = screenPosition4d / screenPosition4d.w(); screenPosition4d = screenPosition4d*pCamera-getViewport()-computeWindowMatrix(); //screenPosition4d.y() = pCamera-getViewport()-height() - screenPosition4d.y(); screenPosition.set(screenPosition4d.x(), screenPosition4d.y()); return screenPosition; } Actually no big difference. I think I've missed one important step some where. But I really don't know why. Perhaps it is because the camera is just viewer.getCamera(). Then how can I deal with it? Thanks a lot in advance. ohh newbie to OSG.. -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=52471#52471 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] How to acquire the screen coordinates of a 3D object?
It looks like you forgot to concatenate the window matrix from the Viewport object onto the MVPW matrix in what you call the automatic version. You also need to remove the matrix mutiply of the window matrix with the screenPosition4d object. This should not happen after the perspective divide. Look again closely at the orginal code snippet you used for your automatic version to see the error. I think it would be helpful for you to understand the OpenGL transformation pipeline since that is what the OSG is using under the hood. Paul Martz does a great job of explaining this in his book. http://www.opengldistilled.com/ Shayne -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=52475#52475 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
[osg-users] How to acquire the screen coordinates of a 3D object?
Hi all, I want to know how to acquire the screen coordinates of a 3D object? posi is a Vec3 containing the coordinates information in WCS. Then I tried: osgViewer::Viewer viewer; osg::Camera* cam = viewer.getCamera(); osg::Matrix viewMatrix = cam-getViewMatrix(); posi = posi*viewMatrix; osg::Matrix projectionMatrix = cam-getProjectionMatrix(); posi = posi*projectionMatrix; Staring here, the codes do not work anymore: osg::Matrix windowMatrix = cam-getViewport()-computeWindowMatrix(); posi = posi*windowMatrix; Here the posi is supposed to be the right screen coordinates but it just does not work. Then how can I do with this? Sorry for this simple post but I don't know very well about OpenGL and OSG, and this question already occupied me two days. So thanks in advance for anyone who gives me a reply! ... Thank you! Cheers, Fan ohh newbie to OSG.. -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=52304#52304 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] How to acquire the screen coordinates of a 3D object?
If you're new to the OSG, it is really helpful to look at the examples and also search the OSG forums for the problems you're looking for. Many of the questions most new folks ask, have already been addressed and answered in the forum. Hopefully the link below will help you... http://forum.openscenegraph.org/viewtopic.php?t=9172highlight= Shayne -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=52305#52305 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org