27namespace Hydrax{
namespace Module
55 , mVerticesChoppyBuffer(0)
64 , mVerticesChoppyBuffer(0)
260 mMesh->
getSubMesh()->vertexData =
new Ogre::VertexData();
261 mMesh->
getSubMesh()->vertexData->vertexStart = 0;
262 mMesh->
getSubMesh()->vertexData->vertexCount = numVertices;
264 Ogre::VertexDeclaration* vdecl = mMesh->
getSubMesh()->vertexData->vertexDeclaration;
265 Ogre::VertexBufferBinding* vbind = mMesh->
getSubMesh()->vertexData->vertexBufferBinding;
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);
280 Ogre::HardwareBuffer::HBU_DYNAMIC_WRITE_ONLY);
286 vdecl->addElement(0, 0, Ogre::VET_FLOAT3, Ogre::VES_POSITION);
291 Ogre::HardwareBuffer::HBU_DYNAMIC_WRITE_ONLY);
298 unsigned int *indexbuffer =
new unsigned int[numEle];
302 indexbuffer[k*3+2] = 0;
303 indexbuffer[k*3+1] = k+1;
307 indexbuffer[k*3] = k+2;
311 indexbuffer[k*3] = 1;
346 Ogre::HardwareBufferManager::getSingleton().createIndexBuffer(
347 Ogre::HardwareIndexBuffer::IT_32BIT,
349 Ogre::HardwareBuffer::HBU_STATIC,
true);
357 delete []indexbuffer;
361 mMesh->
getSubMesh()->indexData->indexStart = 0;
362 mMesh->
getSubMesh()->indexData->indexCount = numEle;
536 Ogre::Vector3 vec1, vec2, normal;
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);
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);
553 normal = vec2.crossProduct(vec1);
555 Vertices[0].
nx = normal.x;
556 Vertices[0].
ny = normal.y;
557 Vertices[0].
nz = normal.z;
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);
567 vec1 = Ogre::Vector3(
572 normal = vec2.crossProduct(vec1);
574 Vertices[1+
x].
nx = normal.x;
575 Vertices[1+
x].
ny = normal.y;
576 Vertices[1+
x].
nz = normal.z;
584 vec2 = Ogre::Vector3(
589 vec1 = Ogre::Vector3(
594 normal = vec2.crossProduct(vec1);
620 Ogre::Vector2 Current, NearStep, CircleStep,
632 Proportion = Ogre::Vector2(
634 (Current-NearStep).length(),
636 (Current-CircleStep).length());
641 Perp = Dir.perpendicular();
643 if (Dir.x < 0) Dir.x = -Dir.x;
644 if (Dir.y < 0) Dir.y = -Dir.y;
646 if (Perp.x < 0) Perp.x = -Perp.x;
647 if (Perp.y < 0) Perp.y = -Perp.y;
649 Norm = Ogre::Vector3(
654 Norm2 = Ogre::Vector2(
Norm.x,
Norm.z) *
655 ( (Dir * Proportion.x) +
656 (Perp * Proportion.y)) *
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.
const Ogre::Vector3 & getPosition() const
Get water position.
void _setStrength(const Ogre::Real &Strength)
Set water strength GPU param.
GPUNormalMapManager * getGPUNormalMapManager()
Get Hydrax::GPUNormalMapManager.
const bool & _isCurrentFrameUnderwater() const
Is current frame underwater?
NormalMode
Normal generation mode.
Class wich contains all funtions/variables related to Hydrax water mesh.
const Ogre::String & getMaterialName() const
Get material name.
Ogre::HardwareIndexBufferSharedPtr & getHardwareIndexBuffer()
Get hardware index buffer reference.
void create()
Create our water mesh, geometry, entity, etc...
void setMaterialName(const Ogre::String &MaterialName)
Set mesh material.
void remove()
Remove all resources.
VertexType
Mesh vertex type enum.
Ogre::SubMesh * getSubMesh()
Get sub mesh.
void setOptions(const Options &Options)
Update options.
bool updateGeometry(const int &numVer, void *verArray)
Update geomtry.
Ogre::HardwareVertexBufferSharedPtr & getHardwareVertexBuffer()
Get hardware vertex buffer reference.
Base module class, Override it for create different ways of create water noise.
virtual void update(const Ogre::Real &timeSinceLastFrame)
Call it each frame.
virtual void remove()
Remove.
const Ogre::String & getName() const
Get module name.
virtual void create()
Create.
const bool & isCreated() const
Is created() called?
Noise::Noise * mNoise
Noise generator pointer.
MaterialManager::NormalMode mNormalMode
Normal map generation mode.
virtual void saveCfg(Ogre::String &Data)
Save config.
Mesh::Options mMeshOptions
Module mesh options.
const MaterialManager::NormalMode & getNormalMode() const
Get the normal generation mode.
virtual bool loadCfg(Ogre::ConfigFile &CfgFile)
Load config.
const Mesh::Options & getMeshOptions() const
Get the mesh options for this module.
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)
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.
void _calculeNormals()
Calcule current normals.
void _performChoppyWaves()
Perform choppy waves.
Hydrax * mHydrax
Our Hydrax pointer.
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.
Base noise class, Override it for create different ways of create water noise.
const Ogre::String & getName() const
Get noise name.
virtual bool createGPUNormalMapResources(GPUNormalMapManager *g)
Create GPUNormalMap resources.
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.
Size MeshSize
Grid size (X/Z) world space.
float MeshStrength
Water strength.
Vertex struct for position and normals data.
Vertex struct for position data.
Struct wich contains Hydrax simple grid module options.
float Radius
Radius (In world units)
float ChoppyStrength
Choppy waves strength.
float StepSizeFive
Step size five.
int Circles
Number of circles.
int Steps
Number of steps (Per circle)
float Strength
Water strength.
bool ChoppyWaves
Choppy waves.
float StepSizeCube
Step cube size.
float StepSizeLin
Step lin size.
Struct wich contains an especific width and height value.