plane.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. ** Command & Conquer Generals(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. /* $Header: /Commando/Code/Tools/pluglib/plane.h 8 4/22/98 6:36p Greg_h $ */
  19. /***********************************************************************************************
  20. *** Confidential - Westwood Studios ***
  21. ***********************************************************************************************
  22. * *
  23. * Project Name : Voxel Technology *
  24. * *
  25. * File Name : PLANE.H *
  26. * *
  27. * Programmer : Greg Hjelstrom *
  28. * *
  29. * Start Date : 03/17/97 *
  30. * *
  31. * Last Update : March 17, 1997 [GH] *
  32. * *
  33. *---------------------------------------------------------------------------------------------*
  34. * Functions: *
  35. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  36. #ifndef PLANE_H
  37. #define PLANE_H
  38. #ifndef VECTOR3_H
  39. #include "vector3.h"
  40. #endif
  41. /*
  42. ** PlaneClass
  43. **
  44. ** 3D-planes. This class needs to be fleshed out but it does what I need for now.
  45. */
  46. class PlaneClass
  47. {
  48. public:
  49. Vector3 N;
  50. float D;
  51. PlaneClass(void) : N(0.0f,0.0f,1.0f), D(0.0f) { }
  52. PlaneClass(float a,float b,float c,float d) : N(a,b,c),D(d) { }
  53. PlaneClass(const Vector3 & normal,float dist) : N(normal), D(dist) { }
  54. // Create a plane given the normal and a point on the plane
  55. PlaneClass(const Vector3 & normal,const Vector3 & point);
  56. // Create a plane out of three points, ordered according to a right-hand convention.
  57. PlaneClass(const Vector3 & point1, const Vector3 & point2, const Vector3 & point3);
  58. void Set(float a,float b,float c,float d) { N[0] = a; N[1] = b; N[2] = c; D = d; }
  59. };
  60. inline PlaneClass::PlaneClass(const Vector3 & normal,const Vector3 & point)
  61. {
  62. N = normal;
  63. D = Vector3::Dot_Product(normal , point);
  64. }
  65. inline PlaneClass::PlaneClass(const Vector3 & point1, const Vector3 & point2, const Vector3 & point3)
  66. {
  67. N = Vector3::Cross_Product((point2 - point1), (point3 - point1));
  68. if (N != Vector3(0.0f, 0.0f, 0.0f)) {
  69. // Points are not colinear. Normalize N and calculate D.
  70. N.Normalize();
  71. D = N * point1;
  72. } else {
  73. // They are colinear - return default plane (constructors can't fail).
  74. N = Vector3(0.0f, 0.0f, 1.0f);
  75. D = 0.0f;
  76. }
  77. }
  78. inline bool In_Front(const Vector3 & point,const PlaneClass & plane)
  79. {
  80. double dist = point * plane.N;
  81. return (dist > plane.D);
  82. }
  83. #endif /*PLANE_H*/