Jump to content
  • Advertisement

Archived

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

Subotron

Combining Octree & Heightmap code, easy question!

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

Hi. Thanx for looking. The question I have is fairly easy I guess, because it''s quite basic C++ I guess, but for some reason it won''t work. In my game engine, I implemented octree code like in the gametutorials.com tutorials. (Octree Tutorial 1 & 2) This was done after I implemented the heightmap loading, also much like on this site. (At least, it also loads in the heightmap in a byte. The rendering is quite different but that''s of no matter at this subject) The octree code loades from a .RAW file in which every line contains 3 floats (x, y, z for a vertex) But a normal .RAW file like the ones used for the heightmap tutorial are totally different. What I''m trying to do is convert the "normal" .RAW data (which I load in into a byte like in the heightmap tutorials) to the data format used in the octree tutorials (load all the vertex data into a list of Vectors, which is necessary/really usefull for the frustum checking) Still with me? K. First, my code for loading in a heightmap .RAW file (into a byte) BOOL CHeightmap::LoadRAW(LPSTR strFile, int size, BYTE *pByteArray) { FILE *pFile = NULL; pFile = fopen(strFile, "rb"); if (pFile == NULL) { g_log.Print("Could not load map file"); return FALSE; } fread(pByteArray, 1, size, pFile); int result = ferror(pFile); if (result) { g_log.Print("Could not get data out of map file"); return FALSE; } fclose(pFile); return TRUE; } now the Y-coord data is in the byte array. The loading code for the octree data is like this: void LoadWorld(char filename[]) { FILE *fp = fopen(filename, "r"); if (!fp) g_log.Print("Could not load world"); CVector vTemp; while (TRUE) { BOOL result = fscanf(fp, "%f %f %f\n", &vTemp.x, &vTemp.y, &vTemp.z); if (result == EOF) break; g_NumberOfVerts++; } g_pVertices = new CVector [g_NumberOfVerts]; rewind(fp); int index = 0; for (int i = 0; i < g_NumberOfVerts; i++) { fscanf(fp, "%f %f %f\n", &g_pVertices[index].x, &g_pVertices[index].y, &g_pVertices[index].z); index++; } fclose(fp); } What I want to do again: Load in a .RAW like in method one, but convert the data in the BYTE pByteArray to the data type which you get from the 2nd piece o'' code. (an int g_NumberOfVerts and the x, y, z for the vertices in Cvector array g_pVertices. I think these 2 variabeles are the only 2 needed for the octree code right? So my attempt was this: if (!g_Heightmapper.LoadRAW("world.raw", 128, g_HeightMap)) return FALSE; g_pVertices = new CVector [128 * 128]; for (int i = 0; i < 128; i++) { for (int j = 0; j < 128; j++) { g_pVertices[i * 128 + j].x = float(j); g_pVertices[i * 128 + j].y = float(g_HeightMap[i * 128 + j]); g_pVertices[i * 128 + j].z = float(i); } } g_NumberOfVerts = 128 * 128; It doesn''t work though... I get REALLY REALLY weird errors (can''t really explain, no debug errors but really weird windows errors.) Once I strip the line g_NumberOfverts = 128 * 128; I don''t get the errors, but now there''s no working code of course... Can anybody tell me what I''m doing wrong or give me a working piece o'' code? Thanks in advance!

Share this post


Link to post
Share on other sites
Advertisement
No... the rendering code makes polys like this: it picks the 4 next vertices and renderes 2 triangles (or a quad) from it

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!