Archived

This topic is now archived and is closed to further replies.

fireking

either changing value in 1d array, or switching to 2d array

Recommended Posts

could someone tell me how to change the value in a 1d array? im basically loading a raw file into a 1d array, and using it to render height maps. that works great, but now i wanna change some of the height values... i know x and z, and i know what i want to change y to, but how to i go through the array to find the location i wanna change? here''s how i return values, but it doesnt seem to work for setting them...
int Height(BYTE *pHeightMap,int X,int Y)
{
		// Make sure we don''t go past our array size
	if(X<0 || X>MAP_SIZE-1) return 0;
	if(Y<0 || Y>MAP_SIZE-1) return 0;
	//int x = X % MAP_SIZE;					// Error check our x value
	//int y = Y % MAP_SIZE;					// Error check our y value

	if(!pHeightMap) return 0;				// Make sure our data is valid

	// Use the equation: index = (x + (y * arrayWidth) ) to find the current height
	return pHeightMap[X+(Y*MAP_SIZE)];	// Index into our height array and return the height
}
if i try to set the value using that index method, i just go out of bounds and debugger starts breaking down and crying about it... i also tried pHeightMap[x*z]=whatever; but that doesnt seem to work... how do i move through the array to change the value located at point x,z thanks..

Share this post


Link to post
Share on other sites