| 127 | } |
| 128 | |
| 129 | static void GenerateSphere(uint64 NumUSlices, uint64 NumVSlices, ID3D11Device* device, |
| 130 | ID3D11BufferPtr& vtxBuffer, ID3D11BufferPtr& idxBuffer, uint64& numIndices) |
| 131 | { |
| 132 | Assert_(NumUSlices >= 3); |
| 133 | Assert_(NumVSlices >= 3); |
| 134 | |
| 135 | std::vector<Float3> sphereVerts; |
| 136 | |
| 137 | // Add the vert at the top |
| 138 | sphereVerts.push_back(Float3(0.0f, 0.0f, 1.0f)); |
| 139 | |
| 140 | // Add the rings |
| 141 | for(uint64 v = 0; v < NumVSlices - 1; ++v) |
| 142 | { |
| 143 | for(uint64 u = 0; u < NumUSlices; ++u) |
| 144 | { |
| 145 | const float theta = ((v + 1.0f) / NumVSlices) * Pi; |
| 146 | const float phi = (float(u) / NumUSlices) * Pi2; |
| 147 | |
| 148 | Float3 pos; |
| 149 | pos.x = std::sin(theta) * std::cos(phi); |
| 150 | pos.y = std::sin(theta) * std::sin(phi); |
| 151 | pos.z = std::cos(theta); |
| 152 | |
| 153 | sphereVerts.push_back(pos); |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | // Add the vert at the bottom |
| 158 | const uint32 lastVertIdx = uint32(sphereVerts.size()); |
| 159 | sphereVerts.push_back(Float3(0.0f, 0.0f, -1.0f)); |
| 160 | |
| 161 | Assert_(sphereVerts.size() <= UINT32_MAX); |
| 162 | |
| 163 | // Add the top ring of triangles |
| 164 | std::vector<uint32> sphereIndices; |
| 165 | for(uint32 u = 0; u < NumUSlices; ++u) |
| 166 | { |
| 167 | sphereIndices.push_back(0); |
| 168 | sphereIndices.push_back(u + 1); |
| 169 | |
| 170 | if(u < NumUSlices - 1) |
| 171 | sphereIndices.push_back(u + 2); |
| 172 | else |
| 173 | sphereIndices.push_back(1); |
| 174 | } |
| 175 | |
| 176 | // Add the rest of the rings |
| 177 | uint32 prevRowStart = 1; |
| 178 | uint32 currRowStart = uint32(NumUSlices + 1); |
| 179 | for(uint32 v = 1; v < NumVSlices - 1; ++v) |
| 180 | { |
| 181 | for(uint32 u = 0; u < NumUSlices; ++u) |
| 182 | { |
| 183 | uint32 nextBottom = currRowStart + u + 1; |
| 184 | uint32 nextTop = prevRowStart + u + 1; |
| 185 | if(u == NumUSlices - 1) |
| 186 | { |