-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCircleComponent.cpp
More file actions
34 lines (28 loc) · 881 Bytes
/
CircleComponent.cpp
File metadata and controls
34 lines (28 loc) · 881 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include "CircleComponent.h"
#include "Actor.h"
#include "Math.h"
#include <iostream>
CircleComponent::CircleComponent(Actor* owner) : Component(owner)
,mRadius(0.0f)
{}
const Vector2& CircleComponent::GetCenter() const
{
Vector2 pos = mOwner->GetPosition();
//std::cout << "Get Center call\n Position x: " << pos.x << " Position y: " << pos.y << std::endl;
return pos;
}
float CircleComponent::GetRadius() const
{
return mOwner->GetScale() * mRadius;
}
bool Intersect(const CircleComponent& circA, const CircleComponent& circB)
{
Vector2 aCenter = circA.GetCenter();
Vector2 bCenter = circB.GetCenter();
Vector2 diff = Vector2(aCenter.x - bCenter.x, aCenter.y - bCenter.y);
float distSq = diff.LengthSq();
// calcualte the sum of radii squared
float radiiSq = circA.GetRadius() + circB.GetRadius();
radiiSq *= radiiSq;
return distSq <= radiiSq;
}