00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #if !defined(_XRB_ENGINE2_POLYGON_HPP_)
00012 #define _XRB_ENGINE2_POLYGON_HPP_
00013
00014 #include "xrb.hpp"
00015
00016 #include <vector>
00017
00018 #include "xrb_gltexture.hpp"
00019 #include "xrb_resourcelibrary.hpp"
00020 #include "xrb_serializer.hpp"
00021 #include "xrb_vector.hpp"
00022
00023 namespace Xrb
00024 {
00025
00026 namespace Engine2
00027 {
00028
00029 struct Polygon
00030 {
00031 struct Vertex
00032 {
00033 FloatVector2 *m_model_coordinate;
00034 FloatVector2 m_texture_coordinate;
00035 };
00036
00037 Uint32 m_vertex_count;
00038
00039 Vertex *m_vertex_array;
00040
00041
00042 Resource<GLTexture> m_texture;
00043
00044 Float m_area;
00045
00046 inline Polygon ()
00047 {
00048 m_vertex_count = 0;
00049 m_vertex_array = NULL;
00050 m_area = 0.0f;
00051 }
00052
00053 inline FloatVector2 const &GetVertex (Uint32 const index) const
00054 {
00055 ASSERT1(index < m_vertex_count);
00056 return *(m_vertex_array[index].m_model_coordinate);
00057 }
00058 inline FloatVector2 const &TextureCoordinate (Uint32 const index) const
00059 {
00060 ASSERT1(index < m_vertex_count);
00061 return m_vertex_array[index].m_texture_coordinate;
00062 }
00063
00064 Float Area () const;
00065 bool IsCounterclockwise () const;
00066 bool IsConvex () const;
00067 inline bool IsDegenerate () const
00068 {
00069 return m_area == 0.0f;
00070 }
00071
00072
00073
00074 void Draw () const;
00075
00076
00077
00078
00079 void CloneProperties (
00080 Polygon const *source_polygon,
00081 FloatVector2 *source_vertex_array,
00082 FloatVector2 *destination_vertex_array);
00083
00084 void Read (
00085 Serializer &serializer,
00086 FloatVector2 *compound_vertex_array);
00087
00088
00089
00090 void Write (
00091 Serializer &serializer,
00092 FloatVector2 const *compound_vertex_array) const;
00093
00094 };
00095
00096 }
00097
00098 }
00099
00100 #endif // !defined(_XRB_ENGINE2_POLYGON_HPP_)
00101