-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAABB.cpp
More file actions
50 lines (40 loc) · 1.36 KB
/
AABB.cpp
File metadata and controls
50 lines (40 loc) · 1.36 KB
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
#include "AABB.hpp"
#include <iostream>
AABB::AABB() : m_position(0.f, 0.f), m_dimension(0.f, 0.f)
{
//ctor
}
AABB::AABB(const AABB& other) : m_position(other.m_position), m_dimension(other.m_dimension), m_flags(other.m_flags)
{
}
AABB::AABB(sf::Vector2f position, sf::Vector2f dimension, CollisionFlags flags) : m_position(position), m_dimension(dimension), m_flags(flags)
{
}
AABB::AABB(float x, float y, float width, float height, CollisionFlags flags) : m_position(x, y), m_dimension(width, height), m_flags(flags)
{
}
AABB::~AABB()
{
//dtor
}
bool AABB::isColliding(const AABB& other)const
{
if((other.m_position.x >= m_position.x + m_dimension.x)
|| (other.m_position.x + other.m_dimension.x <= m_position.x)
|| (other.m_position.y >= m_position.y + m_dimension.y)
|| (other.m_position.y + other.m_dimension.y <= m_position.y))
return false;
else
return true;
}
CollisionOrientation AABB::getCollisionOrientation(const AABB& other)const
{
if(other.m_position.x >= m_position.x + m_dimension.x)
return CollisionOrientation::Right;
else if(other.m_position.x + other.m_dimension.x <= m_position.x)
return CollisionOrientation::Left;
else if(other.m_position.y >= m_position.y + m_dimension.y)
return CollisionOrientation::Bottom;
else
return CollisionOrientation::Top;
}