NL3D::CWaterHeightMap Class Reference

#include <water_height_map.h>

Inheritance diagram for NL3D::CWaterHeightMap:

NL3D::UWaterHeightMap

Public Member Functions

void animate (float deltaT)
bool areWavesEnabled () const
 test wheter automatic waves generation is enabled

 CWaterHeightMap ()
void enableWaves (bool enabled=true)
 enable automatic waves generation

bool getBorderWaves () const
 Test whether waves are enabled on the border.

float getBufferRatio () const
 get the ratio between the previous and the current buffer

float getDamping () const
float getFilterWeight () const
virtual float getHeight (const NLMISC::CVector2f &pos)
const std::string & getName () const
 Get this pool name.

float * getPointer (void)
 get a pointer on the current buffer.

float * getPrevPointer (void)
 get a pointer on the previous buffer.

TAnimationTime getPropagationTime () const
 Get the propagation time.

uint32 getSize (void) const
 return the size of the height map

float getUnitSize () const
 get the size in meter of a heightmap texel

void getUserPos (sint &x, sint &y) const
uint32 getWaveImpulsionRadius () const
 radius of impulsion for the waves

float getWaveIntensity () const
 get the intensity of waves

float getWavePeriod () const
 get the period of waves

virtual void perturbate (const NLMISC::CVector2f &pos, float strenght, float radius)
void perturbate (sint x, sint y, sint radius, float intensity)
 create a perturbation in the height map.

virtual void perturbatePoint (const NLMISC::CVector2f &pos, float strenght)
void perturbatePoint (sint x, sint y, float intensity)
 create a point perturbation in the height map.

void serial (NLMISC::IStream &f) throw (NLMISC::EStream)
 serial the pools data's

void setDamping (float damping)
 damping

void setFilterWeight (float filterWeight)
 filter weight

void setName (const std::string &name)
 Set this pool name.

void setPropagationTime (float time)
 Set the propagation time. This is the time needed to go from one unit to one other in the height map.

void setSize (uint32 size)
void setUnitSize (float unitSize)
 water unit size

void setUserPos (sint x, sint y)
 return the power of 2 used for this quad size

void setWaves (float intensity, float period, uint radius, bool border)
virtual ~CWaterHeightMap ()

Data Fields

sint64 Date
 the last update date


Private Types

typedef std::vector< NLMISC::CVector2fTFloat2Vect
typedef std::vector< float > TFloatVect

Private Member Functions

void animatePart (float startTime, float endTime)
void animateWaves (float deltaT)
void clearArea (uint8 currMap, sint x, sint y, sint width, sint height)
 clear an area of the water height map (has clipping, but no wrapping)

void clearBorder (uint currMap)
 clear the borders

void clearZone (sint x, sint y, sint width, sint height)
void filter (uint startLine, uint endLine)
 apply a filter on the height field

void makeCpy (uint buffer, uint dX, uint dY, uint sX, uint sY, uint width, uint height)
 displace the height map, when a boundary has been reached

void propagate (uint startLine, uint endLine)
void swapBuffers (float deltaT)
 swap the height maps. It must be called once propagation and filtering have been performed

void updateUserPos ()

Private Attributes

bool _BorderWaves
uint8 _CurrMap
float _Damping
float _EmitEllapsedTime
float _FilterWeight
TFloatVect _Map [NumWaterMap]
std::string _Name
uint _NewX
uint _NewY
float _PropagateEllapsedTime
TAnimationTime _PropagationTime
uint32 _Size
float _UnitSize
uint32 _WaveImpulsionRadius
float _WaveIntensity
float _WavePeriod
bool _WavesEnabled
uint _X
uint _Y

Friends

class CWaterPoolManager

Member Typedef Documentation

typedef std::vector<NLMISC::CVector2f > NL3D::CWaterHeightMap::TFloat2Vect [private]
 

Definition at line 237 of file water_height_map.h.

typedef std::vector<float> NL3D::CWaterHeightMap::TFloatVect [private]
 

Definition at line 236 of file water_height_map.h.


Constructor & Destructor Documentation

NL3D::CWaterHeightMap::CWaterHeightMap  ) 
 

Definition at line 42 of file water_height_map.cpp.

00042                                  : Date(-1),
00043                                                                          _WavesEnabled(false),
00044                                                                          _Damping(0.97f),
00045                                                                          _FilterWeight(4),
00046                                                                          _UnitSize(0.6f),
00047                                                                          _WaveIntensity(0),
00048                                                                          _WavePeriod(0),
00049                                                                          _WaveImpulsionRadius(3),
00050                                                                          _BorderWaves(true),
00051                                                                          _EmitEllapsedTime(0),
00052                                                                          _PropagateEllapsedTime(0),
00053                                                                          _PropagationTime(0.10f),
00054                                                                          _X(0),
00055                                                                          _Y(0),
00056                                                                          _NewX(0),
00057                                                                          _NewY(0),
00058                                                                          _CurrMap(0),
00059                                                                          _Size(0)
00060 {               
00061 }

virtual NL3D::CWaterHeightMap::~CWaterHeightMap  )  [inline, virtual]
 

Definition at line 188 of file water_height_map.h.

00188 {}


Member Function Documentation

void NL3D::CWaterHeightMap::animate float  deltaT  ) 
 

Animate this water pool. Usually called by CWaterModel before the display, if this height map date is not the same as the current date.

Definition at line 236 of file water_height_map.cpp.

References _PropagateEllapsedTime, _PropagationTime, animatePart(), animateWaves(), and swapBuffers().

Referenced by NL3D::CWaterModel::traverseRender().

