Introduced typedef vec_type and value_type into LineSemgment class to allow easier

switching between double and float versions.
This commit is contained in:
Robert Osfield 2008-02-18 14:51:05 +00:00
parent 8b77cc4dac
commit a97dc84228
6 changed files with 45 additions and 40 deletions

View File

@ -25,19 +25,22 @@ class OSG_EXPORT LineSegment : public Referenced
{
public:
typedef Vec3d vec_type;
typedef vec_type::value_type value_type;
LineSegment() {};
LineSegment(const LineSegment& seg) : Referenced(),_s(seg._s),_e(seg._e) {}
LineSegment(const Vec3& s,const Vec3& e) : _s(s),_e(e) {}
LineSegment(const vec_type& s,const vec_type& e) : _s(s),_e(e) {}
LineSegment& operator = (const LineSegment& seg) { _s = seg._s; _e = seg._e; return *this; }
inline void set(const Vec3& s,const Vec3& e) { _s=s; _e=e; }
inline void set(const vec_type& s,const vec_type& e) { _s=s; _e=e; }
inline Vec3& start() { return _s; }
inline const Vec3& start() const { return _s; }
inline vec_type& start() { return _s; }
inline const vec_type& start() const { return _s; }
inline Vec3& end() { return _e; }
inline const Vec3& end() const { return _e; }
inline vec_type& end() { return _e; }
inline const vec_type& end() const { return _e; }
inline bool valid() const { return _s.valid() && _e.valid() && _s!=_e; }
@ -71,10 +74,10 @@ class OSG_EXPORT LineSegment : public Referenced
virtual ~LineSegment();
static bool intersectAndClip(Vec3& s,Vec3& e,const BoundingBox& bb);
static bool intersectAndClip(vec_type& s,vec_type& e,const BoundingBox& bb);
Vec3 _s;
Vec3 _e;
vec_type _s;
vec_type _e;
};
}

View File

@ -127,15 +127,15 @@ class OSGMANIPULATOR_EXPORT TranslateInLineCommand : public MotionCommand
TranslateInLineCommand();
TranslateInLineCommand(const osg::Vec3& s, const osg::Vec3& e);
TranslateInLineCommand(const osg::LineSegment::vec_type& s, const osg::LineSegment::vec_type& e);
virtual bool execute();
virtual bool unexecute();
virtual void applyConstraint(const Constraint*);
inline void setLine(const osg::Vec3& s, const osg::Vec3& e) { _line->start() = s; _line->end() = e; }
inline const osg::Vec3& getLineStart() const { return _line->start(); }
inline const osg::Vec3& getLineEnd() const { return _line->end(); }
inline void setLine(const osg::LineSegment::vec_type& s, const osg::LineSegment::vec_type& e) { _line->start() = s; _line->end() = e; }
inline const osg::LineSegment::vec_type& getLineStart() const { return _line->start(); }
inline const osg::LineSegment::vec_type& getLineEnd() const { return _line->end(); }
inline void setTranslation(const osg::Vec3& t) { _translation = t; }
inline const osg::Vec3& getTranslation() const { return _translation; }

View File

@ -92,13 +92,15 @@ class OSGMANIPULATOR_EXPORT LineProjector : public Projector
LineProjector();
LineProjector(const osg::Vec3& s, const osg::Vec3& e);
LineProjector(const osg::LineSegment::vec_type& s, const osg::LineSegment::vec_type& e);
inline void setLine(const osg::Vec3& s, const osg::Vec3& e) { _line->start() = s; _line->end() = e; }
inline const osg::Vec3& getLineStart() const { return _line->start(); }
inline osg::Vec3& getLineStart() { return _line->start(); }
inline const osg::Vec3& getLineEnd() const { return _line->end(); }
inline osg::Vec3& getLineEnd() { return _line->end(); }
inline void setLine(const osg::LineSegment::vec_type& s, const osg::LineSegment::vec_type& e) { _line->start() = s; _line->end() = e; }
inline const osg::LineSegment::vec_type& getLineStart() const { return _line->start(); }
inline osg::LineSegment::vec_type& getLineStart() { return _line->start(); }
inline const osg::LineSegment::vec_type& getLineEnd() const { return _line->end(); }
inline osg::LineSegment::vec_type& getLineEnd() { return _line->end(); }
/**
* Calculates the object coordinates (projectedPoint) of a window

View File

@ -18,7 +18,7 @@ LineSegment::~LineSegment()
{
}
bool LineSegment::intersectAndClip(Vec3& s,Vec3& e,const BoundingBox& bb)
bool LineSegment::intersectAndClip(vec_type& s,vec_type& e,const BoundingBox& bb)
{
// compate s and e against the xMin to xMax range of bb.
if (s.x()<=e.x())
@ -142,7 +142,7 @@ bool LineSegment::intersect(const BoundingBox& bb) const
{
if (!bb.valid()) return false;
Vec3 s=_s,e=_e;
vec_type s=_s,e=_e;
return intersectAndClip(s,e,bb);
}
@ -151,7 +151,7 @@ bool LineSegment::intersect(const BoundingBox& bb,float& r1,float& r2) const
{
if (!bb.valid()) return false;
Vec3 s=_s,e=_e;
vec_type s=_s,e=_e;
bool result = intersectAndClip(s,e,bb);
if (result)
{
@ -174,10 +174,10 @@ bool LineSegment::intersect(const BoundingBox& bb,float& r1,float& r2) const
bool LineSegment::intersect(const BoundingSphere& bs,float& r1,float& r2) const
{
Vec3 sm = _s-bs._center;
vec_type sm = _s-bs._center;
float c = sm.length2()-bs._radius*bs._radius;
Vec3 se = _e-_s;
vec_type se = _e-_s;
float a = se.length2();
@ -219,11 +219,11 @@ bool LineSegment::intersect(const BoundingSphere& bs,float& r1,float& r2) const
bool LineSegment::intersect(const BoundingSphere& bs) const
{
Vec3 sm = _s-bs._center;
vec_type sm = _s-bs._center;
float c = sm.length2()-bs._radius*bs._radius;
if (c<0.0f) return true;
Vec3 se = _e-_s;
vec_type se = _e-_s;
float a = se.length2();
float b = (sm*se)*2.0f;
@ -251,10 +251,10 @@ bool LineSegment::intersect(const Vec3& v1,const Vec3& v2,const Vec3& v3,float&
{
if (v1==v2 || v2==v3 || v1==v3) return false;
Vec3 vse = _e-_s;
vec_type vse = _e-_s;
Vec3 v12 = v2-v1;
Vec3 n12 = v12^vse;
vec_type v12 = v2-v1;
vec_type n12 = v12^vse;
float ds12 = (_s-v1)*n12;
float d312 = (v3-v1)*n12;
if (d312>=0.0f)
@ -268,8 +268,8 @@ bool LineSegment::intersect(const Vec3& v1,const Vec3& v2,const Vec3& v3,float&
if (ds12<d312) return false;
}
Vec3 v23 = v3-v2;
Vec3 n23 = v23^vse;
vec_type v23 = v3-v2;
vec_type n23 = v23^vse;
float ds23 = (_s-v2)*n23;
float d123 = (v1-v2)*n23;
if (d123>=0.0f)
@ -283,8 +283,8 @@ bool LineSegment::intersect(const Vec3& v1,const Vec3& v2,const Vec3& v3,float&
if (ds23<d123) return false;
}
Vec3 v31 = v1-v3;
Vec3 n31 = v31^vse;
vec_type v31 = v1-v3;
vec_type n31 = v31^vse;
float ds31 = (_s-v3)*n31;
float d231 = (v2-v3)*n31;
if (d231>=0.0f)
@ -304,7 +304,7 @@ bool LineSegment::intersect(const Vec3& v1,const Vec3& v2,const Vec3& v3,float&
// float rt = r1+r2+r3;
Vec3 in = v1*r1+v2*r2+v3*r3;
vec_type in = v1*r1+v2*r2+v3*r3;
float length = vse.length();
vse /= length;

View File

@ -55,7 +55,7 @@ TranslateInLineCommand::TranslateInLineCommand()
_line = new osg::LineSegment;
}
TranslateInLineCommand::TranslateInLineCommand(const osg::Vec3& s, const osg::Vec3& e)
TranslateInLineCommand::TranslateInLineCommand(const osg::LineSegment::vec_type& s, const osg::LineSegment::vec_type& e)
{
_line = new osg::LineSegment(s,e);
}

View File

@ -26,10 +26,10 @@ bool computeClosestPoints(const osg::LineSegment& l1, const osg::LineSegment& l2
// An explanation of the algorithm can be found at
// http://www.geometryalgorithms.com/Archive/algorithm_0106/algorithm_0106.htm
osg::Vec3 u = l1.end() - l1.start(); u.normalize();
osg::Vec3 v = l2.end() - l2.start(); v.normalize();
osg::LineSegment::vec_type u = l1.end() - l1.start(); u.normalize();
osg::LineSegment::vec_type v = l2.end() - l2.start(); v.normalize();
osg::Vec3 w0 = l1.start() - l2.start();
osg::LineSegment::vec_type w0 = l1.start() - l2.start();
float a = u * u;
float b = u * v;
@ -227,10 +227,10 @@ Projector::~Projector()
LineProjector::LineProjector()
{
_line = new osg::LineSegment(osg::Vec3(0.0,0.0,0.0), osg::Vec3(1.0,0.0,0.0));
_line = new osg::LineSegment(osg::LineSegment::vec_type(0.0,0.0,0.0), osg::LineSegment::vec_type(1.0,0.0,0.0));
}
LineProjector::LineProjector(const osg::Vec3& s, const osg::Vec3& e)
LineProjector::LineProjector(const osg::LineSegment::vec_type& s, const osg::LineSegment::vec_type& e)
{
_line = new osg::LineSegment(s,e);
}