#include <osg/Node>node
typedef std::vector<Node*> NodePath;
typedef std::vector<NodePath> NodePathList;
typedef std::vector<Matrix> MatrixList;
class OSG_EXPORT Node : public Object{ public:
Node();
Node(const Node&, const CopyOp& copyop = CopyOp::SHALLOW_COPY);
virtual Object* cloneType() const {return new Node();}
virtual Object* clone(const CopyOp& copyop) const {return new Node(*this, copyop);}
virtual bool isSamKindAs(const Object* obj) const {return dynamic_cast<const Node*>(obj) != NULL;}
virtual const char* libraryName() const {return "osg";}
virtual const char* className() const {return "Node";}
virtual Node* asNode() {return this;}
virtual const Node* asNode() const {return this;}
virtual Drawable* asDrawable() {return 0;}
virtual const Drawable* asDrawable() const {return 0;}
virtual Geometry* asGeometry() {return 0;}
virtual const Geometry* asGeometry() const {return 0;}
virtual Group* asGroup() {return 0;}
virtual const Group* asGroup() const {return 0;}
virtual Transform* asTransform() {return 0;}
virtual const Transform* asTransform() const {return 0;}
virtual Camera* asCamera() {return 0;}
virtual const Camera* asCamera() const {return 0;}
virtual Switch* asSwitch() {return 0;}
virtual cosnt Switch* asSwitch() const {return 0;}
virtual Geode* asGeode() {return 0;}
virtual const Geode* asGeode() const {return 0;}
virtual osgTerrain::Terrain* asTerrain() {return 0;}
virtual void accept(NodeVisitor& nv);
virtual void ascend(NodeVisitor& nv);
virtual void traverse(NodeVisitor& /*nv*/){}
typedef std::vector<Group*> ParentList;
inline const ParentList& getParents() const {return _parents;}
inline ParentList getParents() {return _parents;}
inline Group* getParent(unsigned int i) {return _parents[i];}
inline const Group* getParent(unsigned int i) const {return _parents[i];}
inline unsigned int getNumParents() const {return static_cast<unsigned int> (_parents.size());}
NodePathList getParentalNodePaths(osg::Node* haltTraversalAtNode = 0) const;
Matrixlist getWorldMatrices(const osg::Node* haltTraversalAtNode = 0) const;
void setUpdateCallback(Callback* nc);
inline Callback* getUpdateCallback() {return _updateCallback.get();}
inline const Callback* getUpdateCallback() const {return _updateCallback.get();}
inline void addUpdateCallback(Callback* nc){
if(nc != NULL){
if(_updateCallback.valid())
_updateCallback->addNestedCallback(nc);
ele
setUpdateCallback(nc);
}
}
inline void removeUpdateCallback(Callback* nc){
if(nc != NULL && _updateCallback.valid()){
if(_updateCallback == nc)
{
ref_ptr<osg::Callback> new_nested_callback = nc->getNestedCallback();
nc->setNestedCallback(0);
setUpdateCallback(new_nested_callback.get());
}
else
_updateCallback->remvoeNestedCallback(nc);
}
}
inline unsigned int getNumChildrenRequiringUpdateTraversal() const {return _numChildrenRequiringUpdateTraversal;}
void setEvent
typedef std::vector<Group*> ParentList; // 返回父節點的列表 const ParentList& getParents() const; // 返回指定索引處父節點的指針 Group* getParent(unsigned int I); // 返回父節點的數目 unsigned int getNumParents() const; };
osg::Group 組節點類能夠向下繼承有多個 osg::Group 子節點 ,也能夠有多個 osg::Geode 子節點函數
#include <osg/Group>性能
class OSG_EXPORT Group : public Node{ public:
Group();
Group(const Group&, const CopyOp& copyop = CopyOp::SHALLOW_COPY)
META_Node(osg, Group);
virtual Group* asGroup()
virtual const Group* asGroup() consst
virtual void traverse(NodeVisitor& nv)
// 添加一個子節點 bool addChild(Node* child);
//向指定索引位置插入一個子節點
virtual bool insertChild(unsigned int index, Node* child)
// 刪除一個子節點
virtual bool removeChild(Node* child);
//從指定索引位置開始刪除指定數目子節點
inline bool removeChild(unsigned int pos, unsigned int numChildrenToRemove = 1)
virtual bool removeChildren(unsigned int pos, unsigned int numChildrenToRemove)
// 用新的子節點替換一個子節點
virtual bool replaceChild(Node* origChild, Node* newChild)
// 返回子節點的數目
virtual unsigned int getNumChildren() const
virtual bool setChild(unsigned int i, Node* node)
//獲取一個指定位置的子節點
inline Node* getChild(unsigned int i)
inline const Node* getChild(unsigned int i) const
// 若是指定節點是一個子節點,返回true
inline bool containsNode(const Node* node) const
//獲取一個子節點索引位置
inline unsigned int getChildIndex(const Node* node) const
virtual void setThreadSafeRefUnref(bool threadSafe)
virtual void resizeGLObjectBuffers(unsigned int maxSize)
virtual void releaseGLObjects(osg::State* = 0) const
virtual BoundingSphere computeBound() const
protected:
virtual ~Group()
virtual void childRemoved(unsigne int /*pos*/, unsigne int /*numChildrenToRemove*/)
virtual void childInserted(unsigned int /*pos*/)
NodeList _children;
};
osg::Geode 葉節點類用於保存幾何信息以便渲染ui
osg::Geode 葉節點沒法向下繼承子節點,只能向上繼承 osg::Group 父節點this
#include <osg/Geode>spa
class OSG_EXPORT Geode : public Group
{
public:
//構造函數
Geode();
Geode(const Geode&, const CopyOp& copyop = CopyOp::SHALLOW_COPY);
virtual Geode* asGeode()
virtual const Geode* asGeode() const
//從葉節點追加一個可繪製體對象
virtual bool addDrawable(Drawable* drawable);
//從葉節點刪除一個可繪製體對象
virtual bool removeDrawable(Drawable* drawable);
virtual bool removeDrawables(unsigned int i, unsigned int numDrawablesToRemove = 1)
//將當前節點中包含的一個可繪製體替換爲新的可繪製體
virtual bool replaceDrawable(Drawable* origDraw, Drawable* newDraw);
virtual bool setDrawable(unsigned int i, Drawable* drawable);
//獲取可繪製體的數目
inline unsigned int getNumDrawables() const
//獲取一個指定位置的可繪製體
inline Drawable* getDrawable(unsigned int i)
inline const Drawable* getDrawable(unsigned int i) const
inline bool constainsDrawable(const Drawable* drawable) const
//獲取一個可繪製體在葉節點的索引位置
inline unsigned int getDrawableIndex(const Drawable* drawable) const
void compileDrawables(RenderInfo& renderInfo)
inline const BoundingBox& getBoundingBox() const
virtual BoundingSphere computeBound() const;
protected:
virtual ~Geode();
mutable osg::BoundingBox _bbox;
};
在osg中,一般有三種生成幾何體的方法:1.用封裝的OpenGL繪圖基元osg::Geometry,2.是用OSG中預約義的基本幾何體,3.是從文件中導入場景模型指針
osg::Geometry 幾何體類能夠經過指定頂點 顏色和法線的方式,繪製簡單的線段 三角形 多邊形並將繪圖的結果添加到場景的葉節點Geode中code
osg::Group* root = new osg::Group(); //組節點 osg::Geode* geode = new osg::Geode(); //葉節點 osg::Geometry* geometry = new osg::Geometry(); //幾何圖元 root->addChild(geode); geode->addDrawable(geometry);
osg::LOD節點能夠實現不一樣細節層次下物體的渲染。經過指定各個子節點的有效範圍,該範圍包含了最大和最小值。當子節點與觀察者的距離在這個節點的有效範圍以內時,LOD將顯示這個節點。orm
基本實現方法:在不影響渲染外觀的前提下,根據場景對象與觀察者的距離,從多個預置方案中選擇一種更爲簡單的方法來表達要渲染的物體,減輕系統繪製場景的負擔,模型越靠近觀察者時越精細。對象
LOD() bool addChild(Node* child, float min, float max) //添加一個子節點,並設置對應的觀察距離 //設置指定位置的子節點對應的觀察範圍,或者獲取某個子節點對應的觀察最小值/最大值 void setRange(unsigned int childNo, float min, float max) float getMinRange(unsigned int childNo) const float getMaxRange(unsigned int childNo) const const RangeList& getRangeList() const //獲取全部子節點觀察範圍的列表
osg::Switch開關節點類能夠渲染或者跳過指定的子節點。根據當前渲染的負荷有選擇地渲染子圖形以實現渲染性能的均衡,或者在界面和層級進行有選擇地切換