#include <osg/BezierCurves>头文件源码
时间: 2023-12-17 08:05:54 浏览: 70
以下是 `osg/BezierCurves` 头文件的源码:
```cpp
#ifndef OSG_BEZIERCURVES
#define OSG_BEZIERCURVES 1
#include <osg/Array>
#include <osg/Vec3>
namespace osg {
/** A class for representing Bezier curves. */
class BezierCurve
{
public:
BezierCurve() {}
BezierCurve(const BezierCurve& copy, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY):
_controlPoints(copy._controlPoints),
_tessellation(copy._tessellation),
_tessellationCache(copy._tessellationCache),
_dirty(true) {}
BezierCurve(const osg::Vec3Array* controlPoints):
_controlPoints(controlPoints),
_tessellation(10),
_dirty(true) {}
BezierCurve(const osg::Vec3Array* controlPoints, unsigned int tessellation):
_controlPoints(controlPoints),
_tessellation(tessellation),
_dirty(true) {}
inline void setControlPoints(const osg::Vec3Array* controlPoints) { _controlPoints = controlPoints; _dirty=true; }
inline const osg::Vec3Array* getControlPoints() const { return _controlPoints.get(); }
inline void setTessellation(unsigned int tessellation) { _tessellation = tessellation; _dirty=true; }
inline unsigned int getTessellation() const { return _tessellation; }
inline const osg::Vec3Array* getTessellationCache() const { if (_dirty) const_cast<BezierCurve*>(this)->buildCache(); return _tessellationCache.get(); }
inline osg::Vec3 evaluate(float t) const
{
if (_dirty) const_cast<BezierCurve*>(this)->buildCache();
return _tessellationCache->at(unsigned int(t*float(_tessellation)));
}
inline void evaluate(float t, osg::Vec3& P, osg::Vec3& T) const
{
if (_dirty) const_cast<BezierCurve*>(this)->buildCache();
unsigned int index = unsigned int(t*float(_tessellation));
const osg::Vec3& p0 = _tessellationCache->at(index);
const osg::Vec3& p1 = _tessellationCache->at(index+1);
P = p0;
T = p1-p0;
}
private:
void buildCache() const;
osg::ref_ptr<const osg::Vec3Array> _controlPoints;
unsigned int _tessellation;
mutable osg::ref_ptr<osg::Vec3Array> _tessellationCache;
mutable bool _dirty;
};
/** A class for representing a set of Bezier curves */
class BezierCurveArray : public osg::Array<BezierCurve>
{
public:
BezierCurveArray(){}
BezierCurveArray(const BezierCurveArray& copy, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY):
osg::Array<BezierCurve>(copy,copyop) {}
META_Array(osg, BezierCurveArray, 0x160);
};
}
#endif
```
该头文件定义了 `BezierCurve` 和 `BezierCurveArray` 两个类,用于表示贝塞尔曲线。其中, `BezierCurve` 类用于表示一条贝塞尔曲线,包括控制点、分割数量等属性;`BezierCurveArray` 类则是一个贝塞尔曲线数组。
阅读全文