Boris, Attached is a code snippet that moves a simple sky dome model (based on the skydome.osg file) with the eye on a spheroid. The sky dome is centered over the eye. The manipulator viewpoint (eye) is initially positioned on an earth-like spheroid at a given lat/lon/elevation and then you can use the manipulator to move around from that location. I chose to use the TerrainManipulator in this case.
I may have inadvertently left some stuff out of the code since I cut and pasted it out of my original app. If I did, please accept my apologies. Hopefully there's enough code there to get you going... Regards, -Shayne -----Original Message----- From: [email protected] [mailto:[email protected]] On Behalf Of Boris Baljak Sent: Friday, July 17, 2009 9:11 AM To: [email protected] Subject: [osg-users] Skydome Hi, First I must say that I'm still currently learning OpenSceneGraph, although I'm already familiar with scene graphs since I also use Coin3D. However I need to use a skydome in a 3D visualization application which is built upon OSG. My main problem is that there is no 'simple' skydome example around the web using OpenSceneGraph. I know there is osgOcean, which has a nice skydome, however my computer does not support OpenGL shaders, so osgOcean does not work and its SkyDome class does use shaders which make its extraction from osgOcean impossible. Same for osgEphemeris, though I could use its SkyDome class which does not use shaders directly, its extraction and importation in my app seems far too complex for me to handle (I tried it and was unsuccessful). My last hope was to use the osghangglide skydome, however it's supposed to be used with the specific GliderManipulator class and does not work with the standard TrackballManipulator which I need to use... I also see that there is a skydome.osg asset in OSG data files, but could not find any source code using it anywhere. So if anyone has another solution, or could post here some simple skydome code working with a TrackballManipulator, I would really appreciate the help. ------------------ Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=15087#15087 _______________________________________________ osg-users mailing list [email protected] http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
#include <osgViewer/CompositeViewer>
#include <osgGA/TerrainManipulator>
#include <osgGA/MatrixManipulator>
#include <osg/Group>
#include <osg/Node>
.
.
.
osg::EllipsoidModel *earth;
osg::Group *root;
osgViewer::CompositeViewer viewer;
osgViewer::View *view;
class MoveSkyWithEyePointTransform : public osg::Transform
{
public:
MoveSkyWithEyePointTransform()
{
skyscale = 6.0;
skycenterx = skyscale * 26380.0;
skycentery = skyscale * 37684.0;
}
virtual bool computeLocalToWorldMatrix(osg::Matrix & matrix,
osg::NodeVisitor* nv) const
{
osgUtil::CullVisitor* cv =
dynamic_cast<osgUtil::CullVisitor*>(nv);
if (cv)
{
osg::Vec3d eyePointLocal = cv->getEyeLocal();
osg::Matrixd lclm;
// earth is osg::EllipsoidModel*
earth->computeLocalToWorldTransformFromXYZ(eyePointLocal.x(),
eyePointLocal.y(),
eyePointLocal.z(), lclm);
matrix.preMult(osg::Matrix::scale(skyscale, skyscale,
skyscale) *
osg::Matrix::translate(-skycenterx, -skycentery, -10000.0) * lclm);
}
return true;
}
double skyscale;
double skycenterx;
double skycentery;
};
int main()
{
root = new osg::Group;
earth = new osg::EllipsoidModel();
view = new osgViewer::View;
osg::Node *skyNode = osgDB::readNodeFile("skydome.osg");
osg::Transform* skytransform = new MoveSkyWithEyePointTransform;
skytransform->setCullingActive(false);
skytransform->addChild(skyNode);
root->addChild(skytransform);
view->setCameraManipulator(new osgGA::TerrainManipulator);
.
.
.
view->setSceneData(root);
viewer->addView(view);
viewer->realize();
// position the manipulator camera at a lat/lon/elev on the spheroid
looking down
osgGA::MatrixManipulator *tm;
osg::Matrixd matrix;
earth->computeLocalToWorldTransformFromLatLongHeight(osg::DegreesToRadians(latitude),
osg::DegreesToRadians(longitude),
altitude, matrix);
tm = view->getCameraManipulator();
tm->setByMatrix(matrix);
while (!viewer.done())
{
viewer.frame();
}
return 0;
}
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________ osg-users mailing list [email protected] http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

