00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 #include <set>
00018 
00019 #include "Primitive.h"
00020 
00021 #ifndef N_POLYPRIM
00022 #define N_POLYPRIM
00023 
00024 namespace Fluxus
00025 {
00026 
00029 class PolyPrimitive : public Primitive
00030 {
00031 public:
00032     enum Type{TRISTRIP,QUADS,TRILIST,TRIFAN,POLYGON};
00033     
00034     PolyPrimitive(Type t=TRISTRIP);
00035     PolyPrimitive(const PolyPrimitive &other);
00036     virtual ~PolyPrimitive();
00037     
00041     virtual PolyPrimitive *Clone() const;
00042     virtual void Render();
00043     virtual dBoundingBox GetBoundingBox();
00044     virtual void RecalculateNormals(bool smooth);
00045     virtual void ApplyTransform(bool ScaleRotOnly=false);
00046     virtual string GetTypeName() { return "PolyPrimitive"; }
00048     
00049     Type GetType() { return m_Type; }
00050     virtual void AddVertex(const dVertex &Vert);    
00051 
00058 
00066     const vector<vector<int> > &GetConnectedVerts() { GenerateTopology(); return m_ConnectedVerts; }
00067     
00071     const vector<vector<pair<int,int> > > &GetUniqueEdges() { CalculateUniqueEdges(); return m_UniqueEdges; }
00072     
00075     const vector<dVector> &GetGeometricNormals() { GenerateTopology(); return m_GeometricNormals; }
00077 
00081     void SetIndexMode(bool s) { m_IndexMode=s; }
00082     bool IsIndexed() { return m_IndexMode; }
00083     vector<unsigned int> &GetIndex() { return m_IndexData; }
00086     void ConvertToIndexed();
00088     
00089     
00090 protected:
00091 
00092     virtual void PDataDirty();
00093     
00094     
00095     void GenerateTopology();
00096     void CalculateConnected();
00097     void CalculateGeometricNormals();
00098     void CalculateUniqueEdges();
00099     void UniqueEdgesFindShared(pair<int,int> edge, set<pair<int,int> > firstpass, set<pair<int,int> > &stored);
00100     void RecalculateNormalsIndexed();
00101     
00102     vector<vector<int> > m_ConnectedVerts;
00103     vector<dVector> m_GeometricNormals;
00104     vector<vector<pair<int,int> > > m_UniqueEdges;
00105     
00106     bool m_IndexMode;
00107     vector<unsigned int> m_IndexData;
00108     
00109     Type m_Type;
00110     vector<dVector> *m_VertData;
00111     vector<dVector> *m_NormData;
00112     vector<dColour> *m_ColData;
00113     vector<dVector> *m_TexData;
00114 };
00115 
00116 };
00117 
00118 #endif