00237 {       
00238         if (deltaT < 0) deltaT = 0;
00239         if (deltaT > _PropagationTime)
00240         {
00241                 animatePart(0, _PropagationTime);
00242                 swapBuffers(deltaT);
00243                 _PropagateEllapsedTime = 0;
00244         }
00245         else
00246         {
00247                 const float endTime   = _PropagateEllapsedTime + deltaT;                
00248                 const float startTime = _PropagateEllapsedTime;
00249 
00250                 if (endTime < _PropagationTime)
00251                 {
00252                         animatePart(startTime, endTime);
00253                         _PropagateEllapsedTime = endTime;
00254                 }
00255                 else
00256                 {
00257                         animatePart(startTime, _PropagationTime);
00258                         swapBuffers(deltaT);
00259                         //animatePart(0, endTime - _PropagationTime);
00260 
00261                         _PropagateEllapsedTime = 0 /*endTime - _PropagationTime*/;
00262                 }                               
00263         }
00264         animateWaves(deltaT);
00265 }

void NL3D::CWaterHeightMap::animatePart float  startTime,
float  endTime
[private]
 

Definition at line 212 of file water_height_map.cpp.

References _PropagationTime, filter(), propagate(), and uint.

Referenced by animate().

00213 {
00214         if (endTime < 0.5f * _PropagationTime)
00215         {
00216                 // perform propagation
00217                 propagate((uint) (_Size * 2.f * startTime / _PropagationTime), (uint) (_Size * 2.f * endTime / _PropagationTime));      
00218         }
00219         else
00220         {
00221                 //  end propagation and start filter
00222                 if (startTime < 0.5f * _PropagationTime)
00223                 {
00224                         propagate((uint) (_Size * 2.f * startTime / _PropagationTime), _Size);  
00225                         filter(0, (uint) (_Size * 2.f * (endTime / _PropagationTime - 0.5f)));
00226                 }
00227                 else
00228                 {
00229                         filter((uint) (_Size * 2.f * (startTime  / _PropagationTime - 0.5f)), (uint) (_Size * 2.f * (endTime  / _PropagationTime - 0.5f)));
00230                 }
00231         }
00232 }

void NL3D::CWaterHeightMap::animateWaves float  deltaT  )  [private]
 

Definition at line 442 of file water_height_map.cpp.

References _BorderWaves, _EmitEllapsedTime, _NewX, _NewY, _WaveImpulsionRadius, _WaveIntensity, _WavePeriod, _WavesEnabled, perturbate(), and uint.

Referenced by animate().

00443 {
00444         if (_WavesEnabled)
00445         {
00446                 uint numWaves;
00447                 if (_WavePeriod == 0)
00448                 {
00449                         numWaves = 1;
00450                 }
00451                 else
00452                 {
00453                         _EmitEllapsedTime += deltaT;
00454                         if (_EmitEllapsedTime > _WavePeriod)
00455                         {
00456                                 numWaves = (uint) (_EmitEllapsedTime / _WavePeriod);
00457                                 _EmitEllapsedTime -= numWaves * _WavePeriod;
00458                                 if (numWaves > 10) numWaves = 10;
00459                         }
00460                         else
00461                         {
00462                                 numWaves = 0;
00463                         }
00464                 }
00465                 
00466                 uint k;
00467                 // generate automatic waves
00468                 if (!_BorderWaves)
00469                 {
00470                         if (_WaveIntensity != 0)
00471                         {
00472                                 for (k = 0; k < numWaves; ++k)
00473                                 {
00474                                         perturbate(_NewX + rand() % _Size, _NewY + rand() % _Size, _WaveImpulsionRadius, _WaveIntensity);
00475                                 }
00476                         }
00477                 }
00478                 else
00479                 {
00480                         switch(rand() & 3) // choose a random border
00481                         {
00482                                 case 0: // top border
00483                                         for (k = 0; k < numWaves; ++k)
00484                                         {
00485                                                 perturbate(_NewX + (uint) rand() % _Size, _NewY, _WaveImpulsionRadius, _WaveIntensity);
00486                                         }
00487                                 break;
00488                                 case 1: // bottom border
00489                                         for (k = 0; k < numWaves; ++k)
00490                                         {
00491                                                 perturbate(_NewX + (uint) rand() % _Size, _NewY + _Size - 1, _WaveImpulsionRadius, _WaveIntensity);
00492                                         }
00493                                 break;
00494                                 case 2: // right border
00495                                         for (k = 0; k < numWaves; ++k)
00496                                         {
00497                                                 perturbate(_NewX + _Size - 1, _NewY + (uint) rand() % _Size, _WaveImpulsionRadius, _WaveIntensity);
00498                                         }
00499                                 break;
00500                                 case 3: // left border
00501                                         for (k = 0; k < numWaves; ++k)
00502                                         {
00503                                                 perturbate(_NewX, _NewY + (uint) rand() % _Size, _WaveImpulsionRadius, _WaveIntensity);
00504                                         }
00505                                 break;
00506                         }
00507         
00508                 }
00509         }
00510 }

bool NL3D::CWaterHeightMap::areWavesEnabled  )  const [inline]
 

test wheter automatic waves generation is enabled

Definition at line 138 of file water_height_map.h.

References _WavesEnabled.

00138 { return _WavesEnabled; }

void NL3D::CWaterHeightMap::clearArea uint8  currMap,
sint  x,
sint  y,
sint  width,
sint  height
[private]
 

clear an area of the water height map (has clipping, but no wrapping)

Definition at line 533 of file water_height_map.cpp.

References _Map, height, nlassert, sint, uint, uint8, width, x, and y.

Referenced by clearZone(), setPropagationTime(), and setSize().

