| 622 | } |
| 623 | |
| 624 | void Patch::appendPoints(bool columns, bool beginning) { |
| 625 | bool rows = !columns; // Shortcut for readability |
| 626 | |
| 627 | if ((columns && _width + 2 > MAX_PATCH_WIDTH) || |
| 628 | (rows && _height + 2 > MAX_PATCH_HEIGHT)) |
| 629 | { |
| 630 | rError() << "Patch::appendPoints() error: " << |
| 631 | "Cannot make patch any larger.\n"; |
| 632 | return; |
| 633 | } |
| 634 | |
| 635 | // Sanity check passed, now start the action |
| 636 | undoSave(); |
| 637 | |
| 638 | // Create a backup of the old control vertices |
| 639 | PatchControlArray oldCtrl = _ctrl; |
| 640 | std::size_t oldHeight = _height; |
| 641 | std::size_t oldWidth = _width; |
| 642 | |
| 643 | // Resize this patch |
| 644 | setDims(columns ? oldWidth+2 : oldWidth, rows ? oldHeight+2 : oldHeight); |
| 645 | |
| 646 | // Specify the target row to copy the values to |
| 647 | std::size_t targetColStart = (columns && beginning) ? 2 : 0; |
| 648 | std::size_t targetRowStart = (rows && beginning) ? 2 : 0; |
| 649 | |
| 650 | // We're copying the old patch matrix into a sub-matrix of the new patch |
| 651 | // Fill in the control vertex values into the target area using this loop |
| 652 | for (std::size_t newRow = targetRowStart, oldRow = 0; |
| 653 | newRow < _height && oldRow < oldHeight; |
| 654 | newRow++, oldRow++) |
| 655 | { |
| 656 | for (std::size_t newCol = targetColStart, oldCol = 0; |
| 657 | oldCol < oldWidth && newCol < _width; |
| 658 | oldCol++, newCol++) |
| 659 | { |
| 660 | // Copy the control vertex from the old patch to the new patch |
| 661 | ctrlAt(newRow, newCol).vertex = oldCtrl[oldRow*oldWidth + oldCol].vertex; |
| 662 | ctrlAt(newRow, newCol).texcoord = oldCtrl[oldRow*oldWidth + oldCol].texcoord; |
| 663 | } |
| 664 | } |
| 665 | |
| 666 | if (columns) { |
| 667 | // Extrapolate the vertex attributes of the columns |
| 668 | |
| 669 | // These are the indices of the new columns |
| 670 | std::size_t newCol1 = beginning ? 0 : _width - 1; // The outermost column |
| 671 | std::size_t newCol2 = beginning ? 1 : _width - 2; // The nearest column |
| 672 | |
| 673 | // This indicates the direction we are taking the base values from |
| 674 | // If we start at the beginning, we have to take the values on |
| 675 | // the "right", hence the +1 index |
| 676 | int neighbour = beginning ? +1 : -1; |
| 677 | |
| 678 | for (std::size_t row = 0; row < _height; row++) { |
| 679 | // The distance of the two neighbouring columns, |
| 680 | // this is taken as extrapolation value |
| 681 | Vector3 vertexDiff = ctrlAt(row, newCol2 + neighbour).vertex - |
no test coverage detected