NL3D::CCloudScape Class Reference

#include <cloud_scape.h>


Public Member Functions

void anim (double dt, NL3D::CCamera *pCamera)
 CCloudScape (NL3D::IDriver *pDriver)
uint32 getMemSize ()
void init (SCloudScapeSetup *pCSS=NULL, NL3D::CCamera *pCamera=NULL)
bool isDebugQuadEnabled ()
void render ()
void set (SCloudScapeSetup &css)
void setDebugQuad (bool b)
void setNbCloudToUpdateIn80ms (uint32 n)
void setQuality (float threshold)
 ~CCloudScape ()

Private Member Functions

void makeHalfCloud ()

Private Attributes

std::vector< CCloud_AllClouds
NLMISC::CValueSmoother _AverageFrameRate
std::vector< uint8_CloudPower
std::list< SCloudSchedulerEntry_CloudScheduler
std::vector< SCloudSchedulerAccel_CloudSchedulerLastAdded
uint32 _CloudSchedulerSize
CCloud_CurrentCloudInProcess
double _CurrentCloudInProcessFuturTime
SCloudScapeSetup _CurrentCSS
bool _DebugQuad
double _DeltaTime
NL3D::IDriver_Driver
double _DTRest
std::vector< float > _ExtrapolatedPriorities
uint32 _FrameCounter
bool _Generate
double _GlobalTime
SCloudScapeSetup _IncomingCSS
bool _IsIncomingCSS
float _LODQualityThreshold
NL3D::CMaterial _MatBill
NL3D::CMaterial _MatClear
uint32 _NbHalfCloudToUpdate
SCloudScapeSetup _NewCSS
CNoise3d _Noise3D
SCloudScapeSetup _OldCSS
std::vector< bool > _ShouldProcessCloud
std::vector< SSortedCloudEntry_SortedClouds
double _TimeNewCSS
NL3D::CVertexBuffer _VertexBuffer
NL3D::CCamera_ViewerCam
SCloudTexture3D Tex3DTemp
SCloudTextureClamp TexClamp

Friends

class CCloud


Constructor & Destructor Documentation

NL3D::CCloudScape::CCloudScape NL3D::IDriver pDriver  ) 
 

Definition at line 217 of file cloud_scape.cpp.

References _CurrentCloudInProcess, _DebugQuad, _IsIncomingCSS, _LODQualityThreshold, _MatBill, _MatClear, _NbHalfCloudToUpdate, _VertexBuffer, NL3D::CMaterial::initUnlit(), NL3D::CMaterial::setAlphaTest(), NL3D::CMaterial::setAlphaTestThreshold(), NL3D::CMaterial::setBlend(), NL3D::CMaterial::setBlendFunc(), NL3D::CMaterial::setDoubleSided(), NL3D::CVertexBuffer::setNumVertices(), NL3D::CMaterial::setShader(), NL3D::CVertexBuffer::setVertexFormat(), NL3D::CMaterial::setZFunc(), NL3D::CMaterial::setZWrite(), NL3D::CMaterial::texEnvArg0Alpha(), NL3D::CMaterial::texEnvArg0RGB(), NL3D::CMaterial::texEnvArg1Alpha(), NL3D::CMaterial::texEnvArg1RGB(), NL3D::CMaterial::texEnvOpAlpha(), and NL3D::CMaterial::texEnvOpRGB().

00217                                               : _Noise3D (pDriver)
00218 {
00219         _Driver = pDriver;
00220         // Misc purpose VB
00221         _VertexBuffer.setVertexFormat (CVertexBuffer::PositionFlag | CVertexBuffer::TexCoord0Flag | CVertexBuffer::TexCoord1Flag);
00222         _VertexBuffer.setNumVertices (4);
00223 
00224         // Material used for cleaning
00225         _MatClear.initUnlit();
00226         _MatClear.setDoubleSided (true);
00227         _MatClear.setZFunc (CMaterial::always);
00228         _MatClear.setZWrite (false);
00229         _MatClear.setBlend (false);
00230 
00231         _MatBill.initUnlit();
00232         _MatBill.setShader (CMaterial::Normal); // not needed
00233 
00234         _MatBill.texEnvOpRGB (0, CMaterial::Replace);
00235         _MatBill.texEnvArg0RGB (0, CMaterial::Texture, CMaterial::SrcColor);
00236 
00237         _MatBill.texEnvOpAlpha (0, CMaterial::Replace);
00238         _MatBill.texEnvArg0Alpha (0, CMaterial::Texture, CMaterial::SrcAlpha);
00239 
00240         _MatBill.texEnvOpRGB (1, CMaterial::InterpolateDiffuse);
00241         _MatBill.texEnvArg0RGB (1, CMaterial::Texture, CMaterial::SrcColor);
00242         _MatBill.texEnvArg1RGB (1, CMaterial::Previous, CMaterial::SrcColor);
00243 
00244         _MatBill.texEnvOpAlpha (1, CMaterial::InterpolateDiffuse);
00245         _MatBill.texEnvArg0Alpha (1, CMaterial::Texture, CMaterial::SrcAlpha);
00246         _MatBill.texEnvArg1Alpha (1, CMaterial::Previous, CMaterial::SrcAlpha);
00247 
00248         _MatBill.setBlend (true);
00249         _MatBill.setBlendFunc(CMaterial::one, CMaterial::invsrcalpha);
00250         _MatBill.setZFunc (CMaterial::always);
00251         _MatBill.setZWrite (false);
00252         _MatBill.setDoubleSided (true);
00253         _MatBill.setAlphaTest(true);
00254         _MatBill.setAlphaTestThreshold(2.0f/256.0f);
00255 
00256         _LODQualityThreshold = 160.0f;
00257         _IsIncomingCSS = false;
00258         _DebugQuad = false;
00259         _NbHalfCloudToUpdate = 1;
00260         _CurrentCloudInProcess = NULL;
00261 }

NL3D::CCloudScape::~CCloudScape  ) 
 

Definition at line 264 of file cloud_scape.cpp.

00265 {
00266 }


Member Function Documentation

void NL3D::CCloudScape::anim double  dt,
NL3D::CCamera pCamera
 

Definition at line 424 of file cloud_scape.cpp.