00534 {       
00535         nlassert(_Size > 1);
00536         nlassert(width >= 0);
00537         nlassert(height >= 0);
00538         uint sizex2 = _Size << 1;
00539 
00540         if (x < 0)
00541         {               
00542                 width += x;
00543                 x = 0;
00544                 if (width <= 0) return;
00545         }
00546         if (y < 0)
00547         {
00548                 height += y;
00549                 y = 0;
00550                 if (height <= 0) return;
00551         }
00552         if (x + width > (sint) sizex2)
00553         {
00554                 width = width - (x + width - sizex2);
00555         }
00556 
00557         if (y + height > (sint) sizex2)
00558         {
00559                 height = height - (y + height - sizex2);
00560         }
00561         
00562         float *dest = &*(_Map[  currMap  ].begin() + x + (_Size << 1) * y);
00563         do
00564         {
00565                 std::fill(dest, dest + width, 0.f);             
00566                 dest  += (_Size << 1);
00567         }
00568         while (-- height);
00569 }

void NL3D::CWaterHeightMap::clearBorder uint  currMap  )  [private]
 

clear the borders

Definition at line 635 of file water_height_map.cpp.

References _Map, and uint.

Referenced by propagate().

00636 {
00637         float *map  = &_Map[currMap][0];
00638         uint sizex2 = _Size << 1;
00639 
00640         // top and bottom
00641 
00642         float *up    = &map[(_X % _Size) + sizex2 * (_Y % _Size)];
00643         float *curr = up;
00644         const float *endUp = up + _Size;
00645         const uint  downOff  = (_Size - 1) * sizex2;
00646         do
00647         {
00648                 *curr = curr[downOff] = 0.f;
00649                 ++curr;
00650         }
00651         while (curr != endUp);
00652 
00653         // right and left
00654         curr  = up;
00655         const float *endLeft = up + downOff;
00656         const uint  rightOff = _Size - 1;
00657         do
00658         {
00659                 *curr = curr[rightOff] = 0.f;
00660                 curr += sizex2;
00661         }
00662         while (curr != endLeft);
00663 }

void NL3D::CWaterHeightMap::clearZone sint  x,
sint  y,
sint  width,
sint  height
[private]
 

Definition at line 523 of file water_height_map.cpp.

References clearArea(), height, NL3D::NumWaterMap, sint, uint, width, x, and y.

Referenced by updateUserPos().

00524 {
00525         for (uint k = 0; k < NumWaterMap; ++k)
00526         {
00527                 clearArea(k, x, y, width, height);
00528         }
00529 }

void NL3D::CWaterHeightMap::enableWaves bool  enabled = true  )  [inline]
 

enable automatic waves generation

Definition at line 135 of file water_height_map.h.

References _WavesEnabled.

Referenced by NL3D::CWaterPoolManager::createWaterPool().

00135 { _WavesEnabled = enabled; }

void NL3D::CWaterHeightMap::filter uint  startLine,
uint  endLine
[private]
 

apply a filter on the height field

Definition at line 399 of file water_height_map.cpp.

References _CurrMap, _FilterWeight, _Map, min, nlassert, NL3D::NumWaterMap, offset, sint, uint, x, and y.

Referenced by animatePart().

00400 {       
00401         start = std::max(1u, start);
00402         end   = std::min((uint) (_Size - 1), end);
00403         const float blurCoeff = _FilterWeight;
00404         nlassert(_Size != 0);
00405         sint x, y;
00406         uint px = _X % _Size;
00407         uint py = _Y % _Size;
00408         sint offset = px + 1 + ((py + start) * (_Size << 1));
00409         float *buf = &_Map[ (_CurrMap + 1) % NumWaterMap ][offset];
00410         //NLMISC::CVector2f *ptGrad = &_Grad[offset];
00411         y = end - start;
00412         if (y <= 0) return;
00413         const float totalBlurCoeff = (1.f / (4.f + blurCoeff));
00414         const sint  sizeX2 = _Size << 1;
00415         do
00416         {
00417                 x = _Size - 2;
00418                 do
00419                 {
00420                         *buf = totalBlurCoeff * (*buf * blurCoeff
00421                                                                                  + buf[1] 
00422                                                                                  + buf[-1]
00423                                                                                  + buf[sizeX2]
00424                                                                                  + buf[- sizeX2]
00425                                                                          );     
00426                         // compute gradient
00427                         /*ptGrad->x = buf[1]                - buf[- 1];
00428                         ptGrad->y = buf[sizeX2]     - buf[- sizeX2];*/
00429 
00430                         ++buf;
00431                         //++ptGrad;
00432                 }
00433                 while (--x);
00434                 buf    += _Size + 2;
00435                 //ptGrad += _Size + 2;
00436         }
00437         while (--y);    
00438 }

bool NL3D::CWaterHeightMap::getBorderWaves  )  const [inline]
 

Test whether waves are enabled on the border.

Definition at line 159 of file water_height_map.h.

References _BorderWaves.

00159 { return _BorderWaves; }

float NL3D::CWaterHeightMap::getBufferRatio  )  const [inline]
 

get the ratio between the previous and the current buffer

Definition at line 128 of file water_height_map.h.

References _PropagateEllapsedTime, and _PropagationTime.

Referenced by getHeight(), and NL3D::SetupWaterVertex().

00128 { return _PropagationTime != 0 ? _PropagateEllapsedTime / _PropagationTime : 0.f; }

float NL3D::CWaterHeightMap::getDamping  )  const [inline]
 

Definition at line 163 of file water_height_map.h.

References _Damping.

00163 { return _Damping; }

float NL3D::CWaterHeightMap::getFilterWeight  )  const [inline]
 

Definition at line 167 of file water_height_map.h.

References _FilterWeight.

00167 { return _FilterWeight; }

float NL3D::CWaterHeightMap::getHeight const NLMISC::CVector2f pos  )  [virtual]
 

Inherited from UWaterHeightMap. Get the height of water at the given location.

Implements NL3D::UWaterHeightMap.

Definition at line 726 of file water_height_map.cpp.

