00001 00002 00003 #ifndef SGFFILE_H 00004 #define SGFFILE_H 00005 00006 00007 #include "Light.h" 00008 #include "Vector2f.h" 00009 #include "Vector3f.h" 00010 #include "Vector4f.h" 00011 #include "XMLDocument.h" 00012 #include "XMLNode.h" 00013 00014 #include <string> 00015 #include <vector> 00016 00017 00018 namespace pge { 00019 00020 00021 class SGFFile { 00022 00023 00024 public: 00025 //************************************************************************ 00026 // 00027 // Data structures. 00028 // 00029 //************************************************************************ 00030 struct SGFPrimitive { 00031 bool m_isTriangle; 00032 int m_indices[4]; 00033 Vector2f m_texCoords[4]; 00034 std::string m_textureFile; 00035 }; 00036 00037 00038 struct SGFMesh { 00039 std::vector<Vector3f> m_vertices; 00040 std::vector<SGFPrimitive> m_triangles; 00041 }; 00042 00043 00044 struct SGFLight { 00045 float m_intensity; 00046 Vector3f m_color; 00047 Vector3f m_position; 00048 }; 00049 00050 00051 //************************************************************************ 00052 // 00053 // Constructor 00054 // 00055 //************************************************************************ 00057 SGFFile(const std::string &filename); 00058 00059 00060 //************************************************************************ 00061 // 00062 // Destructor 00063 // 00064 //************************************************************************ 00066 virtual ~SGFFile(void); 00067 00068 00069 //************************************************************************ 00070 // 00071 // Functions 00072 // 00073 //************************************************************************ 00074 std::vector<SGFMesh>* getMeshs(void); 00075 std::vector<SGFLight>* getLights(void); 00076 00077 static void sgfLightToLight(SGFLight *sgfLight, Light *dest, Vector4f ambient, Vector4f specular); 00078 00079 00080 private: 00081 //************************************************************************ 00082 // 00083 // Functions 00084 // 00085 //************************************************************************ 00086 bool parseContent(void); 00087 bool parseMesh(xml::CXMLNode *meshNode); 00088 bool parseLight(xml::CXMLNode *lightNode); 00089 void quadToTriangles(SGFPrimitive quad, SGFPrimitive *t0, SGFPrimitive *t1); 00090 00091 00092 //************************************************************************ 00093 // 00094 // Variables 00095 // 00096 //************************************************************************ 00097 xml::CXMLDocument *m_document; 00098 00099 std::vector<SGFMesh> m_meshs; 00100 std::vector<SGFLight> m_lights; 00101 }; 00102 }; 00103 00104 #endif