| 1613 | } |
| 1614 | |
| 1615 | void Flag::FlagAnimate(FrameBase& frame, int level) |
| 1616 | { |
| 1617 | if (_cloth) |
| 1618 | { |
| 1619 | Shape* shape = _shape->Level(level); |
| 1620 | |
| 1621 | int selIndex = _fabric.GetSelection(0); |
| 1622 | if (selIndex >= 0) |
| 1623 | { |
| 1624 | const NamedSelection& sel = shape->NamedSel(selIndex); |
| 1625 | shape->SaveOriginalPos(); |
| 1626 | |
| 1627 | float xSize = _cloth->GetSizeX(); |
| 1628 | float ySize = _cloth->GetSizeY(); |
| 1629 | float xMin = _cloth->GetMinX(); |
| 1630 | float yMin = _cloth->GetMinY(); |
| 1631 | float invXSize = 1 / xSize; |
| 1632 | float invYSize = 1 / ySize; |
| 1633 | |
| 1634 | Matrix4 worldToModel = frame.GetInvTransform(); |
| 1635 | |
| 1636 | for (int i = 0; i < sel.Size(); i++) |
| 1637 | { |
| 1638 | int index = sel[i]; |
| 1639 | Vector3Val val = shape->OrigPos(index); |
| 1640 | |
| 1641 | float xIndexF = (val.X() - xMin) * invXSize; |
| 1642 | float yIndexF = (val.Y() - yMin) * invYSize; |
| 1643 | |
| 1644 | Vector3 pos = _cloth->GetPosition(xIndexF, yIndexF); |
| 1645 | Vector3 norm = _cloth->GetNormal(xIndexF, yIndexF); |
| 1646 | |
| 1647 | Vector3 mpos = worldToModel.FastTransform(pos); |
| 1648 | Vector3 mnorm = worldToModel.Rotate(norm); |
| 1649 | |
| 1650 | shape->SetPos(index) = mpos; |
| 1651 | shape->SetNorm(index) = mnorm; |
| 1652 | } |
| 1653 | shape->InvalidateNormals(); |
| 1654 | } |
| 1655 | } |
| 1656 | |
| 1657 | if (_texture) |
| 1658 | { |
| 1659 | _fabric.SetTexture(_shape, level, _texture); |
| 1660 | } |
| 1661 | |
| 1662 | base::Animate(level); |
| 1663 | } |
| 1664 | |
| 1665 | void Flag::FlagDeanimate(FrameBase& frame, int level) |
| 1666 | { |
no test coverage detected