| 983 | // MARK: visit, draw, transform |
| 984 | |
| 985 | void Sprite::updateTransform() |
| 986 | { |
| 987 | AXASSERT(_renderMode == RenderMode::QUAD_BATCHNODE, |
| 988 | "updateTransform is only valid when Sprite is being rendered using an SpriteBatchNode"); |
| 989 | |
| 990 | // recalculate matrix only if it is dirty |
| 991 | if (isDirty()) |
| 992 | { |
| 993 | // If it is not visible, or one of its ancestors is not visible, then do nothing: |
| 994 | if (!_visible || (_parent && _parent != _batchNode && static_cast<Sprite*>(_parent)->_shouldBeHidden)) |
| 995 | { |
| 996 | _quad.br.vertices.setZero(); |
| 997 | _quad.tl.vertices.setZero(); |
| 998 | _quad.tr.vertices.setZero(); |
| 999 | _quad.bl.vertices.setZero(); |
| 1000 | _shouldBeHidden = true; |
| 1001 | } |
| 1002 | else |
| 1003 | { |
| 1004 | _shouldBeHidden = false; |
| 1005 | |
| 1006 | if (!_parent || _parent == _batchNode) |
| 1007 | _transformToBatch = getNodeToParentTransform(); |
| 1008 | else |
| 1009 | { |
| 1010 | AXASSERT(dynamic_cast<Sprite*>(_parent), "Logic error in Sprite. Parent must be a Sprite"); |
| 1011 | const Mat4& nodeToParent = getNodeToParentTransform(); |
| 1012 | Mat4& parentTransform = static_cast<Sprite*>(_parent)->_transformToBatch; |
| 1013 | _transformToBatch = parentTransform * nodeToParent; |
| 1014 | } |
| 1015 | |
| 1016 | // |
| 1017 | // calculate the Quad based on the Affine Matrix |
| 1018 | // |
| 1019 | |
| 1020 | Vec2& size = _rect.size; |
| 1021 | |
| 1022 | float x1 = _offsetPosition.x; |
| 1023 | float y1 = _offsetPosition.y; |
| 1024 | |
| 1025 | float x2 = x1 + size.width; |
| 1026 | float y2 = y1 + size.height; |
| 1027 | |
| 1028 | float x = _transformToBatch.m[12]; |
| 1029 | float y = _transformToBatch.m[13]; |
| 1030 | |
| 1031 | float cr = _transformToBatch.m[0]; |
| 1032 | float sr = _transformToBatch.m[1]; |
| 1033 | float cr2 = _transformToBatch.m[5]; |
| 1034 | float sr2 = -_transformToBatch.m[4]; |
| 1035 | float ax = x1 * cr - y1 * sr2 + x; |
| 1036 | float ay = x1 * sr + y1 * cr2 + y; |
| 1037 | |
| 1038 | float bx = x2 * cr - y1 * sr2 + x; |
| 1039 | float by = x2 * sr + y1 * cr2 + y; |
| 1040 | |
| 1041 | float cx = x2 * cr - y2 * sr2 + x; |
| 1042 | float cy = x2 * sr + y2 * cr2 + y; |
nothing calls this directly
no test coverage detected