PolyPolygon.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*
  2. Copyright (C) 2011 by Ivan Safrin
  3. Permission is hereby granted, free of charge, to any person obtaining a copy
  4. of this software and associated documentation files (the "Software"), to deal
  5. in the Software without restriction, including without limitation the rights
  6. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. copies of the Software, and to permit persons to whom the Software is
  8. furnished to do so, subject to the following conditions:
  9. The above copyright notice and this permission notice shall be included in
  10. all copies or substantial portions of the Software.
  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  17. THE SOFTWARE.
  18. */
  19. #pragma once
  20. #include "PolyGlobals.h"
  21. #include "PolyVector3.h"
  22. #include "PolyRectangle.h"
  23. #include <vector>
  24. namespace Polycode {
  25. class Vertex;
  26. /**
  27. * A polygon structure.
  28. */
  29. class _PolyExport Polygon {
  30. public:
  31. /**
  32. * Default constructor.
  33. */
  34. Polygon();
  35. ~Polygon();
  36. /**
  37. * Returns the number of vertices in the polygon.
  38. * @return Number of vertices in the polygon.
  39. */
  40. unsigned int getVertexCount();
  41. /**
  42. * Returns the vertex at specified index.
  43. * @return Vertex at specified index.
  44. */
  45. Vertex *getVertex(unsigned int index);
  46. /**
  47. * Adds a new vertex with the specified position coordinates.
  48. * @param x X coordinate of new vertex.
  49. * @param y Y coordinate of new vertex.
  50. * @param z Z coordinate of new vertex.
  51. * @return Newly added vertex.
  52. */
  53. Vertex *addVertex(Number x, Number y, Number z);
  54. /**
  55. * Adds a new vertex with the specified position coordinates and texture coordinates.
  56. * @param x X coordinate of new vertex.
  57. * @param y Y coordinate of new vertex.
  58. * @param z Z coordinate of new vertex.
  59. * @param u Horizontal texture coordinate.
  60. * @param v Vertical texture coordinate.
  61. * @return Newly added vertex.
  62. */
  63. Vertex *addVertex(Number x, Number y, Number z, Number u, Number v);
  64. /**
  65. * Adds a new vertex.
  66. * @param vertex New vertex.
  67. */
  68. void addVertex(Vertex *vertex);
  69. /**
  70. * Removes and deletes the vertex at specified index.
  71. * @param index to remove vertex at.
  72. */
  73. void removeVertex(int index);
  74. /**
  75. * Calculates the average normal for the vertices.
  76. */
  77. void calculateNormal();
  78. /**
  79. * Calculates the tangent space vector for the vertices.
  80. */
  81. void calculateTangent();
  82. /**
  83. * Returns the face normal.
  84. * @return Face normal.
  85. */
  86. Vector3 getFaceNormal();
  87. /**
  88. * Returns the face tangent vector.
  89. * @return Face tangent vector.
  90. */
  91. Vector3 getFaceTangent();
  92. Rectangle getBounds2D();
  93. /**
  94. * Sets the polygon normal.
  95. * @param normal The new normal.
  96. */
  97. void setNormal(Vector3 normal);
  98. /**
  99. * If true, will use vertex normals, if false will use the polygon normal.
  100. */
  101. bool useVertexNormals;
  102. /**
  103. * Flips the texture coordinate vertically.
  104. */
  105. void flipUVY();
  106. protected:
  107. unsigned int vertexCount;
  108. std::vector<Vertex*> vertices;
  109. Vector3 normal;
  110. Vector3 tangent;
  111. };
  112. }