References _AllClouds, _AverageFrameRate, _CloudPower, _CurrentCSS, _DeltaTime, _DTRest, _GlobalTime, _IncomingCSS, _IsIncomingCSS, _NbHalfCloudToUpdate, _NewCSS, _OldCSS, _ShouldProcessCloud, _TimeNewCSS, _ViewerCam, NLMISC::CRGBA::A, NLMISC::CValueSmootherTemplate< float >::addValue(), NL3D::SCloudScapeSetup::Ambient, NLMISC::CRGBA::B, NL3D::CCloud::CloudPower, NL3D::SCloudScapeSetup::CloudSpeed, NL3D::SCloudScapeSetup::Diffuse, NLMISC::CRGBA::G, makeHalfCloud(), MAX_CLOUDS, NL3D::SCloudScapeSetup::NbCloud, NLMISC::CRGBA::R, sint32, NL3D::CCloud::Time, NL3D::SCloudScapeSetup::TimeToChange, uint32, uint8, and NL3D::SCloudScapeSetup::WindSpeed.

Referenced by NL3D::CCloudScapeUser::anim(), and init().

00425 {
00426         sint32 i;
00427 
00428         _ViewerCam = pCamera;
00429 
00430         // 10 fps -> 200 fps
00431         if (dt > 0.1) dt = 0.1;
00432         if (dt < 0.005) dt = 0.005;
00433 
00434         _DeltaTime = dt;
00435         _GlobalTime += _DeltaTime;
00436         _AverageFrameRate.addValue ((float)_DeltaTime);
00437 
00438         // Animate the CSS
00439         if (_TimeNewCSS > _NewCSS.TimeToChange)
00440         {
00441                 _CurrentCSS = _NewCSS;
00442                 _OldCSS = _NewCSS;
00443                 if (_IsIncomingCSS)
00444                 {
00445                         _IsIncomingCSS = false;
00446                         _NewCSS = _IncomingCSS;
00447                         _TimeNewCSS = 0;
00448                         if (_NewCSS.NbCloud > _OldCSS.NbCloud)
00449                         for (i = 0; i < (sint32)(_NewCSS.NbCloud-_OldCSS.NbCloud); ++i)
00450                         {
00451                                 CCloud &c = _AllClouds[_OldCSS.NbCloud+i];
00452                                 c.CloudPower = 0;
00453                                 _CloudPower[_OldCSS.NbCloud+i] = 0;
00454                         }
00455                 }
00456         }
00457         else
00458         {
00459                 float inter = (float)(_TimeNewCSS / _NewCSS.TimeToChange);
00460                 _CurrentCSS.WindSpeed = (_NewCSS.WindSpeed - _OldCSS.WindSpeed)*inter + _OldCSS.WindSpeed;
00461                 _CurrentCSS.CloudSpeed = (_NewCSS.CloudSpeed - _OldCSS.CloudSpeed)*inter + _OldCSS.CloudSpeed;
00462 
00463                 _CurrentCSS.Ambient.R = (uint8)((_NewCSS.Ambient.R - _OldCSS.Ambient.R)*inter + _OldCSS.Ambient.R);
00464                 _CurrentCSS.Ambient.G = (uint8)((_NewCSS.Ambient.G - _OldCSS.Ambient.G)*inter + _OldCSS.Ambient.G);
00465                 _CurrentCSS.Ambient.B = (uint8)((_NewCSS.Ambient.B - _OldCSS.Ambient.B)*inter + _OldCSS.Ambient.B);
00466                 _CurrentCSS.Ambient.A = (uint8)((_NewCSS.Ambient.A - _OldCSS.Ambient.A)*inter + _OldCSS.Ambient.A);
00467 
00468                 _CurrentCSS.Diffuse.R = (uint8)((_NewCSS.Diffuse.R - _OldCSS.Diffuse.R)*inter + _OldCSS.Diffuse.R);
00469                 _CurrentCSS.Diffuse.G = (uint8)((_NewCSS.Diffuse.G - _OldCSS.Diffuse.G)*inter + _OldCSS.Diffuse.G);
00470                 _CurrentCSS.Diffuse.B = (uint8)((_NewCSS.Diffuse.B - _OldCSS.Diffuse.B)*inter + _OldCSS.Diffuse.B);
00471                 _CurrentCSS.Diffuse.A = (uint8)((_NewCSS.Diffuse.A - _OldCSS.Diffuse.A)*inter + _OldCSS.Diffuse.A);
00472 
00473                 if (_NewCSS.NbCloud > _OldCSS.NbCloud)
00474                 {
00475                         // Add some clouds
00476                         float slice = (_NewCSS.TimeToChange/4) / (_NewCSS.NbCloud-_OldCSS.NbCloud);
00477                         sint32 diffCloud = _NewCSS.NbCloud-_OldCSS.NbCloud;
00478 
00479                         _CurrentCSS.NbCloud = _OldCSS.NbCloud + (1+(uint32)(_TimeNewCSS/slice));
00480                         if (_CurrentCSS.NbCloud > _NewCSS.NbCloud)
00481                                 _CurrentCSS.NbCloud = _NewCSS.NbCloud;
00482 
00483                         for (i = 0; i < diffCloud; ++i)
00484                         {
00485                                 _ShouldProcessCloud[_OldCSS.NbCloud+i] = true;
00486                                 if (_TimeNewCSS < i*slice)
00487                                         _CloudPower[_OldCSS.NbCloud+i] = 1;
00488                                 else if (_TimeNewCSS > (i*slice+3*_NewCSS.TimeToChange/4))
00489                                         _CloudPower[_OldCSS.NbCloud+i] = 255;
00490                                 else
00491                                         _CloudPower[_OldCSS.NbCloud+i] = (uint8)(255*(_TimeNewCSS-i*slice)/(3*_NewCSS.TimeToChange/4));
00492                         }
00493                 }
00494                 else
00495                 {
00496                         // Remove some clouds
00497                         sint32 diffCloud = _OldCSS.NbCloud-_NewCSS.NbCloud;
00498                         if (diffCloud)
00499                         {
00500                                 float slice = (_NewCSS.TimeToChange/4) / (float)diffCloud;
00501                                 _CurrentCSS.NbCloud = _OldCSS.NbCloud;
00502 
00503                                 for (i = 0; i < diffCloud; ++i)
00504                                 {
00505                                         if (_TimeNewCSS < i*slice)
00506                                                 _CloudPower[_OldCSS.NbCloud-i-1] = 255;
00507                                         else if (_TimeNewCSS > (i*slice+3*_NewCSS.TimeToChange/4))
00508                                                 _CloudPower[_OldCSS.NbCloud-i-1] = 0;
00509                                         else
00510                                                 _CloudPower[_OldCSS.NbCloud-i-1] = (uint8)(255-255*(_TimeNewCSS-i*slice)/(3*_NewCSS.TimeToChange/4));
00511                                 }
00512                         }
00513                 }
00514         }
00515 
00516         // Make the right number of half cloud
00517         _DTRest += dt;
00518 
00519         while (_DTRest > (0.04/_NbHalfCloudToUpdate))
00520         {
00521                 makeHalfCloud ();
00522                 _DTRest -= 0.04/_NbHalfCloudToUpdate;
00523 
00524                 for (i = 0; i < MAX_CLOUDS; ++i)
00525                 {
00526                         CCloud &c = _AllClouds[i];
00527                         c.Time += 0.04/_NbHalfCloudToUpdate;
00528                 }
00529 
00530                 _TimeNewCSS += 0.04/_NbHalfCloudToUpdate;
00531         }
00532 }

