Beispiel #1
0
Plane::Plane(float quadWidth, float quadHeight, unsigned int width, unsigned int height){
	//There's one more row of vertices than quads, same for columns
	unsigned int quadCount = width*height;
	unsigned int vertexCount = (width+1)*(height+1);

	// This is explained further down, but the formula for the amount of indices in the plane is
	// (quads per row * 2 + 1) * rows + 1
	// The last +1 is for the stitch leading into the plane altogether,
	// while the +1 for each row is for the stitch finalizing each strip (as well as starting the next one.)
	
	unsigned int indexCount = (2 * width + 1) * height + 1;

	Vertex* vertices = new Vertex[vertexCount];
	GLuint* indices = new GLuint[indexCount];

	GenerateVertices(vertices, quadWidth, quadHeight, width + 1, height + 1);
	GenerateUvCoordinates(vertices, 1.0f / quadWidth, 1.0f / quadHeight, width + 1, height + 1);
	GenerateIndices(indices, width, height);
	GenerateNormals(vertices, width + 1, height + 1);

	GenerateVao(vertices, indices, vertexCount, indexCount);

	delete[] vertices;
	delete[] indices;
}
HeightMappedPlane::HeightMappedPlane(float quadWidth, float quadHeight, float maxHeight, unsigned int width, unsigned int height, Texture* heightMap){
	unsigned int quadCount = width * height;
	unsigned int vertexCount = (width + 1) * (height + 1);
	// We're not doing trianglestrips this time, so six indicies per quad (2 triangles * 3 points).
	unsigned int indexCount = quadCount * 6;

	Vertex* vertices = new Vertex[vertexCount];
	GLuint* indices = new GLuint[indexCount];

	//heightMap->PrintData();

	GenerateVertices(vertices, quadWidth, quadHeight, maxHeight, width + 1, height + 1, heightMap);
	GenerateIndices(indices, width, height);
	GenerateUvCoordinates(vertices, 1.0f / quadWidth, 1.0f / quadHeight, width + 1, height + 1);
	Model::GenerateNormals(vertices, indices, vertexCount, indexCount);
	Model::GenerateTangents(vertices, indices, vertexCount, indexCount);
	Model::GenerateBitangents(vertices, vertexCount);
	Model::GenerateVao(vertices, indices, vertexCount, indexCount);
}