Created
November 4, 2022 04:46
-
-
Save injust90/432cec01d79d83f3a77017d839547007 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "CircleComponent.h" | |
#include "Actor.h" | |
CircleComponent::CircleComponent(class Actor* owner) | |
:Component(owner) | |
, mRadius(0.0f) | |
{ | |
} | |
const Vector2& CircleComponent::GetCenter() const | |
{ | |
return mOwner->GetPosition(); | |
} | |
float CircleComponent::GetRadius() const | |
{ | |
return mOwner->GetScale() * mRadius; | |
} | |
// REFERENCE: p 62 Game Programming in C++ Sanjay Madhav | |
// Circle-Versus-Circle Intersection | |
// Two circles intersect with each other if and only if the distance between their centers is less than or equal to the sum of their radii. | |
bool Intersect(const CircleComponent& a, const CircleComponent& b) | |
{ | |
// Calculate distance squared | |
Vector2 diff = a.GetCenter() - b.GetCenter(); | |
float distSq = diff.LengthSq(); | |
// Calculate sum of radii squared | |
float radiiSq = a.GetRadius() + b.GetRadius(); | |
radiiSq *= radiiSq; | |
return distSq <= radiiSq; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ASDF