• Home
  • About
    • 게임 개발자 유정룡 photo

      게임 개발자 유정룡

      포트폴리오

    • Learn More
    • Email
    • Github
    • Bitbucket
  • Projects
    • All Projects
    • All Tags

Direct3D11 공부 19일차(Mesh - Grid)

22 Jun 2021

Reading time ~1 minute

Grid

Quad랑 비슷하지만 원한 칸수에 맞춰 텍스처를 하나하나 입혀준다.

그래서 Quad랑 비슷하게 그려주는 대신 크기에 맟줘 삼각형의 갯수를 넣어줘야 한다.

Grid.cpp

void MeshGrid::Create()
{
	UINT countX = 11;
	UINT countZ = 11;

	float w = ((float)countX - 1) * 0.5f;
	float h = ((float)countZ - 1) * 0.5f;

	vector<MeshVertex> v;
	int index = 0;
	for (UINT z = 0; z < countZ; z++)
	{
		for (UINT x = 0; x < countX; x++)
		{
			MeshVertex vertex;
			vertex.Position = Vector3((float)x - w, 0, (float)z - h);
			vertex.Normal = Vector3(0, 1, 0);
			vertex.Uv.x = (float)x / (float)(countX - 1) * offsetU;
			vertex.Uv.y = (float)z / (float)(countZ - 1) * offsetV;

			v.push_back(vertex);
		}
	}

	vertices = new MeshVertex[v.size()];
	vertexCount = v.size();

	copy(v.begin(), v.end(), stdext::checked_array_iterator<MeshVertex *>(vertices, vertexCount));

	vector<UINT> i;
	for (UINT z = 0; z < countZ-1; z++)
	{
		for (UINT x = 0; x < countX-1; x++)
		{
			i.push_back(countX * z + x);
			i.push_back(countX * (z + 1) + x);
			i.push_back(countX * z + x + 1);
			i.push_back(countX * z + x + 1);
			i.push_back(countX * (z + 1) + x);
			i.push_back(countX * (z + 1) + x + 1);
		}
	}

	indices = new UINT[i.size()];
	indexCount = i.size();

	copy(i.begin(), i.end(), stdext::checked_array_iterator<UINT *>(indices, indexCount));
}

갯수마다 입혀주고 얼마나 큰게 텍스쳐를 입혀주는지 세팅해준다.

정점도 그거에 맞춰 하나하나 넣어준다.

// Grid

UV를 0.2f * Offset크기만큼에 하나씩 넣어준다.

이렇게 그려주면

각 UV가 맞게 잘 나온다.



DirectX Share Tweet +1