uint32 NL3D::CCloudScape::getMemSize  ) 
 

Definition at line 829 of file cloud_scape.cpp.

References _AllClouds, NL3D::CCloud::getMemSize(), MAX_CLOUDS, and uint32.

Referenced by NL3D::CCloudScapeUser::getMemSize().

00830 {
00831         uint32 nMemSize = 0;
00832         for (uint32 i = 0; i < MAX_CLOUDS; ++i)
00833         {
00834                 CCloud &c = _AllClouds[i];
00835                 nMemSize += c.getMemSize();
00836         }
00837         return nMemSize;
00838 }

void NL3D::CCloudScape::init SCloudScapeSetup pCSS = NULL,
NL3D::CCamera pCamera = NULL
 

Definition at line 269 of file cloud_scape.cpp.

References _AllClouds, _AverageFrameRate, _CloudPower, _CloudScheduler, _CloudSchedulerLastAdded, _CloudSchedulerSize, _CurrentCSS, _DTRest, _ExtrapolatedPriorities, _FrameCounter, _Generate, _GlobalTime, _IsIncomingCSS, _NbHalfCloudToUpdate, _NewCSS, _Noise3D, _OldCSS, _ShouldProcessCloud, _SortedClouds, _TimeNewCSS, _ViewerCam, NLMISC::CValueSmootherTemplate< float >::addValue(), NL3D::SCloudScapeSetup::Ambient, NL3D::CCloudScape::SCloudSchedulerEntry::Ambient, anim(), CCloud, NL3D::CCloudScape::SCloudSchedulerEntry::CloudIndex, NL3D::CCloudScape::SCloudSchedulerEntry::DeltaNextCalc, NL3D::SCloudScapeSetup::Diffuse, NL3D::CCloudScape::SCloudSchedulerEntry::Diffuse, NL3D::CCloudScape::SCloudSchedulerEntry::Frame, NL3D::CCloud::FuturTime, NL3D::CCloud::getSizeX(), NL3D::CCloud::getSizeY(), NL3D::CCloud::getSizeZ(), NL3D::CCloud::getX(), NL3D::CCloud::getY(), NL3D::CCloud::getZ(), NLMISC::CValueSmootherTemplate< float >::init(), NL3D::CCloud::init(), NL3D::SCloudTextureClamp::init(), NL3D::SCloudTexture3D::init(), NL3D::CNoise3d::init(), MAX_CLOUDS, MAX_DIST, NL3D::SCloudScapeSetup::NbCloud, NL3D::CCloudScape::SCloudSchedulerEntry::Power, QUEUE_SIZE, NL3D::CCloud::setSizeX(), NL3D::CCloud::setSizeY(), NL3D::CCloud::setSizeZ(), NL3D::CCloud::setTex3DTemp(), NL3D::CCloud::setTexClamp(), NL3D::CCloud::setX(), NL3D::CCloud::setY(), NL3D::CCloud::setZ(), sint32, SQR, Tex3DTemp, TexClamp, NL3D::CCloud::Time, and uint32.

Referenced by NL3D::CCloudScapeUser::init().

