# 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  

flare_shape.cpp

Go to the documentation of this file.
00001 
00007 /* Copyright, 2000, 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 #include "std3d.h"
00027 
00028 #include "3d/flare_shape.h"
00029 #include "3d/flare_model.h"
00030 #include "3d/scene.h"
00031 #include "3d/driver.h"
00032 
00033 namespace NL3D {
00034 
00035 
00036 /*
00037  * Constructor
00038  */
00039 CFlareShape::CFlareShape()  : _Color(NLMISC::CRGBA::White),
00040                                                           _DazzleColor(NLMISC::CRGBA::Black),
00041                                                           _Persistence(1),
00042                                                           _Spacing(1),
00043                                                           _Attenuable(false),
00044                                                           _AttenuationRange (1.0f),                                                       
00045                                                           _FirstFlareKeepSize(false),
00046                                                           _DazzleEnabled(false),
00047                                                           _DazzleAttenuationRange(0.f),                                                   
00048                                                           _MaxViewDistRatio (0.9f),
00049                                                           _InfiniteDist(false)
00050 {
00051         // init default pos
00052         for (uint k = 0; k < MaxFlareNum; ++k)
00053         {
00054                 _Tex [k]  = NULL;
00055                 _Size[k]  = 1.f;
00056                 _Pos[k]   = k * (1.f / MaxFlareNum);
00057         }
00058         _DefaultPos.setValue(CVector::Null);
00059         setDistMax(1000);
00060 }
00061 
00062 
00063 void CFlareShape::serial(NLMISC::IStream &f) throw(NLMISC::EStream)
00064 {
00065         int ver = f.serialVersion(3);
00066         f.serial(_Color, _Persistence, _Spacing);       
00067         f.serial(_Attenuable);
00068         if (_Attenuable)
00069         {
00070                 f.serial(_AttenuationRange);
00071         }
00072         f.serial(_FirstFlareKeepSize);
00073         for (uint k = 0; k < MaxFlareNum; ++k)
00074         {
00075                 ITexture *tex = _Tex[k];
00076                 f.serialPolyPtr(tex);
00077                 if (f.isReading())
00078                 {
00079                         _Tex[k] = tex;
00080                 }
00081                 f.serial(_Size[k], _Pos[k]);
00082         }
00083         f.serial(_InfiniteDist);
00084         if (!_InfiniteDist)
00085         {
00086                 f.serial(_MaxViewDist, _MaxViewDistRatio);
00087         }
00088         f.serial(_DazzleEnabled);
00089         if (_DazzleEnabled)
00090         {
00091                 f.serial(_DazzleColor, _DazzleAttenuationRange);
00092         }
00093         f.serial(_InfiniteDist);
00094 
00095         if (ver >= 2)
00096                 f.serial( _DistMax );   
00097 }
00098 
00099         
00100 CTransformShape         *CFlareShape::createInstance(CScene &scene)
00101 {
00102         CFlareModel *fm = NLMISC::safe_cast<CFlareModel *>(scene.createModel(FlareModelClassId) );
00103         fm->Shape = this;       
00104         fm->_Scene = &scene;
00105         // set default pos
00106         fm->ITransformable::setPos( ((CAnimatedValueVector&)_DefaultPos.getValue()).Value  );
00107         return fm;
00108 }
00109 
00110 float                           CFlareShape::getNumTriangles (float distance)
00111 {
00112         float count = 0;
00113         for (uint k = 0; k < MaxFlareNum; ++k)
00114         {
00115         if (_Tex[k]) count += 2;
00116         }
00117         return count;
00118 }
00119 
00120 bool                            CFlareShape::clip(const std::vector<CPlane>     &pyramid, const CMatrix &worldMatrix)
00121 {               
00122         // compute flare pos in world basis : 
00123         const NLMISC::CVector pos = worldMatrix.getPos();
00124         for (std::vector<NLMISC::CPlane>::const_iterator it = pyramid.begin(); it != pyramid.end(); ++it)
00125         {
00126                 if ((*it) * pos > 0) return false;
00127         }
00128         return true;
00129 }
00130 
00131 
00132 void                            CFlareShape::getAABBox(NLMISC::CAABBox &bbox) const
00133 {
00134         // the flare himself is a point
00135         bbox.setCenter(CVector::Null);
00136         bbox.setHalfSize(CVector::Null);
00137 }
00138 
00139 
00140 void                            CFlareShape::flushTextures (IDriver &driver)
00141 {
00142         // Flush each texture
00143         for (uint tex=0; tex<MaxFlareNum; tex++)
00144         {
00145                 if (_Tex[tex] != NULL)
00146                 {
00148                         driver.setupTexture (*_Tex[tex]);
00149                 }
00150         }
00151 }
00152 
00153 
00154 } // NL3D