00001 /*************************************************************************** 00002 cmesh.h - The libPlanet mesh class 00003 ------------------- 00004 begin : zo nov 4 2007 00005 copyright : (C) 2007 by CJP 00006 email : cornware-cjp@users.sourceforge.net 00007 ***************************************************************************/ 00008 00009 /*************************************************************************** 00010 * * 00011 * This program is free software; you can redistribute it and/or modify * 00012 * it under the terms of the GNU General Public License as published by * 00013 * the Free Software Foundation; either version 2 of the License, or * 00014 * (at your option) any later version. * 00015 * * 00016 ***************************************************************************/ 00017 #ifndef LIBPLANETCMESH_H 00018 #define LIBPLANETCMESH_H 00019 00020 #include <vector> 00021 #include <list> 00022 00023 #include <libprocter/cvector.h> 00024 #include <libprocter/cgridposition.h> 00025 #include <libprocter/ctexture.h> 00026 #include <libprocter/ctilesurface.h> 00027 00028 namespace libProcTer { 00029 00030 class CTileManager; 00031 class CTile; 00032 class CMesh; 00033 00039 struct SVertex 00040 { 00042 CVector pos; 00044 CVector nor; 00046 CVector tex; 00047 00049 CGridPosition gridpos; 00050 }; 00051 00061 struct STriangle 00062 { 00065 00066 unsigned int v1, v2, v3; 00068 00070 CVector nor; 00071 }; 00072 00078 struct SSphere 00079 { 00081 CVector mid; 00083 double R; 00084 }; 00085 00091 typedef std::list<CMesh> CMeshList; 00092 00098 class CMesh { 00099 public: 00103 CMesh(CTile *tile); 00105 ~CMesh(); 00106 00108 inline void setTile(CTile *tile) 00109 {m_Tile = tile;} 00110 00112 std::vector<SVertex> m_Vertices; 00114 std::vector<STriangle> m_Triangles; 00115 00123 SSphere m_BoundingSphere; 00124 00131 void recalcNormals(); 00132 00134 void updateSurface(); 00135 00139 bool checkIntegrity(); 00140 00147 inline CTexture *getTexture(CTileSurface::eTextureType type) const 00148 { 00149 if(m_Surface == NULL) return NULL; 00150 return m_Surface->getTexture(type); 00151 } 00152 00153 private: 00154 //The tile (used to get textures): 00155 CTile *m_Tile; 00156 00157 //The cached surface (from m_Tile): 00158 CTileSurface *m_Surface; 00159 }; 00160 00161 } 00162 00163 #endif