00270 {
00271         _ViewerCam = pCamera;
00272         
00273         _Noise3D.init();
00274 
00275         _AllClouds.resize (MAX_CLOUDS, CCloud(this));
00276         _CloudPower.resize (MAX_CLOUDS);
00277         _ShouldProcessCloud.resize (MAX_CLOUDS);
00278 
00279         // For the moment only one clamp texture (generated)
00280         Tex3DTemp.init (64, 32, 32);
00281         TexClamp.init (64, 32, 32,"");
00282 
00283         if (pCSS != NULL)
00284         {
00285                 _CurrentCSS = *pCSS;
00286                 _NewCSS = *pCSS;
00287                 _OldCSS = *pCSS;
00288         }
00289         _IsIncomingCSS = false;
00290         _TimeNewCSS = 60.0*60.0;
00291 
00292         uint32 i;
00293         for (i = 0; i < MAX_CLOUDS; ++i)
00294         {
00295                 float newX, newY, newZ, newSizeX, newSizeY, newSizeZ;
00296 
00297                 CCloud &c = _AllClouds[i];
00298 
00299                 c.setTex3DTemp (Tex3DTemp);
00300                 c.setTexClamp (TexClamp);
00301 
00302                 while (true)
00303                 {
00304                         bool bRecalc = false;
00305                         newX = MAX_DIST*(1.0f-2.0f*(((float)rand())/RAND_MAX));
00306                         newY = MAX_DIST*(1.0f-2.0f*(((float)rand())/RAND_MAX));
00307                         newZ = 85.0f+40.0f*(1.0f-2.0f*(((float)rand())/RAND_MAX));
00308 
00309                         newSizeX = 60.0f+10.0f*(1.0f-2.0f*(((float)rand())/RAND_MAX));
00310                         newSizeY = 30.0f+10.0f*(1.0f-2.0f*(((float)rand())/RAND_MAX));
00311                         newSizeZ = 30.0f+10.0f*(1.0f-2.0f*(((float)rand())/RAND_MAX));
00312                         float f = 0.7f+0.3f*((float)rand())/RAND_MAX;
00313                         newSizeX *= 1.5f*f;
00314                         newSizeY *= 1.5f*f;
00315                         newSizeZ *= 1.5f*f;
00316 
00317                         float d = sqrtf(SQR(newX)+SQR(newY));
00318                         if (d > MAX_DIST) bRecalc = true;
00319 
00320                         float r1 = sqrtf(SQR(newSizeX/2)+SQR(newSizeY/2)+SQR(newSizeZ/2));
00321                         for (uint32 k = 0;k < i; ++k)
00322                         {
00323                                 CCloud &c2 = _AllClouds[k];
00324 
00325                                 if ((fabs(newX-c2.getX()) < (newSizeX/2+c2.getSizeX()/2)) && 
00326                                         (fabs(newY-c2.getY()) < (newSizeY/2+c2.getSizeY()/2)) && 
00327                                         (fabs(newZ-c2.getZ()) < (newSizeZ/2+c2.getSizeZ()/2)))
00328                                         bRecalc = true;
00329                         }
00330                         if (!bRecalc) break;
00331                 }
00332 
00333                 c.init (64, 32, 32, 0.122f, 4);
00334                 c.setX (newX-newSizeX/2);
00335                 c.setY (newY-newSizeY/2);
00336                 c.setZ (newZ-newSizeZ/2);
00337 
00338                 c.setSizeX (newSizeX);
00339                 c.setSizeY (newSizeY);
00340                 c.setSizeZ (newSizeZ);
00341 
00342                 c.Time = 0;
00343                 c.FuturTime = _CurrentCSS.NbCloud * 2 * (0.04/_NbHalfCloudToUpdate);
00344                 if (i < _CurrentCSS.NbCloud)
00345                 {
00346                         _CloudPower[i] = 255;
00347                         _ShouldProcessCloud[i] = true;
00348                 }
00349                 else
00350                 {
00351                         _CloudPower[i] = 0;
00352                         _ShouldProcessCloud[i] = false;
00353                 }
00354         }
00355 
00356         _SortedClouds.resize (MAX_CLOUDS);
00357 
00358         _CloudSchedulerSize = _CurrentCSS.NbCloud;
00359         _CloudSchedulerLastAdded.resize (MAX_CLOUDS);
00360         _FrameCounter = 0;
00361         _CloudScheduler.clear();
00362         for (i = 0; i < MAX_CLOUDS; ++i)
00363                 _CloudSchedulerLastAdded[i].ValidPos = false;
00364 
00365         if (_CurrentCSS.NbCloud == 0)
00366         {
00367                 for (i = 0; i < QUEUE_SIZE; ++i)
00368                 {
00369                         SCloudSchedulerEntry cse;
00370                         cse.CloudIndex = -1;
00371                         cse.Frame = _FrameCounter;
00372                         cse.Ambient = _CurrentCSS.Ambient;
00373                         cse.Diffuse = _CurrentCSS.Diffuse;
00374                         _CloudScheduler.insert(_CloudScheduler.end(), cse);
00375                         ++_FrameCounter;
00376                 }
00377         }
00378         else
00379         {
00380                 for (i = 0; i < QUEUE_SIZE; ++i)
00381                 {
00382                         sint32 nCloudNb;
00383                         nCloudNb = i%_CurrentCSS.NbCloud;
00384                         SCloudSchedulerEntry cse;
00385                         cse.CloudIndex = nCloudNb;
00386                         if (_CloudSchedulerLastAdded[nCloudNb].ValidPos == true)
00387                         {
00388                                 SCloudSchedulerEntry &lastCSE = *_CloudSchedulerLastAdded[nCloudNb].Pos;
00389                                 sint32 delta = _FrameCounter - lastCSE.Frame;
00390                                 lastCSE.DeltaNextCalc = delta;
00391                         }
00392                         cse.Frame = _FrameCounter;
00393                         cse.Ambient = _CurrentCSS.Ambient;
00394                         cse.Diffuse = _CurrentCSS.Diffuse;
00395                         cse.Power = _CloudPower[cse.CloudIndex];
00396                         _CloudSchedulerLastAdded[cse.CloudIndex].Pos = _CloudScheduler.insert(_CloudScheduler.end(), cse);
00397                         _CloudSchedulerLastAdded[cse.CloudIndex].ValidPos = true;
00398                         //_CloudSchedulerLastAdded[cse.CloudIndex].Pos = _CloudScheduler.end()-1;
00399                         ++_FrameCounter;
00400                 }
00401         }
00402 
00403         _GlobalTime = 0.0f;
00404         _DTRest = 0.0f;
00405         _Generate = true;
00406         _AverageFrameRate.init(16);
00407         for (i = 0; i < 16; ++i)
00408                 _AverageFrameRate.addValue (40.0f/1000.0f);
00409 
00410         _ExtrapolatedPriorities.resize (MAX_CLOUDS);
00411 
00412         for (i = 0; i < QUEUE_SIZE; ++i)
00413                 anim (41.0/1000.0, _ViewerCam);
00414 }

bool NL3D::CCloudScape::isDebugQuadEnabled  )  [inline]
 

Definition at line 97 of file cloud_scape.h.

References _DebugQuad.

Referenced by NL3D::CCloud::dispBill(), and NL3D::CCloudScapeUser::isDebugQuadEnabled().

00097 { return _DebugQuad; }

void NL3D::CCloudScape::makeHalfCloud  )  [private]
 

Definition at line 535 of file cloud_scape.cpp.