References _UnitSize, NL3D::BilinFilter(), getBufferRatio(), getPointer(), getPrevPointer(), offset, sint, uint, NLMISC::CVector2f::x, and NLMISC::CVector2f::y.

Referenced by NL3D::CWaterModel::getAttenuatedHeight(), and NL3D::CWaterModel::getHeight().

00727 {
00728         const float invUnitSize = 1.f / _UnitSize;
00729         
00730         const float xPos = invUnitSize * pos.x; // position in map space
00731         const float yPos = invUnitSize * pos.y; // position in map space
00732 
00733         
00734         if ((uint) xPos - _X < _Size - 1
00735                 && (uint) yPos - _Y < _Size - 1
00736                 )
00737 
00738         {
00739 
00740                 const sint orgX = _X - _X % _Size;
00741                 const sint orgY = _Y - _Y % _Size;
00742                 const uint sizeX2 = _Size << 1;
00743 
00744         
00745                 const sint  fxPos = (sint) floorf(xPos); 
00746                 const sint  fyPos = (sint) floorf(yPos); 
00747 
00748         
00749                         
00750                         const float deltaU        = xPos - fxPos;
00751                         const float deltaV        = yPos - fyPos;
00752                         const uint  offset        = (uint) fxPos - orgX + sizeX2 * ( (uint) fyPos - orgY);
00753                         const float lambda        = getBufferRatio();
00754                         const float *map1     = getPrevPointer();
00755                         const float *map2     = getPointer();
00756 
00757                         return BilinFilter(lambda * map2[offset]                          + (1.f - lambda) * map1[offset        ],                        // top left
00758                                                            lambda * map2[offset + 1]              + (1.f - lambda) * map1[offset + 1],            // top right
00759                                                            lambda * map2[offset + sizeX2 + 1] + (1.f - lambda) * map1[offset + sizeX2 + 1], // bottom right
00760                                                            lambda * map2[offset + sizeX2 ]    + (1.f - lambda) * map1[offset + sizeX2 ],          // bottom left
00761                                                            deltaU,
00762                                                            deltaV
00763                                                            );
00764         }                                               
00765         else return 0;
00766 
00767 }

const std::string& NL3D::CWaterHeightMap::getName void   )  const [inline]
 

Get this pool name.

Definition at line 183 of file water_height_map.h.

00183 { return _Name; }

float* NL3D::CWaterHeightMap::getPointer void   )  [inline]
 

get a pointer on the current buffer.

Definition at line 122 of file water_height_map.h.

References _CurrMap, and _Map.

Referenced by getHeight(), and NL3D::SetupWaterVertex().

00122 { return &(_Map[_CurrMap][0]); }

float* NL3D::CWaterHeightMap::getPrevPointer void   )  [inline]
 

get a pointer on the previous buffer.

Definition at line 125 of file water_height_map.h.

References _CurrMap, _Map, and NL3D::NumWaterMap.

Referenced by getHeight(), and NL3D::SetupWaterVertex().

00125 { return &(_Map[(_CurrMap + (NumWaterMap - 1)) % NumWaterMap][0]); }

TAnimationTime NL3D::CWaterHeightMap::getPropagationTime  )  const [inline]
 

Get the propagation time.

Definition at line 194 of file water_height_map.h.

References _PropagationTime, and NL3D::TAnimationTime.

Referenced by NL3D::CWaveMakerModel::traverseAnimDetail().

00194 { return _PropagationTime; }

uint32 NL3D::CWaterHeightMap::getSize void   )  const [inline]
 

return the size of the height map

Definition at line 82 of file water_height_map.h.

References uint32.

Referenced by NL3D::CWaveMakerShape::clip(), NL3D::CWaterModel::getAttenuatedHeight(), and NL3D::CWaterModel::traverseRender().

00082 { return _Size; }

float NL3D::CWaterHeightMap::getUnitSize  )  const [inline, virtual]
 

get the size in meter of a heightmap texel

Implements NL3D::UWaterHeightMap.

Definition at line 171 of file water_height_map.h.

References _UnitSize.

Referenced by NL3D::CWaveMakerShape::clip(), NL3D::CWaterModel::getAttenuatedHeight(), and NL3D::CWaterModel::traverseRender().

00171 { return _UnitSize; }

void NL3D::CWaterHeightMap::getUserPos sint x,
sint y
const
 

Retrieve the use pos NB: this may be different from the params of a former call to setUserPos (should have been taken in account)

Definition at line 347 of file water_height_map.cpp.

References sint, x, and y.

Referenced by NL3D::CWaterModel::traverseRender().

00348 {               
00349         x = (sint) _X; y = (sint) _Y;
00350 }

uint32 NL3D::CWaterHeightMap::getWaveImpulsionRadius  )  const [inline]
 

radius of impulsion for the waves

Definition at line 156 of file water_height_map.h.

References _WaveImpulsionRadius, and uint32.

00156 { return _WaveImpulsionRadius; }

float NL3D::CWaterHeightMap::getWaveIntensity  )  const [inline]
 

get the intensity of waves

Definition at line 150 of file water_height_map.h.

References _WaveIntensity.

00150 { return _WaveIntensity; }

float NL3D::CWaterHeightMap::getWavePeriod  )  const [inline]
 

get the period of waves

Definition at line 153 of file water_height_map.h.

References _WavePeriod.

00153 { return _WavePeriod; }

void NL3D::CWaterHeightMap::makeCpy uint  buffer,
uint  dX,
uint  dY,
uint  sX,
uint  sY,
uint  width,
uint  height
[private]
 

displace the height map, when a boundary has been reached

Definition at line 283 of file water_height_map.cpp.

References _Map, buffer, height, nlassert, sint, src, stride, uint, and width.

Referenced by updateUserPos().

