Am trying to create some water wich will contain waves (fundamental to my app) and as it will act as big 'terrain' I thought to create it as an ITerrainSceneNode so it benefits the LOD system (<-- the real neat idea).
No need for a heightmap so I did:
- new file: copied ITerrainSceneNode
- new file: copied CTerrainSceneNode.h
- new file: copied CTerrainSceneNode.cpp
- converted those, so it calls the appropriate
- Removed all loadHeightMapRAW
- Changed the loadHeightMap().
- removed some namespace os:: functionallity too
- lost the serialization and clone for now
To instantiate I have this code:
Code: Select all
nodeOcean = new irr::scene::cOceanSceneNode(
m_scenemanager->getRootSceneNode(),
m_scenemanager,
-1,
5,
irr::scene::ETPS_17,
irr::core::vector3df( -128.0f * 4.0f, 0.0f, -128.0f * 4.0f ),
irr::core::vector3df( 0.0f, 0.0f, 0.0f ),
irr::core::vector3df( 4.0f, 1.0f, 4.0f )
);
nodeOcean->loadHeightMap( 257, irr::video::SColor ( 255, 255, 255, 255 ), 0 );
nodeOcean->setMaterialTexture( 0, m_driver->getTexture( "..\\resources\\textures\\islands\\terrain-texture.jpg" ) );
nodeOcean->setDebugDataVisible ( irr::scene::EDS_BBOX | irr::scene::EDS_MESH_WIRE_OVERLAY | irr::scene::EDS_BBOX_BUFFERS );
TODO: The actual dynamic wave wich will happen somewhere in the render func, don't know yet but won't be a (real) pain.
Here is the new function:
Code: Select all
bool cOceanSceneNode::loadHeightMap( irr::s32 size, video::SColor vertexColor, s32 smoothFactor )
{
// ONLY CHANGED PARTS I POST HERE FOR READABILITY
Mesh->MeshBuffers.clear();
/* REMOVED
const u32 startTime = os::Timer::getRealTime();
ENTIRE heightMap MEMBER DECLERATION TOO
video::IImage* heightMap = SceneManager->getVideoDriver()->createImageFromFile(file);
if (!heightMap)
{
os::Printer::log("Unable to load heightmap.");
return false;
}
*/
// Set the size of the surface
TerrainData.Size = size;// <-- heightMap->getDimension().Width;
switch ( TerrainData.PatchSize )
{/*NOT CHANGED*/}
// --- Generate vertex data from heightmap ----
// resize the vertex array for the mesh buffer one time (makes loading faster)
scene::CDynamicMeshBuffer *mb=0;
const u32 numVertices = TerrainData.Size * TerrainData.Size;
if (numVertices <= 65536)
{/*NOT CHANGED
else
SAME
*/}
mb->getVertexBuffer().set_used(numVertices);
// Read the heightmap to get the vertex data
// Apply positions changes, scaling changes
for x && z
{
{
get vertex = static_cast[ index++ ];
vertex.Pos.X = fx;
// The cos and sin for the wave
vertex.Pos.Y = cos( PI / 180.0f * fx ) * sin( PI / 180.0f * fz );//0.0f;
vertex.Pos.Z = fz;
}
}
smoothTerr...UNCHANGED...RenderBuffer->setDirty();
//const u32 endTime = os::Timer::getRealTime();
//c8 tmp[255];
//snprintf(tmp, 255, "Generated terrain data (%dx%d) in %.4f seconds",
// TerrainData.Size, TerrainData.Size, (endTime - startTime) / 1000.0f );
//os::Printer::log(tmp);
return true;
}
Code: Select all
void cOceanSceneNode::render()
{
/* NOTHING CHANGED AT ALL */
}
Thanks,
KP84