References _AllClouds, _CloudPower, _CloudScheduler, _CloudSchedulerLastAdded, _CurrentCloudInProcess, _CurrentCloudInProcessFuturTime, _CurrentCSS, _ExtrapolatedPriorities, _FrameCounter, _Generate, _LODQualityThreshold, _NbHalfCloudToUpdate, _Noise3D, _ShouldProcessCloud, _ViewerCam, NL3D::SCloudScapeSetup::Ambient, NL3D::CCloudScape::SCloudSchedulerEntry::Ambient, NL3D::CCloud::anim(), NL3D::CCloud::CloudAmbient, NL3D::CCloud::CloudDiffuse, NL3D::CCloud::CloudDistAtt, NL3D::CCloudScape::SCloudSchedulerEntry::CloudIndex, NL3D::CCloud::CloudPower, NL3D::SCloudScapeSetup::CloudSpeed, NL3D::CCloudScape::SCloudSchedulerEntry::DeltaNextCalc, NL3D::SCloudScapeSetup::Diffuse, NL3D::CCloudScape::SCloudSchedulerEntry::Diffuse, NL3D::CCloudScape::SCloudSchedulerEntry::Frame, NL3D::CCloud::FuturTime, NL3D::CCloud::genBill(), NL3D::CCloud::generate(), NL3D::CCloud::getLastX(), NL3D::CCloud::getSizeX(), NL3D::CCloud::getSizeY(), NL3D::CCloud::getSizeZ(), NL3D::CCloud::getX(), NL3D::CCloud::getY(), NL3D::CCloud::getZ(), NL3D::CCloud::LastCloudPower, NL3D::CCloud::light(), MAX_CLOUDS, MAX_DIST, NL3D::SCloudScapeSetup::NbCloud, nlassert, NL3D::CCloudScape::SCloudSchedulerEntry::Power, QUEUE_SIZE, r, NLMISC::raiseToNextPowerOf2(), NL3D::CCloud::setLooping(), NL3D::CCloud::setX(), sint32, SQR, NL3D::CCloud::Time, uint32, uint8, NL3D::SCloudScapeSetup::WindSpeed, NLMISC::CVector::x, x, NLMISC::CVector::y, and NLMISC::CVector::z.

Referenced by anim().

