Jump to content
• Advertisement

#### Archived

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

# Lesson 34 HeightMaps Question..using data instead of an image..

This topic is 5453 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

i have read through lesson 34 on heightmaps and had a few questions about this. i have some data in a file that looks something like thisnot the actual data) 1000 1100 1200 1280 1256 1201....... these values represent depths in meters each "point" is spaced out by 150 meters. so starting at 0,0,0, the first point would be (0, 1000, 0)then the next would be (150, 1100, 0). i am wanting to make a 3D represent of this, i.e. a heightmap and was wondering how different this data is from the data in the RAW file that was explained in lesson 34. -- also with these numbers being massive what is the easiest way to scale down my coordinate system but at the same time still seeing a significant different in depth values at different points. thanks and i hope i have been clear. --btw i am using this to try to make up some sort of land mass for a game i am working with. thanks again in advance!

#### Share this post

##### Share on other sites
Advertisement
What format is the data in again?

is it space delimited, tab delimited, are there carriage returns between each line? Is the data even plain text?
If not, how many bits wide is each piece of data?
If it is plain text, are the numbers always xxxx digits long? (eg, 0030 for 30)

Please give a little more detail (plain text or not plain text, and answers to the other questions.)

-Michael

#### Share this post

##### Share on other sites
Oh, by the way, about the size thing: all you have to do is scale the data... so, if you wanted (internally) the distance between each point to be 1 unit (instead of 150, for meters) you'd just multiply everything by destination_unit_size/original_unit_size (in this case 1 unit = 150 meters, so multiply by (1/150)
(EDIT: clarification: multiply the x, y, and z values by that value, that way the overall scale remains the same)

