Game Development Community

Terrain Texture Retrieval using coordinates.

by SimU Group · in RTS Starter Kit · 11/01/2007 (6:29 am) · 4 replies

Does anybody know how to retrieve the terrain's texture given the x,y coordinates on the terrain?
Thanks :)

#1
11/01/2007 (7:57 am)
Some time ago I found this C++ code, that is part of James Holmes's Terrain path following Resource

//--------------------------------------------
// Get the terrain texture under an x,y coord
//
// This fills an array with the alpha value of each of the
// textures under that point. The actual texture names can be
// obtained from the TextureHandle array in the terrain block.
//
// distance - How far to look down for the terrain block
// pt - Point in world space
// alphas - U8 array of size TerrainBlock::materialGroups
//
// JH
//
bool Player::getTerrainTextures(float distance, Point3F& pt, U8 *alphas) {
    RayInfo rInfo;
    if (gClientContainer.castRay(pt, 
            Point3F(pt.x, pt.y, pt.z - distance ),
            TerrainObjectType, &rInfo)) {
         
		TerrainBlock* ter = static_cast<TerrainBlock*>(rInfo.object);
		Point2I gPos;
		const MatrixF & mat = ter->getTransform();
		Point3F origin;
		mat.getColumn(3, &origin);
		F32 squareSize = (F32) ter->getSquareSize();
		F32 halfSquareSize = squareSize / 2;

		float x = (pt.x - origin.x + halfSquareSize) / squareSize;
		float y = (pt.y - origin.y + halfSquareSize) / squareSize;

		ter->getMaterialAlpha(Point2I(x,y), alphas);
		return true;
	}
	return false;
}

You could use it directly in C++ or make a console function to use it from script (if you do do, show us what you have done ;)
#2
11/03/2007 (1:47 pm)
Thanks Novack :)
I followed the link...That's exactly what I was trying to achieve :)
However, I still need to retrieve the texture at a certain co-ordinate.
When inside the terrain editor, I can paint with 6 different textures. I need to know which of those 6 textures the terrain at (x, y) is painted (an integer answer).
#3
11/25/2007 (3:39 pm)
// textures under that point. [b]The actual texture names can be
// obtained from the TextureHandle array in the terrain block.[/b]

I've been working for so long to get the actual texture name at a certain location but I failed.. any ideas ??
#4
11/26/2007 (5:16 am)
Sorry pal, this time I cant help, this seems to need a little more of work, and currently Im at full capacity :(
Anyway, you should take a look at this pretty similar thread: Get terrain texture?
Maybe it can help you with some clue.