00536 {
00537         CVector Viewer = CVector(0,0,0); //_ViewerCam->getMatrix().getPos();
00538 
00539         if (_Generate)
00540         {
00541                 // Find the next cloud in the list
00542                 SCloudSchedulerEntry FrontCSE;
00543 
00544                 FrontCSE = _CloudScheduler.front();
00545 
00546                 // Is the cloud do not have another reference in the list add it now because it should be processed
00547                 sint32 CloudIndexToAdd = -1;
00548 
00549                 if ((FrontCSE.CloudIndex != -1) && 
00550                         (_ShouldProcessCloud[FrontCSE.CloudIndex] == true) && 
00551                         (       (_CloudSchedulerLastAdded[FrontCSE.CloudIndex].ValidPos == false) ||
00552                                 ((_CloudSchedulerLastAdded[FrontCSE.CloudIndex].ValidPos == true) &&
00553                                 (_CloudSchedulerLastAdded[FrontCSE.CloudIndex].Pos == _CloudScheduler.begin()))
00554                         ))
00555                 {
00556                         // It should be added now !
00557                         CloudIndexToAdd = FrontCSE.CloudIndex;
00558                         FrontCSE.DeltaNextCalc = QUEUE_SIZE;
00559                 }
00560                 else if (_CurrentCSS.NbCloud != 0)
00561                 {
00562                         // Choose a Cloud Index To Add at the end of the list
00563                         uint32 nPeriodeMax = _CurrentCSS.NbCloud+_CurrentCSS.NbCloud/10;
00564                         sint32 Priority = -10000;
00565                         uint32 i;
00566 
00567                         float sumPrior = 0.0f;
00568                         for (i = 0; i < MAX_CLOUDS; ++i)
00569                         if (_ShouldProcessCloud[i])
00570                         {
00571                                 CCloud &rC = _AllClouds[i];
00572                                 float ExtrapolatedTime = ((0.04f/_NbHalfCloudToUpdate) * QUEUE_SIZE * 2);
00573                                 float x = rC.getLastX () + ExtrapolatedTime * _CurrentCSS.WindSpeed;
00574                                 //float d = sqrtf(SQR(x+rC.getSizeX()/2-Viewer.x)+SQR(rC.getY()+rC.getSizeY()/2-Viewer.y)+
00575                                 //              SQR(rC.getZ()+rC.getSizeZ()/2-Viewer.z));
00576                                 float d = SQR(x+rC.getSizeX()/2-Viewer.x)+SQR(rC.getY()+rC.getSizeY()/2-Viewer.y)+
00577                                                 SQR(rC.getZ()+rC.getSizeZ()/2-Viewer.z);
00578                                 float d05 = sqrtf(d);
00579                                 float d025 = sqrtf(d05);
00580                                 float d075 = d05*d025;
00581 
00582                                 _ExtrapolatedPriorities[i] = 1.0f / d075;
00583                                 sumPrior += _ExtrapolatedPriorities[i];
00584                         }
00585 
00586                         sint32 sumJeton = 0;
00587                         for (i = 0; i < MAX_CLOUDS; ++i)
00588                         if (_ShouldProcessCloud[i])
00589                         {
00590                                 // Normalize priorities
00591                                 float factor = ((float)QUEUE_SIZE) / sumPrior;
00592                                 sint32 nbJeton = (sint32)(0.5f+(factor * _ExtrapolatedPriorities[i]));
00593 
00594                                 if (nbJeton < 1)
00595                                         nbJeton = 1;
00596 
00597                                 _ExtrapolatedPriorities[i] = (float)nbJeton;
00598                                 sumJeton += nbJeton;
00599                         }
00600 
00601                         if (sumJeton > QUEUE_SIZE)
00602                         {
00603                                 do
00604                                 {
00605                                         for (i = 0; i < MAX_CLOUDS; ++i)
00606                                         if (_ShouldProcessCloud[i])
00607                                         {
00608                                                 if (_ExtrapolatedPriorities[i] > 1)
00609                                                 {
00610                                                         _ExtrapolatedPriorities[i] -= 1;
00611                                                         --sumJeton;
00612                                                         if (sumJeton == QUEUE_SIZE) break;
00613                                                 }
00614                                         }
00615                                 }
00616                                 while (sumJeton > QUEUE_SIZE);
00617                         }
00618 
00619                         for (i = 0; i < MAX_CLOUDS; ++i)
00620                         if (_ShouldProcessCloud[i])
00621                         {                               
00622                                 // Cloud Period
00623                                 sint32 newPriority = nPeriodeMax;
00624                                 // Is there a last entry in array ?
00625                                 if (_CloudSchedulerLastAdded[i].ValidPos == true)
00626                                 {
00627                                         SCloudSchedulerEntry &rLastCSE = *_CloudSchedulerLastAdded[i].Pos;
00628                                         newPriority = (sint32)(QUEUE_SIZE/_ExtrapolatedPriorities[i]);
00629                                         newPriority = (_FrameCounter -  rLastCSE.Frame) - newPriority;
00630                                 }
00631                                 else
00632                                 {
00633                                         newPriority = 10000;
00634                                 }
00635                                 if (newPriority > Priority)
00636                                 {
00637                                         Priority = newPriority;
00638                                         CloudIndexToAdd = i;
00639                                 }
00640                         }
00641                         nlassert (CloudIndexToAdd != -1);
00642                 }
00643 
00644                 // Ok now we have a good cloud index to add so make the new cloud entry
00645                 SCloudSchedulerEntry newCSE;
00646 
00647                 newCSE.CloudIndex = CloudIndexToAdd;
00648                 newCSE.Frame = _FrameCounter;
00649                 newCSE.Ambient = _CurrentCSS.Ambient;
00650                 newCSE.Diffuse = _CurrentCSS.Diffuse;
00651                 if (CloudIndexToAdd != -1)
00652                 {
00653                         newCSE.Power = _CloudPower[CloudIndexToAdd];
00654 
00655                         // If the cloud where added previously to the list
00656                         if (_CloudSchedulerLastAdded[CloudIndexToAdd].ValidPos == true)
00657                         {
00658                                 // This means that the cloud were added from a long time ago
00659                                 SCloudSchedulerEntry &lastCSE = *_CloudSchedulerLastAdded[CloudIndexToAdd].Pos;
00660                                 sint32 delta = _FrameCounter - lastCSE.Frame;                   
00661                                 lastCSE.DeltaNextCalc = delta;
00662 
00663                                 // But the cloud can be removed (if so we have to not process it anymore)
00664                                 if (newCSE.Power == 0)
00665                                         _ShouldProcessCloud[CloudIndexToAdd] = false;
00666                         }
00667                         else
00668                         {
00669                                 // No the cloud do not appear previously in the list... So its a new one
00670                                 _AllClouds[CloudIndexToAdd].reset (_ViewerCam);
00671                         }
00672 
00673                         // If the last cloud occurence of the cloud appear at beginning so no more occurence in list
00674                         if (_CloudSchedulerLastAdded[FrontCSE.CloudIndex].Pos == _CloudScheduler.begin())
00675                                 _CloudSchedulerLastAdded[FrontCSE.CloudIndex].ValidPos = false;
00676 
00677                         _CloudSchedulerLastAdded[CloudIndexToAdd].Pos = _CloudScheduler.insert(_CloudScheduler.end(), newCSE);
00678                         _CloudSchedulerLastAdded[CloudIndexToAdd].ValidPos = true;
00679                         //_CloudSchedulerLastAdded[CloudIndexToAdd].Pos = _CloudScheduler.end()-1;
00680                 }
00681                 else
00682                 {
00683                         _CloudScheduler.insert(_CloudScheduler.end(), newCSE);
00684                 }
00685                 _CloudScheduler.pop_front ();
00686                 ++_FrameCounter;
00687                 // End of scheduling
00688 
00689                 // Get the cloud to process (this must be the next occurence of front cloud)
00690                 std::list<SCloudSchedulerEntry>::iterator it = _CloudScheduler.begin();
00691                 while (it != _CloudScheduler.end())
00692                 {
00693                         SCloudSchedulerEntry &rCSE = *it;
00694                         if (rCSE.CloudIndex == FrontCSE.CloudIndex)
00695                                 break;
00696                         ++it;
00697                 }
00698 
00699                 SCloudSchedulerEntry CSEToCalc;
00700                 // The cloud is no more present in the list
00701                 if (it == _CloudScheduler.end())
00702                 {
00703                         FrontCSE.DeltaNextCalc = 1;
00704                         CSEToCalc = FrontCSE;
00705                 }
00706                 else
00707                 {
00708                         CSEToCalc = *it;
00709                 }
00710 
00711                 // Is the cloud to calc is a real cloud
00712                 if (CSEToCalc.CloudIndex == -1)
00713                 {
00714                         _CurrentCloudInProcess = NULL;  
00715                 }
00716                 else
00717                 {
00718                         _CurrentCloudInProcess = &_AllClouds[CSEToCalc.CloudIndex];
00719                         CCloud &c = *_CurrentCloudInProcess;
00720 
00721                         // To go from Front cloud to CSEToCalc cloud we should take the front DeltaNextCalc
00722 
00723                         _CurrentCloudInProcessFuturTime = ((0.04/_NbHalfCloudToUpdate) * FrontCSE.DeltaNextCalc * 2);
00724                         c.setX ((float)(c.getLastX() +  _CurrentCloudInProcessFuturTime * _CurrentCSS.WindSpeed));
00725 
00726                         float d2D = sqrtf(SQR(c.getX()+c.getSizeX()/2-Viewer.x)+SQR(c.getY()+c.getSizeY()/2-Viewer.y));
00727 
00728                         if (d2D > MAX_DIST)
00729                                 c.CloudDistAtt = 255;
00730                         else if (d2D > (MAX_DIST-100.0f))
00731                                 c.CloudDistAtt = (uint8)(255*((d2D-(MAX_DIST-100.0f))/100.0f));
00732                         else
00733                                 c.CloudDistAtt = 0;
00734 
00735                         c.LastCloudPower = c.CloudPower;
00736                         c.CloudPower = CSEToCalc.Power;
00737                         c.CloudDiffuse = CSEToCalc.Diffuse;
00738                         c.CloudAmbient = CSEToCalc.Ambient;
00739 
00740                         c.anim (_CurrentCloudInProcessFuturTime*_CurrentCSS.CloudSpeed, 
00741                                         _CurrentCloudInProcessFuturTime*_CurrentCSS.WindSpeed);
00742 
00743                         c.generate (_Noise3D);
00744                 }
00745         }
00746         else
00747         {
00748                 if (_CurrentCloudInProcess != NULL)
00749                 {
00750                         CCloud &c = *_CurrentCloudInProcess;
00751 
00752                         c.Time = 0;
00753                         c.FuturTime = _CurrentCloudInProcessFuturTime;
00754                         c.light();
00755 
00756                         if (c.getX() > MAX_DIST)
00757                         {
00758                                 c.setX (c.getX() - (2 * MAX_DIST));
00759                                 c.setLooping ();
00760                         }
00761                         
00762                         float r = sqrtf(SQR(c.getSizeX()/2)+SQR(c.getSizeY()/2)+SQR(c.getSizeZ()/2));
00763                         float d2D = sqrtf(SQR(c.getX()+c.getSizeX()/2-Viewer.x)+SQR(c.getY()+c.getSizeY()/2-Viewer.y));
00764                         float d = sqrtf(SQR(c.getX()+c.getSizeX()/2-Viewer.x)+SQR(c.getY()+c.getSizeY()/2-Viewer.y)+
00765                                                         SQR(c.getZ()+c.getSizeZ()/2-Viewer.z));
00766                         uint32 lookAtSize = (uint32)(_LODQualityThreshold*r/d);
00767                         lookAtSize = raiseToNextPowerOf2 (lookAtSize);
00768                         if (lookAtSize > 128) lookAtSize = 128;
00769 
00770                         c.genBill (_ViewerCam, lookAtSize);
00771                 }
00772         }
00773         _Generate = !_Generate;
00774 }

