PageRenderTime 29ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/llmath/llline.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 80 lines | 27 code | 15 blank | 38 comment | 0 complexity | 8dd7483cf06775bb2d539837efbe9eda MD5 | raw file
Possible License(s): LGPL-2.1
  1. // llline.h
  2. /**
  3. * @file llline.cpp
  4. * @author Andrew Meadows
  5. * @brief Simple line for computing nearest approach between two infinite lines
  6. *
  7. * $LicenseInfo:firstyear=2006&license=viewerlgpl$
  8. * Second Life Viewer Source Code
  9. * Copyright (C) 2010, Linden Research, Inc.
  10. *
  11. * This library is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU Lesser General Public
  13. * License as published by the Free Software Foundation;
  14. * version 2.1 of the License only.
  15. *
  16. * This library is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  19. * Lesser General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Lesser General Public
  22. * License along with this library; if not, write to the Free Software
  23. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  24. *
  25. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  26. * $/LicenseInfo$
  27. */
  28. #ifndef LL_LINE_H
  29. #define LL_LINE_H
  30. #include <iostream>
  31. #include "stdtypes.h"
  32. #include "v3math.h"
  33. const F32 DEFAULT_INTERSECTION_ERROR = 0.000001f;
  34. class LLLine
  35. {
  36. public:
  37. LLLine();
  38. LLLine( const LLVector3& first_point, const LLVector3& second_point );
  39. virtual ~LLLine() {};
  40. void setPointDirection( const LLVector3& first_point, const LLVector3& second_point );
  41. void setPoints( const LLVector3& first_point, const LLVector3& second_point );
  42. bool intersects( const LLVector3& point, F32 radius = DEFAULT_INTERSECTION_ERROR ) const;
  43. // returns the point on this line that is closest to some_point
  44. LLVector3 nearestApproach( const LLVector3& some_point ) const;
  45. // returns the point on this line that is closest to other_line
  46. LLVector3 nearestApproach( const LLLine& other_line ) const;
  47. friend std::ostream& operator<<( std::ostream& output_stream, const LLLine& line );
  48. // returns 'true' if this line intersects the plane
  49. // on success stores the intersection point in 'result'
  50. bool intersectsPlane( LLVector3& result, const LLLine& plane ) const;
  51. // returns 'true' if planes intersect, and stores the result
  52. // the second and third arguments are treated as planes
  53. // where mPoint is on the plane and mDirection is the normal
  54. // result.mPoint will be the intersection line's closest approach
  55. // to first_plane.mPoint
  56. static bool getIntersectionBetweenTwoPlanes( LLLine& result, const LLLine& first_plane, const LLLine& second_plane );
  57. const LLVector3& getPoint() const { return mPoint; }
  58. const LLVector3& getDirection() const { return mDirection; }
  59. protected:
  60. // these are protected because some code assumes that the normal is
  61. // always correct and properly normalized.
  62. LLVector3 mPoint;
  63. LLVector3 mDirection;
  64. };
  65. #endif