2003-01-22 00:45:36 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 Robert Osfield
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* (at your option) any later version. The full license is in LICENSE file
|
|
|
|
* included with this distribution, and on the openscenegraph.org website.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* 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 {
|
|
|
|
|
2001-09-29 04:10:41 +08:00
|
|
|
/** LineSegment class for representing a line segment.*/
|
2001-09-20 05:19:47 +08:00
|
|
|
class SG_EXPORT LineSegment : public Referenced
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
LineSegment() {};
|
|
|
|
LineSegment(const LineSegment& seg) : Referenced(),_s(seg._s),_e(seg._e) {}
|
|
|
|
LineSegment(const Vec3& s,const Vec3& 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 Vec3& start() { return _s; }
|
|
|
|
inline const Vec3& start() const { return _s; }
|
|
|
|
|
|
|
|
inline Vec3& end() { return _e; }
|
|
|
|
inline const Vec3& end() const { return _e; }
|
|
|
|
|
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
|
|
|
|
2001-09-20 05:19:47 +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
|
|
|
|
2002-01-18 18:26:06 +08:00
|
|
|
/** return true if segment intersects BoundingBox and return the intersection ratio's.*/
|
2002-09-02 20:31:35 +08:00
|
|
|
bool intersect(const BoundingBox& bb,float& r1,float& r2) const;
|
2001-09-20 05:19:47 +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
|
|
|
|
|
|
|
/** return true if segment intersects BoundingSphere and return the intersection ratio's.*/
|
2002-09-02 20:31:35 +08:00
|
|
|
bool intersect(const BoundingSphere& bs,float& r1,float& r2) const;
|
2001-09-20 05:19:47 +08:00
|
|
|
|
|
|
|
/** return true if segment intersects triangle and set ratio long segment. */
|
2002-09-02 20:31:35 +08:00
|
|
|
bool intersect(const Vec3& v1,const Vec3& v2,const Vec3& v3,float& r);
|
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; }
|
|
|
|
/** 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();
|
2002-01-30 20:09:18 +08:00
|
|
|
|
2002-09-02 20:31:35 +08:00
|
|
|
static bool intersectAndClip(Vec3& s,Vec3& e,const BoundingBox& bb);
|
2001-09-20 05:19:47 +08:00
|
|
|
|
|
|
|
Vec3 _s;
|
|
|
|
Vec3 _e;
|
|
|
|
};
|
|
|
|
|
2002-02-03 20:33:41 +08:00
|
|
|
}
|
2001-09-20 05:19:47 +08:00
|
|
|
|
|
|
|
#endif
|