Minimap for ITerrainSceneNode

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Serge
Posts: 8
Joined: Mon Jan 31, 2011 8:53 am

Minimap for ITerrainSceneNode

Post by Serge »

Hi all.
Can help me with minimap for ITerrainSceneNode.may be сan ready solutions.
in forum search i dont find any good solution(
nespa
Posts: 167
Joined: Wed Feb 24, 2010 12:02 pm

Post by nespa »

minimap or mipmap?

mipmap is done automaticaly over the color texture depends on the value of the patch size when you load a terrain from a heightmap;
Serge
Posts: 8
Joined: Mon Jan 31, 2011 8:53 am

Post by Serge »

nespa wrote:minimap or mipmap?

mipmap is done automaticaly over the color texture depends on the value of the patch size when you load a terrain from a heightmap;
MiniMap
polylux
Posts: 267
Joined: Thu Aug 27, 2009 12:39 pm
Location: EU

Post by polylux »

I'd say this heavily depends on the features the minimap should have? Can you add some more information? Maybe a screenshot of a game that has what you need.
beer->setMotivationCallback(this);
nake
Posts: 3
Joined: Wed Mar 02, 2011 7:57 pm

Post by nake »

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:

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;
}
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.
randomMesh
Posts: 1186
Joined: Fri Dec 29, 2006 12:04 am

Post by randomMesh »

I made a minimap using a second camera and render that to an RTT.

Image

This works for all kind of geometry, not only for terrains.
"Whoops..."
Serge
Posts: 8
Joined: Mon Jan 31, 2011 8:53 am

Post by Serge »

randomMesh wrote:I made a minimap using a second camera and render that to an RTT.

Image

This works for all kind of geometry, not only for terrains.
Yes, i need similar minimap, but i dont know, show full scalled terrarin on it or scalled fragment.
Can you share you code ? :)
randomMesh
Posts: 1186
Joined: Fri Dec 29, 2006 12:04 am

Post by randomMesh »

Serge wrote:Can you share you code ? :)
I am willing to help, but i won't post a ready-made solution to copy and paste.

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..."
tinhtoitrangtay
Posts: 70
Joined: Tue Oct 28, 2008 12:59 pm

Post by tinhtoitrangtay »

randomMesh wrote:
Serge wrote:Can you share you code ? :)
I am willing to help, but i won't post a ready-made solution to copy and paste.

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.
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...
Post Reply