daily pastebin goal
77%
SHARE
TWEET

Untitled

a guest Sep 19th, 2017 50 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     int segments = 32;
  2.     int sides = 32;
  3.     float radius1 = 2.0f;
  4.     float radius2 = 0.5f;
  5.  
  6.     for (int i = 0; i < segments; ++i)
  7.     {
  8.         for (int j = 0; j < sides; ++j)
  9.         {
  10.             float theta1 = -DirectX::XM_2PI * i / (segments - 1) + 2 * DirectX::XM_PIDIV2;
  11.             float phi1 = -DirectX::XM_2PI * j / sides;
  12.  
  13.             float theta2 = DirectX::XM_PI * i / (segments - 1);
  14.             float phi2 = -DirectX::XM_2PI * j / sides;
  15.  
  16.             Vertex v1((radius1 + radius2 * std::cosf(theta1)) * std::cosf(phi1), (radius1 + radius2 * std::cosf(theta1)) * std::sinf(phi1), radius2 * std::sinf(theta1), (float)i / segments, (float)j / sides);
  17.             Vertex v2(std::cosf(phi2) * std::sinf(theta2) * radius1, std::sinf(phi2) * std::sinf(theta2) * radius1, std::cosf(theta2) * radius1, (float)i / segments, (float)j / sides);
  18.             m_Vertices.push_back(VertexLerp(v1, v2, morphFactor));
  19.  
  20.             if (i < sides - 1)
  21.             {
  22.                 unsigned int jplus1 = (j == sides - 1) ? 0 : (j + 1);
  23.                 m_Indices.push_back((i + 1) * sides + j);
  24.                 m_Indices.push_back(i * sides + j);
  25.                 m_Indices.push_back(i * sides + jplus1);
  26.  
  27.                 m_Indices.push_back((i + 1) * sides + j);
  28.                 m_Indices.push_back(i * sides + jplus1);
  29.                 m_Indices.push_back((i + 1) * sides + jplus1);
  30.             }
  31.         }
  32.     }
RAW Paste Data
Top