Skip to main content
GameDev.net gamedev.net
🔒 Locked

How to store byte array data in vectors (RAW loading)

Started by Subotron Oct 31, 2002 at 1:02 PM 0 replies 150+ views
Original Post
Subotron
Subotron
I''m making a game where I load worlds by a method which reads a .RAW file which resembles a heightmap, and it stores the values in a byte array with this line: fread(pByteArray, 1, size, pFile); So now I have all the data in my pByteArray, let''s say pByteArray[1024 * 1024] for example. These values are the y-coord of the vertices drawn. Now I want to store all the vertex info in vectors. So what I should get is 1024x1024 vectors. (g_pVertices = new CVector [1024 x 1024]) and there I need to store the data. But I can''t create a code which gives the vectors the right x, y, z coords. Can anyone please help me with this? I thought about for (i = ...) { for (j = ...) { code } } but I can''t figure it out Thanks in advance... BTW sorry for double post but I forgot to click "e-mail on reply"
Shannon Barber
Shannon Barber
You only need to store the z value, the x-y information is implicitly known from the position in the array.

Also note that 1024x1024 is friggin huge. That''s one meg for every *byte* that CVector consumes. If it only contains an int z, it''s four megs. If it contains an int x,y,z, then it''s 12 megs.

int get_z(int* pByteArray, int x, int y)
{
return pByteArray[x*1024+y];
}

for(int i=0; i<1024; ++i)
for(int j=0; j<1024; ++j)
get_z((int*)pByteArray), i, j)
The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.