00284 {       
00285         if (width == 0 || height == 0) return;
00286         nlassert(dX <= (2 * _Size));
00287         nlassert(dY <= (2 * _Size));
00288         nlassert(sX <= (2 * _Size));
00289         nlassert(sY <= (2 * _Size));
00290         nlassert(dX + width <= 2 * _Size);
00291         nlassert(sX + width <= 2 * _Size);
00292         nlassert(dY + height <= 2 * _Size);
00293         nlassert(sY + height <= 2 * _Size);
00294         
00295         sint stepY;
00296         float *src, *dest;
00297 
00298         const sint stride = _Size << 1;
00299         if (dY  <= sY)
00300         {
00301                 stepY = stride;
00302                 src   =  &_Map[buffer][sX + sY * stride];
00303                 dest  =  &_Map[buffer][dX + dY * stride];
00304         }
00305         else
00306         {
00307                 stepY = -stride;
00308                 src   =  &_Map[buffer][sX + (sY + height - 1) * stride];
00309                 dest  =  &_Map[buffer][dX + (dY + height - 1) * stride];
00310         }
00311 
00312         sint k = height;
00313         do
00314         {
00315                 if (dest < src)
00316                 {
00317                         std::copy(src, src + width, dest);
00318                 }
00319                 else
00320                 {
00321                         float *rSrc  = src  + width;
00322                         float *rDest = dest + width;
00323                         do
00324                         {
00325                                 --rSrc;
00326                                 --rDest;
00327                                 *rDest = *rSrc;
00328                         }
00329                         while (rSrc != src);
00330                 }
00331                 src  += stepY;
00332                 dest += stepY;
00333         }
00334         while (--k);
00335 }

void NL3D::CWaterHeightMap::perturbate const NLMISC::CVector2f pos,
float  strenght,
float  radius
[virtual]
 

Inherited from UWaterHeightMap. This version takes a location in world space

Implements NL3D::UWaterHeightMap.

Definition at line 601 of file water_height_map.cpp.

References _UnitSize, perturbate(), sint, NLMISC::CVector2f::x, and NLMISC::CVector2f::y.

00602 {
00603         const float invUnitSize = 1.f / _UnitSize;
00604         perturbate((sint) (pos.x * invUnitSize), (sint) (pos.y * invUnitSize), (sint) radius, strenght);
00605 }

void NL3D::CWaterHeightMap::perturbate sint  x,
sint  y,
sint  radius,
float  intensity
 

create a perturbation in the height map.

Definition at line 575 of file water_height_map.cpp.

References _CurrMap, _Map, nlassert, NL3D::NumWaterMap, sint, uint, v, x, and y.

Referenced by animateWaves(), perturbate(), and NL3D::CWaveMakerModel::traverseAnimDetail().

00576 {
00577                 nlassert(_Size != 0);
00578                 nlassert(radius > 0);
00579                 sint orgX = _X - _X % _Size;
00580                 sint orgY = _Y - _Y % _Size;
00581                 TFloatVect &map = _Map[(_CurrMap + 1) % NumWaterMap];
00582                 const uint sizeX2 = _Size << 1;
00583                 for (sint px = -radius + 1; px < radius; ++px)
00584                 {
00585                         for (sint py = -radius + 1; py < radius; ++py)          
00586                         {       
00587                                 if ((uint) (x + px - orgX) < sizeX2 
00588                                         && (uint) (y + py - orgY) < sizeX2)
00589                                 {                                       
00590                                 
00591                                         float dist = ((float) radius - sqrtf((float) (px * px + py * py ))) / (float) radius;
00592                                         float v = dist < radius ? intensity * cosf(dist * (float) NLMISC::Pi * 0.5f) : 0.f;
00593                                         map[x + px - orgX + sizeX2 * (y + py - orgY)] = v;
00594                                 }
00595                         }
00596                 }
00597 }

void NL3D::CWaterHeightMap::perturbatePoint const NLMISC::CVector2f pos,
float  strenght
[virtual]
 

Inherited from UWaterHeightMap. This version takes a location in world space

Implements NL3D::UWaterHeightMap.

Definition at line 627 of file water_height_map.cpp.

References _UnitSize, perturbatePoint(), sint, NLMISC::CVector2f::x, and NLMISC::CVector2f::y.

00628 {
00629         const float invUnitSize = 1.f / _UnitSize;
00630         perturbatePoint((sint) (pos.x * invUnitSize), (sint) (pos.y * invUnitSize), strenght);
00631 }

void NL3D::CWaterHeightMap::perturbatePoint sint  x,
sint  y,
float  intensity
 

create a point perturbation in the height map.

Definition at line 609 of file water_height_map.cpp.

References _CurrMap, _Map, NL3D::NumWaterMap, sint, uint, x, and y.

Referenced by perturbatePoint().

00610 {       
00611         sint orgX = _X - _X % _Size;
00612         sint orgY = _Y - _Y % _Size;
00613         uint X = (uint) (x - orgX);
00614         uint Y = (uint) (y - orgY);     
00615         if (X < (_Size << 1)
00616                 && Y < (_Size << 1)
00617                 )
00618         {
00619                 const uint sizex2 = _Size << 1;         
00620                 TFloatVect &map = _Map[(_CurrMap + 1) % NumWaterMap];
00621                 map[X + sizex2 * Y] = intensity;                
00622         }
00623 }

void NL3D::CWaterHeightMap::propagate uint  startLine,
uint  endLine
[private]
 

Perform water propagation on this quad. You should call swapBuffers after this, or after calling filter.

Parameters:
damping The attenuation factor used for propagation.

Definition at line 356 of file water_height_map.cpp.

References _CurrMap, _Damping, _Map, clearBorder(), min, nlassert, NL3D::NumWaterMap, offset, sint, uint, x, and y.

Referenced by animatePart().

00357 {       
00358         start = std::max(1u, start);
00359         end   = std::min((uint) (_Size - 1), end);
00360         const float damping = _Damping;
00361         clearBorder(0);
00362         clearBorder(1);
00363         nlassert(_Size != 0);
00364         sint x, y;
00365         uint px = _X % _Size;
00366         uint py = _Y % _Size;
00367         sint offset = px + 1 + ((py + start) * (_Size << 1));   
00368         //nlinfo("%d, %d, %d",  (_CurrMap + (NumWaterMap - 1)) % NumWaterMap,  _CurrMap, 
00369         float *buf2 = &_Map[ (_CurrMap + (NumWaterMap - 1)) % NumWaterMap][offset];
00370         float *buf1 = &_Map[_CurrMap][offset];  
00371         float *dest = &_Map[(_CurrMap + 1) % NumWaterMap][offset];
00372         
00373         const sint  sizeX2 = _Size << 1;
00374         y = end - start;
00375         if (y <= 0) return;
00376         do
00377         {
00378                 x = _Size - 2;
00379                 do
00380                 {
00381                         *dest   = damping * ( 0.5f * (buf1[1] + buf1[-1] + buf1[sizeX2] + buf1[- sizeX2]) - *buf2);                     
00382                         ++buf1;
00383                         ++buf2;
00384                         ++dest;
00385                 }
00386                 while (--x);
00387                 buf1 = buf1 + _Size + 2;
00388                 buf2 = buf2 + _Size + 2;
00389                 dest = dest + _Size + 2;
00390         }
00391         while (--y);
00392         
00393 }

void NL3D::CWaterHeightMap::serial NLMISC::IStream f  )  throw (NLMISC::EStream)
 

serial the pools data's

Definition at line 679 of file water_height_map.cpp.

00680 {
00681         f.xmlPushBegin("WaterHeightMap");                       
00682                 f.xmlSetAttrib ("NAME")                                 ;
00683                 f.serial (_Name);
00684         f.xmlPushEnd();
00685         (void)f.serialVersion(0);
00686         f.xmlSerial(_Size, "SIZE");
00687         if (f.isReading())
00688         {
00689                 setSize(_Size);
00690         }
00691         f.xmlSerial(_Damping, "DAMPING");
00692         f.xmlSerial(_FilterWeight, "FILTER_WEIGHT");
00693         f.xmlSerial(_UnitSize, "WATER_UNIT_SIZE");      
00694         f.xmlSerial(_WavesEnabled, "WavesEnabled");
00695         if (_WavesEnabled)
00696         {
00697                 f.xmlPush("WavesParams");
00698                         f.xmlSerial(_WaveIntensity, "WAVE_INTENSITY");
00699                         f.xmlSerial(_WavePeriod, "WAVE_PERIOD");
00700                         f.xmlSerial(_WaveImpulsionRadius, "WAVE_IMPULSION_RADIUS");
00701                         f.xmlSerial(_BorderWaves, "BORDER_WAVES");
00702                         f.xmlSerial(_PropagationTime, "PROPAGATION_TIME");
00703                 f.xmlPop();
00704         }
00705         f.xmlPop();
00706 }

void NL3D::CWaterHeightMap::setDamping float  damping  )  [inline]
 

damping

Definition at line 162 of file water_height_map.h.

References _Damping, and nlassert.

Referenced by NL3D::CWaterPoolManager::createWaterPool().

00162 { nlassert(damping >= 0 && damping < 1); _Damping = damping; }

void NL3D::CWaterHeightMap::setFilterWeight float  filterWeight  )  [inline]
 

filter weight

Definition at line 166 of file water_height_map.h.

References _FilterWeight.

Referenced by NL3D::CWaterPoolManager::createWaterPool().

00166 { _FilterWeight = filterWeight; }

void NL3D::CWaterHeightMap::setName const std::string &  name  )  [inline]
 

Set this pool name.

Definition at line 180 of file water_height_map.h.

Referenced by NL3D::CWaterPoolManager::createWaterPool().

00180 { _Name = name; }

void NL3D::CWaterHeightMap::setPropagationTime float  time  ) 
 

Set the propagation time. This is the time needed to go from one unit to one other in the height map.

Definition at line 66 of file water_height_map.cpp.

References _PropagateEllapsedTime, _PropagationTime, clearArea(), NL3D::NumWaterMap, and uint.

00067 {
00068         _PropagationTime = time;
00069         _PropagateEllapsedTime = 0;
00070         for (uint k = 0; k < NumWaterMap; ++k)
00071         {       
00072                 clearArea(k, 0, 0, _Size << 1, _Size << 1);
00073         }
00074 }

void NL3D::CWaterHeightMap::setSize uint32  size  ) 
 

Set this quad dimension. It is given as a power of 2 This also reset the eightField values

Definition at line 269 of file water_height_map.cpp.

References _Map, clearArea(), nlassert, NL3D::NumWaterMap, size, uint, and uint32.

Referenced by NL3D::CWaterPoolManager::createWaterPool().

00270 {
00271         nlassert(size > 4);
00272         _Size  = size;  
00273         for (uint k = 0; k < NumWaterMap; ++k)
00274         {
00275                 _Map[k].resize(4 * _Size * _Size);
00276                 clearArea(k, 0, 0, _Size << 1, _Size << 1);
00277         }
00278         //_Grad.resize(4 * _Size * _Size);              
00279 }

void NL3D::CWaterHeightMap::setUnitSize float  unitSize  )  [inline]
 

water unit size

Definition at line 170 of file water_height_map.h.

References _UnitSize.

Referenced by NL3D::CWaterPoolManager::createWaterPool().

00170 { _UnitSize = unitSize; }

void NL3D::CWaterHeightMap::setUserPos sint  x,
sint  y
 

return the power of 2 used for this quad size

