osgearth天空盒加载光照和星空

osgearth折腾半天,合着就是几行代码的事

	osgEarth::DateTime dateTime(2019, 5, 8, 9);
	osgEarth::Util::Ephemeris* ephemeris = new osgEarth::Util::Ephemeris;
 
	osgEarth::Util::SkyNode* m_pSkyNode = osgEarth::Util::SkyNode::create(mapNode);
	m_pSkyNode->setName("SkyNode");
	m_pSkyNode->setEphemeris(ephemeris);
	m_pSkyNode->setDateTime(dateTime);
	m_pSkyNode->attach(viewer, 0);
	m_pSkyNode->setLighting(true);
	m_pSkyNode->addChild(mapNode);
	root->addChild(m_pSkyNode);
 
	return viewer->run();

下面是demo的代码

#include 
#include 
#include 
#include 
#include 
#include 
 
#include 
#include 
#include 
 
#include 
#include 
 
using namespace std;
 
#ifdef _DEBUG
#pragma comment(lib,"OpenThreadsd.lib")
#pragma comment(lib,"osgd.lib")
#pragma comment(lib,"osgDBd.lib")
#pragma comment(lib,"osgGAd.lib")
#pragma comment(lib,"osgViewerd.lib")
#pragma comment(lib,"osgEarthd.lib")
#pragma comment(lib,"osgEarthUtild.lib")
#else
#pragma comment(lib,"OpenThreads.lib")
#pragma comment(lib,"osg.lib")
#pragma comment(lib,"osgDB.lib")
#pragma comment(lib,"osgGA.lib")
#pragma comment(lib,"osgViewer.lib")
#pragma comment(lib,"osgEarth.lib")
#pragma comment(lib,"osgEarthUtil.lib")
#endif
 
using namespace osgEarth;
using namespace osgEarth::Util;
 
int main(int argc, char* argv[])
{
	osg::ref_ptr viewer = new osgViewer::Viewer();
	//定义根节点
	//osg::Group* root = new osg::Group();
	osg::ref_ptr root = new osg::Group();	//智能指针方式
	osg::ref_ptr earthNode = osgDB::readNodeFile("gdal_tiff.earth");
	if (!earthNode)
	{
		OE_NOTICE << "Unable to load earth model" << std::endl;
		return 1;
	}
	root->addChild(earthNode);
	//查询地图节点
	osgEarth::MapNode* mapNode = osgEarth::MapNode::findMapNode(earthNode);
	if (!mapNode)
	{
		OE_NOTICE << "Could not find MapNode " << std::endl;
		return 1;
	}
	//添加到场景
	viewer->setSceneData(root.get());
	viewer->realize();
	// 设置时间;
	osgEarth::DateTime dateTime(2019, 5, 8, 9);
	osgEarth::Util::Ephemeris* ephemeris = new osgEarth::Util::Ephemeris;
 
	osgEarth::Util::SkyNode* m_pSkyNode = osgEarth::Util::SkyNode::create(mapNode);
	m_pSkyNode->setName("SkyNode");
	m_pSkyNode->setEphemeris(ephemeris);
	m_pSkyNode->setDateTime(dateTime);
	m_pSkyNode->attach(viewer, 0);
	m_pSkyNode->setLighting(true);
	m_pSkyNode->addChild(mapNode);
	root->addChild(m_pSkyNode);
 
	return viewer->run();
}

你可能感兴趣的:(osgearth天空盒加载光照和星空)