TriangleList.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #ifndef TriangleList_H
  2. #define TriangleList_H
  3. #include "Array.h"
  4. #include "Point.h"
  5. namespace Framework
  6. {
  7. template<typename T>
  8. //! A corner of a triangle
  9. struct TriangleVertex
  10. {
  11. T* punkt;
  12. Vec2<float>* textur;
  13. //! Constructor
  14. //! \param punkt The coordinate of the corner
  15. //! \param textur The coordinate in the texture
  16. TriangleVertex(T* punkt, Vec2<float>* textur)
  17. {
  18. this->punkt = punkt;
  19. this->textur = textur;
  20. }
  21. //! Destructor
  22. ~TriangleVertex()
  23. {
  24. delete punkt;
  25. delete textur;
  26. }
  27. };
  28. template<typename T>
  29. //! A list of triangles where the last two points of the previous triangle
  30. //! together with the next point form a new triangle
  31. class TriangleList : public virtual ReferenceCounter
  32. {
  33. private:
  34. Array<TriangleVertex<T>*>* punkte;
  35. public:
  36. //! Constructor
  37. TriangleList()
  38. : ReferenceCounter()
  39. {
  40. punkte = new Array<TriangleVertex<T>*>();
  41. }
  42. //! Destructor
  43. ~TriangleList()
  44. {
  45. int anz = punkte->getEntryCount();
  46. for (int i = 0; i < anz; i++)
  47. delete punkte->get(i);
  48. punkte->release();
  49. }
  50. //! Adds a point to the list
  51. //! \param p The coordinates of the point
  52. //! \param textur The coordinates in the texture
  53. void addPunkt(T* p, Vec2<float>* textur)
  54. {
  55. punkte->add(new TriangleVertex<T>(p, textur));
  56. }
  57. //! Deletes the last point
  58. void removeLetztenPunkt()
  59. {
  60. int i = punkte->getEntryCount() - 1;
  61. if (!punkte->hat(i)) return;
  62. delete punkte->get(i);
  63. punkte->remove(i);
  64. }
  65. //! Deletes all corners
  66. void lehren()
  67. {
  68. int anz = punkte->getEntryCount();
  69. for (int i = 0; i < anz; i++)
  70. delete punkte->get(i);
  71. punkte->leeren();
  72. }
  73. //! Returns the number of triangles
  74. int getDreieckAnzahl() const
  75. {
  76. return punkte->getEntryCount() - 2;
  77. }
  78. //! Returns whether a texture is used
  79. bool hasTexture() const
  80. {
  81. int anz = punkte->getEntryCount();
  82. bool ret = 1;
  83. for (int i = 0; i < anz; i++)
  84. {
  85. if (punkte->hat(i)) ret &= punkte->get(i)->textur;
  86. }
  87. return ret;
  88. }
  89. //! Returns the list of points
  90. Array<TriangleVertex<T>*>* zListe() const
  91. {
  92. return punkte;
  93. }
  94. };
  95. } // namespace Framework
  96. #endif