00001
00002 #ifndef __H_OBJECT_H_
00003 #define __H_OBJECT_H_
00004
00005 namespace std {}
00006 using namespace std;
00007
00008 #include <fstream>
00009
00010 #include <list>
00011
00012 #include "H_Graphics.h"
00013
00014 class OFFObject
00015 {
00016 public:
00017 class Vertex
00018 {
00019 public:
00020 Vertex();
00021 Vertex(const Point3D &APosition, const Point3D &ANormal, const Point2D &ATexCoord);
00022 Vertex(const Vertex &AVertex);
00023 istream &Read(istream &in);
00024 ostream &Write(ostream &out) const;
00025 public:
00026 Point3D Position;
00027 Point3D Normal;
00028 Point2D TexCoord;
00029 };
00030
00031 class Polygon
00032 {
00033 public:
00034 Polygon();
00035 ~Polygon();
00036 void InitNormal(const vector<Vertex> &OFFVertexes);
00037 void Invert();
00038 istream &Read(istream &in);
00039 ostream &Write(ostream &out) const;
00040 public:
00041 vector<unsigned int> IndexVertexes;
00042 Point3D Normal;
00043 Color MyColor;
00044 static const Color DefaultColor;
00045 };
00046
00047 class Buffer
00048 {
00049 public:
00050 void AddVertex(const Vertex &AOFFVertex);
00051 void AddPolygon(const Polygon &ATriangle);
00052 void SetTexture(const char *ATextureName);
00053 void ReturnOffObject(OFFObject &tmp);
00054 private:
00055 list<Vertex> Vertexes;
00056 list<Polygon> Polygons;
00057 string TextureName;
00058 };
00059
00060 public:
00061 OFFObject();
00062 ~OFFObject();
00063 void readfile(const char* FileName);
00064 void writefile(const char* FileName);
00065 void debug_dump();
00066
00067 void InitMyData();
00068 void draw(const Ref &Position = Ref());
00069
00070 bool IsInit();
00071 REAL GetMaxDist();
00072 void InvertNormals();
00073 void Center();
00074 void Scale(const Point3D &scale);
00075 void Rotate(const Point3D &K);
00076 void Translate(const Point3D &K);
00077 void SetShading(bool AIsSmooth);
00078 bool GetShading();
00079 static bool UseOptimizedDraw;
00080 private:
00081 void Allocate(unsigned int NbVertex, unsigned int NbPolygons);
00082 void Release();
00083
00084 void BuildCompiledLists();
00085 void GLdraw(bool UseMaterial = true);
00086
00087 void GLdraw_NoOpt(bool UseMaterial = true);
00088
00089 private:
00090
00091 bool IsSmooth;
00092
00093 bool AllSameColor;
00094 Texture *MyTexture;
00095 int CompiledList;
00096 int CompiledList_NoMaterial;
00097 vector<Vertex> MyOFFVertexes;
00098 vector<Polygon> MyOFFPolygons;
00099
00100
00101 vector<unsigned int> TriIndexes;
00102
00103 friend class Buffer;
00104 friend istream &operator >> (istream &in, OFFObject::Vertex &AVertex);
00105 friend ostream &operator << (ostream &out, const OFFObject::Vertex &AVertex);
00106
00107 friend istream &operator >> (istream &in, OFFObject::Polygon &APolygon);
00108 friend ostream &operator << (ostream &out, const OFFObject::Polygon &APolygon);
00109 };
00110
00111 istream &operator >> (istream &in, OFFObject::Vertex &APoint);
00112 ostream &operator << (ostream &out, const OFFObject::Vertex &APoint);
00113
00114 istream &operator >> (istream &in, OFFObject::Polygon &APolygon);
00115 ostream &operator << (ostream &out, const OFFObject::Polygon &APolygon);
00116
00117 #endif //__OFF_OBJECT_H_