AaronCameron.net
Because you all make me very, very tired.
Not a Member? - Login or Create an Account
Tuesday the 22nd of May 2012 @ 03:03am
Front Page Journal Projects Your Profile About
[]

LibN2L-4 Library Code Reference

Classes
Compounds
Files
Members
Method Index
Full Reference

cRVisualTriMesh.h

Go to the documentation of this file.
00001 /************************************************************************
00002 Nova-2 Library (libN2L, or simply n2l) Game development C++ Library
00003 Copyright (C) 2002  Aaron Cameron
00004 
00005 This library is free software; you can redistribute it and/or
00006 modify it under the terms of the GNU Lesser General Public
00007 License as published by the Free Software Foundation; either
00008 version 2.1 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 Lesser General Public License for more details.
00014 
00015 You should have received a copy of the GNU Lesser General Public
00016 License along with this library; if not, write to the Free Software
00017 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00018 
00019 A copy of the GNU Lesser General Public License has been provided with
00020 this library in the file 'COPYING'.
00021 
00022 Contact information for the author of this library has been provided
00023 with this library in the file 'AUTHOR'.
00024 ************************************************************************/
00025 #ifndef _n2l4_cRVisualTriMesh_H
00026 #define _n2l4_cRVisualTriMesh_H
00027 
00028 #include "renderObjects/rObjectTypes.h"
00029 //#include "renderObjects/cRVisual.h"
00030 #include "n2l/geometry.h"
00031 
00032 #include <list>
00033 #include <vector>
00034 #include <map>
00035 //  : public cRVisual
00036 namespace n2l
00037 {
00038 
00039     class cVfsNodeInterface;
00040     class cDynVar;
00041     class cMaterial;
00042     class cGLTexture;
00043 
00044     class cRVisualTriMesh
00045     {
00046     public:
00047         class cRTriMeshFace
00048         {
00049         public:
00050             tUint mVA, mVB, mVC;
00051             tUint mNA, mNB, mNC;
00052             tUint mUVA,mUVB,mUVC;
00053             tUint mMat;
00054             tUint mName;
00055             tUint mFlags;
00056         };
00057 
00058         typedef const tVector3f* tConstVertexIterator;
00059         typedef tVector3f* tVertexIterator;
00060 
00061         typedef const cRTriMeshFace* tConstFaceIterator;
00062 
00063         cRVisualTriMesh();
00064         cRVisualTriMesh( const cRVisualTriMesh & iMesh );
00065 
00066         cRVisualTriMesh( const cVfsNodeInterface & iNode );
00067         cRVisualTriMesh( const cDynVar & iDef );
00068 
00069         ~cRVisualTriMesh();
00070 
00074         void load( const cVfsNodeInterface & iNode );
00075 
00079         void load( const cDynVar & iDef );
00080 
00086         void render(const cAutoPtr<const cGLTexture> & i_iTexture,
00087             const tRenderOptions iOptions ) const;
00088 
00089         
00095         void render( const cGLTexture &iTexture ) const;
00096 
00099         void clear();
00100 
00106         cRVisualTriMesh & operator =( const cRVisualTriMesh & iMesh );
00107 
00108         // -----------------------------------------
00109         // Accessors
00110         cMaterial &material( const tString &iMaterialName );
00111         cMaterial &material( const tUint &iIndex );
00112 
00115         void selectVertexListByMaterial( std::list<tVector3f> &oList,
00116             const tString &iMaterialName ) const;
00117 
00121         void selectFaceIndexListByName( std::list<tUint> &oList,
00122             const tString &iName ) const;
00123 
00126         void selectVertexListByName( std::list<tVector3f> &oList,
00127             const tString &iName ) const;
00128 
00129         void selectVertexListByContainer( std::list<tVector3f> &oList,
00130             const tString &iName ) const;
00131 
00132         void selectVertexIndexListByName( std::list<tUint> &oList,
00133             const tString &iName ) const;
00134 
00135         void selectVertexIndexListByContainer( std::list<tUint> &oList,
00136             const tString &iName ) const;
00137 
00144         void selectVertexIndexListByAnyName( std::list<tUint> &oList,
00145             const tString &iName, const tString &iPrefx = "__" ) const;
00146 
00147         void selectVertexListByAnyName( std::list<tVector3f> &oList,
00148             const tString &iName, const tString &iPrefx = "__" ) const;
00149 
00150         inline const tConstVertexIterator vertexBegin() const { return mVertices; }
00151         inline const tConstVertexIterator vertexEnd() const { return mVertices+mNumValues[Header_Vertices]; }
00152 
00153         inline const tConstFaceIterator faceBegin() const { return mFaces; }
00154         inline const tConstFaceIterator faceEnd() const { return mFaces+mNumValues[Header_Faces]; }
00155 
00156         inline const tVertexIterator vertexBegin() { return mVertices; }
00157         inline const tVertexIterator vertexEnd() { return mVertices+mNumValues[Header_Vertices]; }
00158 
00159         inline const tVector3f &vertex( const tUint iIndex ) const { return mVertices[iIndex]; }
00160         inline const tVector3f &normal( const tUint iIndex ) const { return mNormals[iIndex]; }
00161         inline const cRTriMeshFace &face( const tUint iIndex ) const { return mFaces[iIndex]; }
00162         inline const tString &name( const tUint iIndex ) const { return mNames[iIndex]; }
00163 
00164         inline const tUint numVertices() const { return mNumValues[Header_Vertices]; }
00165         inline const tUint numFaces() const { return mNumValues[Header_Faces]; }
00166         inline const tUint numNames() const { return mNumValues[Header_Names]; }
00167 
00172 //      const tUint selectNearestVIndex( const tVector3f &iVertex ) const;
00173 
00178         const tVector3f dimensions() const;
00179 
00188         const tFloat boundingRadius() const;
00189 
00195         const tFloat scaledBoundingRadius( const tVector3f &iScale ) const;
00196 
00199         void scale( const tVector3f &iScale );
00200 
00201     private:
00202         enum {
00203             FaceFlag_SmoothShading = 0x01,
00204             FaceFlag_TwoSided = 0x02,   // This value is not supported
00205             FaceFlag_NoTexture = 0x04,
00206 
00207             FaceFlag_NumFaceFlags = 1
00208         };
00209 
00210         typedef enum {
00211             Header_Vertices,
00212             Header_Normals,
00213             Header_TexCoords,
00214             Header_Materials,
00215             Header_Names,
00216             Header_Faces,
00217             Header_Containers,
00218             
00219             Header_NumHeaders
00220         } tHeader;
00221 
00222         tUint mNumValues[Header_NumHeaders];
00223 
00224         tVector3f   *mVertices;
00225         tVector3f   *mNormals;
00226         tVector2f   *mTexCoords;
00227         cMaterial   *mMaterials;
00228         tString     *mNames;
00229         cRTriMeshFace   *mFaces;
00230 
00231         typedef std::map<tString, std::vector<tUint> > tVertexContainerMap;
00232         tVertexContainerMap mVertexContainers;
00233 
00234         void init();
00235         
00236         void load_serialized( const cDynVar & iDef );
00237         void load_n2lASCII1_0( const tString & iDef );
00238 
00239         const tString::size_type load_n2lASCII1_0_headers(
00240             const tString & iDef, const tString::size_type iSPos );
00241 
00242         void load_n2lASCII1_0_tVector3fLine(tVector3f & oValue,
00243             const tString & iDef, const tString::size_type iSPos,
00244             const tString::size_type iEPos );
00245 
00246         void load_n2lASCII1_0_tVector2fLine(tVector2f & oValue,
00247             const tString & iDef, const tString::size_type iSPos,
00248             const tString::size_type iEPos );
00249 
00250         void load_n2lASCII1_0_cMaterialLine(cMaterial & oValue,
00251             const tString & iDef, const tString::size_type iSPos,
00252             const tString::size_type iEPos );
00253 
00254         void load_n2lASCII1_0_tStringLine(  tString &oValue,
00255             const tString & iDef, const tString::size_type iSPos,
00256             const tString::size_type iEPos );
00257 
00258         void load_n2lASCII1_0_cRTriMeshFaceLine(
00259             cRTriMeshFace & oValue, const tString & iDef,
00260             const tString::size_type iSPos, const tString::size_type iEPos );
00261 
00262         void load_n2lASCII1_0_vertexContainerLine( tVertexContainerMap &ioValue,
00263             const tString & iDef, const tString::size_type iSPos,
00264             const tString::size_type iEPos );
00265 
00266 
00267     }; // class
00268 
00269 }
00270 
00271 #endif
©2012 Aaron Cameron