Exemple #1
0
void MainWindow::GenerateGrass(Mesh *mesh)
{
	if (!mesh->LoadObj("models/grass.obj"))
		return;

	grass_pos[0] = new VertexBuffer(m_rc, GL_ARRAY_BUFFER);
	grass_pos[1] = new VertexBuffer(m_rc, GL_ARRAY_BUFFER);

	bottomPosLoc = grassShader->GetAttribLocation("Position");
	topPosLoc = grassShader->GetAttribLocation("Offset");

	vector<Vector3f> positions;
	vector<float> offsets;

	const float step = 2.0f;
	Vector2i s = terrain->GetSize();
	float hw = s.x * 0.5f;
	float hh = s.y * 0.5f;

	grassInstanceCount = 0;
	for (float x = -hw; x < hw; x += step)
		for (float z = -hh + step; z < hh; z += step)
		{
			float height = terrain->GetHeightAt(x, z);
			if (height < 0.24 * heightScale)
			{
				Vector3f shift_pos(
					randf(-0.5f, 0.5f),
					randf(-0.5f, 0.5f),
					randf(-0.5f, 0.5f));

				Vector3f grassPos = Vector3f(x, height, z);
				positions.push_back(grassPos + shift_pos);
				offsets.push_back(randf(M_PIf));

				grassInstanceCount++;
			}
		}

	grass_pos[0]->SetData(positions.size() * sizeof(Vector3f), positions.data(), GL_STATIC_DRAW);
	grass_pos[1]->SetData(offsets.size() * sizeof(float), offsets.data(), GL_STATIC_DRAW);
}
Exemple #2
0
bool Maze::is_dir_free(int pos, int dir) {
	if( dir_in_bounds(pos, dir) ) {
		return is_free(shift_pos(pos, dir));
	}
	return false;
}