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 #include "PolyEvaluator.h"
00021
00022 #ifndef N_POLYPRIM
00023 #define N_POLYPRIM
00024
00025 namespace Fluxus
00026 {
00027
00030 class PolyPrimitive : public Primitive
00031 {
00032 public:
00033
00034 enum Type{TRISTRIP,QUADS,TRILIST,TRIFAN,POLYGON};
00035
00036 PolyPrimitive(Type t=TRISTRIP);
00037 PolyPrimitive(const PolyPrimitive &other);
00038 virtual ~PolyPrimitive();
00039
00043 virtual PolyPrimitive *Clone() const;
00044 virtual void Render();
00045 virtual dBoundingBox GetBoundingBox();
00046 virtual void RecalculateNormals(bool smooth);
00047 virtual void ApplyTransform(bool ScaleRotOnly=false);
00048 virtual string GetTypeName() { return "PolyPrimitive"; }
00049 virtual Evaluator *MakeEvaluator() { return new PolyEvaluator(this); }
00051
00052 Type GetType() const { return m_Type; }
00053
00055 virtual void AddVertex(const dVertex &Vert);
00056
00058 void Clear();
00059
00066
00074 const vector<vector<int> > &GetConnectedVerts() { GenerateTopology(); return m_ConnectedVerts; }
00075
00079 const vector<vector<pair<int,int> > > &GetUniqueEdges() { CalculateUniqueEdges(); return m_UniqueEdges; }
00080
00083 const vector<dVector> &GetGeometricNormals() { GenerateTopology(); return m_GeometricNormals; }
00085
00089 void SetIndexMode(bool s) { m_IndexMode=s; }
00090 bool IsIndexed() const { return m_IndexMode; }
00091 vector<unsigned int> &GetIndex() { return m_IndexData; }
00092 const vector<unsigned int> &GetIndexConst() const { return m_IndexData; }
00095 void ConvertToIndexed();
00097
00098
00099 protected:
00100
00101 virtual void PDataDirty();
00102
00103
00104 void GenerateTopology();
00105 void CalculateConnected();
00106 void CalculateGeometricNormals();
00107 void CalculateUniqueEdges();
00108 void UniqueEdgesFindShared(pair<int,int> edge, set<pair<int,int> > firstpass, set<pair<int,int> > &stored);
00109 void RecalculateNormalsIndexed();
00110
00111 vector<vector<int> > m_ConnectedVerts;
00112 vector<dVector> m_GeometricNormals;
00113 vector<vector<pair<int,int> > > m_UniqueEdges;
00114
00115 bool m_IndexMode;
00116 vector<unsigned int> m_IndexData;
00117
00118 Type m_Type;
00119 vector<dVector> *m_VertData;
00120 vector<dVector> *m_NormData;
00121 vector<dColour> *m_ColData;
00122 vector<dVector> *m_TexData;
00123 };
00124
00125 };
00126
00127 #endif