void NL3D::CCloudScape::render  ) 
 

Definition at line 777 of file cloud_scape.cpp.

References _AllClouds, _SortedClouds, _ViewerCam, NL3D::CFrustum::Bottom, NL3D::CCloudScape::SSortedCloudEntry::Cloud, NL3D::CCloud::CloudPower, NL3D::CCloud::dispBill(), NL3D::CCloudScape::SSortedCloudEntry::Distance, NL3D::CFrustum::Far, NL3D::CCamera::getFrustum(), NL3D::ITransformable::getMatrix(), NL3D::CCloud::getSizeX(), NL3D::CCloud::getSizeY(), NL3D::CCloud::getSizeZ(), NL3D::CCloud::getX(), NL3D::CCloud::getY(), NL3D::CCloud::getZ(), NLMISC::CMatrix::invert(), NL3D::CCloud::LastCloudPower, NL3D::CFrustum::Left, MAX_CLOUDS, NL3D::CFrustum::Near, NL3D::CFrustum::Perspective, NL3D::CFrustum::Right, s, NL3D::IDriver::setFrustum(), NLMISC::CMatrix::setPos(), NL3D::IDriver::setupModelMatrix(), NL3D::IDriver::setupScissor(), NL3D::IDriver::setupViewMatrix(), NL3D::IDriver::setupViewport(), SQR, NL3D::CFrustum::Top, uint32, v, NLMISC::CVector::x, NLMISC::CVector::y, and NLMISC::CVector::z.

Referenced by NL3D::CCloudScapeUser::render().

00778 {
00779         uint32 i, j;
00780         
00781         CVector Viewer = CVector (0,0,0);
00782 
00783         CMatrix viewMat;
00784         viewMat = _ViewerCam->getMatrix ();
00785         viewMat.setPos(CVector(0,0,0));
00786         viewMat.invert ();
00787         CScissor s;
00788         s.initFullScreen ();
00789         _Driver->setupScissor (s);
00790         CViewport v;
00791         _Driver->setupViewport (v);
00792         CFrustum f = _ViewerCam->getFrustum();
00793         _Driver->setFrustum (f.Left, f.Right, f.Bottom, f.Top, f.Near, f.Far, f.Perspective);
00794         _Driver->setupViewMatrix (viewMat);
00795         _Driver->setupModelMatrix (CMatrix::Identity);
00796 
00797         uint32 nNbCloudToRender = 0;
00798 
00799         for (i = 0; i < MAX_CLOUDS; ++i)
00800         {
00801                 CCloud &c = _AllClouds[i];
00802                 SSortedCloudEntry &sce = _SortedClouds[nNbCloudToRender];
00803                 sce.Cloud = &c;
00804                 sce.Distance = sqrtf(SQR(c.getX()+c.getSizeX()/2-Viewer.x)+SQR(c.getY()+c.getSizeY()/2-Viewer.y)+
00805                                                 SQR(c.getZ()+c.getSizeZ()/2-Viewer.z));
00806                 nNbCloudToRender++;
00807         }
00808 
00809         for (i = 0; i < nNbCloudToRender-1; ++i)
00810         for (j = i+1; j < nNbCloudToRender; ++j)
00811         {
00812                 if (_SortedClouds[i].Distance < _SortedClouds[j].Distance)
00813                 {
00814                         SSortedCloudEntry sceTmp = _SortedClouds[i];
00815                         _SortedClouds[i] = _SortedClouds[j];
00816                         _SortedClouds[j] = sceTmp;
00817                 }
00818         }
00819 
00820         for (i = 0; i < nNbCloudToRender; ++i)
00821         {
00822                 CCloud *pC = _SortedClouds[i].Cloud;
00823                 if ((pC->CloudPower > 0) || (pC->LastCloudPower > 0))
00824                         pC->dispBill (_ViewerCam);
00825         }
00826 }

void NL3D::CCloudScape::set SCloudScapeSetup css  ) 
 

Definition at line 417 of file cloud_scape.cpp.

References _IncomingCSS, and _IsIncomingCSS.

Referenced by NL3D::CCloudScapeUser::set().

00418 {
00419         _IncomingCSS = css;
00420         _IsIncomingCSS = true;
00421 }

void NL3D::CCloudScape::setDebugQuad bool  b  )  [inline]
 

Definition at line 98 of file cloud_scape.h.

References _DebugQuad.

Referenced by NL3D::CCloudScapeUser::setDebugQuad().

00098 { _DebugQuad = b; }

void NL3D::CCloudScape::setNbCloudToUpdateIn80ms uint32  n  )  [inline]
 

Definition at line 95 of file cloud_scape.h.

References _NbHalfCloudToUpdate, and uint32.

Referenced by NL3D::CCloudScapeUser::setNbCloudToUpdateIn80ms().

00095 { _NbHalfCloudToUpdate = n; }

void NL3D::CCloudScape::setQuality float  threshold  )  [inline]
 

Definition at line 93 of file cloud_scape.h.

References _LODQualityThreshold.

Referenced by NL3D::CCloudScapeUser::setQuality().

00093 { _LODQualityThreshold = threshold; }


Friends And Related Function Documentation

friend class CCloud [friend]
 

Definition at line 186 of file cloud_scape.h.

Referenced by init().


Field Documentation

std::vector<CCloud> NL3D::CCloudScape::_AllClouds [private]
 

Definition at line 128 of file cloud_scape.h.

Referenced by anim(), getMemSize(), init(), makeHalfCloud(), and render().

