| 214 | } |
| 215 | |
| 216 | std::shared_ptr<Visual> MeshFactory::CreateDisk(uint32_t numShellSamples, |
| 217 | uint32_t numRadialSamples, float radius) |
| 218 | { |
| 219 | // Quantities derived from inputs. |
| 220 | uint32_t ssm1 = numShellSamples - 1; |
| 221 | uint32_t rsm1 = numRadialSamples - 1; |
| 222 | float invSSm1 = 1.0f / static_cast<float>(ssm1); |
| 223 | float invRS = 1.0f / static_cast<float>(numRadialSamples); |
| 224 | uint32_t numVertices = 1 + numRadialSamples * ssm1; |
| 225 | uint32_t numTriangles = numRadialSamples * (2 * ssm1 - 1); |
| 226 | |
| 227 | // Generate geometry. |
| 228 | auto vbuffer = CreateVBuffer(numVertices); |
| 229 | if (!vbuffer) |
| 230 | { |
| 231 | return nullptr; |
| 232 | } |
| 233 | |
| 234 | Vector3<float> pos; |
| 235 | Vector3<float> nor{ 0.0f, 0.0f, 1.0f }; |
| 236 | Vector3<float> tan{ 1.0f, 0.0f, 0.0f }; |
| 237 | Vector3<float> bit{ 0.0f, 1.0f, 0.0f }; // = Cross(nor,tan) |
| 238 | Vector2<float> tcd; |
| 239 | |
| 240 | // Center of disk. |
| 241 | pos = { 0.0f, 0.0f, 0.0f }; |
| 242 | tcd = { 0.5f, 0.5f }; |
| 243 | SetPosition(0, pos); |
| 244 | SetNormal(0, nor); |
| 245 | SetTangent(0, tan); |
| 246 | SetBitangent(0, bit); |
| 247 | SetTCoord(0, tcd); |
| 248 | |
| 249 | for (uint32_t r = 0; r < numRadialSamples; ++r) |
| 250 | { |
| 251 | float angle = invRS * r * static_cast<float>(GTE_C_TWO_PI); |
| 252 | float cs = std::cos(angle); |
| 253 | float sn = std::sin(angle); |
| 254 | Vector3<float> radial{ cs, sn, 0.0f }; |
| 255 | |
| 256 | for (uint32_t s = 1; s < numShellSamples; ++s) |
| 257 | { |
| 258 | float fraction = invSSm1 * s; // in (0,R] |
| 259 | Vector3<float> fracRadial = fraction * radial; |
| 260 | uint32_t i = s + ssm1 * r; |
| 261 | pos = radius * fracRadial; |
| 262 | tcd[0] = 0.5f + 0.5f * fracRadial[0]; |
| 263 | tcd[1] = 0.5f + 0.5f * fracRadial[1]; |
| 264 | |
| 265 | SetPosition(i, pos); |
| 266 | SetNormal(i, nor); |
| 267 | SetTangent(i, tan); |
| 268 | SetBitangent(i, bit); |
| 269 | SetTCoord(i, tcd); |
| 270 | } |
| 271 | } |
| 272 | |
| 273 | // Generate indices. |
no test coverage detected