Converted osg::LOD from used n+1 successive ranges to n min/max ranges,
one min/max pair per child. Converted the rest of the OSG to use the new osg::LOD node.
This commit is contained in:
@@ -26,6 +26,9 @@ class SG_EXPORT CollectOccludersVisitor : public osg::NodeVisitor, public osg::C
|
||||
|
||||
virtual void reset();
|
||||
|
||||
virtual float getDistanceToEyePoint(const Vec3& pos, bool withLODBias) const;
|
||||
virtual float getDistanceFromEyePoint(const Vec3& pos, bool withLODBias) const;
|
||||
|
||||
virtual void apply(osg::Node&);
|
||||
virtual void apply(osg::Transform& node);
|
||||
virtual void apply(osg::Projection& node);
|
||||
|
||||
@@ -140,7 +140,7 @@ class SG_EXPORT CullStack
|
||||
inline osg::Viewport* getViewport();
|
||||
inline osg::Matrix& getModelViewMatrix();
|
||||
inline osg::Matrix& getProjectionMatrix();
|
||||
inline const osg::Matrix getWindowMatrix();
|
||||
inline osg::Matrix getWindowMatrix();
|
||||
inline const osg::Matrix& getMVPW();
|
||||
|
||||
inline const osg::Vec3& getEyeLocal() const { return _eyePointStack.back(); }
|
||||
@@ -156,7 +156,7 @@ class SG_EXPORT CullStack
|
||||
const osg::Matrix& matrix = *_modelviewStack.back();
|
||||
return osg::Vec3(-matrix(0,2),-matrix(1,2),-matrix(2,2));
|
||||
}
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
void pushCullingSet();
|
||||
@@ -239,7 +239,7 @@ inline osg::Matrix& CullStack::getProjectionMatrix()
|
||||
}
|
||||
}
|
||||
|
||||
inline const osg::Matrix CullStack::getWindowMatrix()
|
||||
inline osg::Matrix CullStack::getWindowMatrix()
|
||||
{
|
||||
if (!_viewportStack.empty())
|
||||
{
|
||||
|
||||
@@ -110,6 +110,18 @@ class SG_EXPORT Group : public Node
|
||||
return _children.end();
|
||||
}
|
||||
|
||||
/** Find the index number of child, return a value between
|
||||
* 0 and _children.size()-1 if found, if not found then
|
||||
* return _children.size().*/
|
||||
inline unsigned int findChildNo( const Node* node ) const
|
||||
{
|
||||
for (unsigned int childNo=0;childNo<_children.size();++childNo)
|
||||
{
|
||||
if (_children[childNo]==node) return childNo;
|
||||
}
|
||||
return _children.size(); // node not found.
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
virtual ~Group();
|
||||
|
||||
@@ -36,68 +36,58 @@ class SG_EXPORT LOD : public Group
|
||||
|
||||
virtual void traverse(NodeVisitor& nv);
|
||||
|
||||
/** Sets the value of range list element index to range which
|
||||
is a floating point distance specified in world coordinates.
|
||||
Range list automatically expands to accommodate values beyond
|
||||
the current getNumRanges().*/
|
||||
void setRange(unsigned int index, float range);
|
||||
|
||||
/** returns the range for specified index.*/
|
||||
inline float getRange(unsigned int index) const { return _rangeList[index]; }
|
||||
|
||||
/** returns the number of ranges currently set.*/
|
||||
inline unsigned int getNumRanges() const { return _rangeList.size(); }
|
||||
virtual bool addChild( Node *child );
|
||||
|
||||
virtual bool removeChild( Node *child );
|
||||
|
||||
|
||||
typedef std::pair<float,float> MinMaxPair;
|
||||
typedef std::vector<MinMaxPair> RangeList;
|
||||
|
||||
enum CenterMode
|
||||
{
|
||||
USE_BOUNDING_SPHERE_CENTER,
|
||||
USER_DEFINED_CENTER
|
||||
};
|
||||
|
||||
void setCenterMode(CenterMode mode) { _centerMode=mode; }
|
||||
|
||||
CenterMode getCenterMode() const { return _centerMode; }
|
||||
|
||||
/** Sets the object-space point which defines the center of the osg::LOD.
|
||||
center is affected by any transforms in the hierarchy above the osg::LOD.*/
|
||||
inline void setCenter(const Vec3& center) { _center = center; }
|
||||
inline void setCenter(const Vec3& center) { _centerMode=USER_DEFINED_CENTER; _userDefinedCenter = center; }
|
||||
|
||||
/** return the LOD center point. */
|
||||
inline const Vec3& getCenter() const { return _center; }
|
||||
inline const Vec3& getCenter() const { if (_centerMode==USER_DEFINED_CENTER) return _userDefinedCenter; else return getBound().center(); }
|
||||
|
||||
|
||||
/** Callback attached to an LOD which allows the users to customize the selection of LOD children.*/
|
||||
struct EvaluateLODCallback : public osg::Referenced
|
||||
{
|
||||
/** Compute the child to select.*/
|
||||
virtual int evaluateLODChild(const osg::LOD* lod, const Vec3& eye_local, float bias) const = 0;
|
||||
};
|
||||
|
||||
/** Set the EvaluateLODCallback which allows users to attach customize computation of the the selection of LOD children.*/
|
||||
void setEvaluateLODCallback(EvaluateLODCallback* cbc) { _evaluateLODCallback=cbc; }
|
||||
/** Sets the min and max visible ranges of range of specifiec child.
|
||||
Values are floating point distance specified in local objects coordinates.*/
|
||||
void setRange(unsigned int childNo, float min,float max);
|
||||
|
||||
/** Get the non const ComputeBillboardCallback.*/
|
||||
EvaluateLODCallback* getEvaluateLODCallback() { return _evaluateLODCallback.get(); }
|
||||
/** returns the min visible range for specified child.*/
|
||||
inline float getMinRange(unsigned int childNo) const { return _rangeList[childNo].first; }
|
||||
|
||||
/** returns the max visible range for specified child.*/
|
||||
inline float getMaxRange(unsigned int childNo) const { return _rangeList[childNo].second; }
|
||||
|
||||
/** Get the const ComputeBillboardCallback.*/
|
||||
const EvaluateLODCallback* getEvaluateLODCallback() const { return _evaluateLODCallback.get(); }
|
||||
/** returns the number of ranges currently set.
|
||||
* An LOD which has been fully set up will have getNumChildren()==getNumRanges(). */
|
||||
inline unsigned int getNumRanges() const { return _rangeList.size(); }
|
||||
|
||||
/** return the child to traverse.
|
||||
Selected by the distance between the eye point in local
|
||||
coordinates and the LOD center, multiplied by the bias.*/
|
||||
inline int evaluate(const Vec3& eye_local,float bias=1.0f) const
|
||||
{
|
||||
if (_evaluateLODCallback.valid())
|
||||
return _evaluateLODCallback->evaluateLODChild(this,eye_local,bias);
|
||||
else
|
||||
return evaluateLODChild(eye_local,bias);
|
||||
}
|
||||
|
||||
|
||||
virtual int evaluateLODChild(const Vec3& eye_local,float bias) const;
|
||||
/** return the list of MinMax ranges for each child.*/
|
||||
inline RangeList& getRangeList() { return _rangeList; }
|
||||
|
||||
/** return the list of MinMax ranges for each child.*/
|
||||
inline const RangeList& getRangeList() const { return _rangeList; }
|
||||
|
||||
protected :
|
||||
virtual ~LOD() {}
|
||||
|
||||
CenterMode _centerMode;
|
||||
Vec3 _userDefinedCenter;
|
||||
|
||||
typedef std::vector<float> RangeList;
|
||||
RangeList _rangeList;
|
||||
RangeList _rangeList2;
|
||||
|
||||
ref_ptr<EvaluateLODCallback> _evaluateLODCallback;
|
||||
|
||||
Vec3 _center;
|
||||
|
||||
RangeList _rangeList;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -184,11 +184,20 @@ class SG_EXPORT NodeVisitor : public Referenced
|
||||
const NodePath& getNodePath() const { return _nodePath; }
|
||||
|
||||
/** Get the Local To World Matrix from the NodePath for specified Transform::Mode, and u.*/
|
||||
bool getLocalToWorldMatrix(Matrix& matrix, Node* node);
|
||||
virtual bool getLocalToWorldMatrix(Matrix& matrix, Node* node);
|
||||
|
||||
/** Get the World To Local Matrix from the NodePath for specified Transform::Mode.*/
|
||||
bool getWorldToLocalMatrix(Matrix& matrix, Node* node);
|
||||
virtual bool getWorldToLocalMatrix(Matrix& matrix, Node* node);
|
||||
|
||||
/** Get the distance from a point to the eye point, distance value in local coordinate system.
|
||||
* Note, not all NodeVisitor implement this method, it is mainly cull visitors which will implement.
|
||||
* If the getDistianceFromEyePoint(pos) is not implmented than a default value of 0.0 is returned.*/
|
||||
virtual float getDistanceToEyePoint(const Vec3& /*pos*/, bool /*useLODBias*/) const { return 0.0f; }
|
||||
|
||||
/** Get the distance of a point from the eye point, distance value in the eye coordinate system.
|
||||
* Note, not all NodeVisitor implement this method, it is mainly cull visitors which will implement.
|
||||
* If the getDistianceFromEyePoint(pos) is not implmented than a default value of 0.0 is returned.*/
|
||||
virtual float getDistanceFromEyePoint(const Vec3& /*pos*/, bool /*useLODBias*/) const { return 0.0f; }
|
||||
|
||||
virtual void apply(Node& node) { traverse(node);}
|
||||
|
||||
|
||||
@@ -47,6 +47,9 @@ class OSGUTIL_EXPORT CullVisitor : public osg::NodeVisitor, public osg::CullStac
|
||||
virtual CullVisitor* cloneType() const { return osgNew CullVisitor(); }
|
||||
|
||||
virtual void reset();
|
||||
|
||||
virtual float getDistanceToEyePoint(const osg::Vec3& pos, bool withLODBias) const;
|
||||
virtual float getDistanceFromEyePoint(const osg::Vec3& pos, bool withLODBias) const;
|
||||
|
||||
virtual void apply(osg::Node&);
|
||||
virtual void apply(osg::Geode& node);
|
||||
|
||||
Reference in New Issue
Block a user