TA的每日心情 | 奋斗 2019-11-7 20:26 |
---|
签到天数: 6 天 [LV.2]偶尔看看I
|
osgearth添加了星空背景和光照,在加入模型之后,视角移动到某些位置会出现地球消失的问题
代码如下,求大佬指点
#include "stdafx.h"
int main()
{
osg::ref_ptr<osgViewer::Viewer> viewer = new osgViewer::Viewer;
osg::ref_ptr<osg::Group> root = new osg::Group;
osg::ref_ptr<osg::Node> earthNode = osgDB::readNodeFile("gdal_tiff.earth");
osg::ref_ptr<osgEarth::MapNode> mapNode = osgEarth::MapNode::findMapNode(earthNode);
osg::ref_ptr<osgEarth::Util::EarthManipulator> em = new osgEarth::Util::EarthManipulator;
em->getSettings()->setArcViewpointTransitions(true);
viewer->setCameraManipulator(em);
//root->addChild(mapNode); //同时加载mapNode和m_pSkyNode会出现瓦片闪烁
if(mapNode.valid()) em->setNode(mapNode);
//设置星空,添加光照
{
osgEarth::Config skyConf;
double hours = skyConf.value("hours", 6.0);
osgEarth:ateTime dateTime(2020, 8, 29, hours);
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, 1);
m_pSkyNode->setLighting(true);
m_pSkyNode->addChild(mapNode);
root->addChild(m_pSkyNode);
}
//添加一个模型
{
const osgEarth::SpatialReference* geoSRS = mapNode->getMapSRS()->getGeographicSRS();
osg::Node* model = osgDB::readNodeFile("cow.osg");
model->getOrCreateStateSet()->setMode(GL_RESCALE_NORMAL, osg::StateAttribute::ON);
osg::Matrix Lmatrix;
geoSRS->getEllipsoid()->computeLocalToWorldTransformFromLatLongHeight(
osg::DegreesToRadians(40.0),
osg::DegreesToRadians(116.0),
100000.0, Lmatrix);
Lmatrix.preMult(osg::Matrix::scale(osg::Vec3(10000, 10000, 10000)));
osg::MatrixTransform* mt = new osg::MatrixTransform;
mt->setMatrix(Lmatrix);
mt->addChild(model);
root->addChild(mt);
}
viewer->setSceneData(root.get());
viewer->run();
return 0;
}
/*************************************/
// stdafx.h : 标准系统包含文件的包含文件,
// 或是经常使用但不常更改的
// 特定于项目的包含文件
//
#pragma once
#include <stdio.h>
#include <tchar.h>
#include <vector>
#include <iostream>
#include <fstream>
#include <cstring>
#include <time.h>
#include <Windows.h>
#include <assert.h>
// TODO: 在此处引用程序需要的其他头文件
#include <osgViewer/Viewer>
#include <osgViewer/CompositeViewer>
#include <osg/Node>
#include <osg/Geode>
#include <osg/Group>
#include <osg/MatrixTransform>
#include <osg/CoordinateSystemNode>
#include <osg/ComputeBoundsVisitor>
#include <osgDB/ReadFile>
#include <osgDB/writefile>
#include <osgGA/CameraManipulator>
#include <osgGA/GUIEventHandler>
#include <osgGA/KeySwitchMatrixManipulator>
#include <osgGA/StateSetManipulator>
#include <osgUtil/LineSegmentIntersector>
#include <osgUtil/optimizer>
#include <osgEarth/Utils>
#include <osgEarth/MapNode>
#include <osgEarth/Viewpoint>
#include <osgEarth/GeoData>
#include <osgEarth/ImageLayer>
#include <osgEarthUtil/Controls>
#include <osgEarthAnnotation/PlaceNode>
#include <osgEarthUtil/EarthManipulator>
#include <osgEarthUtil/AutoClipPlaneHandler> //解决裁剪面问题
//#include <osgEarthUtil/SkyNode> 包含会出错,“osgEarth::Util::SkyNode”:“class”类型重定义,osgEarthUtil/Sky和osgEarthUtil/SkyNode
#include <osgEarthUtil/ExampleResources>
#include <osgEarthDrivers/model_simple/SimpleModelOptions>
using namespace std;
using namespace osgEarth;
using namespace osgEarth::Util; |
|