# Home    # nevrax.com   
Nevrax
Nevrax.org
#News
#Mailing-list
#Documentation
#CVS
#Bugs
#License
Docs
 
Documentation  
Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages   Search  

ps_ribbon.h

Go to the documentation of this file.
00001 
00007 /* Copyright, 2001 Nevrax Ltd.
00008  *
00009  * This file is part of NEVRAX NEL.
00010  * NEVRAX NEL is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2, or (at your option)
00013  * any later version.
00014 
00015  * NEVRAX NEL is distributed in the hope that it will be useful, but
00016  * WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00018  * General Public License for more details.
00019 
00020  * You should have received a copy of the GNU General Public License
00021  * along with NEVRAX NEL; see the file COPYING. If not, write to the
00022  * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00023  * MA 02111-1307, USA.
00024  */
00025 
00026 #ifndef NL_PS_RIBBON_H
00027 #define NL_PS_RIBBON_H
00028 
00029 #include "3d/ps_particle_basic.h"
00030 #include "3d/ps_ribbon_base.h"
00031 #include "3d/vertex_buffer.h"
00032 #include "3d/vertex_buffer.h"
00033 #include "3d/primitive_block.h"
00034 #include "nel/misc/vector.h"
00035 #include <hash_map>
00036 
00037 
00038 namespace NL3D 
00039 {
00040 
00045 class CPSRibbon : public CPSRibbonBase,
00046                                   public CPSColoredParticle,
00047                                   public CPSSizedParticle,
00048                                   public CPSMaterial,
00049                                   public CPSTexturedParticleNoAnim
00050 {
00051 public: 
00054 
00061                 CPSRibbon();            
00063                 ~CPSRibbon();
00065                 virtual void            serial(NLMISC::IStream &f) throw(NLMISC::EStream);
00066                 //
00067                 NLMISC_DECLARE_CLASS(CPSRibbon);
00069 
00070         
00073 
00076                         virtual void setColorFading(bool onOff = true) 
00077                         {
00078                                 _ColorFading = onOff;
00079                                 touch();
00080                         }
00081 
00084                         virtual bool getColorFading(void) const
00085                         {
00086                                 return _ColorFading;
00087                         }
00088 
00093                         virtual void setSystemBasis(bool yes) {}
00094                 
00096                         virtual bool isInSystemBasis(void) const { return true; }
00097                 
00098                 //void setPersistAfterDeath(bool persit = true);
00099 
00103                 //bool getPersistAfterDeath(void) const { return _DyingRibbons != NULL; }
00104                 
00106 
00108         virtual void                    step(TPSProcessPass pass, TAnimationTime ellapsedTime, TAnimationTime realEt);
00109 
00111         virtual bool                    hasTransparentFaces(void);
00112 
00114         virtual bool                    hasOpaqueFaces(void);
00115 
00116         virtual uint32                  getMaxNumFaces(void) const;
00117 
00118 
00120         void setTexture(NLMISC::CSmartPtr<ITexture> tex) { _Tex = tex; touch(); }
00122         void setTexFactor(float uFactor = 1.f, float vFactor = 1.f)
00123         {                       
00124                 _UFactor = uFactor;
00125                 _VFactor = vFactor;
00126                 touch();
00127         }
00128         // get the u-factor for texture mapping
00129         float getUFactor(void) const { return _UFactor; }
00130         // get the v-factor for texture mapping
00131         float getVFactor(void) const { return _VFactor; }
00133         ITexture *getTexture(void) { return _Tex; }
00134         const ITexture *getTexture(void) const { return _Tex; }
00135 
00143         void setShape(const NLMISC::CVector *shape, uint32 nbPointsInShape);
00144 
00146         uint32 getNbVerticesInShape(void) const { return _Shape.size(); }
00147         
00152         void getShape(NLMISC::CVector *shape) const;
00153 
00157                 static const NLMISC::CVector  Losange[];
00159                 static const uint NbVerticesInLosange;
00161                 static const NLMISC::CVector  HeightSides[];
00163                 static const uint NbVerticesInHeightSide;
00165                 static const NLMISC::CVector Pentagram[];
00166                 static const uint NbVerticesInPentagram;
00168                 static const NLMISC::CVector Triangle[];
00169                 static const uint NbVerticesInTriangle; 
00171 protected:              
00173         
00174         // the number of dying ribbons that are present
00175         //uint32                                                        _NbDyingRibbons;
00176         // a counter to tell how much frame is left for each ribbon
00177         //std::vector<uint32>                           _DyingRibbonsLifeLeft;
00178 
00180         virtual void                                    newElement(CPSLocated *emitterLocated, uint32 emitterIndex) ;
00182         virtual void                                    deleteElement(uint32 index);
00184         virtual void                                    resize(uint32 size);
00186         virtual CPSLocated                              *getSizeOwner(void) { return _Owner; }
00188         virtual CPSLocated                              *getColorOwner(void) { return _Owner; } 
00189 private:                
00190 
00192         virtual void                                    updateMatAndVbForColor(void);   
00193 
00195         void                                                    displayRibbons(uint32 nbRibbons, uint32 srcStep);
00196 
00207                         struct CVBnPB
00208                         {
00209                                 CVertexBuffer           VB;
00210                                 CPrimitiveBlock         PB;
00211                         };
00212 
00213                         typedef std::hash_map<uint, CVBnPB> TVBMap;
00214 
00216                         static TVBMap                                   _VBMap;                        // index / vertex buffers with no color
00217                         static TVBMap                                   _FadedVBMap;           // index / vertex buffers for constant color with fading
00218                         static TVBMap                                   _ColoredVBMap;             // index / vertex buffer + colors
00219                         static TVBMap                                   _FadedColoredVBMap;    // index / vertex buffer + faded colors
00220 
00222                         static TVBMap                                   _TexVBMap;                          // index / vertex buffers with no color + texture
00223                         static TVBMap                                   _TexFadedVBMap;         // index / vertex buffers for constant color with fading + texture
00224                         static TVBMap                                   _TexColoredVBMap;               // index / vertex buffer + colors + texture
00225                         static TVBMap                                   _TexFadedColoredVBMap;  // index / vertex buffer + faded colors + texture
00226 
00228                         CVBnPB &getVBnPB();
00229 
00231                         uint    getNumRibbonsInVB() const;
00233 
00234         CSmartPtr<ITexture>                      _Tex;
00235         std::vector<NLMISC::CVector> _Shape;
00236         float _UFactor, _VFactor;
00237                         
00238 
00239         bool _ColorFading : 1;
00240         bool _GlobalColor : 1; // to see wether the system uses global color
00241         bool _Touch               : 1; // we use this to see if we must setup the material again
00242 
00243         void touch() { _Touch = true; }
00244 
00245         void            updateMaterial();
00246         void            updateTexturedMaterial();
00247         void            updateUntexturedMaterial();
00248         void            setupGlobalColor();
00249         void            setupTexturedGlobalColor();
00250         void            setupUntexturedGlobalColor();
00251         void            setupTextureMatrix();
00252 
00254         uint            getNumVerticesInSlice() const;
00255 };
00256 
00257 
00258 } // NL3D
00259 
00260 
00261 #endif // NL_PS_RIBBON_H
00262 
00263 /* End of ps_ribbon.h */