-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCircle.cpp
63 lines (47 loc) · 1.62 KB
/
Circle.cpp
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include "Circle.h"
Circle::Circle(
const Primitives& primitives,
float rad ): primitives(primitives) {
this->translation = this->initialPosition;
this->radius = rad;
this->scale.x = rad;
this->scale.y = rad;
}
void Circle::MoveTo( glm::vec3 position ) {
this->translation = position;
}
void Circle::Draw( Shader& shader, Camera& camera ) {
this->primitives.DrawCircle(
shader,
camera,
this->matrix,
this->translation,
this->rotation,
this->scale );
}
void Circle::ApplyForce( glm::vec3 force ) {
this->velocity += force;
}
void Circle::Update() {
//this->translation += this->velocity;
}
void Circle::Translate( glm::vec3 translationVec ) {
this->translation += translationVec;
}
void Circle::ResetPosition() {
this->MoveTo( glm::vec3( this->translation.x, 0, 0 ) );
this->velocity = glm::vec3( 0, 0, 0 );
}
bool Circle::CheckCollision( const Rectangle& rect ) {
glm::vec3 circleDistance;
circleDistance.x = std::abs( this->translation.x - rect.translation.x );
circleDistance.y = std::abs( this->translation.y - rect.translation.y );
if( circleDistance.x > ( rect.width / 2 + this->radius ) ) return false;
if( circleDistance.y > ( rect.height / 2 + this->radius ) ) return false;
if( circleDistance.x <= rect.width / 2 ) return true;
if( circleDistance.y <= rect.height / 2 ) return true;
float cornerDistanceSquared =
std::pow( circleDistance.x - rect.width / 2, 2 ) +
std::pow( circleDistance.y - rect.height / 2, 2 );
return cornerDistanceSquared <= std::pow( this->radius, 2 );
}