Rigs of Rods 2023.09
Soft-body Physics Simulation
Loading...
Searching...
No Matches
RadialGrid.cpp
Go to the documentation of this file.
1/*
2--------------------------------------------------------------------------------
3This source file is part of Hydrax.
4Visit ---
5
6Copyright (C) 2008 Xavier Verguín González <xavierverguin@hotmail.com>
7 <xavyiy@gmail.com>
8
9This program is free software; you can redistribute it and/or modify it under
10the terms of the GNU Lesser General Public License as published by the Free Software
11Foundation; either version 2 of the License, or (at your option) any later
12version.
13
14This program is distributed in the hope that it will be useful, but WITHOUT
15ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
17
18You should have received a copy of the GNU Lesser General Public License along with
19this program; if not, write to the Free Software Foundation, Inc., 59 Temple
20Place - Suite 330, Boston, MA 02111-1307, USA, or go to
21http://www.gnu.org/copyleft/lesser.txt.
22--------------------------------------------------------------------------------
23*/
24
25#include <RadialGrid.h>
26
27namespace 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
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();
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
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
171 }
172
174 {
175 HydraxLOG("Creating " + getName() + " module.");
176
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
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 {
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
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
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
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
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}}
float Norm() const
#define HydraxLOG(msg)
Definition Application.h:60
static Ogre::String _getCfgString(const Ogre::String &Name, const int &Value)
static Ogre::Real _getFloatValue(Ogre::ConfigFile &CfgFile, const Ogre::String Name)
Get float value.
static bool _getBoolValue(Ogre::ConfigFile &CfgFile, const Ogre::String Name)
Get bool value.
static int _getIntValue(Ogre::ConfigFile &CfgFile, const Ogre::String Name)
Get int value.
Mesh * getMesh()
Get Hydrax::Mesh.
Definition Hydrax.h:317
const Ogre::Vector3 & getPosition() const
Get water position.
Definition Hydrax.h:413
void _setStrength(const Ogre::Real &Strength)
Set water strength GPU param.
Definition Hydrax.cpp:764
GPUNormalMapManager * getGPUNormalMapManager()
Get Hydrax::GPUNormalMapManager.
Definition Hydrax.h:365
const bool & _isCurrentFrameUnderwater() const
Is current frame underwater?
Definition Hydrax.h:621
NormalMode
Normal generation mode.
Class wich contains all funtions/variables related to Hydrax water mesh.
Definition Mesh.h:47
const Ogre::String & getMaterialName() const
Get material name.
Definition Mesh.h:269
Ogre::HardwareIndexBufferSharedPtr & getHardwareIndexBuffer()
Get hardware index buffer reference.
Definition Mesh.h:285
void create()
Create our water mesh, geometry, entity, etc...
Definition Mesh.cpp:117
void setMaterialName(const Ogre::String &MaterialName)
Set mesh material.
Definition Mesh.cpp:107
void remove()
Remove all resources.
Definition Mesh.cpp:52
VertexType
Mesh vertex type enum.
Definition Mesh.h:84
@ VT_POS_NORM
Definition Mesh.h:86
Ogre::SubMesh * getSubMesh()
Get sub mesh.
Definition Mesh.h:213
void setOptions(const Options &Options)
Update options.
Definition Mesh.cpp:78
bool updateGeometry(const int &numVer, void *verArray)
Update geomtry.
Definition Mesh.cpp:281
Ogre::HardwareVertexBufferSharedPtr & getHardwareVertexBuffer()
Get hardware vertex buffer reference.
Definition Mesh.h:277
Base module class, Override it for create different ways of create water noise.
Definition Module.h:47
virtual void update(const Ogre::Real &timeSinceLastFrame)
Call it each frame.
Definition Module.cpp:94
virtual void remove()
Remove.
Definition Module.cpp:53
const Ogre::String & getName() const
Get module name.
Definition Module.h:99
virtual void create()
Create.
Definition Module.cpp:46
const bool & isCreated() const
Is created() called?
Definition Module.h:107
Noise::Noise * mNoise
Noise generator pointer.
Definition Module.h:156
MaterialManager::NormalMode mNormalMode
Normal map generation mode.
Definition Module.h:160
virtual void saveCfg(Ogre::String &Data)
Save config.
Definition Module.cpp:99
Mesh::Options mMeshOptions
Module mesh options.
Definition Module.h:158
const MaterialManager::NormalMode & getNormalMode() const
Get the normal generation mode.
Definition Module.h:125
virtual bool loadCfg(Ogre::ConfigFile &CfgFile)
Load config.
Definition Module.cpp:105
const Mesh::Options & getMeshOptions() const
Get the mesh options for this module.
Definition Module.h:133
float getHeigth(const Ogre::Vector2 &Position)
Get the current heigth at a especified world-space point.
void saveCfg(Ogre::String &Data)
Save config.
bool loadCfg(Ogre::ConfigFile &CfgFile)
Load config.
void * mVertices
Vertex pointer (Mesh::POS_NORM_VERTEX or Mesh::POS_VERTEX)
Definition RadialGrid.h:222
RadialGrid(Hydrax *h, Noise::Noise *n, const MaterialManager::NormalMode &NormalMode)
Constructor.
Mesh::POS_NORM_VERTEX * mVerticesChoppyBuffer
Use it to store vertex positions when choppy displacement is enabled.
Definition RadialGrid.h:225
void _calculeNormals()
Calcule current normals.
void _performChoppyWaves()
Perform choppy waves.
Hydrax * mHydrax
Our Hydrax pointer.
Definition RadialGrid.h:231
const bool _createGeometry(Mesh *mMesh) const
Create geometry in module(If special geometry is needed)
void setOptions(const Options &Options)
Set options.
void update(const Ogre::Real &timeSinceLastFrame)
Call it each frame.
Options mOptions
Our projected grid options.
Definition RadialGrid.h:228
Base noise class, Override it for create different ways of create water noise.
Definition Noise.h:43
const Ogre::String & getName() const
Get noise name.
Definition Noise.h:92
virtual bool createGPUNormalMapResources(GPUNormalMapManager *g)
Create GPUNormalMap resources.
Definition Noise.cpp:52
virtual float getValue(const float &x, const float &y)=0
Get the especified x/y noise value.
Ogre::String _RG_getNormalModeString(const MaterialManager::NormalMode &NormalMode)
Mesh::VertexType _RG_getVertexTypeFromNormalMode(const MaterialManager::NormalMode &NormalMode)
VertexType MeshVertexType
Vertex type.
Definition Mesh.h:139
Size MeshSize
Grid size (X/Z) world space.
Definition Mesh.h:135
float MeshStrength
Water strength.
Definition Mesh.h:137
Vertex struct for position and normals data.
Definition Mesh.h:61
Vertex struct for position data.
Definition Mesh.h:77
Struct wich contains Hydrax simple grid module options.
Definition RadialGrid.h:50
float Radius
Radius (In world units)
Definition RadialGrid.h:56
float ChoppyStrength
Choppy waves strength.
Definition RadialGrid.h:62
float StepSizeFive
Step size five.
Definition RadialGrid.h:66
int Circles
Number of circles.
Definition RadialGrid.h:54
int Steps
Number of steps (Per circle)
Definition RadialGrid.h:52
float Strength
Water strength.
Definition RadialGrid.h:70
float StepSizeCube
Step cube size.
Definition RadialGrid.h:64
float StepSizeLin
Step lin size.
Definition RadialGrid.h:68
Struct wich contains an especific width and height value.
Definition Help.h:41