Set the userPos (relative to the height map coordinates). This is needed because a height map can't be used with large surface (such as a sea). As a consequence, the height map is only valid below the user (e.g from user.x - 0.5 * size to user.x + 0.5 *size). When setPos is called, and if a move has occured, new area of the height field are set to 0 The pos set will be taken in account when buffers have been swapped (e.g when the propagation time as ellapsed)

Definition at line 339 of file water_height_map.cpp.

References _NewX, _NewY, sint, x, and y.

Referenced by NL3D::CWaterModel::traverseRender().

00340 {       
00341         _NewX = x;      
00342         _NewY = y;      
00343 }

void NL3D::CWaterHeightMap::setWaves float  intensity,
float  period,
uint  radius,
bool  border
 

Tells this height map the params to automatically generate waves. They are generated as perturbation on the border of the field

Parameters:
intensity The intensity of the waves. 0 disable waves the time ellapsed between each waves the radius od the impulsion of the waves to be created true if waves should only be generated on the border of height map, (actually, where waves can't be seen because of distance, this avoid to see the impulsion)

Definition at line 667 of file water_height_map.cpp.

References _BorderWaves, _WaveImpulsionRadius, _WaveIntensity, _WavePeriod, border, and uint.

Referenced by NL3D::CWaterPoolManager::createWaterPool().

00668 {
00669         _WaveIntensity            = intensity;
00670         _WavePeriod                       = period;
00671         _WaveImpulsionRadius  = radius;
00672         _BorderWaves              = border;
00673 
00674 }

void NL3D::CWaterHeightMap::swapBuffers float  deltaT  )  [private]
 

swap the height maps. It must be called once propagation and filtering have been performed

Definition at line 514 of file water_height_map.cpp.

References _CurrMap, NL3D::NumWaterMap, and updateUserPos().

Referenced by animate().

00515 {
00516         updateUserPos();
00517         _CurrMap = (_CurrMap + 1) % NumWaterMap;
00518 }

void NL3D::CWaterHeightMap::updateUserPos  )  [private]
 

Definition at line 78 of file water_height_map.cpp.

References _NewX, _NewY, clearZone(), makeCpy(), min, nlassert, NL3D::NumWaterMap, sint, uint, x, and y.

Referenced by swapBuffers().

00079 {
00080         const sint x = _NewX;
00081         const sint y = _NewY;
00082 
00083         nlassert(_Size != 0);
00084         if ((uint) x == _X && (uint) y == _Y) return;
00085         if ((uint) abs((long int)(x - _X)) < _Size && (uint) abs((long int)(y - _Y)) < _Size) // are there common pixels with the previous location?
00086         {
00087                 // compute zone
00088         
00089                 sint XDivSize;
00090                 if ((sint) _X >= 0) XDivSize = (sint) _X / (sint) _Size;
00091                 else XDivSize = ((sint) (_X + 1) / (sint) _Size) - 1;
00092 
00093                 sint YDivSize;
00094                 if ((sint) _Y >= 0) YDivSize = (sint) _Y / (sint) _Size;
00095                 else YDivSize = ((sint) (_Y + 1) / (sint) _Size) - 1;
00096 
00097                 sint xDivSize;
00098                 if (x >= 0) xDivSize = (sint) x / (sint) _Size;
00099                 else xDivSize = ((sint) (x + 1) / (sint) _Size) - 1;
00100 
00101                 sint yDivSize;
00102                 if (y >= 0) yDivSize = (sint) y / (sint) _Size;
00103                 else yDivSize = ((sint) (y + 1) / (sint) _Size) - 1;
00104 
00105                 // different zone -> must decal datas
00106                 if (xDivSize != XDivSize || yDivSize != YDivSize)
00107                 {
00108                         sint left   = std::max(x, (sint) _X);
00109                         sint top    = std::max(y, (sint) _Y);
00110                         sint right  = std::min(x + (sint) _Size, (sint) (_X + _Size));
00111                         sint bottom = std::min(y + (sint) _Size, (sint) (_Y + _Size));
00112                         sint offsetX, offsetY;
00113                         if (xDivSize != XDivSize) 
00114                         {
00115                                 offsetX = xDivSize < XDivSize ?  _Size : -(sint)_Size;
00116                         }
00117                         else
00118                         {
00119                                 offsetX = 0;
00120                         }
00121 
00122                         if (yDivSize != YDivSize) 
00123                         {
00124                                 offsetY = yDivSize < YDivSize ?  _Size : -(sint)_Size;
00125                         }
00126                         else
00127                         {
00128                                 offsetY = 0;
00129                         }
00130 
00131                         sint orgX = _Size * XDivSize;
00132                         sint orgY = _Size * YDivSize;
00133                         for (uint k = 0; k < NumWaterMap; ++k)
00134                         {
00135                                 makeCpy(k, (uint) (left - orgX + offsetX) , (uint) (top - orgY + offsetY),
00136                                                 (uint) (left - orgX), (uint) (top - orgY),
00137                                                 (uint) (right - left), (uint) (bottom - top));
00138                         }
00139                 }
00140                 
00141                 sint newOrgX = _Size * xDivSize;
00142                 sint newOrgY = _Size * yDivSize;
00143                 // clear new area
00144                 if (x == (sint) _X)
00145                 {
00146                         if (y < (sint) _Y)
00147                         {
00148                                 // x, y, width, height
00149                                 clearZone(x - newOrgX, y - newOrgY, _Size, _Y - y);
00150                         }
00151                         else
00152                         {
00153                                 clearZone(x - newOrgX, y + _Size - newOrgY, _Size, y - _Y);
00154                         }
00155                 }
00156                 else
00157                 {
00158                         if (x > (sint) _X)
00159                         {
00160                                 if (y == (sint) _Y)
00161                                 {
00162                                         clearZone(_X + _Size - newOrgX, y - newOrgY, x - _X, _Size);
00163                                 }
00164                                 else if (y < (sint) _Y)
00165                                 {
00166                                         clearZone(_X + _Size - newOrgX, _Y - newOrgY, x - _X, _Size - (_Y - y));
00167                                         clearZone(x - newOrgX, y - newOrgY, _Size, _Y - y);
00168                                 }
00169                                 else
00170                                 {
00171                                         clearZone(_X + _Size - newOrgX, y - newOrgY, x - _X, _Size - (y - _Y));
00172                                         clearZone(x - newOrgX, _Y + _Size - newOrgY, _Size, y - _Y);
00173                                 }
00174                         }
00175                         else
00176                         {
00177                                 if (y == (sint) _Y)
00178                                 {
00179                                         clearZone(x - newOrgX, y - newOrgY, _X - x, _Size);
00180                                 }
00181                                 else if (y < (sint) _Y)
00182                                 {
00183                                         clearZone(x - newOrgX, y - newOrgY, _Size, _Y - y);
00184                                         clearZone(x - newOrgX, _Y - newOrgY, _X - x, _Size - (_Y - y));
00185                                 }
00186                                 else
00187                                 {
00188                                         clearZone(x - newOrgX, y - newOrgY, _X - x, _Size - (y -_Y));
00189                                         clearZone(x - newOrgX, _Y + _Size - newOrgY, _Size, y - _Y);
00190                                 }
00191                         }
00192                 }
00193                 
00194         }
00195         else
00196         {
00197                 // the new area has no common pixel's with the previous one
00198                 // clear the whole new area
00199                 uint px = _X % _Size;
00200                 uint py = _Y % _Size;
00201                 clearZone(px, py, _Size, _Size);
00202         }
00203 
00204         _X = (uint) x;
00205         _Y = (uint) y;
00206 }


