第一句: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::Node> pNode = 0; // 添加模型 { // osgDB::Options* a = new osgDB::Options(std::string("noTriStripPolygons")); // osg::ref_ptr<osg::Node> node1 = osgDB::readNodeFile("D:/qtProject/osgDemo/modelData/grass.obj", a); ...
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::ShapeDrawable> shape = new osg::ShapeDrawable(new osg::Box(osg::Vec3(x,y,z),长,宽,高),hints.get()); geode->addDrawable(shape); TessellationHints(精度)参数对圆柱几何的影响以及shapedrawable继承关系: ! 自定义几何体时: ...
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...
osg::ref_ptr<osg::Node> model = osgDB::readNodeFile("path_to_model/cessna.osg"); if (!model) { // 处理模型加载失败的情况 } 步骤2:调整光照 // 假设root是场景图的根节点 // 确保模型使用root的光源 model->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::ON); // 如果...
osg::ref_ptr<osg::GraphicsContext> _gc; 34 }; 以上是自己的图形上下文,必须要有这个的存在才能正确的调用到上面提到的两个函数,下面是其使用: 1 int main(int argc, char* argv[]) 2 { 3 MyGraphicsContext gc; 4 if (!gc.valid())