Skip to content

Instantly share code, notes, and snippets.

@injust90
Created November 4, 2022 04:46
Show Gist options
  • Save injust90/432cec01d79d83f3a77017d839547007 to your computer and use it in GitHub Desktop.
Save injust90/432cec01d79d83f3a77017d839547007 to your computer and use it in GitHub Desktop.
#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;
}
@injust90
Copy link
Author

injust90 commented Nov 4, 2022

ASDF

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment