lineseg.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. ** Command & Conquer Renegade(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /***********************************************************************************************
  19. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : WWMath *
  23. * *
  24. * $Archive:: /Commando/Code/wwmath/lineseg.h $*
  25. * *
  26. * Author:: Greg_h *
  27. * *
  28. * $Modtime:: 3/16/00 3:16p $*
  29. * *
  30. * $Revision:: 21 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #if defined(_MSC_VER)
  36. #pragma once
  37. #endif
  38. #ifndef LINESEG_H
  39. #define LINESEG_H
  40. #include "always.h"
  41. #include "vector3.h"
  42. #include "castres.h"
  43. class TriClass;
  44. class AABoxClass;
  45. class OBBoxClass;
  46. class PlaneClass;
  47. class SphereClass;
  48. class Matrix3D;
  49. class LineSegClass
  50. {
  51. public:
  52. LineSegClass(void) { }
  53. LineSegClass(const Vector3 & p0,const Vector3 & p1) : P0(p0), P1(p1) { recalculate(); }
  54. LineSegClass(const LineSegClass & that,const Matrix3D & tm) { Set(that,tm); }
  55. void Set(const Vector3 & p0,const Vector3 & p1) { P0 = p0; P1 = p1; recalculate(); }
  56. void Set(const LineSegClass & that,const Matrix3D & tm);
  57. void Set_Random(const Vector3 & min,const Vector3 & max);
  58. const Vector3 & Get_P0() const { return P0; } // start point
  59. const Vector3 & Get_P1() const { return P1; } // end point
  60. const Vector3 & Get_DP() const { return DP; } // difference of the two points
  61. const Vector3 & Get_Dir() const { return Dir; } // normalized direction.
  62. float Get_Length() const { return Length; } // length of the segment
  63. void Compute_Point(float t,Vector3 * set) const { Vector3::Add(P0,t*DP,set); }
  64. Vector3 Find_Point_Closest_To(const Vector3 &pos) const;
  65. bool Find_Intersection (const LineSegClass &other_line, Vector3 *p1, float *fraction1, Vector3 *p2, float *fraction2) const;
  66. protected:
  67. void recalculate(void) { DP = P1 - P0; Dir = DP; Dir.Normalize(); Length = DP.Length(); }
  68. Vector3 P0; // start point
  69. Vector3 P1; // end point
  70. Vector3 DP; // difference of the two points
  71. Vector3 Dir; // normalized direction.
  72. float Length; // length of the segment
  73. };
  74. #endif