cstool/primitives.h Source File (Crystal Space 2.0 Public API Reference)

| ## Public API Reference

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

cstool/primitives.h
Go to the documentation of this file.

    00001 /*
    00002     Copyright (C) 2005 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_PRIMITIVES_H__
    00020 #define __CS_PRIMITIVES_H__
    00021
    00026 #include "csextern.h"
    00027
    00028 #include "csgeom/vector3.h"
    00029 #include "csgeom/vector2.h"
    00030 #include "csgeom/tri.h"
    00031 #include "csutil/cscolor.h"
    00032 #include "csutil/dirtyaccessarray.h"
    00033
    00034 class csBox3;
    00035 class csEllipsoid;
    00036
    00037 namespace CS
    00038 {
    00039 namespace Geometry
    00040 {
    00041
    00047 struct TextureMapper
    00048 {
    00049   virtual ~TextureMapper() {}
    00050
    00058   virtual csVector2 Map (const csVector3& point, const csVector3& normal,
    00059         size_t idx) = 0;
    00060 };
    00061
    00066 class TableTextureMapper : public TextureMapper
    00067 {
    00068 private:
    00069   const csVector2* table;
    00070
    00071 public:
    00072   TableTextureMapper (const csVector2* table) : table (table) { }
    00073   virtual ~TableTextureMapper () { }
    00074   virtual csVector2 Map (const csVector3&, const csVector3&, size_t idx)
    00075   {
    00076     return table[idx];
    00077   }
    00078 };
    00079
    00086 class CS_CRYSTALSPACE_EXPORT DensityTextureMapper : public TextureMapper
    00087 {
    00088 private:
    00089   float density;
    00090
    00091 public:
    00098   DensityTextureMapper (float density) : density (density) { }
    00099   virtual ~DensityTextureMapper () { }
    00100   virtual csVector2 Map (const csVector3&, const csVector3&, size_t idx);
    00101 };
    00102
    00106 class CS_CRYSTALSPACE_EXPORT Primitives
    00107 {
    00108 public:
    00109   static csVector2 boxTable[];
    00110   static csVector2 quadTable[];
    00111
    00112   enum BoxFlags
    00113   {
    00114     CS_PRIMBOX_INSIDE = 1,
    00115     CS_PRIMBOX_SMOOTH = 2
    00116   };
    00117
    00128   static void GenerateBox (
    00129       const csBox3& box,
    00130       csDirtyAccessArray<csVector3>& mesh_vertices,
    00131       csDirtyAccessArray<csVector2>& mesh_texels,
    00132       csDirtyAccessArray<csVector3>& mesh_normals,
    00133       csDirtyAccessArray<csTriangle>& mesh_triangles,
    00134       uint32 flags = CS_PRIMBOX_SMOOTH,
    00135       TextureMapper* mapper = 0);
    00136
    00142   static void GenerateQuad (
    00143       const csVector3 &v1, const csVector3 &v2,
    00144       const csVector3 &v3, const csVector3 &v4,
    00145       csDirtyAccessArray<csVector3>& mesh_vertices,
    00146       csDirtyAccessArray<csVector2>& mesh_texels,
    00147       csDirtyAccessArray<csVector3>& mesh_normals,
    00148       csDirtyAccessArray<csTriangle>& mesh_triangles,
    00149       TextureMapper* mapper = 0);
    00150
    00161   static void GenerateTesselatedQuad (
    00162       const csVector3 &v0,
    00163       const csVector3 &v1, const csVector3 &v2,
    00164       int tesselations,
    00165       csDirtyAccessArray<csVector3>& mesh_vertices,
    00166       csDirtyAccessArray<csVector2>& mesh_texels,
    00167       csDirtyAccessArray<csVector3>& mesh_normals,
    00168       csDirtyAccessArray<csTriangle>& mesh_triangles,
    00169       TextureMapper* mapper = 0);
    00170
    00180   static void GenerateCylinder (float l, float r, uint sides,
    00181       csDirtyAccessArray<csVector3>& mesh_vertices,
    00182       csDirtyAccessArray<csVector2>& mesh_texels,
    00183       csDirtyAccessArray<csVector3>& mesh_normals,
    00184       csDirtyAccessArray<csTriangle>& mesh_triangles,
    00185       TextureMapper* mapper = 0);
    00186
    00196   static void GenerateCapsule (float l, float r, uint sides,
    00197       csDirtyAccessArray<csVector3>& mesh_vertices,
    00198       csDirtyAccessArray<csVector2>& mesh_texels,
    00199       csDirtyAccessArray<csVector3>& mesh_normals,
    00200       csDirtyAccessArray<csTriangle>& mesh_triangles,
    00201       TextureMapper* mapper = 0);
    00202
    00218   static void GenerateSphere (const csEllipsoid& ellips, int num,
    00219       csDirtyAccessArray<csVector3>& mesh_vertices,
    00220       csDirtyAccessArray<csVector2>& mesh_texels,
    00221       csDirtyAccessArray<csVector3>& mesh_normals,
    00222       csDirtyAccessArray<csTriangle>& mesh_triangles,
    00223       bool cyl_mapping = false,
    00224       bool toponly = false,
    00225       bool reversed = false,
    00226       TextureMapper* mapper = 0);
    00227
    00237   static void GenerateCone (float l, float r, uint sides,
    00238       csDirtyAccessArray<csVector3>& mesh_vertices,
    00239       csDirtyAccessArray<csVector2>& mesh_texels,
    00240       csDirtyAccessArray<csVector3>& mesh_normals,
    00241       csDirtyAccessArray<csTriangle>& mesh_triangles,
    00242       TextureMapper* mapper = 0);
    00243 };
    00244
    00245 } // namespace Geometry
    00246 } // namespace CS
    00247
    00253 class CS_CRYSTALSPACE_EXPORT
    00254   CS_DEPRECATED_TYPE_MSG ("csPrimitives is deprecated. Use CS::Geometry::Primitives instead")
    00255   csPrimitives : public CS::Geometry::Primitives
    00256 {
    00257 };
    00258
    00261 #endif // __CS_PRIMITIVES_H__
    00262