Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages
polymesh.h
00001 /* 00002 Crystal Space 3D engine 00003 Copyright (C) 2003 by Jorrit Tyberghein 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Library General Public 00007 License as published by the Free Software Foundation; either 00008 version 2 of the License, or (at your option) any later version. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Library General Public License for more details. 00014 00015 You should have received a copy of the GNU Library General Public 00016 License along with this library; if not, write to the Free 00017 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00018 */ 00019 00020 #ifndef __CS_CSGEOM_POLYMESH_H__ 00021 #define __CS_CSGEOM_POLYMESH_H__ 00022 00023 #include "csextern.h" 00024 00025 #include "csgeom/box.h" 00026 #include "csgeom/tri.h" 00027 #include "csgeom/vector3.h" 00028 #include "csutil/flags.h" 00029 #include "csutil/scf_implementation.h" 00030 00031 #include "igeom/polymesh.h" 00032 00033 struct csTriangle; 00034 00035 00045 class CS_CRYSTALSPACE_EXPORT csPolygonMesh : 00046 public scfImplementation1<csPolygonMesh,iPolygonMesh> 00047 { 00048 private: 00049 uint32 change_nr; 00050 00051 int vt_count; 00052 csVector3* vt; 00053 bool delete_vt; // If true this class is responsible for cleanup. 00054 00055 int po_count; 00056 csMeshedPolygon* po; 00057 bool delete_po; // If true this class is responsible for cleanup. 00058 00059 int* po_indices; // Index table used in 'po'. 00060 bool delete_po_indices; 00061 00062 csFlags flags; 00063 00064 // Not given by default but automatically calculated. 00065 csTriangle* triangles; 00066 int triangle_count; 00067 00068 void Triangulate (); 00069 00070 public: 00074 csPolygonMesh () : scfImplementationType(this) 00075 { 00076 change_nr = 0; 00077 vt = 0; 00078 vt_count = 0; 00079 delete_vt = false; 00080 po = 0; 00081 po_count = 0; 00082 delete_po = false; 00083 po_indices = 0; 00084 delete_po_indices = false; 00085 triangles = 0; 00086 triangle_count = 0; 00087 } 00088 00089 virtual ~csPolygonMesh () 00090 { 00091 if (delete_vt) delete[] vt; 00092 if (delete_po) delete[] po; 00093 if (delete_po_indices) delete[] po_indices; 00094 delete[] triangles; 00095 } 00096 00103 void SetVertices (csVector3* vt, int vt_count, bool delete_vt) 00104 { 00105 csPolygonMesh::vt = vt; 00106 csPolygonMesh::vt_count = vt_count; 00107 csPolygonMesh::delete_vt = delete_vt; 00108 ShapeChanged (); 00109 } 00110 00117 void SetPolygons (csMeshedPolygon* po, int po_count, bool delete_po) 00118 { 00119 csPolygonMesh::po = po; 00120 csPolygonMesh::po_count = po_count; 00121 csPolygonMesh::delete_po = delete_po; 00122 ShapeChanged (); 00123 } 00124 00128 void SetPolygonIndices (int* po_indices, bool delete_po_indices) 00129 { 00130 csPolygonMesh::po_indices = po_indices; 00131 csPolygonMesh::delete_po_indices = delete_po_indices; 00132 ShapeChanged (); 00133 } 00134 00140 void SetPolygonIndexCount (int po_index_count) 00141 { 00142 po_indices = new int[po_index_count]; 00143 delete_po_indices = true; 00144 ShapeChanged (); 00145 } 00146 00148 int* GetPolygonIndices () 00149 { 00150 return po_indices; 00151 } 00152 00158 void SetVertexCount (int vt_count) 00159 { 00160 vt = new csVector3[vt_count]; 00161 csPolygonMesh::vt_count = vt_count; 00162 delete_vt = true; 00163 ShapeChanged (); 00164 } 00165 00171 void SetPolygonCount (int po_count) 00172 { 00173 po = new csMeshedPolygon[po_count]; 00174 csPolygonMesh::po_count = po_count; 00175 delete_po = true; 00176 ShapeChanged (); 00177 } 00178 00182 void ShapeChanged () 00183 { 00184 change_nr++; 00185 } 00186 00187 virtual int GetVertexCount () { return vt_count; } 00188 virtual csVector3* GetVertices () { return vt; } 00189 virtual int GetPolygonCount () { return po_count; } 00190 virtual csMeshedPolygon* GetPolygons () { return po; } 00191 virtual int GetTriangleCount () 00192 { 00193 Triangulate (); 00194 return triangle_count; 00195 } 00196 virtual csTriangle* GetTriangles () 00197 { 00198 Triangulate (); 00199 return triangles; 00200 } 00201 virtual void Lock () { } 00202 virtual void Unlock () { } 00203 virtual csFlags& GetFlags () { return flags; } 00204 virtual uint32 GetChangeNumber () const { return change_nr; } 00205 }; 00206 00210 class CS_CRYSTALSPACE_EXPORT csPolygonMeshBox : 00211 public virtual scfImplementation1<csPolygonMeshBox,iPolygonMesh> 00212 { 00213 private: 00214 csVector3 vertices[8]; 00215 csMeshedPolygon polygons[6]; 00216 csTriangle* triangles; 00217 int vertex_indices[4*6]; 00218 uint32 change_nr; 00219 csFlags flags; 00220 00221 public: 00225 csPolygonMeshBox (const csBox3& box) : scfImplementationType(this) 00226 { 00227 change_nr = 0; 00228 int i; 00229 for (i = 0 ; i < 6 ; i++) 00230 { 00231 polygons[i].num_vertices = 4; 00232 polygons[i].vertices = &vertex_indices[i*4]; 00233 } 00234 vertex_indices[0*4+0] = 4; 00235 vertex_indices[0*4+1] = 5; 00236 vertex_indices[0*4+2] = 1; 00237 vertex_indices[0*4+3] = 0; 00238 vertex_indices[1*4+0] = 5; 00239 vertex_indices[1*4+1] = 7; 00240 vertex_indices[1*4+2] = 3; 00241 vertex_indices[1*4+3] = 1; 00242 vertex_indices[2*4+0] = 7; 00243 vertex_indices[2*4+1] = 6; 00244 vertex_indices[2*4+2] = 2; 00245 vertex_indices[2*4+3] = 3; 00246 vertex_indices[3*4+0] = 6; 00247 vertex_indices[3*4+1] = 4; 00248 vertex_indices[3*4+2] = 0; 00249 vertex_indices[3*4+3] = 2; 00250 vertex_indices[4*4+0] = 6; 00251 vertex_indices[4*4+1] = 7; 00252 vertex_indices[4*4+2] = 5; 00253 vertex_indices[4*4+3] = 4; 00254 vertex_indices[5*4+0] = 0; 00255 vertex_indices[5*4+1] = 1; 00256 vertex_indices[5*4+2] = 3; 00257 vertex_indices[5*4+3] = 2; 00258 SetBox (box); 00259 00260 flags.SetAll (CS_POLYMESH_CLOSED | CS_POLYMESH_CONVEX 00261 | CS_POLYMESH_TRIANGLEMESH); 00262 triangles = 0; 00263 } 00264 00265 virtual ~csPolygonMeshBox () 00266 { 00267 delete[] triangles; 00268 } 00269 00273 void SetBox (const csBox3& box) 00274 { 00275 change_nr++; 00276 vertices[0] = box.GetCorner (0); 00277 vertices[1] = box.GetCorner (1); 00278 vertices[2] = box.GetCorner (2); 00279 vertices[3] = box.GetCorner (3); 00280 vertices[4] = box.GetCorner (4); 00281 vertices[5] = box.GetCorner (5); 00282 vertices[6] = box.GetCorner (6); 00283 vertices[7] = box.GetCorner (7); 00284 } 00285 00286 virtual int GetVertexCount () { return 8; } 00287 virtual csVector3* GetVertices () { return vertices; } 00288 virtual int GetPolygonCount () { return 6; } 00289 virtual csMeshedPolygon* GetPolygons () { return polygons; } 00290 virtual int GetTriangleCount () { return 12; } 00291 virtual csTriangle* GetTriangles (); 00292 virtual void Lock () { } 00293 virtual void Unlock () { } 00294 virtual csFlags& GetFlags () { return flags; } 00295 virtual uint32 GetChangeNumber () const { return change_nr; } 00296 }; 00297 00298 00299 00302 #endif // __CS_CSGEOM_POLYMESH_H__ 00303
Generated for Crystal Space by doxygen 1.4.4