使用osg将全球海洋表面风场可视化纹理贴在地球表面,彩色深浅表明风速大小,颜色越趋向红色表明此处风速越大,颜色越趋向蓝色表明风速越小。
#include "createSphere.h"
#include <osg/Group>
#include <osgDB/ReadFile>
#include <osgViewer/Viewer>
#include <osg/TexEnv>
#include <osg/Texture2D>
#include <osg/PositionAttitudeTransform>
#include <iostream>
#ifdef _DEBUG
#pragma comment(lib,"osgDBd.lib");
#pragma comment(lib,"osgViewerd.lib")
#pragma comment(lib,"osgd.lib");
#else
#pragma comment(lib,"osgDB.lib");
#pragma comment(lib,"osgviewer.lib");
#pragma comment(lib,"osg.lib");
#endif
int main()
{
osg::ref_ptr<osg::Group> root = new osg::Group;
osgViewer::Viewer myViewer;
osg::ref_ptr<osg::Texture2D> fogTexture =new osg::Texture2D;
fogTexture->setDataVariance(osg::Object::DYNAMIC);
osg::ref_ptr<osg::Image> smokeImage = osgDB::readImageFile("Image/global_0.01.jpg");
if (!smokeImage.get())
{
std::cout<<"open file is failed!"<<std::endl;
return -1;
}
fogTexture->setImage(smokeImage.get());
osg::ref_ptr<osg::Geode> sphereOne = createSphere(2.0);
osg::ref_ptr<osg::TexEnv> sphereOneTexEnv = new osg::TexEnv;
sphereOneTexEnv->setMode(osg::TexEnv::DECAL);
osg::ref_ptr<osg::StateSet> sphereOneStateSet = new osg::StateSet;
sphereOneStateSet->setAttribute(sphereOneTexEnv.get());
sphereOneStateSet->setAttributeAndModes(fogTexture.get());
sphereOne->setStateSet(sphereOneStateSet.get());
root->setStateSet(sphereOneStateSet.get());
root->addChild(sphereOne.get());
myViewer.setSceneData(root.get());
myViewer.realize();
myViewer.run();
}
效果图:彩色覆盖区域是海洋,黑色区域是陆地