In openGL I don't think you'll come upon too many constraints in size... I know they're out there, I just don't remember what they are. Btw, try to keep your zNear Cliping plane as far out as possible (ie. Don't set it to 0.0f)

-Michael

[edited by - thr33d on November 12, 2003 1:37:50 PM]

#### Share this post

##### Share on other sites
micheal,
heya, thanks for the info. the data is in plain ASCII Text and each depth point is always 4 numbers in length. right now there are 10 rows followed by 30 points for each row... so my array is dataArray[30][10], since when going through the point in my loop the points will increment first of course. each point is separated by a space and each row is ended by a '/n' character. i have already written and program to read the data in my array and print them out again to make sure i am reading them in correctly. this part has been done,now i need to turn these points into the heightmap as lesson 34 does.

i have my far clipping plane set to the following:

gluPerspective(45.0f,(GLfloat)width/(GLfloat
height,0.1f,1000.0f);

i hope this answers more of your questions, thanks so much for your help, i really do appreciate it.

[edited by - opengl_guru on November 12, 2003 1:42:57 PM]

[edited by - opengl_guru on November 12, 2003 1:43:56 PM]

#### Share this post

##### Share on other sites
*grin*
It''s been awhile since I''ve done any c/c++, and when I did, we used io streams.

Here''s my stab at it (this, I can guarentee, is not the fastest way to do it.)
So, based off of tutorial #34, find this line:// Here We Load The .RAW File Into Our pHeightMap Data Array// We Are Only Reading In ''1'', And The Size Is (Width * Height)fread( pHeightMap, 1, nSize, pFile );

and change it to something like this:
char *value = (char *)malloc(5 * sizeof(char));for(int y=0;y<100;y++){    for(int x=0;x<30;x++){        fgets(value, 5, pFile); //get the next 4 character + space block        pHeightMap[y*30+x]=atoi(value) //convert it to an integer, put it int the heightmap    }    //at this point you''ll probably have to get rid of the carraige returns    fgets(value, 2, pFile);}

Again, I don''t code in c++ much anymore, and have never done anything like this w/o the streaming classes. (Ask me how to do it in vb and I''ll be johnny on the spot.)

Hope it works (but it will probably require some tweaking) - if nothing else, the concept is right.

To speed the thing up, you might try loading the while file into memory (a byte array) and converting the stuff from there. That way there aren''t so many independant reads, and delays between them.

[help] someone please fix my errors now? [/help]

-Michael

#### Share this post

##### Share on other sites
hi again thanks for the code! well as far as converting the ascii text to integers and every 4 characters that has already been done and '/n' char already into account. i actually do all the convering b4 i store the depth values into the array. so all i have to do now is read back from the array(that has the integer values(depths) stored) and convert the heightmap according to this. i think since i have already done this part your code would be compressed some. ill get back with you. thanks again, let me know please if you have any other suggestions.

[edited by - opengl_guru on November 13, 2003 11:59:11 AM]

#### Share this post

##### Share on other sites
Oh... that's not where the problem was - you'd already done that (nm)

All you have to adjust, to get a 30x10 size heightmap in there is, in the defines:
#define		MAP_SIZE	1024				// Size Of Our .RAW Height Map ( NEW )#define		STEP_SIZE	16				// Width And Height Of Each Quad ( NEW )#define		HEIGHT_RATIO	1.5f

change the stuff to something like
#define		MAP_WIDTH	30#define		MAP_HEIGHT	10#define		STEP_SIZE	1				// Width And Height Of Each Quad ( NEW )#define		HEIGHT_RATIO	0.125f	//just picking a value that should work ok with your data

this line
BYTE g_HeightMap[MAP_SIZE*MAP_SIZE];
becomes:
BYTE g_HeightMap[MAP_WIDTH*MAP_HEIGHT];

This section
int Height(BYTE *pHeightMap, int X, int Y)			// This Returns The Height From A Height Map Index{	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

becomes
int Height(BYTE *pHeightMap, int X, int Y)			// This Returns The Height From A Height Map Index{	int x = X % MAP_WIDTH;					// Error Check Our x Value	int y = Y % MAP_HEIGHT;					// Error Check Our y Value	if(!pHeightMap) return 0;				// Make Sure Our Data Is Valid

This line:
return pHeightMap[x + (y * MAP_SIZE)];
Becomes
return pHeightMap[x + (y * MAP_WIDTH)];
(YES, it is multiplied by WIDTH, not a typo)

and finally
this section
for ( X = 0; X < (MAP_SIZE-STEP_SIZE); X += STEP_SIZE )		for ( Y = 0; Y < (MAP_SIZE-STEP_SIZE); Y += STEP_SIZE )

becomes
for ( X = 0; X < (MAP_WIDTH-STEP_SIZE); X += STEP_SIZE )		for ( Y = 0; Y < (MAP_HEIGHT-STEP_SIZE); Y += STEP_SIZE )

Is that all you needed? (You could have figured that out )

-Michael

(EDIT: put in the right numbers for width and height so not to confuse anyone.)

[edited by - thr33d on November 13, 2003 12:19:36 PM]

#### Share this post

##### Share on other sites
haha yeah i was working on what you are writing, but once again thanks for the info. i guess it would help to know how data from a RAW image is stored, ya know, regardless of whether it be 8 , 16.... 32 bit image. thanks for the pointers i have been and am working on this sounds like you have done much with heightmaps before?

#### Share this post

##### Share on other sites
still unsuccessful i think i am having a problem scaling it down and being able to view it through a camera. my code is the same as lesson 34 except i already know how big my 2D array is and with each vertex(x, y,z) x changes the same amount whereas Y(the depth) changes according the next number inside the array. z according to that code should stay left alone. im stumped i tell you

#### Share this post

##### Share on other sites
What is it not doing? Could you either give compiler error messages listing, or a screenshot, and/or a link to your code?

Btw, I notice that the heightmap originally was stored as a BYTE, you might want to change that to be an integer (int when you delcare it and receive it in functions.)

Btw, you said talked about x,y, and z.
x is assigned the value of X
y is assigned the heightmap''s value at that coordinate (x,y)
z is assigned the value of Y

It''s actually drawing in the order a typewriter works.
(start at the top, step to the right, when you come to the end of the line, start over, step down a line.
Continue until at the bottom of the map.)

-Michael

#### Share this post

##### Share on other sites

• Advertisement
• Advertisement

• ### Popular Contributors

1. 1
Rutin
26
2. 2
3. 3
4. 4
5. 5
• Advertisement

• 9
• 13
• 19
• 14
• 9
• ### Forum Statistics

• Total Topics
632940
• Total Posts
3009328
• ### Who's Online (See full list)

There are no registered users currently online

×

## 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!