RigsofRods
Soft-body Physics Simulation
RadialGrid.cpp
Go to the documentation of this file.
1 /*
2 --------------------------------------------------------------------------------
3 This source file is part of Hydrax.
4 Visit ---
5 
6 Copyright (C) 2008 Xavier Verguín González <xavierverguin@hotmail.com>
7  <xavyiy@gmail.com>
8 
9 This program is free software; you can redistribute it and/or modify it under
10 the terms of the GNU Lesser General Public License as published by the Free Software
11 Foundation; either version 2 of the License, or (at your option) any later
12 version.
13 
14 This program is distributed in the hope that it will be useful, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
17 
18 You should have received a copy of the GNU Lesser General Public License along with
19 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
20 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
21 http://www.gnu.org/copyleft/lesser.txt.
22 --------------------------------------------------------------------------------
23 */
24 
25 #include <RadialGrid.h>
26 
27 namespace Hydrax{namespace Module
28 {
30  {
31  if (NormalMode == MaterialManager::NM_VERTEX)
32  {
33  return Mesh::VT_POS_NORM;
34  }
35 
36  // NM_RTT
37  return Mesh::VT_POS;
38  }
39 
40  Ogre::String _RG_getNormalModeString(const MaterialManager::NormalMode& NormalMode)
41  {
42  if (NormalMode == MaterialManager::NM_VERTEX)
43  {
44  return "Vertex";
45  }
46 
47  return "Rtt";
48  }
49 
51  : Module("RadialGrid" + _RG_getNormalModeString(NormalMode),
52  n, Mesh::Options(0, Size(200), _RG_getVertexTypeFromNormalMode(NormalMode)), NormalMode)
53  , mHydrax(h)
54  , mVertices(0)
55  , mVerticesChoppyBuffer(0)
56  {
57  }
58 
60  : Module("RadialGrid" + _RG_getNormalModeString(NormalMode),
61  n, Mesh::Options(0, Size(Options.Radius*2), _RG_getVertexTypeFromNormalMode(NormalMode)), NormalMode)
62  , mHydrax(h)
63  , mVertices(0)
64  , mVerticesChoppyBuffer(0)
65  {
67  }
68 
70  {
71  remove();
72 
73  HydraxLOG(getName() + " destroyed.");
74  }
75 
77  {
80 
83 
84  if (isCreated())
85  {
87  {
88  remove();
89  mOptions = Options;
90  create();
91 
93  {
95  {
96  HydraxLOG(mNoise->getName() + " doesn't support GPU Normal map generation.");
97  }
98  }
99 
100  Ogre::String MaterialNameTmp = mHydrax->getMesh()->getMaterialName();
101  mHydrax->getMesh()->remove();
103  mHydrax->getMesh()->setMaterialName(MaterialNameTmp);
104  mHydrax->getMesh()->create();
105 
106  return;
107  }
108 
109  mOptions = Options;
110 
111  int x, y;
113  {
114  Mesh::POS_NORM_VERTEX* Vertices = static_cast<Mesh::POS_NORM_VERTEX*>(mVertices);
115 
116  Vertices[0].x = mOptions.Radius;
117  Vertices[0].z = mOptions.Radius;
118 
119  float r_scale = mOptions.Radius/
121  mOptions.StepSizeCube * Ogre::Math::Pow(mOptions.Circles, 3) +
122  mOptions.StepSizeFive * Ogre::Math::Pow(mOptions.Circles, 5));
123 
124  for(y=0;y<mOptions.Circles;y++)
125  {
126  float r = r_scale*(mOptions.StepSizeLin * (y+1) + mOptions.StepSizeCube * Ogre::Math::Pow(y+1, 3) + mOptions.StepSizeFive * Ogre::Math::Pow(y+1, 5));
127 
128  for(x=0;x<mOptions.Steps;x++)
129  {
130  Vertices[1+y*mOptions.Steps + x].x = mOptions.Radius + r * Ogre::Math::Cos(Ogre::Math::TWO_PI * x / mOptions.Steps);
131  Vertices[1+y*mOptions.Steps + x].z = mOptions.Radius + r * Ogre::Math::Sin(Ogre::Math::TWO_PI * x / mOptions.Steps);
132  }
133  }
134 
136  {
137  for(int i = 0; i < 1+mOptions.Circles*mOptions.Steps; i++)
138  {
139  mVerticesChoppyBuffer[i] = Vertices[i];
140  }
141  }
142  }
144  {
145  Mesh::POS_VERTEX* Vertices = static_cast<Mesh::POS_VERTEX*>(mVertices);
146 
147  Vertices[0].x = mOptions.Radius;
148  Vertices[0].z = mOptions.Radius;
149 
150  float r_scale = mOptions.Radius/
152  mOptions.StepSizeCube * Ogre::Math::Pow(mOptions.Circles, 3) +
153  mOptions.StepSizeFive * Ogre::Math::Pow(mOptions.Circles, 5));
154 
155  for(y=0;y<mOptions.Circles;y++)
156  {
157  float r = r_scale*(mOptions.StepSizeLin * (y+1) + mOptions.StepSizeCube * Ogre::Math::Pow(y+1, 3) + mOptions.StepSizeFive * Ogre::Math::Pow(y+1, 5));
158 
159  for(x=0;x<mOptions.Steps;x++)
160  {
161  Vertices[1+y*mOptions.Steps + x].x = mOptions.Radius + r * Ogre::Math::Cos(Ogre::Math::TWO_PI * x / mOptions.Steps);
162  Vertices[1+y*mOptions.Steps + x].z = mOptions.Radius + r * Ogre::Math::Sin(Ogre::Math::TWO_PI * x / mOptions.Steps);
163  }
164  }
165  }
166 
167  return;
168  }
169 
170  mOptions = Options;
171  }
172 
174  {
175  HydraxLOG("Creating " + getName() + " module.");
176 
177  Module::create();
178 
179  int x, y;
181  {
183  Mesh::POS_NORM_VERTEX* Vertices = static_cast<Mesh::POS_NORM_VERTEX*>(mVertices);
184 
185  Vertices[0].x = mOptions.Radius;
186  Vertices[0].y = 0;
187  Vertices[0].z = mOptions.Radius;
188 
189  Vertices[0].nx = 0;
190  Vertices[0].ny = -1;
191  Vertices[0].nz = 0;
192 
193  float r_scale = mOptions.Radius/
195  mOptions.StepSizeCube * Ogre::Math::Pow(mOptions.Circles, 3) +
196  mOptions.StepSizeFive * Ogre::Math::Pow(mOptions.Circles, 5));
197 
198  for(y=0;y<mOptions.Circles;y++)
199  {
200  float r = r_scale*(mOptions.StepSizeLin * (y+1) + mOptions.StepSizeCube * Ogre::Math::Pow(y+1, 3) + mOptions.StepSizeFive * Ogre::Math::Pow(y+1, 5));
201 
202  for(x=0;x<mOptions.Steps;x++)
203  {
204  Vertices[1+y*mOptions.Steps + x].x = mOptions.Radius + r * Ogre::Math::Cos(Ogre::Math::TWO_PI * x / mOptions.Steps);
205  Vertices[1+y*mOptions.Steps + x].y = 0;
206  Vertices[1+y*mOptions.Steps + x].z = mOptions.Radius + r * Ogre::Math::Sin(Ogre::Math::TWO_PI * x / mOptions.Steps);
207 
208  Vertices[1+y*mOptions.Steps + x].nx = 0;
209  Vertices[1+y*mOptions.Steps + x].ny = -1;
210  Vertices[1+y*mOptions.Steps + x].nz = 0;
211  }
212  }
213 
214  if (mOptions.ChoppyWaves)
215  {
217 
218  for(int i = 0; i < 1+mOptions.Circles*mOptions.Steps; i++)
219  {
220  mVerticesChoppyBuffer[i] = Vertices[i];
221  }
222  }
223  }
225  {
227  Mesh::POS_VERTEX* Vertices = static_cast<Mesh::POS_VERTEX*>(mVertices);
228 
229  Vertices[0].x = mOptions.Radius;
230  Vertices[0].y = 0;
231  Vertices[0].z = mOptions.Radius;
232 
233  float r_scale = mOptions.Radius/
235  mOptions.StepSizeCube * Ogre::Math::Pow(mOptions.Circles, 3) +
236  mOptions.StepSizeFive * Ogre::Math::Pow(mOptions.Circles, 5));
237 
238  for(y=0;y<mOptions.Circles;y++)
239  {
240  float r = r_scale*(mOptions.StepSizeLin * (y+1) + mOptions.StepSizeCube * Ogre::Math::Pow(y+1, 3) + mOptions.StepSizeFive * Ogre::Math::Pow(y+1, 5));
241 
242  for(x=0;x<mOptions.Steps;x++)
243  {
244  Vertices[1+y*mOptions.Steps + x].x = mOptions.Radius + r * Ogre::Math::Cos(Ogre::Math::TWO_PI * x / mOptions.Steps);
245  Vertices[1+y*mOptions.Steps + x].y = 0;
246  Vertices[1+y*mOptions.Steps + x].z = mOptions.Radius + r * Ogre::Math::Sin(Ogre::Math::TWO_PI * x / mOptions.Steps);
247  }
248  }
249  }
250 
251  HydraxLOG(getName() + " created.");
252  }
253 
254  const bool RadialGrid::_createGeometry(Mesh *mMesh) const
255  {
256  int numVertices = mOptions.Steps * mOptions.Circles + 1;
257  int numEle = 6 * mOptions.Steps * (mOptions.Circles-1) + 3 * mOptions.Steps;
258 
259  // Vertex buffers
260  mMesh->getSubMesh()->vertexData = new Ogre::VertexData();
261  mMesh->getSubMesh()->vertexData->vertexStart = 0;
262  mMesh->getSubMesh()->vertexData->vertexCount = numVertices;
263 
264  Ogre::VertexDeclaration* vdecl = mMesh->getSubMesh()->vertexData->vertexDeclaration;
265  Ogre::VertexBufferBinding* vbind = mMesh->getSubMesh()->vertexData->vertexBufferBinding;
266 
267  size_t offset = 0;
268 
270  {
271  case Mesh::VT_POS_NORM:
272  {
273  vdecl->addElement(0, 0, Ogre::VET_FLOAT3, Ogre::VES_POSITION);
274  offset += Ogre::VertexElement::getTypeSize(Ogre::VET_FLOAT3);
275  vdecl->addElement(0, offset, Ogre::VET_FLOAT3, Ogre::VES_NORMAL);
276 
277  mMesh->getHardwareVertexBuffer() = Ogre::HardwareBufferManager::getSingleton().
278  createVertexBuffer(sizeof(Mesh::POS_NORM_VERTEX),
279  numVertices,
280  Ogre::HardwareBuffer::HBU_DYNAMIC_WRITE_ONLY);
281  }
282  break;
283 
284  case Mesh::VT_POS:
285  {
286  vdecl->addElement(0, 0, Ogre::VET_FLOAT3, Ogre::VES_POSITION);
287 
288  mMesh->getHardwareVertexBuffer() = Ogre::HardwareBufferManager::getSingleton().
289  createVertexBuffer(sizeof(Mesh::POS_VERTEX),
290  numVertices,
291  Ogre::HardwareBuffer::HBU_DYNAMIC_WRITE_ONLY);
292  }
293  break;
294  }
295 
296  vbind->setBinding(0, mMesh->getHardwareVertexBuffer());
297 
298  unsigned int *indexbuffer = new unsigned int[numEle];
299 
300  for (int k = 0; k < mOptions.Steps; k++)
301  {
302  indexbuffer[k*3+2] = 0;
303  indexbuffer[k*3+1] = k+1;
304 
305  if (k != mOptions.Steps-1)
306  {
307  indexbuffer[k*3] = k+2;
308  }
309  else
310  {
311  indexbuffer[k*3] = 1;
312  }
313  }
314 
315  for(int y=0; y<mOptions.Circles-1; y++)
316  {
317  for(int x=0; x<mOptions.Steps; x++)
318  {
319  unsigned int *twoface = indexbuffer + (y*mOptions.Steps+x)*6 + 3 * mOptions.Steps;
320 
321  int p0 = 1+y * mOptions.Steps + x ;
322  int p1 = 1+y * mOptions.Steps + x + 1 ;
323  int p2 = 1+(y+1)* mOptions.Steps + x ;
324  int p3 = 1+(y+1)* mOptions.Steps + x + 1 ;
325 
326  if (x == mOptions.Steps-1)
327  {
328  p1 -= x+1;
329  p3 -= x+1;
330  }
331 
332  // First triangle
333  twoface[0]=p0;
334  twoface[1]=p1;
335  twoface[2]=p2;
336 
337  // Second triangle
338  twoface[3]=p1;
339  twoface[4]=p3;
340  twoface[5]=p2;
341  }
342  }
343 
344  // Prepare buffer for indices
345  mMesh->getHardwareIndexBuffer() =
346  Ogre::HardwareBufferManager::getSingleton().createIndexBuffer(
347  Ogre::HardwareIndexBuffer::IT_32BIT,
348  numEle,
349  Ogre::HardwareBuffer::HBU_STATIC, true);
350 
351  mMesh->getHardwareIndexBuffer()->
352  writeData(0,
353  mMesh->getHardwareIndexBuffer()->getSizeInBytes(),
354  indexbuffer,
355  true);
356 
357  delete []indexbuffer;
358 
359  // Set index buffer for this submesh
360  mMesh->getSubMesh()->indexData->indexBuffer = mMesh->getHardwareIndexBuffer();
361  mMesh->getSubMesh()->indexData->indexStart = 0;
362  mMesh->getSubMesh()->indexData->indexCount = numEle;
363 
364  return true;
365  }
366 
368  {
369  if (!isCreated())
370  {
371  return;
372  }
373 
374  Module::remove();
375 
376  if (mVertices)
377  {
379  {
380  delete [] static_cast<Mesh::POS_NORM_VERTEX*>(mVertices);
381  mVertices = 0;
382  }
384  {
385  delete [] static_cast<Mesh::POS_VERTEX*>(mVertices);
386  mVertices = 0;
387  }
388  }
389 
391  {
392  delete [] mVerticesChoppyBuffer;
393  }
394  }
395 
396  void RadialGrid::saveCfg(Ogre::String &Data)
397  {
398  Module::saveCfg(Data);
399 
400  Data += CfgFileManager::_getCfgString("RG_Steps", mOptions.Steps);
401  Data += CfgFileManager::_getCfgString("RG_Circles", mOptions.Circles);
402  Data += CfgFileManager::_getCfgString("RG_Radius", mOptions.Radius);
403  Data += CfgFileManager::_getCfgString("RG_Smooth", mOptions.Smooth);
404  Data += CfgFileManager::_getCfgString("RG_ChoppyWaves", mOptions.ChoppyWaves);
405  Data += CfgFileManager::_getCfgString("RG_ChoppyStrength", mOptions.ChoppyStrength);
406  Data += CfgFileManager::_getCfgString("RG_StepSizeCube", mOptions.StepSizeCube);
407  Data += CfgFileManager::_getCfgString("RG_StepSizeFive", mOptions.StepSizeFive);
408  Data += CfgFileManager::_getCfgString("RG_StepSizeLin", mOptions.StepSizeLin);
409  Data += CfgFileManager::_getCfgString("RG_Strength", mOptions.Strength);Data += "\n";
410  }
411 
412  bool RadialGrid::loadCfg(Ogre::ConfigFile &CfgFile)
413  {
414  if (!Module::loadCfg(CfgFile))
415  {
416  return false;
417  }
418 
419  setOptions(
420  Options(CfgFileManager::_getIntValue(CfgFile, "RG_Steps"),
421  CfgFileManager::_getIntValue(CfgFile, "RG_Circles"),
422  CfgFileManager::_getFloatValue(CfgFile, "RG_Radius"),
423  CfgFileManager::_getBoolValue(CfgFile, "RG_Smooth"),
424  CfgFileManager::_getBoolValue(CfgFile, "RG_ChoppyWaves"),
425  CfgFileManager::_getFloatValue(CfgFile, "RG_ChoppyStrength"),
426  CfgFileManager::_getFloatValue(CfgFile, "RG_StepSizeCube"),
427  CfgFileManager::_getFloatValue(CfgFile, "RG_StepSizeFive"),
428  CfgFileManager::_getFloatValue(CfgFile, "RG_StepSizeLin"),
429  CfgFileManager::_getFloatValue(CfgFile, "RG_Strength")));
430 
431  return true;
432  }
433 
434  void RadialGrid::update(const Ogre::Real &timeSinceLastFrame)
435  {
436  if (!isCreated())
437  {
438  return;
439  }
440 
441  Module::update(timeSinceLastFrame);
442 
443  // Update heigths
444  int i, x, y;
445 
447  {
448  Mesh::POS_NORM_VERTEX* Vertices = static_cast<Mesh::POS_NORM_VERTEX*>(mVertices);
449 
450  if (mOptions.ChoppyWaves)
451  {
452  for(i = 0; i < 1+mOptions.Circles*mOptions.Steps; i++)
453  {
454  Vertices[i] = mVerticesChoppyBuffer[i];
455  }
456  }
457 
458  Ogre::Vector3 HydraxPos = mHydrax->getPosition();
459 
460  for(i = 0; i <1+mOptions.Circles*mOptions.Steps; i++)
461  {
462  Vertices[i].y = mNoise->getValue(HydraxPos.x + Vertices[i].x, HydraxPos.z + Vertices[i].z)*mOptions.Strength;
463  }
464  }
466  {
467  Mesh::POS_VERTEX* Vertices = static_cast<Mesh::POS_VERTEX*>(mVertices);
468 
469  Ogre::Vector3 HydraxPos = mHydrax->getPosition();
470 
471  for(i = 0; i <1+mOptions.Circles*mOptions.Steps; i++)
472  {
473  Vertices[i].y = mNoise->getValue(HydraxPos.x + Vertices[i].x, HydraxPos.z + Vertices[i].z)*mOptions.Strength;
474  }
475  }
476 
477  // Smooth the heightdata
478  if (mOptions.Smooth)
479  {
481  {
482  Mesh::POS_NORM_VERTEX* Vertices = static_cast<Mesh::POS_NORM_VERTEX*>(mVertices);
483 
484  for(y=1;y<mOptions.Circles-1;y++)
485  {
486  for(x=1;x<mOptions.Steps-1;x++)
487  {
488  Vertices[y*mOptions.Steps + x].y =
489  0.2f *
490  (Vertices[y*mOptions.Steps + x ].y +
491  Vertices[y*mOptions.Steps + x + 1].y +
492  Vertices[y*mOptions.Steps + x - 1].y +
493  Vertices[(y+1)*mOptions.Steps + x].y +
494  Vertices[(y-1)*mOptions.Steps + x].y);
495  }
496  }
497  }
499  {
500  Mesh::POS_VERTEX* Vertices = static_cast<Mesh::POS_VERTEX*>(mVertices);
501 
502  for(y=1;y<mOptions.Circles-1;y++)
503  {
504  for(x=1;x<mOptions.Steps-1;x++)
505  {
506  Vertices[y*mOptions.Steps + x].y =
507  0.2f *
508  (Vertices[y*mOptions.Steps + x ].y +
509  Vertices[y*mOptions.Steps + x + 1].y +
510  Vertices[y*mOptions.Steps + x - 1].y +
511  Vertices[(y+1)*mOptions.Steps + x].y +
512  Vertices[(y-1)*mOptions.Steps + x].y);
513  }
514  }
515  }
516  }
517 
518  // Update normals
519  _calculeNormals();
520 
521  // Perform choppy waves
523 
524  // Upload geometry changes
526  }
527 
529  {
531  {
532  return;
533  }
534 
535  int x, y;
536  Ogre::Vector3 vec1, vec2, normal;
537 
538  Mesh::POS_NORM_VERTEX* Vertices = static_cast<Mesh::POS_NORM_VERTEX*>(mVertices);
539 
540  int Steps_4 = static_cast<int>(mOptions.Steps/4);
541 
542  // Calculate the normal of the center grid point
543  vec2 = Ogre::Vector3(
544  Vertices[1].x-Vertices[1+Steps_4*2].x,
545  Vertices[1].y-Vertices[1+Steps_4*2].y,
546  Vertices[1].z-Vertices[1+Steps_4*2].z);
547 
548  vec1 = Ogre::Vector3(
549  Vertices[1+Steps_4].x - Vertices[1+Steps_4*3].x,
550  Vertices[1+Steps_4].y - Vertices[1+Steps_4*3].y,
551  Vertices[1+Steps_4].z - Vertices[1+Steps_4*3].z);
552 
553  normal = vec2.crossProduct(vec1);
554 
555  Vertices[0].nx = normal.x;
556  Vertices[0].ny = normal.y;
557  Vertices[0].nz = normal.z;
558 
559  // Calculate first circle normals
560  for(x=0;x<mOptions.Steps;x++)
561  {
562  vec2 = Ogre::Vector3(
563  Vertices[x + 2].x-Vertices[x].x,
564  Vertices[x + 2].y-Vertices[x].y,
565  Vertices[x + 2].z-Vertices[x].z);
566 
567  vec1 = Ogre::Vector3(
568  Vertices[0].x - Vertices[mOptions.Steps + x].x,
569  Vertices[0].y - Vertices[mOptions.Steps + x].y,
570  Vertices[0].z - Vertices[mOptions.Steps + x].z);
571 
572  normal = vec2.crossProduct(vec1);
573 
574  Vertices[1+x].nx = normal.x;
575  Vertices[1+x].ny = normal.y;
576  Vertices[1+x].nz = normal.z;
577  }
578 
579  // Calculate all the other vertex normals
580  for(y=1;y<mOptions.Circles-1;y++)
581  {
582  for(x=0;x<mOptions.Steps;x++)
583  {
584  vec2 = Ogre::Vector3(
585  Vertices[y*mOptions.Steps + x + 2].x-Vertices[y*mOptions.Steps + x].x,
586  Vertices[y*mOptions.Steps + x + 2].y-Vertices[y*mOptions.Steps + x].y,
587  Vertices[y*mOptions.Steps + x + 2].z-Vertices[y*mOptions.Steps + x].z);
588 
589  vec1 = Ogre::Vector3(
590  Vertices[(y-1)*mOptions.Steps + x + 1].x - Vertices[(y+1)*mOptions.Steps + x].x,
591  Vertices[(y-1)*mOptions.Steps + x + 1].y - Vertices[(y+1)*mOptions.Steps + x].y,
592  Vertices[(y-1)*mOptions.Steps + x + 1].z - Vertices[(y+1)*mOptions.Steps + x].z);
593 
594  normal = vec2.crossProduct(vec1);
595 
596  Vertices[1+y*mOptions.Steps+x].nx = normal.x;
597  Vertices[1+y*mOptions.Steps+x].ny = normal.y;
598  Vertices[1+y*mOptions.Steps+x].nz = normal.z;
599  }
600  }
601  }
602 
604  {
606  {
607  return;
608  }
609 
610  int x, y,
611  Underwater = 1;
612 
614  {
615  Underwater = -1;
616  }
617 
618  Mesh::POS_NORM_VERTEX* Vertices = static_cast<Mesh::POS_NORM_VERTEX*>(mVertices);
619 
620  Ogre::Vector2 Current, NearStep, CircleStep,
621  Proportion,
622  Dir, Perp,
623  Norm2;
624  Ogre::Vector3 Norm;
625 
626  for(y=0;y<mOptions.Circles-1;y++)
627  {
628  Current = Ogre::Vector2(Vertices[y*mOptions.Steps + 1].x, Vertices[y*mOptions.Steps + 1].z);
629  NearStep = Ogre::Vector2(Vertices[y*mOptions.Steps + 2].x, Vertices[y*mOptions.Steps + 2].z);
630  CircleStep = Ogre::Vector2(Vertices[(y+1)*mOptions.Steps + 1].x, Vertices[(y+1)*mOptions.Steps + 1].z);
631 
632  Proportion = Ogre::Vector2(
633  // Distance per step vertex
634  (Current-NearStep).length(),
635  // Distance per circle vertex
636  (Current-CircleStep).length());
637 
638  for(x=0;x<mOptions.Steps;x++)
639  {
640  Dir = Ogre::Vector2(Vertices[1+y*mOptions.Steps + x].nx, Vertices[1+y*mOptions.Steps + x].nz).normalisedCopy();
641  Perp = Dir.perpendicular();
642 
643  if (Dir.x < 0) Dir.x = -Dir.x;
644  if (Dir.y < 0) Dir.y = -Dir.y;
645 
646  if (Perp.x < 0) Perp.x = -Perp.x;
647  if (Perp.y < 0) Perp.y = -Perp.y;
648 
649  Norm = Ogre::Vector3(
650  Vertices[1+y*mOptions.Steps + x].nx,
651  Vertices[1+y*mOptions.Steps + x].ny,
652  Vertices[1+y*mOptions.Steps + x].nz).normalisedCopy();
653 
654  Norm2 = Ogre::Vector2(Norm.x, Norm.z) *
655  ( (Dir * Proportion.x) +
656  (Perp * Proportion.y)) *
658 
659  Vertices[1+y*mOptions.Steps + x].x += Norm2.x * Underwater;
660  Vertices[1+y*mOptions.Steps + x].z += Norm2.y * Underwater;
661  }
662  }
663  }
664 
665  float RadialGrid::getHeigth(const Ogre::Vector2 &Position)
666  {
667  return mHydrax->getPosition().y + mNoise->getValue(Position.x, Position.y)*mOptions.Strength;
668  }
669 }}
Hydrax::Mesh::create
void create()
Create our water mesh, geometry, entity, etc...
Definition: Mesh.cpp:117
Hydrax::Module::RadialGrid::update
void update(const Ogre::Real &timeSinceLastFrame)
Call it each frame.
Definition: RadialGrid.cpp:434
Hydrax::Module::RadialGrid::saveCfg
void saveCfg(Ogre::String &Data)
Save config.
Definition: RadialGrid.cpp:396
Hydrax::Mesh::VertexType
VertexType
Mesh vertex type enum.
Definition: Mesh.h:83
Hydrax::Module::Module::saveCfg
virtual void saveCfg(Ogre::String &Data)
Save config.
Definition: Module.cpp:99
y
float y
Definition: (ValueTypes) quaternion.h:6
Hydrax::Mesh::Options::MeshStrength
float MeshStrength
Water strength.
Definition: Mesh.h:137
Hydrax::Noise::Noise::createGPUNormalMapResources
virtual bool createGPUNormalMapResources(GPUNormalMapManager *g)
Create GPUNormalMap resources.
Definition: Noise.cpp:52
Hydrax::Mesh::POS_VERTEX
Vertex struct for position data.
Definition: Mesh.h:76
Hydrax::Module::Module::isCreated
const bool & isCreated() const
Is created() called?
Definition: Module.h:107
Hydrax::Hydrax::getPosition
const Ogre::Vector3 & getPosition() const
Get water position.
Definition: Hydrax.h:413
Hydrax::Module::RadialGrid::_createGeometry
const bool _createGeometry(Mesh *mMesh) const
Create geometry in module(If special geometry is needed)
Definition: RadialGrid.cpp:254
Hydrax::Hydrax::getMesh
Mesh * getMesh()
Get Hydrax::Mesh.
Definition: Hydrax.h:317
Hydrax
Definition: CfgFileManager.cpp:28
Hydrax::Mesh::Options::MeshVertexType
VertexType MeshVertexType
Vertex type.
Definition: Mesh.h:139
z
float z
Definition: (ValueTypes) quaternion.h:7
Hydrax::Mesh::POS_VERTEX::z
float z
Definition: Mesh.h:78
Hydrax::Module::RadialGrid::Options::Circles
int Circles
Number of circles.
Definition: RadialGrid.h:54
Hydrax::Mesh::updateGeometry
bool updateGeometry(const int &numVer, void *verArray)
Update geomtry.
Definition: Mesh.cpp:281
Hydrax::Size
Struct wich contains an especific width and height value.
Definition: Help.h:40
Hydrax::Module::RadialGrid::Options::StepSizeFive
float StepSizeFive
Step size five.
Definition: RadialGrid.h:66
Hydrax::Mesh::POS_VERTEX::x
float x
Definition: Mesh.h:78
RadialGrid.h
Hydrax::Module::RadialGrid::_calculeNormals
void _calculeNormals()
Calcule current normals.
Definition: RadialGrid.cpp:528
Hydrax::Mesh::POS_NORM_VERTEX::nx
float nx
Definition: Mesh.h:63
Hydrax::Mesh::POS_NORM_VERTEX::ny
float ny
Definition: Mesh.h:63
Hydrax::Hydrax::_setStrength
void _setStrength(const Ogre::Real &Strength)
Set water strength GPU param.
Definition: Hydrax.cpp:763
Hydrax::CfgFileManager::_getBoolValue
static bool _getBoolValue(Ogre::ConfigFile &CfgFile, const Ogre::String Name)
Get bool value.
Definition: CfgFileManager.cpp:460
Hydrax::Module::RadialGrid::Options::StepSizeLin
float StepSizeLin
Step lin size.
Definition: RadialGrid.h:68
Hydrax::Mesh::getHardwareIndexBuffer
Ogre::HardwareIndexBufferSharedPtr & getHardwareIndexBuffer()
Get hardware index buffer reference.
Definition: Mesh.h:285
Hydrax::Module::RadialGrid::mOptions
Options mOptions
Our projected grid options.
Definition: RadialGrid.h:228
Hydrax::Mesh::getSubMesh
Ogre::SubMesh * getSubMesh()
Get sub mesh.
Definition: Mesh.h:213
Hydrax::Module::Module::create
virtual void create()
Create.
Definition: Module.cpp:46
Hydrax::Noise::Noise::getValue
virtual float getValue(const float &x, const float &y)=0
Get the especified x/y noise value.
Hydrax::Mesh::getMaterialName
const Ogre::String & getMaterialName() const
Get material name.
Definition: Mesh.h:269
Hydrax::Mesh::POS_NORM_VERTEX::z
float z
Definition: Mesh.h:62
Hydrax::Module::RadialGrid::getHeigth
float getHeigth(const Ogre::Vector2 &Position)
Get the current heigth at a especified world-space point.
Definition: RadialGrid.cpp:665
Hydrax::Mesh::setMaterialName
void setMaterialName(const Ogre::String &MaterialName)
Set mesh material.
Definition: Mesh.cpp:107
Hydrax::Hydrax::getGPUNormalMapManager
GPUNormalMapManager * getGPUNormalMapManager()
Get Hydrax::GPUNormalMapManager.
Definition: Hydrax.h:365
Hydrax::Noise::Noise::getName
const Ogre::String & getName() const
Get noise name.
Definition: Noise.h:92
Hydrax::Module::RadialGrid::mVerticesChoppyBuffer
Mesh::POS_NORM_VERTEX * mVerticesChoppyBuffer
Use it to store vertex positions when choppy displacement is enabled.
Definition: RadialGrid.h:225
Hydrax::Noise::Noise
Base noise class, Override it for create different ways of create water noise.
Definition: Noise.h:42
Hydrax::Module::Module::getMeshOptions
const Mesh::Options & getMeshOptions() const
Get the mesh options for this module.
Definition: Module.h:133
Hydrax::MaterialManager::NormalMode
NormalMode
Normal generation mode.
Definition: MaterialManager.h:100
HydraxLOG
#define HydraxLOG(msg)
Definition: Application.h:59
Hydrax::Module::RadialGrid::mHydrax
Hydrax * mHydrax
Our Hydrax pointer.
Definition: RadialGrid.h:231
Hydrax::Mesh::remove
void remove()
Remove all resources.
Definition: Mesh.cpp:52
Hydrax::Module::Module
Base module class, Override it for create different ways of create water noise.
Definition: Module.h:46
Hydrax::Module::RadialGrid::Options::StepSizeCube
float StepSizeCube
Step cube size.
Definition: RadialGrid.h:64
Hydrax::Mesh::getHardwareVertexBuffer
Ogre::HardwareVertexBufferSharedPtr & getHardwareVertexBuffer()
Get hardware vertex buffer reference.
Definition: Mesh.h:277
Hydrax::Mesh
Class wich contains all funtions/variables related to Hydrax water mesh.
Definition: Mesh.h:46
Hydrax::Module::Module::update
virtual void update(const Ogre::Real &timeSinceLastFrame)
Call it each frame.
Definition: Module.cpp:94
Hydrax::Mesh::VT_POS
@ VT_POS
Definition: Mesh.h:88
Hydrax::Module::RadialGrid::Options::Strength
float Strength
Water strength.
Definition: RadialGrid.h:70
Hydrax::MaterialManager::NM_RTT
@ NM_RTT
Definition: MaterialManager.h:107
Hydrax::CfgFileManager::_getCfgString
static Ogre::String _getCfgString(const Ogre::String &Name, const int &Value)
Definition: CfgFileManager.cpp:155
Hydrax::Module::Module::loadCfg
virtual bool loadCfg(Ogre::ConfigFile &CfgFile)
Load config.
Definition: Module.cpp:105
Hydrax::Module::RadialGrid::setOptions
void setOptions(const Options &Options)
Set options.
Definition: RadialGrid.cpp:76
Hydrax::Module::RadialGrid::loadCfg
bool loadCfg(Ogre::ConfigFile &CfgFile)
Load config.
Definition: RadialGrid.cpp:412
Hydrax::Mesh::POS_NORM_VERTEX::y
float y
Definition: Mesh.h:62
Hydrax::Mesh::Options::MeshSize
Size MeshSize
Grid size (X/Z) world space.
Definition: Mesh.h:135
Hydrax::Module::Module::mNormalMode
MaterialManager::NormalMode mNormalMode
Normal map generation mode.
Definition: Module.h:160
Hydrax::Module::RadialGrid::mVertices
void * mVertices
Vertex pointer (Mesh::POS_NORM_VERTEX or Mesh::POS_VERTEX)
Definition: RadialGrid.h:222
Norm
float Norm() const
Hydrax::Mesh::POS_NORM_VERTEX
Vertex struct for position and normals data.
Definition: Mesh.h:60
Hydrax::Mesh::POS_NORM_VERTEX::x
float x
Definition: Mesh.h:62
Hydrax::Module::_RG_getNormalModeString
Ogre::String _RG_getNormalModeString(const MaterialManager::NormalMode &NormalMode)
Definition: RadialGrid.cpp:40
Hydrax::Mesh::setOptions
void setOptions(const Options &Options)
Update options.
Definition: Mesh.cpp:78
Hydrax::Module::_RG_getVertexTypeFromNormalMode
Mesh::VertexType _RG_getVertexTypeFromNormalMode(const MaterialManager::NormalMode &NormalMode)
Definition: RadialGrid.cpp:29
Hydrax::Module::Module::getNormalMode
const MaterialManager::NormalMode & getNormalMode() const
Get the normal generation mode.
Definition: Module.h:125
Hydrax::Mesh::POS_VERTEX::y
float y
Definition: Mesh.h:78
Hydrax::Mesh::VT_POS_NORM
@ VT_POS_NORM
Definition: Mesh.h:86
Hydrax::Module::RadialGrid::Options
Struct wich contains Hydrax simple grid module options.
Definition: RadialGrid.h:49
Hydrax::Module::RadialGrid::Options::ChoppyStrength
float ChoppyStrength
Choppy waves strength.
Definition: RadialGrid.h:62
Hydrax::Module::RadialGrid::remove
void remove()
Remove.
Definition: RadialGrid.cpp:367
Hydrax::CfgFileManager::_getIntValue
static int _getIntValue(Ogre::ConfigFile &CfgFile, const Ogre::String Name)
Get int value.
Definition: CfgFileManager.cpp:432
Hydrax::Module::RadialGrid::Options::Radius
float Radius
Radius (In world units)
Definition: RadialGrid.h:56
Hydrax::Hydrax::_isCurrentFrameUnderwater
const bool & _isCurrentFrameUnderwater() const
Is current frame underwater?
Definition: Hydrax.h:621
Hydrax::Module::RadialGrid::Options::Steps
int Steps
Number of steps (Per circle)
Definition: RadialGrid.h:52
Hydrax::Module::RadialGrid::_performChoppyWaves
void _performChoppyWaves()
Perform choppy waves.
Definition: RadialGrid.cpp:603
Hydrax::Module::Module::getName
const Ogre::String & getName() const
Get module name.
Definition: Module.h:99
Hydrax::Module::Module::mNoise
Noise::Noise * mNoise
Noise generator pointer.
Definition: Module.h:156
Hydrax::Module::RadialGrid::create
void create()
Create.
Definition: RadialGrid.cpp:173
Hydrax::Module::RadialGrid::Options::ChoppyWaves
bool ChoppyWaves
Choppy waves.
Definition: RadialGrid.h:60
Hydrax::Mesh::POS_NORM_VERTEX::nz
float nz
Definition: Mesh.h:63
Hydrax::Module::Module::remove
virtual void remove()
Remove.
Definition: Module.cpp:53
Hydrax::CfgFileManager::_getFloatValue
static Ogre::Real _getFloatValue(Ogre::ConfigFile &CfgFile, const Ogre::String Name)
Get float value.
Definition: CfgFileManager.cpp:446
Hydrax::Module::RadialGrid::Options::Smooth
bool Smooth
Smooth.
Definition: RadialGrid.h:58
x
float x
Definition: (ValueTypes) quaternion.h:5
Hydrax::Module::RadialGrid::RadialGrid
RadialGrid(Hydrax *h, Noise::Noise *n, const MaterialManager::NormalMode &NormalMode)
Constructor.
Definition: RadialGrid.cpp:50
Hydrax::Module::Module::mMeshOptions
Mesh::Options mMeshOptions
Module mesh options.
Definition: Module.h:158
Hydrax::Module::RadialGrid::~RadialGrid
~RadialGrid()
Destructor.
Definition: RadialGrid.cpp:69
Hydrax::MaterialManager::NM_VERTEX
@ NM_VERTEX
Definition: MaterialManager.h:105