IceTriangle.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2. /**
  3. * Contains a handy triangle class.
  4. * \file IceTriangle.h
  5. * \author Pierre Terdiman
  6. * \date January, 17, 2000
  7. */
  8. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  9. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  10. // Include Guard
  11. #ifndef __ICETRIANGLE_H__
  12. #define __ICETRIANGLE_H__
  13. // Forward declarations
  14. class Moment;
  15. // Partitioning values
  16. enum PartVal
  17. {
  18. TRI_MINUS_SPACE = 0, //!< Triangle is in the negative space
  19. TRI_PLUS_SPACE = 1, //!< Triangle is in the positive space
  20. TRI_INTERSECT = 2, //!< Triangle intersects plane
  21. TRI_ON_PLANE = 3, //!< Triangle and plane are coplanar
  22. TRI_FORCEDWORD = 0x7fffffff
  23. };
  24. // A triangle class.
  25. class ICEMATHS_API Triangle
  26. {
  27. public:
  28. //! Constructor
  29. inline_ Triangle() {}
  30. //! Constructor
  31. inline_ Triangle(const Point& p0, const Point& p1, const Point& p2) { mVerts[0]=p0; mVerts[1]=p1; mVerts[2]=p2; }
  32. //! Copy constructor
  33. inline_ Triangle(const Triangle& triangle)
  34. {
  35. mVerts[0] = triangle.mVerts[0];
  36. mVerts[1] = triangle.mVerts[1];
  37. mVerts[2] = triangle.mVerts[2];
  38. }
  39. //! Destructor
  40. inline_ ~Triangle() {}
  41. //! Vertices
  42. Point mVerts[3];
  43. // Methods
  44. void Flip();
  45. float Area() const;
  46. float Perimeter() const;
  47. float Compacity() const;
  48. void Normal(Point& normal) const;
  49. void DenormalizedNormal(Point& normal) const;
  50. void Center(Point& center) const;
  51. inline_ Plane PlaneEquation() const { return Plane(mVerts[0], mVerts[1], mVerts[2]); }
  52. PartVal TestAgainstPlane(const Plane& plane, float epsilon) const;
  53. // float Distance(Point& cp, Point& cq, Tri& tri);
  54. void ComputeMoment(Moment& m);
  55. float MinEdgeLength() const;
  56. float MaxEdgeLength() const;
  57. void ComputePoint(float u, float v, Point& pt, udword* nearvtx=null) const;
  58. void Inflate(float fat_coeff, bool constant_border);
  59. };
  60. #endif // __ICETRIANGLE_H__