Advertisement
Guest User

Untitled

a guest
Mar 15th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. SharedPtr<Mesh> MeshMgr::CreatePlane(const std::wstring & id, const UINT width, const UINT height, const float spacing)
  2. {
  3.     Array<Vertex> verts(width * height);
  4.     Array<UINT> indices;
  5.  
  6.     const float fWidth = static_cast<float>(width);
  7.     const float fHeight = static_cast<float>(height);
  8.     const float halfWidth = fWidth / 2.f;
  9.     const float halfHeight = fHeight / 2.f;
  10.  
  11.     for (UINT y = 0; y < height; ++y)
  12.     {
  13.         for (UINT x = 0; x < width; ++x)
  14.         {
  15.             verts[y * width + x] = Vertex((x - halfWidth) * spacing, 0.f, (y - halfHeight) * spacing, 0.f, 1.f, 0.f, x / fWidth, y / fHeight);
  16.         }
  17.     }
  18.  
  19.     for (UINT y = 1; y < height; ++y)
  20.     {
  21.         for (UINT x = 1; x < width; ++x)
  22.         {
  23.             indices.push_back((y - 1) * width + (x - 1));
  24.             indices.push_back((y - 0) * width + (x - 0));
  25.             indices.push_back((y - 1) * width + (x - 0));
  26.  
  27.             indices.push_back((y - 1) * width + (x - 1));
  28.             indices.push_back((y - 0) * width + (x - 1));
  29.             indices.push_back((y - 0) * width + (x - 0));
  30.         }
  31.     }
  32.  
  33.     return CreateMesh(id, verts, indices);
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement