第一句:ref_ptr() : _ptr(0) {} 解析:构造函数,把内置变量_ptr置0,用例一般为:osg::ref_ptr<osg::Node> node;这样就用到了这个构造函数 第二句:ref_ptr(T* ptr) : _ptr(ptr) { if (_ptr) _ptr->ref(); } 解析:重载的构造函数,新申请一个T*的指针赋值给_ptr,_ref()表示为内存的计时器...
OSG的智能指针,osg::ref_ptr<> osg::Referenced类管理引用计数内存块,osg::ref_ptr需要使用以它为基类的其它类作为模板参数。 osg::ref_ptr<>类模板重新实现了一系列C++重载符和成员函数,主要有: T* get(): 返回管理的指针, { return _ptr; } T& operator*(): 返回间接引用,{ return *_ptr; } T*...
osg::ref_ptr<osg::Node>createSceneGraph() { //osg::ref_ptr<osg::Node> node = new osg::Node; osg::ref_ptr<osg::Node>node=createGeode(); //osg::ref_ptr<osg::StateSet> state = new osg::StateSet; osg::ref_ptr<osg::StateSet>state=node->getOrCreateStateSet(); state->setMode...
//osg::ref_ptr<osg::Geode> lightPoint = new osg::Geode; osg::ref_ptr<osg::Geode>lightPoint=createLightPoint(); { osg::ref_ptr<osg::MatrixTransform>mt=newosg::MatrixTransform; //osg::Matrix 没有继承Referenced 所以不能用智能指针 osg::Matrixm; osg::ref_ptr<RefMatrix>refM=newosg::R...
osg::ref_ptr<osg::Vec3Array> pVec3Array = new osg::Vec3Array; // 添加四个顶点 pGeometry->setVertexArray(pVec3Array.get()); // 创建四种颜色的数据 osg::ref_ptr<osg::Vec4Array> pVec4Array = new osg::Vec4Array; // 添加四种颜色 ...
OSG的垃圾回收主要是包含两个方面: osg::ref_ptr<>-自动回收内存 和 osg::Referenced-引用计数类. osg::ref_ptr<> osg::ref_ptr<>既可以向c++的普通指针一样使用(operator*(),operator->,operator=()),也有它的高级功能(operator==(), operator!=() , operator!(),valid(),release()). ...
osg::ref_ptr<osg::TessellationHints> hints = new osg::TessellationHints; //设置精度 hints->setDetailRatio(0.1); osg::ref_ptr<osg::ShapeDrawable> shape = new osg::ShapeDrawable(new osg::Box(osg::Vec3(x,y,z),长,宽,高),hints.get()); ...
创建地图节点osg::ref_ptr<osgEarth::Map>map=newosgEarth::Map(mapOpts);osg::ref_ptr<osgEarth::MapNode>mapNode=newosgEarth::MapNode(map);osgEarth::Drivers::GDALOptions gdal;gdal.url()="D:/Work/OSGNewBuild/osgearth-2.10.1/data/world.tif";osg::ref_ptr<osgEarth::ImageLayer>layer=new...
osg::ref_ptr<osg::GraphicsContext> _gc; 34 }; 以上是自己的图形上下文,必须要有这个的存在才能正确的调用到上面提到的两个函数,下面是其使用: 1 int main(int argc, char* argv[]) 2 { 3 MyGraphicsContext gc; 4 if (!gc.valid())
h> #include <osgViewer/Viewer> #include <osgDB/ReadFile> #include <osgUtil/Tessellator> #include <osg/TriangleFunctor> using namespace std; using namespace osg; osg::ref_ptr<osg::Geometry> redPolygon; //计算空间三角形的面积 double CalTriangleArea(const osg::Vec3& a, const osg::Vec3...