Initializes the mesh as a plane
| 482 | |
| 483 | // Initializes the mesh as a plane |
| 484 | void Mesh::InitCornea(ID3D11Device* device, uint32 materialIdx) |
| 485 | { |
| 486 | const float R = 5.5f; |
| 487 | const float IrisDepth = 2.18f; |
| 488 | |
| 489 | const uint64 XRes = 100; |
| 490 | const uint64 YRes = 100; |
| 491 | const uint64 NumVerts = XRes * YRes; |
| 492 | const uint64 NumTriangles = (XRes - 1) * (YRes - 1) * 2; |
| 493 | const uint64 NumIndices = NumTriangles * 6; |
| 494 | StaticAssert_(NumVerts <= UINT32_MAX); |
| 495 | |
| 496 | std::vector<Vertex> corneaVerts(NumVerts); |
| 497 | std::vector<uint32> corneaIndices(NumIndices, 0); |
| 498 | |
| 499 | uint64 vIdx = 0; |
| 500 | for(uint64 yIdx = 0; yIdx < YRes; ++yIdx) |
| 501 | { |
| 502 | for(uint64 xIdx = 0; xIdx < XRes; ++xIdx) |
| 503 | { |
| 504 | const float u = xIdx / (XRes - 1.0f); |
| 505 | const float v = yIdx / (YRes - 1.0f); |
| 506 | const float x = (u * 2.0f - 1.0f) * R; |
| 507 | const float y = (v * 2.0f - 1.0f) * R; |
| 508 | const float r = std::min(std::sqrt(x * x + y * y), R); |
| 509 | const float z = CorneaZ(r); |
| 510 | |
| 511 | const float uStep = 1.0f / (XRes - 1.0f); |
| 512 | const float vStep = 1.0f / (YRes - 1.0f); |
| 513 | const float x1 = x; |
| 514 | const float y1 = y; |
| 515 | const float z1 = z; |
| 516 | |
| 517 | // [1, 0] |
| 518 | const float v0 = v - vStep; |
| 519 | const float y0 = (v0 * 2.0f - 1.0f) * R; |
| 520 | const float r10 = std::min(std::sqrt(x1 * x1 + y0 * y0), R); |
| 521 | const float z10 = CorneaZ(r10); |
| 522 | |
| 523 | // [2, 1] |
| 524 | const float u2 = u + uStep; |
| 525 | const float x2 = (u2 * 2.0f - 1.0f) * R; |
| 526 | const float r21 = std::min(std::sqrt(x2 * x2 + y1 * y1), R); |
| 527 | const float z21 = CorneaZ(r21); |
| 528 | |
| 529 | // [1, 2] |
| 530 | const float v2 = v + vStep; |
| 531 | const float y2 = (v2 * 2.0f - 1.0f) * R; |
| 532 | const float r12 = std::min(std::sqrt(x1 * x1 + y2 * y2), R); |
| 533 | const float z12 = CorneaZ(r12); |
| 534 | |
| 535 | // [0, 1] |
| 536 | const float u0 = u - uStep; |
| 537 | const float x0 = (u0 * 2.0f - 1.0f) * R; |
| 538 | const float r01 = std::min(std::sqrt(x0 * x0 + y1 * y1), R); |
| 539 | const float z01 = CorneaZ(r01); |
| 540 | |
| 541 | const Float3 p11 = Float3(x1, y1, z1); |