std::vector<int> _heightmap;
bool Terrain::readRawFile(std::string fileName)
{
// A height for each vertex
std::vector<BYTE> in( numVertices );
std::ifstream inFile(fileName.c_str(), std::ios_base::binary);
if( inFile == 0 )
return false;
inFile.read(
(char*)&in[0], // buffer
in.size());// number of bytes to read into buffer
inFile.close();
// copy BYTE vector to int vector
_heightmap.resize( numVertices );
for(int i = 0; i < in.size(); i++)
_heightmap = in;
return true;
}
Because what is done was:
So in.size() == numVertices. They are the same thing [wink] As for why, I don't know, I'd just use numVertices rather than call the member function to get the size.
// A height for each vertexstd::vector<BYTE> in( numVertices );
So in.size() == numVertices. They are the same thing [wink] As for why, I don't know, I'd just use numVertices rather than call the member function to get the size.
Who knows! Either should be just fine. I'm assuming that you didn't write the code.
I'd have written the resize line differently (were I considering writing code in this manner):
I'd possibly have used iterators for copying from one vector to another too. Everybody does things differently.
I'd have written the resize line differently (were I considering writing code in this manner):
_heightmap.resize( in.size() );
That way they are then the same size regardless of whatever else changes within that function.I'd possibly have used iterators for copying from one vector to another too. Everybody does things differently.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement