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=9172&highlight=
>
> 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.
------------------------
ohhhhhhhhhhhhhh newbie to OSG......................
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=52471#52471
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org