Bromeon
Multimedia/ConcaveShape.hpp
Go to the documentation of this file.
00001 
00002 //
00003 // Thor C++ Library
00004 // Copyright (c) 2011 Jan Haller
00005 // 
00006 // This software is provided 'as-is', without any express or implied
00007 // warranty. In no event will the authors be held liable for any damages
00008 // arising from the use of this software.
00009 // 
00010 // Permission is granted to anyone to use this software for any purpose,
00011 // including commercial applications, and to alter it and redistribute it
00012 // freely, subject to the following restrictions:
00013 // 
00014 // 1. The origin of this software must not be misrepresented; you must not
00015 //    claim that you wrote the original software. If you use this software
00016 //    in a product, an acknowledgment in the product documentation would be
00017 //    appreciated but is not required.
00018 // 
00019 // 2. Altered source versions must be plainly marked as such, and must not be
00020 //    misrepresented as being the original software.
00021 // 
00022 // 3. This notice may not be removed or altered from any source distribution.
00023 //
00025 
00028 
00029 #ifndef THOR_CONCAVESHAPE_HPP
00030 #define THOR_CONCAVESHAPE_HPP
00031 
00032 #include <Thor/Math/TriangulationFigures.hpp>
00033 #include <Thor/Detail/Swap.hpp>
00034 #include <Thor/Config.hpp>
00035 
00036 #include <SFML/Graphics/Drawable.hpp>
00037 #include <SFML/Graphics/Shape.hpp>
00038 
00039 #include <vector>
00040 
00041 
00042 namespace thor
00043 {
00044 
00047 
00051 class THOR_API ConcaveShape : public sf::Drawable
00052 {
00053     // ---------------------------------------------------------------------------------------------------------------------------
00054     // Public member functions
00055     public:
00058                                     ConcaveShape();
00059                             
00063                                     ConcaveShape(const sf::Shape& shape);
00064 
00067         void                        Swap(ConcaveShape& other);
00068         
00073         void                        AddPoint(float x, float y, const sf::Color& color, const sf::Color& outlineColor = sf::Color(0,0,0));
00074                                 
00079         void                        AddPoint(sf::Vector2f position, const sf::Color& color, const sf::Color& outlineColor = sf::Color(0,0,0));
00080 
00083         void                        SetOutlineThickness(float outlineThickness);
00084         
00087         float                       GetOutlineThickness() const;
00088         
00089 
00090     // ---------------------------------------------------------------------------------------------------------------------------
00091     // Private types
00092     private:     
00093         struct Point : Vertex
00094         {
00095                                         Point(sf::Vector2f position, const sf::Color& fillColor, const sf::Color& outlineColor);
00096 
00097             sf::Color                   fillColor;
00098             sf::Color                   outlineColor;
00099         };
00100         
00101         // Container typedefs
00102         typedef std::vector<sf::Shape>      ShapeContainer;
00103         typedef std::vector<Point>          PointContainer;
00104         typedef std::vector< Edge<Point> >  EdgeContainer;
00105 
00106         struct TriangleGenerator;
00107 
00108 
00109     // ---------------------------------------------------------------------------------------------------------------------------
00110     // Private member functions
00111     private:
00112         // Renders the shape to target.
00113         virtual void                Render(sf::RenderTarget& target, sf::Renderer& renderer) const;
00114         
00115         // Computes how the shape can be split up into convex triangles.
00116         void                        Decompose() const;
00117                 
00118         // Forms the outline out of the given edges.
00119         void                        FormOutline() const;
00120                 
00121 
00122     // ---------------------------------------------------------------------------------------------------------------------------
00123     // Private variables
00124     private:
00125         PointContainer              mPoints;
00126         float                       mOutlineThickness;
00127 
00128         mutable EdgeContainer       mEdges;
00129         mutable ShapeContainer      mTriangleShapes;
00130         mutable ShapeContainer      mEdgeShapes;
00131         mutable bool                mNeedsTriangleUpdate;
00132         mutable bool                mNeedsEdgeUpdate;
00133 };
00134 
00137 THOR_GLOBAL_SWAP(ConcaveShape)
00138 
00139 
00140 
00141 } // namespace thor
00142 
00143 #endif // THOR_CONCAVESHAPE_HPP