Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members | Related Pages | Examples

vos/3D/a3dl/polygonmesh.hh

Go to the documentation of this file.
00001 /*
00002     This file is part of the Virtual Object System of
00003     the Interreality project (http://interreality.org).
00004 
00005     Copyright (C) 2001, 2002 Peter Amstutz
00006 
00007     This library is free software; you can redistribute it and/or
00008     modify it under the terms of the GNU Lesser General Public
00009     License as published by the Free Software Foundation; either
00010     version 2 of the License, or (at your option) any later version.
00011 
00012     This library is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015     Lesser General Public License for more details.
00016 
00017     You should have received a copy of the GNU Lesser General Public
00018     License along with this library; if not, write to the Free Software
00019     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
00020 
00021     Peter Amstutz <tetron@interreality.org>
00022 */
00023 #ifndef _POLYGONMESH_HH_
00024 #define _POLYGONMESH_HH_
00025 
00026 #if defined(_WIN32) && defined(_MSC_VER)
00027 # ifdef A3DL_EXPORTS
00028 #  define A3DL_API __declspec(dllexport)
00029 # else
00030 #  define A3DL_API __declspec(dllimport)
00031 # endif
00032 #else
00033 # define A3DL_API
00034 #endif
00035 
00036 #include <vos/corelibs/vos/vos.hh>
00037 #include <vos/metaobjects/property/property.hh>
00038 #include <vector>
00039 #include "object3d.hh"
00040 #include "portal.hh"
00041 
00042 namespace A3DL
00043 {
00044     class A3DL_API PolygonMesh : public virtual Object3D
00045     {
00046     public:
00047         PolygonMesh(MetaObject* superobject);
00048         ~PolygonMesh();
00049 
00050         struct Vertex
00051         {
00052             float x, y, z;
00053         };
00054 
00055         typedef vector<int> Polygon;
00056 
00057         struct Texel
00058         {
00059             float x, y;
00060         };
00061 
00062         enum TextureType { NoTexture = 0, UVcoord = 1, PolygonPlane = 2, ArbitraryPlane = 3, TexMatrix = 4};
00063         struct TextureSpace {
00064             TextureType type;
00065             bool isPortal;
00066             unsigned char material;
00067             union {
00068                 struct {
00069                     int vert1;
00070                     float u1, v1;
00071                     int vert2;
00072                     float u2, v2;
00073                     int vert3;
00074                     float u3, v3;
00075                 } UVcoord;
00076                 struct {
00077                     float xorg, yorg, zorg;
00078                     float x, y, z, len;
00079                 } PolygonPlane;
00080                 struct {
00081                     float xorg, yorg, zorg;
00082                     float x1, y1, z1, len1;
00083                     float x2, y2, z2, len2;
00084                 } ArbitraryPlane;
00085                 struct {
00086                     float m11, m12, m13;
00087                     float m21, m22, m23;
00088                     float m31, m32, m33;
00089                     float x, y, z;
00090                 } Matrix;
00091             } Rep;
00092         };
00093 
00094 
00095         /** Set a single vertex.
00096             @param which the index of vertex to set
00097             @param v the new vertex value
00098         */
00099         virtual void setVertex(unsigned int which, Vertex& v);
00100 
00101         /** Set all vertices at once.
00102             @param v the new vertex array
00103          */
00104         virtual void setVertices(const vector<Vertex>& v);
00105 
00106         /** Get all vertices
00107             @param v the vertices will be filled into this vector
00108          */
00109         virtual void getVertices(vector<Vertex>& v);
00110 
00111 
00112         /** Change a single polygon.  This is very efficient for
00113             strictly triangular meshes, less efficient for polygonal
00114             meshes.
00115             @param which the index of polygon to set
00116             @param v the new polygon
00117         */
00118         virtual void setPolygon(unsigned int which, Polygon& v);
00119 
00120         /** Set all polygons at once.
00121             @param v new polygon list
00122         */
00123         virtual void setPolygons(const vector<Polygon>& v);
00124 
00125         /** Get all polygons.
00126             @param v the polygons will be filled into this vector
00127          */
00128         virtual void getPolygons(vector<Polygon>& v);
00129 
00130 
00131         /** Set the vertex normal vector, used for lighting.
00132             @param which the index of the vertex this normal applies to
00133             @param v the normal vector value
00134         */
00135         virtual void setNormal(unsigned int which, Vertex& v);
00136 
00137         /** Set all the normals at once.
00138             @param v array of vertex normals
00139          */
00140         virtual void setNormals(const vector<Vertex>& v);
00141 
00142         /** Get the normal vectors.
00143             @param v the normals will be stored in this vector
00144         */
00145         virtual void getNormals(vector<Vertex>& v);
00146 
00147 
00148         /** Set all UV coordinates at once.
00149             @param which the vertex index this UV coordinate applies to
00150             @param v the UV coordinates for this
00151         */
00152         virtual void setTexel(int which, Texel& v);
00153 
00154         /** Set all UV coordinates at once.
00155             @param v the UV coordinates for each vertex.
00156         */
00157         virtual void setTexels(const vector<Texel>& v);
00158 
00159         /** Get all UV coordinates.
00160             @param v the UV coordinates will be stored in this vector
00161         */
00162         virtual void getTexels(vector<Texel>& v);
00163 
00164         /** Set the texture mapping for a specific polygon.
00165             @param which the polygon index to be changed
00166             @param t the new texture space to use
00167         */
00168         virtual void setTextureSpace(unsigned int which, const TextureSpace& t);
00169 
00170         /** Set the per-polygon texture spaces.
00171             @param t the texture space to use for each polygon
00172         */
00173         virtual void setTextureSpaces(const vector<TextureSpace>& t);
00174 
00175         /** Get the current texture spaces used for polygons.
00176             @param t the texture spaces will be stored here
00177          */
00178         virtual void getTextureSpaces(vector<TextureSpace>& t);
00179 
00180         /** Set whether to treat polygons as double sided or single
00181             sided.  Direction is determined using the cross product of
00182             the first two edges, with the vertices listed in clockwise
00183             order.
00184             @param ds the flag, true for double sided, false for single sided
00185         */
00186         virtual void setDoubleSided(bool ds);
00187 
00188         /** Are these polygons double sided?
00189             @return true for double sided polygons, false for single
00190             sided polygons.
00191         */
00192         virtual bool getDoubleSided();
00193 
00194         virtual vector<Portal*> getPortals();
00195 
00196         static void unpackTextureSpace(const unsigned char* data, TextureSpace& t);
00197         static void packTextureSpace(unsigned char* data, const TextureSpace& t);
00198 
00199         virtual const string getType();
00200         static void registerExtenders();
00201         static MetaObject* new_PolygonMesh(MetaObject* superobject, const string& type);
00202     };
00203 }
00204 
00205 #endif

Generated on Tue Aug 12 03:55:36 2003 for Interreality Project - VOS by doxygen 1.3.2