Thanks all for the reply!
This is actually the full function:
bool HeightMap::Init(int size, int gridSpacing, float scale){ m_heightScale = scale; m_size = size; m_gridSpacing = gridSpacing; try { m_heights.resize(m_size * m_size); } catch (const std::bad_alloc &) { return false; } memset(&m_heights[0], 0, m_heights.size()); return true;}
m_heights will then be filled in another function :
void HeightMap::createFractaltype(float roughness){ srand(static_cast<unsigned int>(time(0))); std::fill(m_heights.begin(), m_heights.end(), 0.0f); int p1, p2, p3, p4, mid; float dH = m_size * 0.5f; float dHFactor = powf(2.0f, -roughness); float minH = 0.0f, maxH = 0.0f; for (int w = m_size; w > 0; dH *= dHFactor, w /= 2) { // Diamond Step. for (int z = 0; z < m_size; z += w) { for (int x = 0; x < m_size; x += w) { p1 = heightIndexAt(x, z); p2 = heightIndexAt(x + w, z); p3 = heightIndexAt(x + w, z + w); p4 = heightIndexAt(x, z + w); mid = heightIndexAt(x + w / 2, z + w / 2); m_heights[mid] = Math::random(-dH, dH) + (m_heights[p1] + m_heights[p2] + m_heights[p3] + m_heights[p4]) * 0.25f;//etc
Isn't using memset the only way in this application?
edit: To make things clearer I need to store m_heights value when I call this function once into a temp vector (lets say v_temp1)and then call this function the second time and store it in the other vector (v_temp2). I would then need to interpolate between these two vector values.
Pretty tired at the moment so sorry if I am sounding incoherent and asking silly questions! Thanks!