CrystalSpace

Public API Reference

csgeom/trimesh.h

Go to the documentation of this file.
00001 /*
00002     Copyright (C) 2002 by Jorrit Tyberghein
00003 
00004     This library is free software; you can redistribute it and/or
00005     modify it under the terms of the GNU Library General Public
00006     License as published by the Free Software Foundation; either
00007     version 2 of the License, or (at your option) any later version.
00008 
00009     This library is distributed in the hope that it will be useful,
00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012     Library General Public License for more details.
00013 
00014     You should have received a copy of the GNU Library General Public
00015     License along with this library; if not, write to the Free
00016     Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00017 */
00018 
00019 #ifndef __CS_TRIMESH_H__
00020 #define __CS_TRIMESH_H__
00021 
00022 #include "csextern.h"
00023 #include "csutil/scf_implementation.h"
00024 
00025 #include "csgeom/tri.h"
00026 #include "csgeom/vector3.h"
00027 #include "csgeom/box.h"
00028 #include "igeom/trimesh.h"
00029 
00030 #include "csutil/array.h"
00031 #include "csutil/flags.h"
00032 #include "csutil/dirtyaccessarray.h"
00033 
00045 class CS_CRYSTALSPACE_EXPORT csTriangleMesh :
00046   public scfImplementation1<csTriangleMesh, iTriangleMesh>
00047 {
00048 protected:
00050   csDirtyAccessArray<csTriangle> triangles;
00051   // The vertices.
00052   csDirtyAccessArray<csVector3> vertices;
00053 
00054   uint32 change_nr;
00055   csFlags flags;
00056 
00057 public:
00059   csTriangleMesh () : scfImplementationType (this), change_nr (0) { }
00061   csTriangleMesh (const csTriangleMesh& mesh);
00063   virtual ~csTriangleMesh ();
00064 
00066   void AddVertex (const csVector3& v);
00068   virtual size_t GetVertexCount () { return vertices.GetSize (); }
00070   size_t GetVertexCount () const { return vertices.GetSize (); }
00072   virtual csVector3* GetVertices () { return vertices.GetArray (); }
00074   const csVector3* GetVertices () const { return vertices.GetArray (); }
00075 
00077   void AddTriangle (int a, int b, int c);
00079   virtual csTriangle* GetTriangles () { return triangles.GetArray (); }
00081   const csTriangle* GetTriangles () const { return triangles.GetArray (); }
00083   csTriangle& GetTriangle (int i) { return triangles[i]; }
00085   size_t GetTriangleCount () const { return triangles.GetSize (); }
00087   virtual size_t GetTriangleCount () { return triangles.GetSize (); }
00088 
00090   void Clear ();
00092   void SetSize (int count);
00094   void SetTriangles (csTriangle const* trigs, int count);
00095 
00096   virtual void Lock () { }
00097   virtual void Unlock () { }
00098   virtual csFlags& GetFlags () { return flags; }
00099   virtual uint32 GetChangeNumber () const { return change_nr; }
00100 };
00101 
00107 class CS_CRYSTALSPACE_EXPORT csTriangleVertex
00108 {
00109 public:
00111   csVector3 pos;
00113   int idx;
00114 
00116   csArray<size_t> con_triangles;
00117 
00119   csArray<int> con_vertices;
00120 
00122   csTriangleVertex () { }
00124   ~csTriangleVertex () { }
00126   void AddTriangle (size_t idx);
00128   void AddVertex (int idx);
00129 };
00130 
00135 class CS_CRYSTALSPACE_EXPORT csTriangleVertices
00136 {
00137 protected:
00138   csTriangleVertex* vertices;
00139   int num_vertices;
00140 
00141 public:
00143   csTriangleVertices (csTriangleMesh* mesh, csVector3* verts, int num_verts);
00145   ~csTriangleVertices ();
00150   void UpdateVertices (csVector3* verts);
00151 
00153   int GetVertexCount () const { return num_vertices; }
00155   csTriangleVertex& GetVertex (int idx) { return vertices[idx]; }
00156 };
00157 
00161 class CS_CRYSTALSPACE_EXPORT csTriangleMeshBox :
00162   public virtual scfImplementation1<csTriangleMeshBox,iTriangleMesh>
00163 {
00164 private:
00165   csVector3 vertices[8];
00166   csTriangle triangles[12];
00167   uint32 change_nr;
00168   csFlags flags;
00169 
00170 public:
00174   csTriangleMeshBox (const csBox3& box) : scfImplementationType(this)
00175   {
00176     change_nr = 0;
00177     triangles[0].Set (4, 5, 1);
00178     triangles[1].Set (4, 1, 0);
00179     triangles[2].Set (5, 7, 3);
00180     triangles[3].Set (5, 3, 1);
00181     triangles[4].Set (7, 6, 2);
00182     triangles[5].Set (7, 2, 3);
00183     triangles[6].Set (6, 4, 0);
00184     triangles[7].Set (6, 0, 2);
00185     triangles[8].Set (6, 7, 5);
00186     triangles[9].Set (6, 5, 4);
00187     triangles[10].Set (0, 1, 3);
00188     triangles[11].Set (0, 3, 2);
00189     SetBox (box);
00190 
00191     flags.SetAll (CS_TRIMESH_CLOSED | CS_TRIMESH_CONVEX);
00192   }
00193 
00194   virtual ~csTriangleMeshBox ()
00195   {
00196   }
00197 
00201   void SetBox (const csBox3& box)
00202   {
00203     change_nr++;
00204     vertices[0] = box.GetCorner (0);
00205     vertices[1] = box.GetCorner (1);
00206     vertices[2] = box.GetCorner (2);
00207     vertices[3] = box.GetCorner (3);
00208     vertices[4] = box.GetCorner (4);
00209     vertices[5] = box.GetCorner (5);
00210     vertices[6] = box.GetCorner (6);
00211     vertices[7] = box.GetCorner (7);
00212   }
00213 
00214   virtual size_t GetVertexCount () { return 8; }
00215   virtual csVector3* GetVertices () { return vertices; }
00216   virtual size_t GetTriangleCount () { return 12; }
00217   virtual csTriangle* GetTriangles () { return triangles; }
00218   virtual void Lock () { }
00219   virtual void Unlock () { }
00220   virtual csFlags& GetFlags () { return flags; }
00221   virtual uint32 GetChangeNumber () const { return change_nr; }
00222 };
00223 
00231 class CS_CRYSTALSPACE_EXPORT csTriangleMeshPointer :
00232   public virtual scfImplementation1<csTriangleMeshPointer,iTriangleMesh>
00233 {
00234 private:
00235   csVector3* vertices;
00236   size_t num_vertices;
00237   csTriangle* triangles;
00238   size_t num_triangles;
00239   uint32 change_nr;
00240   csFlags flags;
00241 
00242 public:
00246   csTriangleMeshPointer (csVector3* vertices, size_t num_vertices,
00247       csTriangle* triangles, size_t num_triangles)
00248     : scfImplementationType(this)
00249   {
00250     change_nr = 0;
00251     csTriangleMeshPointer::vertices = vertices;
00252     csTriangleMeshPointer::num_vertices = num_vertices;
00253     csTriangleMeshPointer::triangles = triangles;
00254     csTriangleMeshPointer::num_triangles = num_triangles;
00255   }
00256 
00257   virtual ~csTriangleMeshPointer ()
00258   {
00259   }
00260 
00261   virtual size_t GetVertexCount () { return num_vertices; }
00262   virtual csVector3* GetVertices () { return vertices; }
00263   virtual size_t GetTriangleCount () { return num_triangles; }
00264   virtual csTriangle* GetTriangles () { return triangles; }
00265   virtual void Lock () { }
00266   virtual void Unlock () { }
00267   virtual csFlags& GetFlags () { return flags; }
00268   virtual uint32 GetChangeNumber () const { return change_nr; }
00269 };
00270 
00271 #include "csutil/win32/msvc_deprecated_warn_off.h"
00272 
00273 #include "igeom/polymesh.h"
00274 
00281 class CS_CRYSTALSPACE_EXPORT csTriangleMeshPolyMesh
00282   : public virtual scfImplementation1<csTriangleMeshPolyMesh,iTriangleMesh>
00283 {
00284 private:
00285   iPolygonMesh* polymesh;
00286 
00287 public:
00288 
00289 #ifndef CS_DEPRECATION_SUPPRESS_HACK
00290   CS_DEPRECATED_METHOD_MSG("You shouldn't use this class!")
00291 #endif
00292   csTriangleMeshPolyMesh (iPolygonMesh* polymesh)
00293     : scfImplementationType(this), polymesh (polymesh)
00294   {
00295   }
00296 
00297   virtual ~csTriangleMeshPolyMesh ()
00298   {
00299   }
00300 
00301   virtual size_t GetVertexCount ()
00302   {
00303     return (size_t)polymesh->GetVertexCount ();
00304   }
00305   virtual csVector3* GetVertices ()
00306   {
00307     return polymesh->GetVertices ();
00308   }
00309   virtual size_t GetTriangleCount ()
00310   {
00311     return (size_t)polymesh->GetTriangleCount ();
00312   }
00313   virtual csTriangle* GetTriangles () { return polymesh->GetTriangles (); }
00314   virtual void Lock () { polymesh->Lock (); }
00315   virtual void Unlock () { polymesh->Unlock (); }
00316   virtual csFlags& GetFlags ()
00317   {
00318     // This works because CS_POLYMESH flags are compatible with
00319     // CS_TRIMESH flags. Since this is a temporary class that goes
00320     // away once iPolygonMesh goes away this is not a problem.
00321     return polymesh->GetFlags ();
00322   }
00323   virtual uint32 GetChangeNumber () const
00324   {
00325     return polymesh->GetChangeNumber ();
00326   }
00327 };
00328 
00329 #include "csutil/win32/msvc_deprecated_warn_on.h"
00330 
00331 
00334 #endif // __CS_TRIMESH_H__
00335 

Generated for Crystal Space 1.2.1 by doxygen 1.5.3