Jump to content
  • Advertisement

Archived

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

fireking

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

This topic is 5476 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
Guest Anonymous Poster
pHeightMap[z*MAP_SIZE+x]=whatever;

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!