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

OgreEdgeListBuilder.h

Go to the documentation of this file.
00001 /*
00002 -----------------------------------------------------------------------------
00003 This source file is part of OGRE
00004     (Object-oriented Graphics Rendering Engine)
00005 For the latest info, see http://www.ogre3d.org/
00006 
00007 Copyright © 2000-2003 The OGRE Team
00008 Also see acknowledgements in Readme.html
00009 
00010 This program is free software; you can redistribute it and/or modify it under
00011 the terms of the GNU Lesser General Public License as published by the Free Software
00012 Foundation; either version 2 of the License, or (at your option) any later
00013 version.
00014 
00015 This program is distributed in the hope that it will be useful, but WITHOUT
00016 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00017 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
00018 
00019 You should have received a copy of the GNU Lesser General Public License along with
00020 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
00021 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
00022 http://www.gnu.org/copyleft/lesser.txt.
00023 -----------------------------------------------------------------------------
00024 */
00025 #ifndef __EdgeListBuilder_H__
00026 #define __EdgeListBuilder_H__
00027 
00028 #include "OgrePrerequisites.h"
00029 #include "OgreVector4.h"
00030 #include "OgreHardwareVertexBuffer.h"
00031 #include "OgreRenderOperation.h"
00032 
00033 namespace Ogre {
00034 
00035 
00042     class _OgreExport EdgeData
00043     {
00044     public:
00046         struct Triangle {
00049             size_t indexSet; 
00051             size_t vertexSet;
00052             size_t vertIndex[3];
00053             size_t sharedVertIndex[3]; 
00054                                         // duplicates eliminated (this buffer is not exposed)
00055             Vector4 normal;   // unit vector othogonal to this face, plus distance from origin
00056             bool lightFacing; // Working vector used when calculating the silhouette
00057         };
00059         struct Edge {
00063             size_t triIndex[2];
00066             size_t vertIndex[2];
00068             size_t sharedVertIndex[2];
00070             bool degenerate;
00071         };
00072 
00073         typedef std::vector<Triangle> TriangleList;
00074         typedef std::vector<Edge> EdgeList;
00075 
00077         struct EdgeGroup
00078         {
00080             size_t vertexSet;
00082             const VertexData* vertexData;
00084             EdgeList edges;
00085 
00086         };
00087 
00088         typedef std::vector<EdgeGroup> EdgeGroupList;
00089         TriangleList triangles;
00090         EdgeGroupList edgeGroups;
00091 
00102         void updateTriangleLightFacing(const Vector4& lightPos);
00108         void updateFaceNormals(size_t vertexSet, HardwareVertexBufferSharedPtr positionBuffer);
00109 
00110 
00111         // Debugging method
00112         void log(Log* log);
00113         
00114     };
00115 
00125     class _OgreExport EdgeListBuilder 
00126     {
00127     public:
00128 
00129         EdgeListBuilder();
00130         virtual ~EdgeListBuilder();
00136         void addVertexData(const VertexData* vertexData);
00147         void addIndexData(const IndexData* indexData, size_t vertexSet = 0, 
00148             RenderOperation::OperationType opType = RenderOperation::OT_TRIANGLE_LIST);
00149 
00154         EdgeData* build(void);
00155 
00157         void log(Log* l);
00158     protected:
00159 
00165         struct CommonVertex {
00166             Vector3  position;  // location of point in euclidean space
00167             size_t index;       // place of vertex in original vertex set
00168             size_t vertexSet;   // The vertex set this came from
00169         };
00170 
00171         typedef std::vector<const VertexData*> VertexDataList;
00172         typedef std::vector<const IndexData*> IndexDataList;
00173         typedef std::vector<CommonVertex> CommonVertexList;
00174         typedef std::vector<RenderOperation::OperationType> OperationTypeList;
00175 
00176         IndexDataList mIndexDataList;
00177         OperationTypeList mOperationTypeList;
00178         std::vector<size_t> mIndexDataVertexDataSetList;
00179         VertexDataList mVertexDataList;
00180         CommonVertexList mVertices;
00181         EdgeData* mEdgeData;
00182 
00183         void buildTrianglesEdges(size_t indexSet, size_t vertexSet);
00184         void connectEdges(void);
00185         EdgeData::Edge* findEdge(size_t sharedIndex1, size_t sharedIndex2);
00186 
00188         size_t findOrCreateCommonVertex(const Vector3& vec, size_t vertexSet);
00189 
00190     };
00191 
00192 }
00193 #endif
00194 

Copyright © 2002-2003 by The OGRE Team
Last modified Fri May 14 23:22:07 2004