Friends And Related Function Documentation

friend class CWaterPoolManager [friend]
 

Definition at line 218 of file water_height_map.h.


Field Documentation

bool NL3D::CWaterHeightMap::_BorderWaves [private]
 

Definition at line 228 of file water_height_map.h.

Referenced by animateWaves(), getBorderWaves(), and setWaves().

uint8 NL3D::CWaterHeightMap::_CurrMap [private]
 

Definition at line 241 of file water_height_map.h.

Referenced by filter(), getPointer(), getPrevPointer(), perturbate(), perturbatePoint(), propagate(), and swapBuffers().

float NL3D::CWaterHeightMap::_Damping [private]
 

Definition at line 222 of file water_height_map.h.

Referenced by getDamping(), propagate(), and setDamping().

float NL3D::CWaterHeightMap::_EmitEllapsedTime [private]
 

Definition at line 229 of file water_height_map.h.

Referenced by animateWaves().

float NL3D::CWaterHeightMap::_FilterWeight [private]
 

Definition at line 223 of file water_height_map.h.

Referenced by filter(), getFilterWeight(), and setFilterWeight().

TFloatVect NL3D::CWaterHeightMap::_Map[NumWaterMap] [private]
 

Definition at line 239 of file water_height_map.h.

Referenced by clearArea(), clearBorder(), filter(), getPointer(), getPrevPointer(), makeCpy(), perturbate(), perturbatePoint(), propagate(), and setSize().

std::string NL3D::CWaterHeightMap::_Name [private]
 

Definition at line 220 of file water_height_map.h.

uint NL3D::CWaterHeightMap::_NewX [private]
 

Definition at line 235 of file water_height_map.h.

Referenced by animateWaves(), setUserPos(), and updateUserPos().

uint NL3D::CWaterHeightMap::_NewY [private]
 

Definition at line 235 of file water_height_map.h.

Referenced by animateWaves(), setUserPos(), and updateUserPos().

float NL3D::CWaterHeightMap::_PropagateEllapsedTime [private]
 

Definition at line 230 of file water_height_map.h.

Referenced by animate(), getBufferRatio(), and setPropagationTime().

TAnimationTime NL3D::CWaterHeightMap::_PropagationTime [private]
 

Definition at line 231 of file water_height_map.h.

Referenced by animate(), animatePart(), getBufferRatio(), getPropagationTime(), and setPropagationTime().

uint32 NL3D::CWaterHeightMap::_Size [private]
 

Definition at line 242 of file water_height_map.h.

float NL3D::CWaterHeightMap::_UnitSize [private]
 

Definition at line 224 of file water_height_map.h.

Referenced by getHeight(), getUnitSize(), perturbate(), perturbatePoint(), and setUnitSize().

uint32 NL3D::CWaterHeightMap::_WaveImpulsionRadius [private]
 

Definition at line 227 of file water_height_map.h.

Referenced by animateWaves(), getWaveImpulsionRadius(), and setWaves().

float NL3D::CWaterHeightMap::_WaveIntensity [private]
 

Definition at line 225 of file water_height_map.h.

Referenced by animateWaves(), getWaveIntensity(), and setWaves().

float NL3D::CWaterHeightMap::_WavePeriod [private]
 

Definition at line 226 of file water_height_map.h.

Referenced by animateWaves(), getWavePeriod(), and setWaves().

bool NL3D::CWaterHeightMap::_WavesEnabled [private]
 

Definition at line 221 of file water_height_map.h.

Referenced by animateWaves(), areWavesEnabled(), and enableWaves().

uint NL3D::CWaterHeightMap::_X [private]
 

Definition at line 234 of file water_height_map.h.

uint NL3D::CWaterHeightMap::_Y [private]
 

Definition at line 234 of file water_height_map.h.

sint64 NL3D::CWaterHeightMap::Date
 

the last update date

Definition at line 174 of file water_height_map.h.

Referenced by NL3D::CWaterModel::traverseRender().


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