# 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  

cloud.h

Go to the documentation of this file.
00001 
00007 /* Copyright, 2002 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_CLOUD_H
00027 #define NL_CLOUD_H
00028 
00029 // ------------------------------------------------------------------------------------------------
00030 
00031 #include "3d/camera.h"
00032 #include "3d/material.h"
00033 #include "3d/texture.h"
00034 #include "3d/texture_mem.h"
00035 #include "3d/vertex_buffer.h"
00036 #include "nel/misc/smart_ptr.h"
00037 #include "nel/misc/geom_ext.h"
00038 
00039 namespace NL3D
00040 {
00041 
00042 // ------------------------------------------------------------------------------------------------
00043 class CNoise3d;
00044 class CCloudScape;
00045 struct SCloudTexture3D;
00046 struct SCloudTextureClamp;
00047 
00048 // ------------------------------------------------------------------------------------------------
00049 class CCloud
00050 {
00051 public:
00052 
00053         CCloud (CCloudScape *pCloudScape);
00054 
00055         ~CCloud ();
00056 
00057         void init (uint32 nVoxelW, uint32 nVoxelH, uint32 nVoxelD, float rBaseFreq, uint32 nNbOctave);
00058         void generate (CNoise3d &noise);
00059         void light ();
00060         
00061         void reset (NL3D::CCamera *pViewer);
00062 
00063         void anim (double dt, double dt2);
00064 
00065         // Debug
00066         void disp ();
00067         void dispXYZ (NL3D::CMaterial *pMat = NULL);
00068         // Debug
00069 
00070         // Create the billboard (in the screen at pos (NbW*Width, 0)
00071         void genBill (NL3D::CCamera *pViewer, uint32 nBillSize=128);
00072         
00073         // Display billboard to the screen
00074         void dispBill (NL3D::CCamera *pViewer);
00075 
00076         // Accessors
00077 
00078         float getX() { return _Pos.x; }
00079         float getLastX() { return _LastX; }
00080         float getY() { return _Pos.y; }
00081         float getZ() { return _Pos.z; }
00082 
00083         float getSizeX() { return _Size.x; }
00084         float getSizeY() { return _Size.y; }
00085         float getSizeZ() { return _Size.z; }
00086 
00087         void setX(float x) { _Pos.x = x; _LastX = x; }
00088         void setY(float y) { _Pos.y = y; }
00089         void setZ(float z) { _Pos.z = z; }
00090 
00091         void setSizeX(float x) { _Size.x = x; }
00092         void setSizeY(float y) { _Size.y = y; }
00093         void setSizeZ(float z) { _Size.z = z; }
00094 
00095         void setTexClamp (SCloudTextureClamp &t) { _CloudTexClamp = &t; }
00096         void setTex3DTemp (SCloudTexture3D &t) { _CloudTexTmp = &t; }
00097 
00098         void setLooping () { _WaitState = 2; }
00099 
00100         uint32 getBillSize() { return _BillSize; }
00101 
00102         uint32 getMemSize () 
00103         {
00104                 return _OldBillSize*_OldBillSize*4 + _BillSize*_BillSize*4;
00105         }
00106 
00107         //uint32 Trans, TransTotal;
00108         double Time, FuturTime;
00109 
00110         NLMISC::CRGBA   CloudDiffuse;
00111         NLMISC::CRGBA   CloudAmbient;
00112         uint8                   CloudPower;
00113         uint8                   CloudDistAtt;
00114 
00115         uint8                   LastCloudPower; // Cloud power of the old bill board
00116 private:
00117 
00118         void setMode2D ();
00119 
00120         // in ; viewer, center
00121         // out I,J,K, left,right,top,bottom,near,far
00122         void calcBill (const NLMISC::CVector &Viewer, const NLMISC::CVector &Center, const NLMISC::CVector &Size,
00123                                         NLMISC::CVector &I, NLMISC::CVector &J, NLMISC::CVector &K,
00124                                         float &Left, float &Right, float &Top, float &Bottom, float &Near, float &Far);
00125         
00126 private:
00127 
00128         uint32 _Width, _Height, _Depth;
00129         uint32 _NbW, _NbH; // Number of slice in width and height (NbW*NbH = Depth
00130 
00131         NLMISC::CVector _Size;
00132         NLMISC::CVector _Pos;
00133         float _LastX;
00134 
00135         float   _BaseFreq; // 1 -> 1 voxel is 1 noise3d pixel 0.5 -> 2 voxels are 1 noise3d pixel (Lowest octave freq)
00136         uint32  _NbOctave;
00137         double  *_UStart, *_VStart, *_WStart; // 1st Lowest octave
00138 
00139         CCloudScape                     *_CloudScape;
00140         SCloudTexture3D         *_CloudTexTmp;          // Temporary cloud texture 3D
00141         SCloudTextureClamp      *_CloudTexClamp;
00142 
00143         // BillBoard
00144 
00145         // The billboard is a texture where the cloud is rendered
00146         uint32                                                                  _BillSize; // ( The texture is always sqare)
00147         uint8                                                                   *_MemBill;
00148         NLMISC::CSmartPtr<NL3D::CTextureMem>    _TexBill;
00149 
00150         // The last texture
00151         uint32                                                                  _OldBillSize;
00152         uint8                                                                   *_MemOldBill;
00153         NLMISC::CSmartPtr<NL3D::CTextureMem>    _TexOldBill;
00154 
00155         uint8 _WaitState;
00156 
00157         // Accel for calc bill
00158         
00159         NLMISC::CVector _BillViewer, _BillCenter, _BillOldCenter;
00160 
00161 private:
00162 
00163         NL3D::IDriver *_Driver;
00164 };
00165 
00166 // ------------------------------------------------------------------------------------------------
00167 
00168 } // namespace NL3D
00169 
00170 #endif // NL_CLOUD_H
00171