csgeom/polymesh.h
Go to the documentation of this file.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 00026 #include "csutil/win32/msvc_deprecated_warn_off.h" 00027 00028 #include "csgeom/box.h" 00029 #include "csgeom/tri.h" 00030 #include "csgeom/vector3.h" 00031 #include "csutil/flags.h" 00032 #include "csutil/scf_implementation.h" 00033 00034 #include "igeom/polymesh.h" 00035 00036 00037 struct csTriangle; 00038 00052 class CS_DEPRECATED_TYPE_MSG("csPolygonMesh is deprecated; use csTriangleMesh instead") 00053 CS_CRYSTALSPACE_EXPORT csPolygonMesh : 00054 public scfImplementation1<csPolygonMesh, iPolygonMesh> 00055 { 00056 private: 00057 uint32 change_nr; 00058 00059 int vt_count; 00060 csVector3* vt; 00061 bool delete_vt; // If true this class is responsible for cleanup. 00062 00063 int po_count; 00064 csMeshedPolygon* po; 00065 bool delete_po; // If true this class is responsible for cleanup. 00066 00067 int* po_indices; // Index table used in 'po'. 00068 bool delete_po_indices; 00069 00070 csFlags flags; 00071 00072 // Not given by default but automatically calculated. 00073 csTriangle* triangles; 00074 int triangle_count; 00075 00076 void Triangulate (); 00077 00078 public: 00082 csPolygonMesh () : scfImplementationType(this) 00083 { 00084 change_nr = 0; 00085 vt = 0; 00086 vt_count = 0; 00087 delete_vt = false; 00088 po = 0; 00089 po_count = 0; 00090 delete_po = false; 00091 po_indices = 0; 00092 delete_po_indices = false; 00093 triangles = 0; 00094 triangle_count = 0; 00095 } 00096 00097 virtual ~csPolygonMesh () 00098 { 00099 if (delete_vt) delete[] vt; 00100 if (delete_po) delete[] po; 00101 if (delete_po_indices) delete[] po_indices; 00102 delete[] triangles; 00103 } 00104 00111 void SetVertices (csVector3* vt, int vt_count, bool delete_vt) 00112 { 00113 csPolygonMesh::vt = vt; 00114 csPolygonMesh::vt_count = vt_count; 00115 csPolygonMesh::delete_vt = delete_vt; 00116 ShapeChanged (); 00117 } 00118 00125 void SetPolygons (csMeshedPolygon* po, int po_count, bool delete_po) 00126 { 00127 csPolygonMesh::po = po; 00128 csPolygonMesh::po_count = po_count; 00129 csPolygonMesh::delete_po = delete_po; 00130 ShapeChanged (); 00131 } 00132 00136 void SetPolygonIndices (int* po_indices, bool delete_po_indices) 00137 { 00138 csPolygonMesh::po_indices = po_indices; 00139 csPolygonMesh::delete_po_indices = delete_po_indices; 00140 ShapeChanged (); 00141 } 00142 00148 void SetPolygonIndexCount (int po_index_count) 00149 { 00150 po_indices = new int[po_index_count]; 00151 delete_po_indices = true; 00152 ShapeChanged (); 00153 } 00154 00156 int* GetPolygonIndices () 00157 { 00158 return po_indices; 00159 } 00160 00166 void SetVertexCount (int vt_count) 00167 { 00168 vt = new csVector3[vt_count]; 00169 csPolygonMesh::vt_count = vt_count; 00170 delete_vt = true; 00171 ShapeChanged (); 00172 } 00173 00179 void SetPolygonCount (int po_count) 00180 { 00181 po = new csMeshedPolygon[po_count]; 00182 csPolygonMesh::po_count = po_count; 00183 delete_po = true; 00184 ShapeChanged (); 00185 } 00186 00190 void ShapeChanged () 00191 { 00192 change_nr++; 00193 } 00194 00195 virtual int GetVertexCount () { return vt_count; } 00196 virtual csVector3* GetVertices () { return vt; } 00197 virtual int GetPolygonCount () { return po_count; } 00198 virtual csMeshedPolygon* GetPolygons () { return po; } 00199 virtual int GetTriangleCount () 00200 { 00201 Triangulate (); 00202 return triangle_count; 00203 } 00204 virtual csTriangle* GetTriangles () 00205 { 00206 Triangulate (); 00207 return triangles; 00208 } 00209 virtual void Lock () { } 00210 virtual void Unlock () { } 00211 virtual csFlags& GetFlags () { return flags; } 00212 virtual uint32 GetChangeNumber () const { return change_nr; } 00213 }; 00214 00219 class CS_DEPRECATED_TYPE_MSG("csPolygonMeshBox is deprecated; use csTriangleMeshBox instead") 00220 CS_CRYSTALSPACE_EXPORT csPolygonMeshBox : 00221 public virtual scfImplementation1<csPolygonMeshBox,iPolygonMesh> 00222 { 00223 private: 00224 csVector3 vertices[8]; 00225 csMeshedPolygon polygons[6]; 00226 csTriangle* triangles; 00227 int vertex_indices[4*6]; 00228 uint32 change_nr; 00229 csFlags flags; 00230 00231 public: 00235 csPolygonMeshBox (const csBox3& box) : scfImplementationType(this) 00236 { 00237 change_nr = 0; 00238 int i; 00239 for (i = 0 ; i < 6 ; i++) 00240 { 00241 polygons[i].num_vertices = 4; 00242 polygons[i].vertices = &vertex_indices[i*4]; 00243 } 00244 vertex_indices[0*4+0] = 4; 00245 vertex_indices[0*4+1] = 5; 00246 vertex_indices[0*4+2] = 1; 00247 vertex_indices[0*4+3] = 0; 00248 vertex_indices[1*4+0] = 5; 00249 vertex_indices[1*4+1] = 7; 00250 vertex_indices[1*4+2] = 3; 00251 vertex_indices[1*4+3] = 1; 00252 vertex_indices[2*4+0] = 7; 00253 vertex_indices[2*4+1] = 6; 00254 vertex_indices[2*4+2] = 2; 00255 vertex_indices[2*4+3] = 3; 00256 vertex_indices[3*4+0] = 6; 00257 vertex_indices[3*4+1] = 4; 00258 vertex_indices[3*4+2] = 0; 00259 vertex_indices[3*4+3] = 2; 00260 vertex_indices[4*4+0] = 6; 00261 vertex_indices[4*4+1] = 7; 00262 vertex_indices[4*4+2] = 5; 00263 vertex_indices[4*4+3] = 4; 00264 vertex_indices[5*4+0] = 0; 00265 vertex_indices[5*4+1] = 1; 00266 vertex_indices[5*4+2] = 3; 00267 vertex_indices[5*4+3] = 2; 00268 SetBox (box); 00269 00270 flags.SetAll (CS_POLYMESH_CLOSED | CS_POLYMESH_CONVEX 00271 | CS_POLYMESH_TRIANGLEMESH); 00272 triangles = 0; 00273 } 00274 00275 virtual ~csPolygonMeshBox () 00276 { 00277 delete[] triangles; 00278 } 00279 00283 void SetBox (const csBox3& box) 00284 { 00285 change_nr++; 00286 vertices[0] = box.GetCorner (0); 00287 vertices[1] = box.GetCorner (1); 00288 vertices[2] = box.GetCorner (2); 00289 vertices[3] = box.GetCorner (3); 00290 vertices[4] = box.GetCorner (4); 00291 vertices[5] = box.GetCorner (5); 00292 vertices[6] = box.GetCorner (6); 00293 vertices[7] = box.GetCorner (7); 00294 } 00295 00296 virtual int GetVertexCount () { return 8; } 00297 virtual csVector3* GetVertices () { return vertices; } 00298 virtual int GetPolygonCount () { return 6; } 00299 virtual csMeshedPolygon* GetPolygons () { return polygons; } 00300 virtual int GetTriangleCount () { return 12; } 00301 virtual csTriangle* GetTriangles (); 00302 virtual void Lock () { } 00303 virtual void Unlock () { } 00304 virtual csFlags& GetFlags () { return flags; } 00305 virtual uint32 GetChangeNumber () const { return change_nr; } 00306 }; 00307 00308 00309 00312 #include "csutil/win32/msvc_deprecated_warn_on.h" 00313 00314 #endif // __CS_CSGEOM_POLYMESH_H__ 00315
Generated for Crystal Space 1.2.1 by doxygen 1.5.3