2012-03-22 01:36:20 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2004 Robert Osfield
|
2003-01-22 00:45:36 +08:00
|
|
|
*
|
2012-03-22 01:36:20 +08:00
|
|
|
* This library is open source and may be redistributed and/or modified under
|
|
|
|
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
2003-01-22 00:45:36 +08:00
|
|
|
* (at your option) any later version. The full license is in LICENSE file
|
|
|
|
* included with this distribution, and on the openscenegraph.org website.
|
2012-03-22 01:36:20 +08:00
|
|
|
*
|
2003-01-22 00:45:36 +08:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2012-03-22 01:36:20 +08:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2003-01-22 00:45:36 +08:00
|
|
|
* OpenSceneGraph Public License for more details.
|
|
|
|
*/
|
2001-10-04 23:12:57 +08:00
|
|
|
|
2001-09-20 05:19:47 +08:00
|
|
|
#ifndef OSG_LINESEGMENT
|
|
|
|
#define OSG_LINESEGMENT 1
|
|
|
|
|
|
|
|
#include <osg/Matrix>
|
|
|
|
#include <osg/BoundingBox>
|
|
|
|
#include <osg/BoundingSphere>
|
|
|
|
|
|
|
|
namespace osg {
|
|
|
|
|
2004-08-31 21:19:30 +08:00
|
|
|
/** LineSegment class for representing a line segment. */
|
2005-04-12 01:14:17 +08:00
|
|
|
class OSG_EXPORT LineSegment : public Referenced
|
2001-09-20 05:19:47 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2008-02-18 22:51:05 +08:00
|
|
|
typedef Vec3d vec_type;
|
|
|
|
typedef vec_type::value_type value_type;
|
|
|
|
|
2001-09-20 05:19:47 +08:00
|
|
|
LineSegment() {};
|
|
|
|
LineSegment(const LineSegment& seg) : Referenced(),_s(seg._s),_e(seg._e) {}
|
2008-02-18 22:51:05 +08:00
|
|
|
LineSegment(const vec_type& s,const vec_type& e) : _s(s),_e(e) {}
|
2001-09-20 05:19:47 +08:00
|
|
|
|
|
|
|
LineSegment& operator = (const LineSegment& seg) { _s = seg._s; _e = seg._e; return *this; }
|
|
|
|
|
2008-02-18 22:51:05 +08:00
|
|
|
inline void set(const vec_type& s,const vec_type& e) { _s=s; _e=e; }
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2008-02-18 22:51:05 +08:00
|
|
|
inline vec_type& start() { return _s; }
|
|
|
|
inline const vec_type& start() const { return _s; }
|
2001-09-20 05:19:47 +08:00
|
|
|
|
2008-02-18 22:51:05 +08:00
|
|
|
inline vec_type& end() { return _e; }
|
|
|
|
inline const vec_type& end() const { return _e; }
|
2001-09-20 05:19:47 +08:00
|
|
|
|
2002-09-02 20:31:35 +08:00
|
|
|
inline bool valid() const { return _s.valid() && _e.valid() && _s!=_e; }
|
2001-11-06 18:34:51 +08:00
|
|
|
|
2015-04-28 03:31:13 +08:00
|
|
|
|
2004-08-31 21:19:30 +08:00
|
|
|
/** return true if segment intersects BoundingBox. */
|
2002-09-02 20:31:35 +08:00
|
|
|
bool intersect(const BoundingBox& bb) const;
|
2001-09-20 05:19:47 +08:00
|
|
|
|
2015-04-28 03:31:13 +08:00
|
|
|
/** return true if segment intersects BoundingBox and
|
|
|
|
* set float ratios for the first and second intersections, where the ratio is 0.0 at the segment start point, and 1.0 at the segment end point.
|
2004-08-31 21:19:30 +08:00
|
|
|
*/
|
2015-04-28 03:31:13 +08:00
|
|
|
bool intersectAndComputeRatios(const BoundingBox& bb, float& ratioFromStartToEnd1, float& ratioFromStartToEnd2) const;
|
2001-09-20 05:19:47 +08:00
|
|
|
|
2015-04-28 03:31:13 +08:00
|
|
|
/** return true if segment intersects BoundingBox and
|
|
|
|
* set double ratios for the first and second intersections, where the ratio is 0.0 at the segment start point, and 1.0 at the segment end point.
|
2008-03-14 00:05:40 +08:00
|
|
|
*/
|
2015-04-28 03:31:13 +08:00
|
|
|
bool intersectAndComputeRatios(const BoundingBox& bb, double& ratioFromStartToEnd1, double& ratioFromStartToEnd2) const;
|
|
|
|
|
2008-03-14 00:05:40 +08:00
|
|
|
|
2004-08-31 21:19:30 +08:00
|
|
|
/** return true if segment intersects BoundingSphere. */
|
2002-09-02 20:31:35 +08:00
|
|
|
bool intersect(const BoundingSphere& bs) const;
|
2001-09-20 05:19:47 +08:00
|
|
|
|
2015-04-28 03:31:13 +08:00
|
|
|
/** return true if segment intersects BoundingSphere and
|
|
|
|
* set float ratios for the first and second intersections, where the ratio is 0.0 at the segment start point, and 1.0 at the segment end point.
|
2004-08-31 21:19:30 +08:00
|
|
|
*/
|
2015-04-28 03:31:13 +08:00
|
|
|
bool intersectAndComputeRatios(const BoundingSphere& bs, float& ratioFromStartToEnd1, float& ratioFromStartToEnd2) const;
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2015-04-28 03:31:13 +08:00
|
|
|
/** return true if segment intersects BoundingSphere and
|
|
|
|
* set double ratios for the first and second intersections, where the ratio is 0.0 at the segment start point, and 1.0 at the segment end point.
|
2008-03-14 00:05:40 +08:00
|
|
|
*/
|
2015-04-28 03:31:13 +08:00
|
|
|
bool intersectAndComputeRatios(const BoundingSphere& bs,double& ratioFromStartToEnd1, double& ratioFromStartToEnd2) const;
|
2008-03-14 00:05:40 +08:00
|
|
|
|
2015-04-28 03:31:13 +08:00
|
|
|
/** return true if segment intersects triangle and
|
|
|
|
* set float ratios where the ratio is 0.0 at the segment start point, and 1.0 at the segment end point.
|
2008-03-14 00:05:40 +08:00
|
|
|
*/
|
2015-04-28 03:31:13 +08:00
|
|
|
bool intersect(const Vec3f& v1,const Vec3f& v2,const Vec3f& v3,float& ratioFromStartToEnd);
|
2008-03-14 00:05:40 +08:00
|
|
|
|
2015-04-28 03:31:13 +08:00
|
|
|
/** return true if segment intersects triangle and
|
|
|
|
* set double ratios where the ratio is 0.0 at the segment start point, and 1.0 at the segment end point.
|
2004-08-31 21:19:30 +08:00
|
|
|
*/
|
2015-04-28 03:31:13 +08:00
|
|
|
bool intersect(const Vec3d& v1,const Vec3d& v2,const Vec3d& v3,double& ratioFromStartToEnd);
|
2008-03-14 00:05:40 +08:00
|
|
|
|
2001-09-20 05:19:47 +08:00
|
|
|
|
|
|
|
/** post multiply a segment by matrix.*/
|
|
|
|
inline void mult(const LineSegment& seg,const Matrix& m) { _s = seg._s*m; _e = seg._e*m; }
|
2015-04-28 03:31:13 +08:00
|
|
|
|
2001-09-20 05:19:47 +08:00
|
|
|
/** pre multiply a segment by matrix.*/
|
|
|
|
inline void mult(const Matrix& m,const LineSegment& seg) { _s = m*seg._s; _e = m*seg._e; }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
2004-03-19 17:18:21 +08:00
|
|
|
virtual ~LineSegment();
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2008-02-18 22:51:05 +08:00
|
|
|
static bool intersectAndClip(vec_type& s,vec_type& e,const BoundingBox& bb);
|
2001-09-20 05:19:47 +08:00
|
|
|
|
2008-02-18 22:51:05 +08:00
|
|
|
vec_type _s;
|
|
|
|
vec_type _e;
|
2001-09-20 05:19:47 +08:00
|
|
|
};
|
|
|
|
|
2002-02-03 20:33:41 +08:00
|
|
|
}
|
2001-09-20 05:19:47 +08:00
|
|
|
|
|
|
|
#endif
|