Sign in to follow this  
derek7

look!

Recommended Posts

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[i] = in[i];

     return true;
}

 


I wonder why use in.size() instead of numVertices?

Share this post


Link to post
Share on other sites
Because what is done was:

// A height for each vertex
std::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.

Share this post


Link to post
Share on other sites
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):
     _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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this