From a97dc84228a5259059ac10acde6ff420ea3e4a82 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 18 Feb 2008 14:51:05 +0000 Subject: [PATCH] Introduced typedef vec_type and value_type into LineSemgment class to allow easier switching between double and float versions. --- include/osg/LineSegment | 21 ++++++++++++--------- include/osgManipulator/Command | 8 ++++---- include/osgManipulator/Projector | 14 ++++++++------ src/osg/LineSegment.cpp | 30 +++++++++++++++--------------- src/osgManipulator/Command.cpp | 2 +- src/osgManipulator/Projector.cpp | 10 +++++----- 6 files changed, 45 insertions(+), 40 deletions(-) diff --git a/include/osg/LineSegment b/include/osg/LineSegment index 800922fb4..83fb69e41 100644 --- a/include/osg/LineSegment +++ b/include/osg/LineSegment @@ -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; }; } diff --git a/include/osgManipulator/Command b/include/osgManipulator/Command index 90a717b08..0f51a3ff8 100644 --- a/include/osgManipulator/Command +++ b/include/osgManipulator/Command @@ -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; } diff --git a/include/osgManipulator/Projector b/include/osgManipulator/Projector index 15a0d1c14..b92dc1e97 100644 --- a/include/osgManipulator/Projector +++ b/include/osgManipulator/Projector @@ -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 diff --git a/src/osg/LineSegment.cpp b/src/osg/LineSegment.cpp index 09b968fe2..70f4ca847 100644 --- a/src/osg/LineSegment.cpp +++ b/src/osg/LineSegment.cpp @@ -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=0.0f) @@ -283,8 +283,8 @@ bool LineSegment::intersect(const Vec3& v1,const Vec3& v2,const Vec3& v3,float& if (ds23=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; diff --git a/src/osgManipulator/Command.cpp b/src/osgManipulator/Command.cpp index 4ed41e6a5..75291dd96 100644 --- a/src/osgManipulator/Command.cpp +++ b/src/osgManipulator/Command.cpp @@ -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); } diff --git a/src/osgManipulator/Projector.cpp b/src/osgManipulator/Projector.cpp index dcda94a18..eabfe74c3 100644 --- a/src/osgManipulator/Projector.cpp +++ b/src/osgManipulator/Projector.cpp @@ -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); }