| 790 | } |
| 791 | |
| 792 | bool ActorBase::IsCollidingWith(ActorBase* other) |
| 793 | { |
| 794 | bool perPixel1 = (_state & ActorState::SkipPerPixelCollisions) != ActorState::SkipPerPixelCollisions; |
| 795 | bool perPixel2 = (other->_state & ActorState::SkipPerPixelCollisions) != ActorState::SkipPerPixelCollisions; |
| 796 | |
| 797 | if ((perPixel1 && std::abs(_renderer.rotation()) > 0.1f) || (perPixel2 && std::abs(other->_renderer.rotation()) > 0.1f)) { |
| 798 | if (!perPixel1 && std::abs(other->_renderer.rotation()) > 0.1f) { |
| 799 | return other->IsCollidingWithAngled(AABBInner); |
| 800 | } else if (!perPixel2 && std::abs(_renderer.rotation()) > 0.1f) { |
| 801 | return IsCollidingWithAngled(other->AABBInner); |
| 802 | } |
| 803 | return IsCollidingWithAngled(other); |
| 804 | } |
| 805 | |
| 806 | GraphicResource* res1 = (_currentTransition != nullptr ? _currentTransition : _currentAnimation); |
| 807 | GraphicResource* res2 = (other->_currentTransition != nullptr ? other->_currentTransition : other->_currentAnimation); |
| 808 | if (res1 == nullptr || res2 == nullptr) { |
| 809 | if (res1 != nullptr) { |
| 810 | return IsCollidingWith(other->AABBInner); |
| 811 | } |
| 812 | if (res2 != nullptr) { |
| 813 | return other->IsCollidingWith(AABBInner); |
| 814 | } |
| 815 | return false; |
| 816 | } |
| 817 | |
| 818 | Vector2i& hotspot1 = res1->Base->Hotspot; |
| 819 | Vector2i& hotspot2 = res2->Base->Hotspot; |
| 820 | |
| 821 | Vector2i& size1 = res1->Base->FrameDimensions; |
| 822 | Vector2i& size2 = res2->Base->FrameDimensions; |
| 823 | |
| 824 | AABBf aabb1, aabb2; |
| 825 | if (!perPixel1) { |
| 826 | aabb1 = AABBInner; |
| 827 | } else if (GetState(ActorState::IsFacingLeft)) { |
| 828 | aabb1 = AABBf(_pos.X + hotspot1.X - size1.X, _pos.Y - hotspot1.Y, (float)size1.X, (float)size1.Y); |
| 829 | aabb1.B += aabb1.T; |
| 830 | aabb1.R += aabb1.L; |
| 831 | } else { |
| 832 | aabb1 = AABBf(_pos.X - hotspot1.X, _pos.Y - hotspot1.Y, (float)size1.X, (float)size1.Y); |
| 833 | aabb1.B += aabb1.T; |
| 834 | aabb1.R += aabb1.L; |
| 835 | } |
| 836 | if (!perPixel2) { |
| 837 | aabb2 = other->AABBInner; |
| 838 | } else if (other->GetState(ActorState::IsFacingLeft)) { |
| 839 | aabb2 = AABBf(other->_pos.X + hotspot2.X - size2.X, other->_pos.Y - hotspot2.Y, (float)size2.X, (float)size2.Y); |
| 840 | aabb2.B += aabb2.T; |
| 841 | aabb2.R += aabb2.L; |
| 842 | } else { |
| 843 | aabb2 = AABBf(other->_pos.X - hotspot2.X, other->_pos.Y - hotspot2.Y, (float)size2.X, (float)size2.Y); |
| 844 | aabb2.B += aabb2.T; |
| 845 | aabb2.R += aabb2.L; |
| 846 | } |
| 847 | |
| 848 | // Bounding Box intersection |
| 849 | AABBf inter = AABBf::Intersect(aabb1, aabb2); |
no test coverage detected