NLMISC::CValueSmoother NL3D::CCloudScape::_AverageFrameRate [private]
 

Definition at line 110 of file cloud_scape.h.

Referenced by anim(), and init().

std::vector<uint8> NL3D::CCloudScape::_CloudPower [private]
 

Definition at line 115 of file cloud_scape.h.

Referenced by anim(), init(), and makeHalfCloud().

std::list<SCloudSchedulerEntry> NL3D::CCloudScape::_CloudScheduler [private]
 

Definition at line 156 of file cloud_scape.h.

Referenced by init(), and makeHalfCloud().

std::vector<SCloudSchedulerAccel> NL3D::CCloudScape::_CloudSchedulerLastAdded [private]
 

Definition at line 158 of file cloud_scape.h.

Referenced by init(), and makeHalfCloud().

uint32 NL3D::CCloudScape::_CloudSchedulerSize [private]
 

Definition at line 157 of file cloud_scape.h.

Referenced by init().

CCloud* NL3D::CCloudScape::_CurrentCloudInProcess [private]
 

Definition at line 112 of file cloud_scape.h.

Referenced by CCloudScape(), and makeHalfCloud().

double NL3D::CCloudScape::_CurrentCloudInProcessFuturTime [private]
 

Definition at line 113 of file cloud_scape.h.

Referenced by makeHalfCloud().

SCloudScapeSetup NL3D::CCloudScape::_CurrentCSS [private]
 

Definition at line 118 of file cloud_scape.h.

Referenced by anim(), init(), and makeHalfCloud().

bool NL3D::CCloudScape::_DebugQuad [private]
 

Definition at line 174 of file cloud_scape.h.

Referenced by CCloudScape(), isDebugQuadEnabled(), and setDebugQuad().

double NL3D::CCloudScape::_DeltaTime [private]
 

Definition at line 108 of file cloud_scape.h.

Referenced by anim().

NL3D::IDriver* NL3D::CCloudScape::_Driver [private]
 

Definition at line 176 of file cloud_scape.h.

Referenced by NL3D::CCloud::CCloud().

double NL3D::CCloudScape::_DTRest [private]
 

Definition at line 109 of file cloud_scape.h.

Referenced by anim(), and init().

std::vector<float> NL3D::CCloudScape::_ExtrapolatedPriorities [private]
 

Definition at line 160 of file cloud_scape.h.

Referenced by init(), and makeHalfCloud().

uint32 NL3D::CCloudScape::_FrameCounter [private]
 

Definition at line 159 of file cloud_scape.h.

Referenced by init(), and makeHalfCloud().

bool NL3D::CCloudScape::_Generate [private]
 

Definition at line 111 of file cloud_scape.h.

Referenced by init(), and makeHalfCloud().

double NL3D::CCloudScape::_GlobalTime [private]
 

Definition at line 107 of file cloud_scape.h.

Referenced by anim(), and init().

SCloudScapeSetup NL3D::CCloudScape::_IncomingCSS [private]
 

Definition at line 124 of file cloud_scape.h.

Referenced by anim(), and set().

bool NL3D::CCloudScape::_IsIncomingCSS [private]
 

Definition at line 123 of file cloud_scape.h.

Referenced by anim(), CCloudScape(), init(), and set().

float NL3D::CCloudScape::_LODQualityThreshold [private]
 

Definition at line 173 of file cloud_scape.h.

Referenced by CCloudScape(), makeHalfCloud(), and setQuality().

NL3D::CMaterial NL3D::CCloudScape::_MatBill [private]
 

Definition at line 179 of file cloud_scape.h.

Referenced by CCloudScape(), and NL3D::CCloud::dispBill().

NL3D::CMaterial NL3D::CCloudScape::_MatClear [private]
 

Definition at line 178 of file cloud_scape.h.

Referenced by CCloudScape(), NL3D::CCloud::genBill(), NL3D::CCloud::generate(), NL3D::CCloud::light(), and NL3D::CCloud::reset().

uint32 NL3D::CCloudScape::_NbHalfCloudToUpdate [private]
 

Definition at line 106 of file cloud_scape.h.

Referenced by anim(), CCloudScape(), init(), makeHalfCloud(), and setNbCloudToUpdateIn80ms().

SCloudScapeSetup NL3D::CCloudScape::_NewCSS [private]
 

Definition at line 119 of file cloud_scape.h.

Referenced by anim(), and init().

CNoise3d NL3D::CCloudScape::_Noise3D [private]
 

Definition at line 126 of file cloud_scape.h.

Referenced by init(), and makeHalfCloud().

SCloudScapeSetup NL3D::CCloudScape::_OldCSS [private]
 

Definition at line 120 of file cloud_scape.h.

Referenced by anim(), and init().

std::vector<bool> NL3D::CCloudScape::_ShouldProcessCloud [private]
 

Definition at line 116 of file cloud_scape.h.

Referenced by anim(), init(), and makeHalfCloud().

std::vector<SSortedCloudEntry> NL3D::CCloudScape::_SortedClouds [private]
 

Definition at line 169 of file cloud_scape.h.

Referenced by init(), and render().

double NL3D::CCloudScape::_TimeNewCSS [private]
 

Definition at line 121 of file cloud_scape.h.

Referenced by anim(), and init().

NL3D::CVertexBuffer NL3D::CCloudScape::_VertexBuffer [private]
 

Definition at line 177 of file cloud_scape.h.

Referenced by CCloudScape(), NL3D::CCloud::disp(), NL3D::CCloud::dispBill(), NL3D::CCloud::dispXYZ(), NL3D::CCloud::genBill(), NL3D::CCloud::generate(), NL3D::CCloud::light(), and NL3D::CCloud::reset().

NL3D::CCamera* NL3D::CCloudScape::_ViewerCam [private]
 

Definition at line 181 of file cloud_scape.h.

Referenced by anim(), init(), makeHalfCloud(), and render().

SCloudTexture3D NL3D::CCloudScape::Tex3DTemp [private]
 

Definition at line 183 of file cloud_scape.h.

Referenced by init().

SCloudTextureClamp NL3D::CCloudScape::TexClamp [private]
 

Definition at line 184 of file cloud_scape.h.

Referenced by init().


The documentation for this class was generated from the following files:
Generated on Tue Mar 16 06:45:08 2004 for NeL by doxygen 1.3.6