Hi all.
Can help me with minimap for ITerrainSceneNode.may be сan ready solutions.
in forum search i dont find any good solution(
Minimap for ITerrainSceneNode
You can use the heightmap as a texture for the minimap. If you want it with colors and such, just create a new texture based on the heightmap.
If you don't have the texture (you created the ITerrainSceneNode proceduraly) you can easily get the height values of the vertex using this:
Then create your own texture using that float array and use it as a minimap.
If you need your coords in the map, just check your player's position and the terrain position, substract those vectors and you'll get the local position in the minimap.
If you don't have the texture (you created the ITerrainSceneNode proceduraly) you can easily get the height values of the vertex using this:
Code: Select all
float* getRawHeightfieldData(irr::scene::ITerrainSceneNode* node, float& minHeight, float& maxHeight, unsigned int& vertices)
{
irr::scene::CDynamicMeshBuffer* buffer = NULL;
unsigned int vertexCount = 0;
float* heightMap = NULL;
// we need to know the total number of vertices
const unsigned int numVertices = node->getMesh()->getMeshBuffer(0)->getVertexCount();
try
{
// a fount this in the Irllicht's sources of CTerrainSceneNode
if (numVertices <= 65536)
{
//small enough for 16bit buffers
buffer = new irr::scene::CDynamicMeshBuffer(irr::video::EVT_2TCOORDS, irr::video::EIT_16BIT);
}
else
{
//we need 32bit buffers
buffer = new irr::scene::CDynamicMeshBuffer(irr::video::EVT_2TCOORDS, irr::video::EIT_32BIT);
}
// get the mesh data for LOD 0
node->getMeshBufferForLOD(*buffer, 0);
// should be the same as the numVertices - you can test for that
vertexCount = buffer->getVertexCount();
vertices = vertexCount;
// get some memory for the heightmap
heightMap = new float[vertexCount];
}
catch (std::bad_alloc)
{
// If the heightMap allocation fails, this will be already allocated.
if (buffer != NULL) buffer->drop();
return NULL;
}
// initialize the min/max
minHeight = heightMap[0];
maxHeight = minHeight;
float* hm = &heightMap[0];
for (unsigned int i = 0; i < vertexCount; i++)
{
float height = buffer->getVertexBuffer()[i].Pos.Y;
// update min/max
if (height < minHeight)
{
minHeight = height;
}
if (height > maxHeight)
{
maxHeight = height;
}
// store the height
*hm++ = height;
}
buffer->drop();
if (maxHeight < -minHeight)
{
maxHeight = -minHeight;
}
if (minHeight > -maxHeight)
{
minHeight = -maxHeight;
}
return heightMap;
}
If you need your coords in the map, just check your player's position and the terrain position, substract those vectors and you'll get the local position in the minimap.
-
- Posts: 1186
- Joined: Fri Dec 29, 2006 12:04 am
-
- Posts: 1186
- Joined: Fri Dec 29, 2006 12:04 am
I am willing to help, but i won't post a ready-made solution to copy and paste.Serge wrote:Can you share you code ?
Please have a look at example 13.RenderToTexture.
My code pretty much is the same, except that the second camera is an orthogonal one and moves with the player, looking down.
Try to setup a minimal compilable snippet and if it doesn't work, ask again.
"Whoops..."
-
- Posts: 70
- Joined: Tue Oct 28, 2008 12:59 pm
Thank you very much but i am very bad. Please you share your source code for us. I very need your source it help me slove my problem. Please...randomMesh wrote:I am willing to help, but i won't post a ready-made solution to copy and paste.Serge wrote:Can you share you code ?
Please have a look at example 13.RenderToTexture.
My code pretty much is the same, except that the second camera is an orthogonal one and moves with the player, looking down.
Try to setup a minimal compilable snippet and if it doesn't work, ask again.